C#
Before I start cramming code, I’ll like to know what you guys think. I’ve been working heavily on my key value store and it has been working as expected, however, the main reason for me building this store does not seem to be completely eliminated with the functionalities that I have in place so far. therefore, I’ll like to add an extra piece to the jigsaw but before I do so I’ll like to hear what you have to say. The storage engine itself is solid and it works with the minimal functionalities that it currently has. As a...
As I stated in my previous posts here and here, I have set out to write my own NoSQL database simply because I can – well not really but because it will give me the edge, learning experience will be great and there isn’t really too many options when it comes to native .NET NoSQL Databases. I want to be able to build web applications without the RDBMS overhead and schema design time. I haven’t done much yet with distributed or replicating side of things yet, so far all I wanted was a prototype to show that it...
In the old days, we have to manually create custom configuration sections if we want to do cool stuff with app/web.config or simply just put the values in the appSettings section. However, there are a few config options that are out there that most developers don’t know about, a perfect example is the mailSettings config section which allows you to setup your mail settings in your configuration file and simply call the SMTPClient to send an email and by doing so, changing settings can be done on the fly and oh’ if you are worried about security, don’t forget you...
Here is a very simple way to resize an image using a bitmap as a canvas and the graphics object as a the resizing tool. Don’t forget to reference System.Drawing. /// <summary>
/// Resizes an image from a source file to a destination file
/// the destination file will contain the exact image at the size specified
/// </summary>
/// <param name="sourceImagePath">the source image file that needs to be resized</param>
/// <param name="destinationImagePath">the destination path that the source
/// image file needs to be resized to</param>
/// <param name="width">the new width</param>
/// <param name="height">the new height</param>
static void ResizeImage(string sourceImagePath,
...
One of the most efficient and non-intrusive ways you can implement an intercepting procedure is via an HttpModule. An HttpModule simply receives every request going to or coming from IIS and it allows you to manipulate the content as you see fit and pass it along. I wanted to spit out the time it takes from receiving a request to writing the response on one or more web pages and there was no other better way of doing it except writing an HttpModule, it toke me all but 10mins. Here is the code, feel free to blow it up. ...
/// <summary>
/// using reflection to create an instance of a generic type
/// </summary>
/// <returns>T as the generic type</returns>
private static T GetNewObject()
{
try
{
return (T)typeof(T).GetConstructor(new Type[] { }).Invoke(new object[] { });
}
catch...
Once you start building applications that run every so often for an undefined/unknown amount of time, its very possible that two processes may overlap. For example, if you have a schedule task that executes a console application every 5 mins, it is possible that very much possible that it will execute another before the previous one completes. So, how do we determine if a process is already running? So far I've seen three ways of doing it. Use the Singleton pattern Use Mutex Use System.Diagnostics (my preffered method) /// <summary>
/// Determines if this process is already running, if so it will kill itself.
/// </summary>
static void ExitIfRunning()
{
...
I've been playing with the DateTime object a lot recently and came across a bunch of weird inaccuracies, therefore, I decided to strip out all the unnecessary text from the Microsoft article and just post the best practices for using the DateTime object. When coding, store the time-zone information associated with a DateTime type in an adjunct variable. When testing, check to see that stored values represent the point-in-time value you intend in the time zone you intend. When coding, be careful if you need to perform DateTime calculations (add/subtract) on values representing time zones that practice daylight savings...
Ok, seriously, this debate must end! I strongly believe that changing a variable to a property is breaking a change! However, others feel otherwise. Update: Yes, this debate is not valid for C# 3.0, however, the question is intended for the earlier versions of C# which is still widely used.private string name;
public string Name
{
get
{
return name;
}
set
{
name=value;
}
}
How many times have you seen a similar snippet just like...
At some point in time, especially when you are doing some serious SEO optimization, you may want to use separate titles, keywords, description and etc. for each page. Thanks, to .NET we can quickly create HtmlMeta controls programmatically and add them to the page header. Here is a quick and dirty snippet. private void SetupPageHeader() { // Page title Page.Title = GetGlobalResourceObject("resource","ApplicationWebTitle").ToString(); // Description meta tag HtmlMeta descMeta = new HtmlMeta(); descMeta.Name = "Description"; descMeta.Content = GetGlobalResourceObject("resource", "MetaDescription").ToString(); Page.Header.Controls.Add(descMeta); // Keywords meta tag HtmlMeta keysMeta = new HtmlMeta(); keysMeta.Name = "keywords"; keysMeta.Content = GetGlobalResourceObject("resource", "MetaKeywords").ToString(); Page.Header.Controls.Add(keysMeta); } ...
Full C# Archive
Next entries »