I need to send like 100 000 mails, so I need my process to be efficient.
We are using MvcMailer because the enables us to use Razor as the template engine.
My problem : the resulting email is in 2 part:
A common part for everyone
A custom part for each recipients
Because there is a custom part I have to create a new mail for everyone. But MvcMailer is running the view engine for every mail, so the common part is rendered 100 000, and that is not acceptable.
My only idea so far :
use the EmailBody method for rendering the common part at the very beginning of my process (in this common part there'll be something like "{USER-CONTENT}")
string commonContent = mailer.EmailBody("Common");
Populate my mail body with only the user content and do
myMail.Body = commonContent.Replace("{USER-CONTENT}",myMail.Body)
But it's still a dirty solution : creating my own template language inside Razor.
Do you have a better idea ?
Related
I'm working with ABBYY cloud OCR, when my popruse is to scan 3 specific places in each document that I'm scanning. These 3 places will always be the same so I want to use the ProcessFields function do it and having some problems with it.
When I want to scan only one specific place I used this :
string url1 = String.Format("http://cloud.ocrsdk.com/processFields?region=0,0,200,200&language=english");
When trying to scan 2 places I've tried this :
string url1 = String.Format("http://cloud.ocrsdk.com/processFields?region=0,0,200,200 region 100,100,100,100&language=english");
it gave me an error.
Anyone has any advise how to do it?
I also tried defieng 3 Uri's but as the upload is done only once - how can I reach the 2 other Uri's without scanning it again?
thanks a lot!
According to documentation of processField method, you can't pass field parameters in URI, you should form an XML and submit it using POST method instead of GET. There is also a sample XML file on that page.
Simple method with URI works only for one field and processTextField method.
I am going to create a function in my application that is going to send som status mails to several receivers in a list.
Earlier i used plane text format on the email, but now i want to send the mail based on som html templates. I need tips reguarding a good way to insert data into these templates before sending them.
eks
%CpuStatus%
%HardriveStatus%
and so on. I have the solution for everything except a way to fill anchors like that with data. This is a WinForm application so i dont have access to the ASP functionality
Maybe this sort of thing would be the simplest?
// This would most likely be loaded from a file or database.
string emailBody = "CPU Status: %CpuStatus%\nHard Drive Status: %HardriveStatus%";
string cpuStatus = MyService.GetCpuStatus();
emailBody.Replace("%CpuStatus%", cpuStatus);
If you really wanted to make a big project out of it, you can use a webbrowser control, load it with your html file and then use the WebBrowser's Document property to get an HtmlDocument object. You can then loop through it's children (recursively) to find the tags you want to change.
Personally, I would do the .Replace method suggested previously.
I'm struggling on logic here - can i get some ideas please! :)
basically i have a c# MVC3 application that accepts a huge amount of text (100+ text areas), modifies it, and then outputs it.
i want to check the length of the combined text boxes and have the process fail validation if they are over X length.
the only solution i can think of is by combining all the text into a string server side and get the length. I'm expecting my competitors to fully abuse the system and attempt to overload my servers when i go live, so i want to try and validate on the client side too if possible.
can anyone think of an efficient way to do this (client or server-side if you have a nice idea).
You could use maxlength css property or you could decorate your model with [StringLength] data annotation to check length of the string
Build a custom validator using a technique similar to this answer by Daron Dimitrov. That will do the check on both client and server side and you can use a ViewModel to decorate the attribute to apply to all of the inputs.
My application sends notification mails to users so I created a html template for each type of notification. I set something like fields in the template as {n} in order to use something like this when I'm sending the message:
string bodyTemplate = GetBodyTemplate(); //gets the html template with {n} in it
message.Body = String.Format(bodyTemplate, fieldZeroValue, fieldOneValue);
For example, the template can have a piece of this:
<td style="vertical-align:middle;padding:0.5em 0.5em 0.5em 0.5em;">
Go to page
</td>
In this example I would use:
message.Body = String.Format(bodyTemplate, IdValue.ToString());
Here is my question: Where should I store those very long string with the html templates?
I don't want to connect to the the database to get them and storing them in string constants looks awful.
Please tell me what is the recomended practice to store those strings.
I create text files and store the templates in the project. If there aren't too many, you could build them into your assembly and get them out of the Resources. If there are a lot, I would point to a directory that contains the files and use a string reader to pick out a filename.
I heard a pearl of wisdom the other day over an argument of using #regions or not. The "pro #regions" guy said, "But I want to hide ugly code" and the "anti #regions" guy said "if it's so ugly, you shouldn't have written it."
It made me laugh to see that you were getting a code smell from ugly constants.
What is the aversion to putting it in the db? is it the cost of having to get it frequently? If that's so, then perhaps cache it and re-pull from the db at a reasonable interval. That way you can maintain the flexibility of being able to add or change templates without having to hit the db every time.
If constants would genuenly work and you're bawlking that they're ugly, then hide them with a #region :)
I have researched on spidering and think that it is a little too complex for quite a simple app I am trying to make. Some data on a web page is not available to view in the source as it is just being displayed by the browser.
If I wanted to get a value from a specific web page that I was to display in a WebBrowser control, is there any method to read values off of the contents of this browser?
If not, does anyone have any suggestions on how they might approach this?
You’re not looking for spidering, you’re looking for screen scraping.
I'd have to agree with Bombe, it sounds more like you want HTML Screen Scraping. It requires lots of parsing, and if the page your scraping ever changes, your app will break, however here's a small example of how to do it:
WebClient webClient = new WebClient();
const string strUrl = "http://www.yahoo.com/";
byte[] reqHTML;
reqHTML = webClient.DownloadData(strUrl);
UTF8Encoding objUTF8 = new UTF8Encoding();
string html = objUTF8.GetString(reqHTML);
Now the html variable has the entire HTML in it, and you can start parsing away.
Because the browser simply renders the underlying content, the most flexible approach would be to parse the underlying content (html/css/js/whatever) yourself.
I would create a parsing engine that looks for the things your spider application needs.
This could be a basic string searching algorithm which looks for href="" for example and reads the values in order to produce new requests and continue spidering. Your engine could be written to only look for things it is interested in and extended in that way for more functionality.