<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Aleem Bawany</title>
	<atom:link href="http://aleembawany.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aleembawany.com</link>
	<description>tech, web and the rest</description>
	<pubDate>Wed, 10 Jun 2009 23:57:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JSON Serializers In .NET</title>
		<link>http://aleembawany.com/2009/05/22/json-serializers-in-net/</link>
		<comments>http://aleembawany.com/2009/05/22/json-serializers-in-net/#comments</comments>
		<pubDate>Fri, 22 May 2009 16:22:59 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Technophilia]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=696</guid>
		<description><![CDATA[<p>I was introduced to the various serialization options in .NET while trying to build the <a href="http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/">JSON and XML</a> filters for ASP.NET MVC. In this post I'll take a look at the different JSON serializers available in .NET and the reasons to pick one over the other.</p>
]]></description>
			<content:encoded><![CDATA[<p>I was introduced to the various serialization options in .NET while trying to build the <a href="http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/">JSON and XML filter for ASP.NET MVC</a>. In this post I&#8217;ll take a look at the different JSON serializers in .NET and the reasons to pick one over the other.</p>
<h2 id="toc-javascriptserializer">JavaScriptSerializer</h2>
<p>The <a title="JavaScriptSerializer" href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx"><code>JavaScriptSerializer</code></a> lives in the <a title="System.Web.Script.Serialization namespace" href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.aspx">System.Web.Script.Serialization</a> namespace and the usage is fairly straight forward for serialization:</p>
<pre class="prettyprint">JavaScriptSerializer serializer = new JavaScriptSerializer();
String json = serializer.Serialize(data);</pre>
<p>For deserialization however, there is a minor annoyance in that the deserializer accepts a generic type along with the content:</p>
<pre class="prettyprint">serializer.Deserialize&lt;T&gt;(String s)</pre>
<p>which can be a problem if the type T is not known at compile time and needs to be dynamic. The work around is a bit ugly as I <a title="Invoke JavaScriptSerializer with Dynamic Type" href="http://stackoverflow.com/questions/856665/how-to-turn-a-type-instance-into-a-generic-type-argument">learnt</a> because it uses reflection to create a generic method but it works:</p>
<pre class="prettyprint">var result = typeof(JavaScriptSerializer).GetMethod("Deserialize")
             .MakeGenericMethod(JsonDataType)
             .Invoke(serializer, new object[] { inputContent });</pre>
<p>The <code>JavaScriptSerializer</code> is excellent for general purpose serialization and deserialization, however, one downside is that it cannot handle circular references.</p>
<p>A useful feature of the <code>JavaScriptSerializer</code> is that you can also implement a custom <a title="JavaScriptConverter custom serialization" href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptconverter.aspx"><code>JavaScriptConverter</code></a> and pass that in to <code>JavaScriptSerializer</code> for fine-grained control over the serialization/deserialization. However, for it to be really useful you need to know the types at compile time and have references to those types. This really limits the usefulness of this feature because by referencing those classes your code becomes tightly coupled so you cannot easily use it in something like an MVC filter.</p>
<p>The <code>JavaScriptSerializer</code> includes all public fields and properties for serialization by default which makes it useful when working with auto-generated classes or if you don&#8217;t have access to the source. This is different from how <code>DataContractJsonSerializer</code> works.</p>
<h2 id="toc-datacontractjsonserializer">DataContractJsonSerializer</h2>
<p>The <a title="DataContractJsonSerializer in .NET" href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx"><code>DataContractJsonSerializer</code></a> lives in the <a title="System.Runtime.Serialization.Json namespace" href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.aspx">System.Runtime.Serialization.Json</a> namespace. Unlike the <code>JavaScriptSerializer</code>, the <code>DataContractJsonSerializer</code> is a contract-based serializer so classes or members need to have the <code><a title="DataContract Attribute for serialization with DataContractSerializer" href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx">[DataContract]</a></code>, <code><a title="DataMember Attribute for serialization with DataContractSerializer" href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx">[DataMember]</a></code> or the <code><a title="Serializable Attribute" href="http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx">[Serializable]</a></code> attribute.</p>
<pre class="prettyprint">[Serializable]
class Person {
    public String Name;
    public Int32 Age;
}

...

String json;
using (var stream = new MemoryStream()) {
    DataContractJsonSerializer serializer =
       new DataContractJsonSerializer(data.GetType());
    serializer.WriteObject(stream, data);
    json = Encoding.UTF8.GetString(stream.ToArray());
}</pre>
<p>And for deserialization:</p>
<pre class="prettyprint">using(var stream = new MemoryStream(Encoding.Unicode.GetBytes(json)) {
    Object data = serializer.ReadObject(stream);
}</pre>
<p>Since <code>DataContractJsonSerializer</code> is contract based and relies on attributes, it is not particularly suitable for auto-generated classes (unless they have these attributes) or when source is not accessible because the relevant attributes <a title="DataMember Attribute at Runtime for DataContractSerializer" href="http://stackoverflow.com/questions/713543/set-datacontracts-datamember-attributes-during-runtime">cannot be added at runtime</a> as far as I know. However, for other situations attributes are an easy way to control the serialization aspects.</p>
<p>The most compelling feature of the <code>DataContractJsonSerializer</code> is that it can handle complex object graphs with circular references. This makes it particularly useful with the <a title="New Features in Entity Framework 4.0" href="http://aleembawany.com/2009/05/17/new-features-in-entity-framework-40-v2/">Entity Framework 4.0</a> which now support T4 templates allowing required <code>[Serializable]</code> or <code>[DataMember]</code> attributes to be added to auto-generated classes.</p>
<h2 id="toc-json-in-mvc">Json in MVC</h2>
<p>The <a title="ASP.NET MVC Json Serializer" href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.json.aspx">System.Web.Mvc</a> namespace contains the <code>Json</code> function intended for use within ASP.NET MVC. There is no real reason to use it outside of ASP.NET MVC when <code>JavaScriptSerializer</code> and <code>DataContractJsonSerializer</code> are available. This function makes it extremely easy to serialize objects to a JSON string. It is not intended for deserialization, however, serialization is just one call:</p>
<pre class="prettyprint">String content = Json(data);</pre>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/05/22/json-serializers-in-net/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New Features in Entity Framework 4.0 (V2)</title>
		<link>http://aleembawany.com/2009/05/17/new-features-in-entity-framework-40-v2/</link>
		<comments>http://aleembawany.com/2009/05/17/new-features-in-entity-framework-40-v2/#comments</comments>
		<pubDate>Sun, 17 May 2009 09:02:35 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Technophilia]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=684</guid>
		<description><![CDATA[<p>Entity Framework 4.0 is just around the corner and it will bring some long awaited relief. I previously wrote and explained the issues around <a title="POCO and Persistence Ignorance in the Entity Framework" href="http://aleembawany.com/2009/04/06/persistence-ignorance-in-adonet-entity-framework/">Persistence Ignorance and POCO</a> as they apply to the Entity Framework. So obviously I'm quite excited about migrating from the interim EFPocoAdapter over to EF 4.0. Let's take a quick look at the new features in Entity Framework 4.0.</p>]]></description>
			<content:encoded><![CDATA[<p>Entity Framework 4.0 is just around the corner and it will bring some long awaited relief. I previously wrote and explained the issues around <a title="POCO and Persistence Ignorance in the Entity Framework" href="http://aleembawany.com/2009/04/06/persistence-ignorance-in-adonet-entity-framework/">Persistence Ignorance and POCO</a> as they apply to the Entity Framework. So obviously I&#8217;m quite excited about migrating from the interim EFPocoAdapter over to EF 4.0. Let&#8217;s take a quick look at the new features in Entity Framework 4.0.</p>
<h2 id="toc-poco-support">POCO Support</h2>
<p>If you are not up to date on POCO, quickly read up on <a title="Entity Framework support for POCO" href="http://aleembawany.com/2009/04/06/persistence-ignorance-in-adonet-entity-framework/">POCO and Persistence Ignorance</a> first. Entity Framework 4.0 has full support for POCO or Plain Old CLR Objects.</p>
<p>If you have a class called Person with name, address and phone number then that&#8217;s how it will stay. It will not have EntityKey or some other such properties. It does not need to implement any interface specific to Entity Framework nor does it need to add any special attributes on properties and methods.</p>
<p>You can pass this plain object around much more cleanly and your domain logic is not polluted with any persistence code. This is also useful for Test Driven Development (TDD)  or migrating out of EF to another framework down the line.</p>
<h2 id="toc-entity-model-designer-improvements">Entity Model Designer Improvements</h2>
<p>Previously you had to design the database schema in SQL Server and then import that into the Entity Designer. With 4.0 you can build the <a title="Entity Framework Model First" href="http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx">model first</a> in the Entity Designer and generate your database and classes from there.  Alternately a lot of DDD (Domain Driven Design) folks prefer to hand code their model classes. Since those classes end up being POCO and EF has full support for POCO, it works out quite well for everyone.</p>
<h2 id="toc-t4-templates">T4 templates</h2>
<p>Currently the Entity Designer generates classes from models by using EntityClassGenerator which provides little to no control over the generated classes. In 4.0 you will have <a title="T4 templates" href="http://msdn.microsoft.com/en-us/library/bb126445.aspx">T4 templates</a> which provide for greater control over the generated classes with <a title="T4 Templates for Entity Framework" href="http://blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx">richer functionality</a> like adding attributes to properties or having the generated classes implement a custom interface.</p>
<p>T4 templates are used not only to generate classes but also to generate tables if you choose to start off by building the models first. For example, by default the mapping is table-per-type which can be overridden through T4 templates to produce a table-per-hierarchy schema. You can also add prefixes to the generated table names and so on.</p>
<h2 id="toc-self-tracking-entities-and-n-tier-applications">Self Tracking Entities and N-Tier applications</h2>
<p>Self tracking entities are a very cool feature of the Entity Framework that allow for N-tier applications. Currently when you have entities on which you wish to track changes, the object context does that for you. However, the object context only exists in the current tier and if you decide to pass that object around to other tiers where the context is not present, you cannot track the entities any more. For example, if you pass the Person object to the UI layer which presents it to the user for modification, those modifications are not being tracked because the object context is not available in the UI tier. N-tier support can now handle this scenario quite elegantly.</p>
<p>One way to do this is to generate <strong>self-tracking entities</strong> as these entities have logic to track changes within. If the UI modifies the Person object&#8217;s address, the Person object will now contain information on how it&#8217;s been modified because it is self-tracking. When you pass the Person object back to the data tier, the object can easily relay what&#8217;s changed and the context can use this to persist the object.</p>
<p>Of course, this means that the object is not POCO any more because it has logic to track changes within itself so there is yet another approach. You can pass the POCO object back to the Entity Framework and attach it to the context which can then do a diff on the object and the original object to determine what&#8217;s changed. This requires more processing obviously.</p>
<h2 id="toc-proxy-tracking">Proxy Tracking</h2>
<p>Besides diff&#8217;ing the POCO entities or using self-tracking entities for change detection, another approach is provided by the Entity Framework 4.0 which is proxy tracking. It provides the benefits of POCO without the performance implications of doing a diff (to check what&#8217;s changed each time the POCO object is re-attached to the context) albiet it cannot be used in an n-tier scenario.</p>
<p>If using proxies to track changes, EF sets up proxy classes to communicate with your POCO classes. These proxy classes inherit from the POCO classes and any property getter/setter calls are still made to the POCO class but through the proxy class. This allows the Entity Framework to stay in sync with entities at all times. You do however need to be a bit careful if you are going to serialize these objects because the resulting output could be a proxy object (though easily remedied by calling something like EFPocoAdapter&#8217;s ProxiesToPoco() equivalent in EF 4.0).</p>
<h2 id="toc-conclusion">Conclusion</h2>
<p>This is going to be a big release for EF to bring it in line with the other major ORMs out there. The MVC community right now favors Linq to SQL but hopefully we&#8217;ll see more ASP.NET MVC + Entity Framework projects coming out.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/05/17/new-features-in-entity-framework-40-v2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Properties vs Fields</title>
		<link>http://aleembawany.com/2009/05/14/properties-vs-fields/</link>
		<comments>http://aleembawany.com/2009/05/14/properties-vs-fields/#comments</comments>
		<pubDate>Thu, 14 May 2009 21:35:53 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Technophilia]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=676</guid>
		<description><![CDATA[<p>There has been a lot of discussion around this topic and I only recently caught up and found some interesting gems from a variety of locations. Jon Skeet's article <a href="http://csharpindepth.com/Articles/Chapter8/PropertiesMatter.aspx">Why Properties Matter</a> is a good starting point. Robert Paulson also has a <a href="http://stackoverflow.com/questions/205568/have-trivial-properties-ever-saved-your-bacon/207146#207146">comprehensive list</a> of pros. Summary of the pros and cons follows.</p>
]]></description>
			<content:encoded><![CDATA[<p>There has been a lot of discussion around this topic and I only recently caught up and found some interesting gems from a variety of locations. Jon Skeet&#8217;s article <a href="http://csharpindepth.com/Articles/Chapter8/PropertiesMatter.aspx">Why Properties Matter</a> is a good starting point. Robert Paulson also has a <a href="http://stackoverflow.com/questions/205568/have-trivial-properties-ever-saved-your-bacon/207146#207146">comprehensive list</a> of pros. To summarize the pros and cons:</p>
<ol>
<li>Properties allow access modifiers on getters and setters
<pre class="prettyprint">
public string Name { get; private set; }</pre>
<p>which makes the property read only publicly but read/write privately.</li>
<li>Properties can be virtual. Fields cannot be overwritten.</li>
<li>Properties can be declared in an interface. Fields cannot.</li>
<li>Properties provide fine-grained control such as data validation or simultaneously logging to a file.</li>
<li>.NET (by design) uses properties for data-binding making them necessary.</li>
<li>Changing a field to a property (or vice-versa) breaks binary compatibility, thus it&#8217;s a <a href="http://blogs.msdn.com/abhinaba/archive/2006/04/11/572694.aspx">breaking change</a> (requires recompilation). It may be desirable to use properties for future extensibility instead of thinking YAGNI.</li>
<li>Moving from fields to properties breaks source compatibility. For example, if you are using reflection on any of the fields which have since been changed to properties, then the code for reflection will need to be updated (PropertyInfo vs FieldInfo). Similarly, serialization will also break.</li>
<li>Since properties can contain some additional logic, they can throw arbitrary exceptions. Fields cannot.</li>
<li>Break points can be set on properties making them easier to debug. They can&#8217;t be set on fields.</li>
<li>Fields can be used for <code>ref</code> or <code>out</code> arguments but properties can&#8217;t.</li>
<li>Properties can do lazy loading
<pre class="prettyprint">
public string Name {
    get {
        if (this._name = null) LoadName();
        return this._name;
    }
}
</pre>
</li>
</ol>
<p>These reasons should be good enough to persuade you to use properties instead of fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/05/14/properties-vs-fields/feed/</wfw:commentRss>
		</item>
		<item>
		<title>YUI Compressor for NAnt</title>
		<link>http://aleembawany.com/2009/04/08/yui-compressor/</link>
		<comments>http://aleembawany.com/2009/04/08/yui-compressor/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 01:38:39 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Technophilia]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=654</guid>
		<description><![CDATA[I had my first go with <a href="http://nant.sourceforge.net/">NAnt</a> just a few hours ago and it was so easy, I am already porting my batch scripts over and creating build scripts with a few good examples off the web as my starting point.]]></description>
			<content:encoded><![CDATA[<p>I had my first go with <a href="http://nant.sourceforge.net/">NAnt</a> just a few hours ago and it was so easy, I am already porting my batch scripts over and creating build scripts with a few good examples off the web as my starting point.</p>
<p>I came across the <a href="http://ra-ajax.org/custom-nant-jsmin-task-for-minifying-javascript-files.blog">JSMin</a> task for NAnt which was pretty good but not as good as YUI Compressor. I came across a .NET C# port of the JAVA based YUI Compressor and also found a <a href="http://code.google.com/p/devfuelnet/source/browse/trunk/DevFuel.NAnt.Tasks/YuiCompressorTask.cs">custom task</a> for it but no DLL. I threw the two together with the latest <a href="http://yuicompressor.codeplex.com/">.NET port of YUI Compressor</a> and put it up on my projects for download under <a href="http://aleembawany.com/projects/nant/yui-compressor/">NAnt task for YUI Compressor</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/04/08/yui-compressor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Persistence Ignorance in ADO.NET Entity Framework</title>
		<link>http://aleembawany.com/2009/04/06/persistence-ignorance-in-adonet-entity-framework/</link>
		<comments>http://aleembawany.com/2009/04/06/persistence-ignorance-in-adonet-entity-framework/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 12:25:40 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Technophilia]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=625</guid>
		<description><![CDATA[Serializing objects within the Entity Framework is a common enough scenario that I expected to work around it farily easily. Because as it turned out, the serialized objects only contained some additional undesirable key/value pairs that I did not expect. This is when I first got introduced to Persistence Ignorance.]]></description>
			<content:encoded><![CDATA[<div class="toc">
<ol>
<li><a href="#toc-persistence-ignorance">Persistence Ignorance</a></li>
<li><a href="#toc-single-responsibility-principle">Single Responsibility Principle</a></li>
<li><a href="#toc-domain-driven-design">Domain Driven Design</a></li>
<li><a href="#toc-an-interim-solution">An Interim Solution</a></li>
</ol>
</div>
<p>I previously published a <a href="http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/">JSON / POX Filter</a> for MVC developers working with RESTful services. It works really well in that it allows a Controller Action to speak two additional languages (JSON and XML) other than View rendition without requiring any extra modifications. Everything was fine until I pulled out Linq to SQL and plugged in Entity Framework and got an education on a variety of issues with the framework.</p>
<h2 id="toc-persistence-ignorance">Persistence Ignorance</h2>
<p>Serializing objects within the Entity Framework is a common enough scenario that I expected to work around it farily easily. More so because the serialized objects only contained some additional undesirable key/value pairs that I did not expect. This is when I first got introduced to Persistence Ignorance.</p>
<p>In the Entity Framework an object generated from the Persons table for example contains not only the properties and relationships of that table (such as Age and Name) but also has additional properties used for tracking changes to the object (such as EntityState). In my scenario, serializing the entity object ought to have resulted in a plain object representation (JSON format shown):</p>
<pre class="prettyprint">// Plain Old CLR Object
{"Id":1, "Name":"John"}</pre>
<p>But instead I saw this:</p>
<pre class="prettyprint">// Entity Object
{"Id":1, "Name":"John",
 "EntityState":2, "EntityKey": {"EntitySetName":"Persons",
    "EntityContainerName":"PersonEntities","EntityKeyValues":
     [{"Key":"Id","Value":1}],"IsTemporary":false}}</pre>
<p>In laymen&#8217;s terms Persistence Ignorance is a design principle which suggests that the underlying object hide the details of how it is persisted so you can ignore it and work with a simple object. The term &#8220;ignorance&#8221; suggests that this behaviour be <em>encapsulated</em> which is a tenet of Object Oriented design.</p>
<h2 id="toc-single-responsibility-principle">Single Responsibility Principle</h2>
<p>Instead, the Entity Object has additional properties used by the Entity Framework for managing data persistence. An object that plainly represents the Person table and does not contain any additional service-level properties and functions is called a Plain Old CLR Object or POCO. The Entity Object violates the Single Responsibility Principle because other than representing a Person it takes on the additional responsibility of managing data persistence.</p>
<p>Albeit, this makes it very convenient for the Entity Framework to persist the object in the database if, for example, you make modifications to the Person object and save it back to the database. Because the state information is stored within the object itself, the Entity Framework easily knows if the object has changed (by looking at the EntityState property) and what changes were made. It can then update the appropriate fields in the database. Even though this makes things easy for the Entity Framework, it is clearly a big second responsibility tacked on to what should be a plain old Person object. Besides, developers need not be confused by nor concerned with lower level implementation details of state and persistence. Consequently, the Entity Framework recognizes and intends to fix this in Version 2 which will support POCO and Persistence Ignorance.</p>
<h2 id="toc-domain-driven-design">Domain Driven Design</h2>
<p>Lack of POCO objects means that developers are left dealing with an Entity Object and while for me this started off with a naive problem of serializing a Person object, the actual issue has further implications. My over simplified understanding of Domain Driven Design is that domain objects should be Plain Old CLR Objects and should encapsulate only domain logic. So for example, if you are building a warehousing application, the objects used to represent the warehouse domain should only encapsulate functionality within the warehouse (such as orders, storage and delivery). Anything more in the objects (such as database persistence) and the application breaks the Domain Driven Design model. It gets much harder to manage or extend, and Separation of Concerns is lost. For further discussion Ian Cooper&#8217;s article on <a href="http://codebetter.com/blogs/ian_cooper/archive/2008/06/26/the-criticism-of-the-entity-framework-is-not-just-around-domain-driven-design.aspx">Entity Framework and Domain Drive Design</a> provides an interesting and insightful background on this issue.</p>
<h2 id="toc-an-interim-solution">An Interim Solution</h2>
<p>The <a href="http://code.msdn.microsoft.com/EFPocoAdapter">EFPocoAdapater</a> is just what the name suggests &#8212; a POCO adapter for the Entity Framework which solves the issues outlined above. The EFPocoAdapter currently serves as a sort of staging platform for supporting these scenarios until they become available in version 2 of the Entity Framework, at which time EFPocoAdapter will be made obsolete.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/04/06/persistence-ignorance-in-adonet-entity-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Kodak Turns on its Online Users</title>
		<link>http://aleembawany.com/2009/03/31/kodak-turns-on-its-online-users/</link>
		<comments>http://aleembawany.com/2009/03/31/kodak-turns-on-its-online-users/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:35:07 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Finance]]></category>

		<category><![CDATA[Technophilia]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=603</guid>
		<description><![CDATA[Eastman Kodak Company (<a title="Kodak Stock" href="http://www.google.com/finance?client=ob&#38;q=NYSE:EK">NYSE:EK</a>) which lost nearly $1 billion for the quarter ended Dec '08 and has seen it's stock plummet over 75% in the past year, recently sent an email telling its customers that if you have been hosting pictures with Kodak Gallery, you are now  going to have to pay up to retain those pictures or lose them (hope you made backups). Following is the recent email from Kodak.]]></description>
			<content:encoded><![CDATA[<p>Eastman Kodak Company (<a title="Kodak Stock" href="http://www.google.com/finance?client=ob&amp;q=NYSE:EK">NYSE:EK</a>) which lost nearly $1 billion for the quarter ended Dec &#8216;08 and has seen it&#8217;s stock plummet over 75% in the past year, recently sent an email telling its customers that if you have been hosting pictures with Kodak Gallery, you are now  going to have to pay up to retain those pictures or lose them (hope you made backups). This is the recent email from Kodak:</p>
<blockquote><p>We wanted to make you aware that we have modified our Terms of Service: To more effectively serve our Gallery members, we have adjusted our photo-storage policy to align with storage usage.</p>
<p>How this affects you.</p>
<p>Once you begin storing photos at the Gallery, you must make the following purchases to continue such storage:</p>
<p>- Members with photo storage of 2 gigabytes (GB) or less must make annual minimum purchases totaling at least $4.99.</p>
<p>- Members with photo storage exceeding 2GB must make annual minimum purchases totaling at least $19.99.</p>
<p>Failure to meet this requirement may result in your photos being deleted from the Gallery.</p>
</blockquote>
<p>The recession has hit Kodak (<a href="http://www.google.com/finance?client=ob&amp;q=NYSE:EK" target="_blank">NYSE:EK</a>) quite hard as is clearly apparent from their stock price for the prior 12 months.</p>
<p><a href="http://aleembawany.com/wordpress/wp-content/uploads/2009/03/kodak-stock-price.jpg"><img class="alignnone size-full wp-image-604" title="kodak-stock-price" src="http://aleembawany.com/wordpress/wp-content/uploads/2009/03/kodak-stock-price.jpg" alt="kodak-stock-price" width="580" height="254" /></a></p>
<p>My sympathies to their shareholders, employees and customers alike but unless this is a last ditch effort, I am not sure what they aim to achieve with this move. Those Kodak Gallery users that stay on will do so only because they are coerced into it&#8211;pay up or lose the pictures. Those that have backups will probably ditch Kodak with a bad taste in their mouth and unlikely to return. I am not sure how much money they intend to salvage from this move, but it seems like a downward spiral for Kodak. Must be really desperate times.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/03/31/kodak-turns-on-its-online-users/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET MVC - Create easy REST API with JSON and XML</title>
		<link>http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/</link>
		<comments>http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 18:03:34 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=533</guid>
		<description><![CDATA[So I just hopped on the <a href="http://www.asp.net/mvc/" title="ASP.NET MVC Framework">ASP.NET MVC</a> bandwagon. As my first task, I undertook custom Action Filters for returning either JSON or XML as determined by the HTTP Request. Fortunately Omar AL Zabir did most of the work for creating a <a href="http://weblogs.asp.net/omarzabir/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx" title="MVC.NET JSON and XML Output">RESTful API</a> with ASP.NET MVC. The following is a filter which makes the whole thing much cleaner.]]></description>
			<content:encoded><![CDATA[<div class="toc">
<ol>
<li><a href="#toc-json-and-xml-action-filter-code">JSON and XML Action Filter Code</a></li>
<li><a href="#toc-usage-example">Usage Example</a></li>
<li><a href="#toc-sample-output">Sample Output</a></li>
</ol>
</div>
<p>So I just hopped on the <a href="http://www.asp.net/mvc/" title="ASP.NET MVC Framework">ASP.NET MVC</a> bandwagon. As my first task, I undertook custom Action Filters for returning either JSON or XML as determined by the HTTP Request. Fortunately Omar AL Zabir did most of the work for creating a <a href="http://weblogs.asp.net/omarzabir/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx" title="MVC.NET JSON and XML Output">RESTful API</a> with ASP.NET MVC.</p>
<h2 id="toc-json-and-xml-action-filter-code">JSON and XML Action Filter Code</h2>
<p>The following is a filter which makes the whole thing much cleaner. The filter looks for <code>Content-Type</code> headers in the HTTP request. If it matches <code>text/xml</code> then Plain Old XML (POX) is returned and if it matches <code>application/json</code> the output is JSON. This eliminates the need to write separate actions for JSON/XML and Views.</p>
<pre class="prettyprint">
using System;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Xml;
using System.Text;
using System.Xml.Serialization;
namespace AleemBawany.ActionFilters
{
  public class JsonPox : ActionFilterAttribute
  {
    private static UTF8Encoding UTF8 = new UTF8Encoding(false);
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
      // setup the request, view and data
      HttpRequestBase request = filterContext.RequestContext.HttpContext.Request;
      ViewResult view = (ViewResult)(filterContext.Result);
      var data = view.ViewData.Model;
      String contentType = request.ContentType ?? string.Empty;
      // JSON
      if (contentType.Contains("application/json"))
      {
        filterContext.Result = new JsonResult
        {
          Data = data
        };
      }
      // POX
      else if (contentType.Contains("text/xml"))
      {
        // MemoryStream to encapsulate as UTF-8 (default UTF-16)
        // http://stackoverflow.com/questions/427725/
        using (MemoryStream stream = new MemoryStream(500))
        {
          using (var xmlWriter =
            XmlTextWriter.Create(stream,
              new XmlWriterSettings()
              {
                // Plain Old XML (no XML headers)
                OmitXmlDeclaration = true,
                Encoding = UTF8,
                Indent = true
              }))
          {
            new XmlSerializer(data.GetType()).Serialize(xmlWriter, data);
          }
          filterContext.Result = new ContentResult
          {
            ContentType = "text/xml",
            Content = UTF8.GetString(stream.ToArray()),
            ContentEncoding = UTF8
          };
        }
      }
    }
  }
}
</pre>
<p>I suggest you get the code directly through <a href="http://aleemb.svn.beanstalkapp.com/code/asp-net-mvc/JsonPoxFilter.cs">JsonPoxFilter.cs</a> in my SVN repository. It will be updated if I make any improvements.</p>
<h2 id="toc-usage-example">Usage Example</h2>
<p>To use this code in your Controller Action, you simply need to decorate it with the <code>[JsonPox]</code> attribute:</p>
<pre class="prettyprint">
// Depending on HTTP Content-Type header
// this returns JSON, XML or the default View

[JsonPox]
public ActionResult Index()
{
        ArrayList stuff = new ArrayList();
        stuff.Add("Hello World");
        stuff.Add(999);
        stuff.Add(1.0001);
        ViewData.Model = stuff;
        return View();
}
</pre>
<h2 id="toc-sample-output">Sample Output</h2>
<p>If <code>Content-Type: text/xml</code> HTTP header is present the output is:</p>
<pre class="prettyprint">
&lt;ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;anyType xsi:type="xsd:string"&gt;Hello World&lt;/anyType&gt;
  &lt;anyType xsi:type="xsd:int"&gt;999&lt;/anyType&gt;
  &lt;anyType xsi:type="xsd:double"&gt;1.0001&lt;/anyType&gt;
&lt;/ArrayOfAnyType&gt;
</pre>
<p>For the HTTP header <code>Content-Type: application/json</code> the output is:</p>
<pre class="prettyprint">
["Hello World",999,1.0001]
</pre>
<p>And if neither of those headers are present, the default View is returned.</p>
<p>Once again, if you intend to use it, get the latest bits for <a href="http://aleemb.svn.beanstalkapp.com/code/asp-net-mvc/JsonPoxFilter.cs">JsonPoxFilter.cs here</a> instead of copying the above code.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MediaCatch Hosting Review</title>
		<link>http://aleembawany.com/2009/03/15/mediacatch-hosting-review/</link>
		<comments>http://aleembawany.com/2009/03/15/mediacatch-hosting-review/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 17:11:32 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=530</guid>
		<description><![CDATA[The web hosting services at <a href="http://mediacatch.com/">MediaCatch</a> have gone AWOL on me which has resulted in some downtime for this site and numerous other sites I own. During my 4 years of hosting with MediaCatch, I have suffered about 5 failures (that I can find records for) during which I have had to roll back my data from personal backups. There have been other occasions when I have had to suffer down times of over a day because they were moving data centres or some such stuff. But I stuck it out with them--mostly because I was lazy to switch and the problems happened far apart so it didn't seem like a constant annoyance. Their recent behaviour, however, takes the cake.]]></description>
			<content:encoded><![CDATA[<p>The web hosting services at <a href="http://mediacatch.com/">MediaCatch</a> have gone AWOL on me which has resulted in some downtime for this site and numerous other sites I own. During my 4 years of hosting with MediaCatch, I have suffered about 5 failures (that I can find records for) during which I have had to roll back my data from personal backups. There have been other occasions when I have had to suffer down times of over a day because they were moving data centres or some such stuff. But I stuck it out with them&#8211;mostly because I was lazy to switch and the problems happened far apart so it didn&#8217;t seem like a constant annoyance. Their recent behaviour, however, takes the cake.</p>
<p>Recently, I wanted to downgrade my account from a reseller to a shared hosting plan because I no longer resell hosting. After 3 chat sessions which all resulted in tickets being opened, another 3 tickets being opened by me personally and a call to their 1-800 number (which was not received so I had to leave a message), I was forced to switch.</p>
<p>It&#8217;s annoying enough that they don&#8217;t care about my domains or my requests but not caring to response is downright horrendous. Maybe it&#8217;s because my request is for a downgrade to a cheaper plan which doesn&#8217;t bode well or maybe they are going through their bi-annual internal reorientation.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/03/15/mediacatch-hosting-review/feed/</wfw:commentRss>
		</item>
		<item>
		<title>tagName vs nodeName</title>
		<link>http://aleembawany.com/2009/02/11/tagname-vs-nodename/</link>
		<comments>http://aleembawany.com/2009/02/11/tagname-vs-nodename/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:35:44 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=524</guid>
		<description><![CDATA[<code>tagName</code> and <code>nodeName</code> are both useful Javascript properties for checking the name of an html element. For most purposes, either will do fine but <code>nodeName</code> is preferred if you are supporting only A grade browsers and <code>tagName</code> is preferred if you intend to support IE5.5 as well.]]></description>
			<content:encoded><![CDATA[<p><code>tagName</code> and <code>nodeName</code> are both useful Javascript properties for checking the name of an html element. For most purposes, either will do fine but <code>nodeName</code> is preferred if you are supporting only A-grade browsers and <code>tagName</code> is preferred if you intend to support IE5.5 as well.</p>
<p>There are two issues with <code>tagName</code>:</p>
<ul>
<li>In all versions of IE, <code>tagName</code> returns <code>!</code> when called on a comment node</li>
<li>For text nodes, <code>tagName</code> returns <code>undefined</code> where as nodeName returns <code>#text</code></li>
</ul>
<p><code>nodeName</code> has it&#8217;s own set of <a href="http://www.quirksmode.org/dom/w3c_core.html#t20" title="nodeName property browser support chart">issues</a> but they are less severe:</p>
<ul>
<li>IE 5.5 returns <code>!</code> when called on a comment node. This is less harmful than <code>tagName</code> which suffers from this behaviour across <em>all</em> versions of IE</li>
<li>IE 5.5 doesn&#8217;t support <tag>nodeName</tag> for the <code>document</code> element or for attributes. Neither of these should be a concern for most practical purposes but should be kept in mind in any case</li>
<li>Konqueror ignores comment nodes when using this property. But then again, Konqueror, along with IE 5.5 is not an <a href="http://developer.yahoo.com/yui/articles/gbs/">A-grade browser</a></li>
</ul>
<p>So for most practical purposes stick to nodeName due to its support for a wider range of scenarios and potentially better forward compatibility. Not to mention that it doesn&#8217;t hiccup on a comment node, which has a tendency to creep into code unannounced. Don&#8217;t worry about IE 5.5 or Konqueror as their market share is near 0%.</p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/02/11/tagname-vs-nodename/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# Shell / Interpreter for testing code snippets</title>
		<link>http://aleembawany.com/2009/02/05/c-shell-interpreter-for-testing-code-snippets/</link>
		<comments>http://aleembawany.com/2009/02/05/c-shell-interpreter-for-testing-code-snippets/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 23:58:25 +0000</pubDate>
		<dc:creator>Aleem</dc:creator>
		
		<category><![CDATA[Technophilia]]></category>

		<guid isPermaLink="false">http://aleembawany.com/?p=509</guid>
		<description><![CDATA[Not a shell exactly but close enough (since C# is not a script language). <a href="http://www.codeplex.com/snippy">Snippy</a> is must-have for any C# developer wanting to quickly test out code. This screen shot explains it.]]></description>
			<content:encoded><![CDATA[<p>Well, not quite a shell but close enough (since C# is not a scripted language). <a href="http://www.codeplex.com/snippy">Snippy</a> is must-have for any C# developer wanting to quickly test out code.</p>
<p><img src="http://aleembawany.com/wp-content/uploads/2009/02/snippy.jpg" alt="C# Snippy Screenshot" title="snippy" width="534" height="469" class="size-full wp-image-510" /></p>
]]></content:encoded>
			<wfw:commentRss>http://aleembawany.com/2009/02/05/c-shell-interpreter-for-testing-code-snippets/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->