2012-04-28

Note to self: DropCreateDatabaseIfModelChanges during development

While developing using Entity Framework, code first, I should add the following to Global.asax:

protected void Application_Start()
{
    #if DEBUG
    Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DbCtx>());
    #endif
}
That way, given that that the models have changed, when I am running the application in debug mode, the database will be dropped and recreated.

2012-03-07

Reflections from taking the EPiServer (CMS 6) Certified Developer exam

I passed the exam earlier today and thought I should share some reflections. The test wasn't really that difficult but it was very broad. On top of actual questions regarding programming it ranged from the product as such (almost bordering on sales talk at times) to configuring and licensing.

2012-02-21

Programmatically adding options to EPi CMS 6 R2 drop-down list property when using PageTypeBuilder 2.0

Since EPi CMS had property types with custom settings added I have found the drop-down list (EPiServer.SpecializedProperties.PropertyDropDownList) especially useful for allowing an editor to choose from a few different teaser content block appearances when creating teaser page types. The out-of-the-box approach is for an CmsAdmin or developer to manually add key-value pair type options in the CMS admin mode for the property but when using PageTypeBuilder there is a nice way of adding settings programmatically:

2011-09-05

Extensions...

Here's a little extension on Object in C#

public static bool EqualsAny<T>(this T obj, params T[] compareTo)
{
  for (int i = compareTo.Length - 1; i >= 0; --i)
  {
    if (obj.Equals(compareTo[i]))
    {
      return true;
    }
  }

  return false;
}
If the original code would have looked something like this before:
int nowHour = DateTime.Now.Hour;

if (nowHour.Equals(10) ||
    nowHour.Equals(12) ||
    nowHour.Equals(15) ||
    nowHour.Equals(17) ||
    nowHour.Equals(19) ||
    nowHour.Equals(23))
{
  //Happy hour!
}
the after code would look like this:
if (DateTime.Now.Hour.EqualsAny(10, 12, 15, 17, 19, 23))
{
  //Happy hour!
}

2011-09-04

Lazy mans guide to code syntax highlighting on Blogger

Having just moved some old blog entries to a brand new blogger.com blog from Wordpress I was looking for an easy way to publish highlighted code in my posts.

There are several different tools freely available such as SyntaxHighlighter, highlight.js and Prettify which I decided on using.

2011-03-15

Using the Stopwatch class in C#

During the development of any kind of C# application you might find you need to measure how long some part of your code take to execute. Perhaps your customer demand an operation to finish in a maximum amount of time or you might be puzzled what part of a function is making it run slower than expected.

2011-03-09

XOR enciphering data for medium security

Sometimes when developing systems that involve sending or storing semi-sensitive data as a string there might not be an easy option or enough time to implement conventional encryption even though there might be some need to hide the contents of the data in some way. Such situations may include where you want to send scrambled messages between servers on the interwebs, store data in places where others may have access to it (on shared environments with nosy admins etc) or where you want to be able to easily unscramble data in something like javascript or some other language that lack libraries for conventional encryption.