<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>debug &gt; release &gt;</title>
	
	<link>http://www.debugrelease.com</link>
	<description>Programming notes of Deepak Kapoor</description>
	<lastBuildDate>Fri, 24 May 2013 02:38:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<feedburner:info uri="take37" /><feedburner:emailServiceId>take37</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ThereforeSystems" /><feedburner:info uri="thereforesystems" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>ThereforeSystems</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>.NET Framework – Serialize and Deserialize</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/hchPdJq9-w4/</link>
		<comments>http://www.debugrelease.com/2013/05/24/net-framework-serialize-and-deserialize-c-sharp/#comments</comments>
		<pubDate>Fri, 24 May 2013 01:54:21 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.debugrelease.com/?p=1957</guid>
		<description><![CDATA[This article is about serialization and deserialization in Microsoft .NET Framework. At the time of writing this article I am using .NET Framework 4.5. The concepts I talk about here &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/05/24/net-framework-serialize-and-deserialize-c-sharp/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>This article is about serialization and deserialization in Microsoft .NET Framework. At the time of writing this article I am using .NET Framework 4.5. The concepts I talk about here also apply to all earlier versions.</p>
<p>Motivation to write this article came from a colleague on one of the projects I am busy with these days. I am mentoring a couple of developers who have joined the project straight out of university. They are here to learn the ropes of Microsoft .NET centric software development. Yesterday during a design discussion we talked about serialization of objects in our system. They are well familiar with the concepts of serialization, I showed them how it is done in .NET world.</p>
<p>Serialization is a technique we use to convert the state of an object to a format which can be persisted for later retrieval. Last sentence perhaps sounded very bookish. Let&#8217;s try some plain English and understand the concept using an example. We will use an example which involves pizza.</p>
<p>We will write a class to represent a Pizza. The class has a property Slices to hold the number of slices. When pizza object is initialized, the number of slices are set to 8. Pizza class also has methods for eating a slice, saving the pizza for later consumption and a method to get leftover pizza. Here are the stubs for properties and methods.</p>
<p></p><pre class="crayon-plain-tag">public int Slices
public bool IsThereAnyPizzaLeftForMe

public void EatSlice()
public void SaveForLater()
public static Pizza GetLeftOverPizza()</pre><p> </p>
<p>We will now fill in the stubs for SaveForLater() and GetLeftOverPizza(). This is where we will serialize and deserialize our pizza object.</p>
<p></p><pre class="crayon-plain-tag">public void SaveForLater()
{
	XmlSerializer serializer = new XmlSerializer(typeof(Pizza));

	using (StreamWriter writer = new StreamWriter(@"c:\temp\pizza.xml"))
	{
		serializer.Serialize(writer,this);
	}
}</pre><p> </p>
<p>In the code above we are saying that serialize the pizza object to XML file. XmlSerializer comes with .NET framework and can be found in System.Xml.Serialization namespace. Objects can also be serialized to binary format. We can look at that some other day. For now let&#8217;s go with XML.</p>
<p>Here is the code from a console application which creates an instance of Pizza class, eats a slice and calls SaveForLater() to serialize the object state to XML.</p>
<p></p><pre class="crayon-plain-tag">static void Main(string[] args)
{
	Pizza pizza = new Pizza();
	Console.WriteLine("{0} slices left in the pizza", pizza.Slices);
	
	pizza.EatSlice();
	Console.WriteLine("{0} slices left in the pizza", pizza.Slices);

	pizza.SaveForLater();
}</pre><p> </p>
<p>Let&#8217;s look at the XML to which our pizza object was serialized. </p>
<p></p><pre class="crayon-plain-tag">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;Pizza xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;Slices&gt;7&lt;/Slices&gt;
&lt;/Pizza&gt;</pre><p> </p>
<p>Note that it only saves Slices property. There is no need to save/serialize the IsThereAnyPizzaLeftForMe property because it&#8217;s value can be determined by checking if Slices is equal to zero. XmlSerializer is smart enough to know which data is absolutely required to deserialize an object. Also methods are behaviors which act upon data so there is no need to retain them.</p>
<p>GetLefOverPizza() method creates an instance of Pizza object from XML. To be technically correct, it deserializes a pizza object from XML.</p>
<p></p><pre class="crayon-plain-tag">public static Pizza GetLeftOverPizza()
{
	Pizza pizza = null;
	XmlSerializer serializer = new XmlSerializer(typeof(Pizza));

	using (FileStream fileStream = new FileStream(@"c:\temp\pizza.xml", FileMode.Open))
	{
	pizza = (Pizza)serializer.Deserialize(fileStream);
	}

	return pizza;
}</pre><p> </p>
<p>Another console application shows retrieving a left over pizza, eating a slice and then again saving it for later.</p>
<p></p><pre class="crayon-plain-tag">static void Main(string[] args)
{
	Pizza pizza = Pizza.GetLeftOverPizza();
	Console.WriteLine("{0} slices left in the pizza", pizza.Slices);

	pizza.EatSlice();
	Console.WriteLine("{0} slices left in the pizza", pizza.Slices);

	pizza.SaveForLater();
	
}</pre><p> </p>
<p>So there you have it. A simple example which shows how to serialize and deserialize an object in .NET Framework.</p>
<img src="http://feeds.feedburner.com/~r/take37/~4/DGIn8oGB2Vw" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/hchPdJq9-w4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/05/24/net-framework-serialize-and-deserialize-c-sharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/05/24/net-framework-serialize-and-deserialize-c-sharp/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/DGIn8oGB2Vw/</feedburner:origLink></item>
		<item>
		<title>My Windows Phone app is runner-up in Lifehacker and Microsoft’s developer challenge</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/1xEQmaheLjQ/</link>
		<comments>http://www.debugrelease.com/2013/05/20/my-windows-phone-app-is-runner-up-in-lifehacker-and-microsofts-developer-challenge/#comments</comments>
		<pubDate>Mon, 20 May 2013 10:43:38 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://www.take37.com/?p=1938</guid>
		<description><![CDATA[Found an uplifting email today in my mailbox which informed me that my app for Windows Phone has been a runner-up in round 5 of Lifehacker and Microsoft’s developer challenge. &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/05/20/my-windows-phone-app-is-runner-up-in-lifehacker-and-microsofts-developer-challenge/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>Found an uplifting email today in my mailbox which informed me that my app for Windows Phone has been a runner-up in <a href="http://www.lifehacker.com.au/2013/05/round-5-winners-lifehacker-and-microsofts-developer-challenge/">round 5 of Lifehacker and Microsoft’s developer challenge</a>. I am very happy about this and I&#8217;d like to thank those who judged my app to be worthy of recognition.&nbsp; I would also like to congratulate <a href="http://apps.microsoft.com/windows/en-ph/app/fair-football-coach/13eaa6b2-f12d-433a-8d50-5f5385c5ea99">Jared Homes</a> who won round 5 and <a href="https://twitter.com/almichener">Alistair Michener</a> who is also a runner-up for his awesome app <a href="http://apps.microsoft.com/windows/en-US/app/drawboard-pdf/6d65bcd8-8390-4533-af58-307d2e1ec1dd">Drawboard PDF</a>.</p>
<p>Thanks also to <a href="http://blogs.msdn.com/b/acoat/">Andrew Coates</a> and <a href="http://blogs.msdn.com/b/dglover/">Dave Glover</a> for their support and feedback.</p>
<p>Link to my app: <a href="http://www.windowsphone.com/en-au/store/app/visuals/f5fae584-ed47-4e26-a606-cd424767b632?appid=f5fae584-ed47-4e26-a606-cd424767b632">Visuals</a></p>
<img src="http://feeds.feedburner.com/~r/take37/~4/i3EA18w0zdU" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/1xEQmaheLjQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/05/20/my-windows-phone-app-is-runner-up-in-lifehacker-and-microsofts-developer-challenge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/05/20/my-windows-phone-app-is-runner-up-in-lifehacker-and-microsofts-developer-challenge/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/i3EA18w0zdU/</feedburner:origLink></item>
		<item>
		<title>Disable StyleCop settings for a project</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/F5EVfRWLia4/</link>
		<comments>http://www.debugrelease.com/2013/05/03/disable-stylecop-settings-for-a-project/#comments</comments>
		<pubDate>Fri, 03 May 2013 00:27:57 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.take37.com/?p=1908</guid>
		<description><![CDATA[Tools like StyleCop have their place in the world and I have nothing against using them to produce consistently formatted code. It kinda makes the person higher up in the &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/05/03/disable-stylecop-settings-for-a-project/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>Tools like <a href="http://www.debugrelease.com/stylecop-tutorial/">StyleCop</a> have their place in the world and I have nothing against using them to produce consistently formatted code. It kinda makes the person higher up in the food chain brag to those higher above him about the quality of code being produced. However when I write code to try out things , I want the bloody thing to just go away and stop irritating me with you are missing a file header, using statements must be within namespace declaration etc.</p>
<p>It turns out that all the rules can be disabled easily by right clicking the project &#8211;&gt; StyleCop Settings. Then in the Rules tab by unchecking Enabled rules.</p>
<p><a href="http://www.debugrelease.com/wp-content/uploads/2013/05/stylecopsettings.png"><img class="alignnone size-full wp-image-1909" alt="stylecopsettings" src="http://www.debugrelease.com/wp-content/uploads/2013/05/stylecopsettings.png" width="579" height="478" /></a></p>
<img src="http://feeds.feedburner.com/~r/take37/~4/aurpMN1P628" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/F5EVfRWLia4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/05/03/disable-stylecop-settings-for-a-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/05/03/disable-stylecop-settings-for-a-project/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/aurpMN1P628/</feedburner:origLink></item>
		<item>
		<title>Nuget packages and source control</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/88bUQJZe4QE/</link>
		<comments>http://www.debugrelease.com/2013/04/11/nuget-packages-and-source-control/#comments</comments>
		<pubDate>Thu, 11 Apr 2013 06:01:38 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.take37.com/?p=1805</guid>
		<description><![CDATA[I use NuGet packages all the time for most of my projects. I ran into an issue on a project I am working on with another developer. We are using &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/04/11/nuget-packages-and-source-control/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>I use NuGet packages all the time for most of my projects. I ran into an issue on a project I am working on with another developer. We are using Github for source control and we are using many NuGet packages in our solution. The issue was that after adding NuGet packages and making sure that the code compiles and pushing my changes, my developer friend pulled the solution and could not build it. The reason being missing references. </p>
<p>The solution:</p>
<p>Right click on the solution and click <strong>Enable NuGet Package Restore</strong>. </p>
<p><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2013/04/image40.png" width="380" height="592"></p>
<p>This option saved many hours of cannot-compile frustration.</p>
<img src="http://feeds.feedburner.com/~r/take37/~4/0dKf7MhWKL0" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/88bUQJZe4QE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/04/11/nuget-packages-and-source-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/04/11/nuget-packages-and-source-control/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/0dKf7MhWKL0/</feedburner:origLink></item>
		<item>
		<title>Select photos on Windows Phone with PhotoChooserTask</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/TnAWM6Fi3IE/</link>
		<comments>http://www.debugrelease.com/2013/04/09/select-photos-on-windows-phone-with-photochoosertask/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 11:23:32 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://www.take37.com/?p=10</guid>
		<description><![CDATA[It is a common feature of many apps to select photos stored on the device. The feature can be implemented by using PhotoChooserTask class. In this post I will show &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/04/09/select-photos-on-windows-phone-with-photochoosertask/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>It is a common feature of many apps to select photos stored on the device. The feature can be implemented by using PhotoChooserTask class. In this post I will show you how to use PhotoChooserTask to select existing photos and also take photos using the camera.</p>
<p>Code for this post is available on <a href="https://github.com/deepak-kapoor/photochooser">Github</a>.</p>
<p>The UI for this app is very simple. It contains just one Image control and a button</p>
<p></p><pre class="crayon-plain-tag">&lt;StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"&gt;
  &lt;Image x:Name="ImageChosen" /&gt;
  &lt;Button x:Name="ButtonChoosePhoto"
    Content="choose photo"
    Click="ButtonChoosePhoto_OnClick"/&gt;
&lt;/StackPanel</pre><p></p>
<p>In the OnClick event handler I instantiate a PhotoChooserTask object, hook it with an event handler when Completed event is fired and finally call Show method on PhotoChooserTask.</p>
<p></p><pre class="crayon-plain-tag">private void ButtonChoosePhoto_OnClick(object sender, RoutedEventArgs e)
{
  PhotoChooserTask photoChooser = new PhotoChooserTask();
  photoChooser.Completed += photoChooser_Completed;
  photoChooser.Show();
}</pre><p> </p>
<p>Within the event handler I place this code. The code checks if the TaskResult is OK and then creates a new BitmapImage object from the stream in PhotoResult object which is supplied as an argument to the handler.</p>
<p></p><pre class="crayon-plain-tag">void photoChooser_Completed(object sender, PhotoResult e)
{
  if (e.TaskResult == TaskResult.OK)
  {
    BitmapImage bitmap = new BitmapImage();
    bitmap.SetSource(e.ChosenPhoto);
    ImageChosen.Source = bitmap;
  }
}</pre><p> </p>
<p>Here is the app in working.</p>
<p><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="Photo Chooser" alt="Photo Chooser" src="http://www.debugrelease.com/wp-content/uploads/2013/04/image.png" width="332" height="599" border="0" /></p>
<p><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2013/04/image1.png" width="332" height="599" border="0" /></p>
<p><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2013/04/image2.png" width="332" height="599" border="0" /></p>
<p><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2013/04/image3.png" width="332" height="599" border="0" /></p>
<h3>What about the camera?</h3>
<p>What if the photo I am interested in is not on the phone and I’d like to use the camera. That’s very easy. PhotoChooserTask has an boolean property ShowCamera. I can set it to true to get an option to use camera.</p>
<p></p><pre class="crayon-plain-tag">private void ButtonChoosePhoto_OnClick(object sender, RoutedEventArgs e)
{
  PhotoChooserTask photoChooser = new PhotoChooserTask();
  photoChooser.Completed += photoChooser_Completed;
  photoChooser.ShowCamera = true;
  photoChooser.Show();
}</pre><p> </p>
<p>Easy, isn’t it?</p>
<img src="http://feeds.feedburner.com/~r/take37/~4/PLdPRRjz5RU" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/TnAWM6Fi3IE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/04/09/select-photos-on-windows-phone-with-photochoosertask/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/04/09/select-photos-on-windows-phone-with-photochoosertask/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/PLdPRRjz5RU/</feedburner:origLink></item>
		<item>
		<title>Free Python Books</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/InTh7eC_T-M/</link>
		<comments>http://www.debugrelease.com/2013/03/25/free-python-books/#comments</comments>
		<pubDate>Mon, 25 Mar 2013 01:23:44 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.thereforesystems.com/?p=1793</guid>
		<description><![CDATA[Found a great collection of Python books available for free. Sharing it with readers of Therefore Systems. Screenshot below is just a small sample. Link]]></description>
				<content:encoded><![CDATA[<p>Found a great collection of Python books available for free. Sharing it with readers of Therefore Systems. Screenshot below is just a small sample. </p>
<p><a href="http://pythonbooks.revolunet.com/"><img title="Free Python Books" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="Free Python Books" src="http://www.debugrelease.com/wp-content/uploads/2013/03/image2.png" width="640" height="532"></a></p>
<p><a href="http://pythonbooks.revolunet.com/">Link</a></p>
<img src="http://feeds.feedburner.com/~r/take37/~4/xSFL1kgXjRo" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/InTh7eC_T-M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/03/25/free-python-books/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/03/25/free-python-books/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/xSFL1kgXjRo/</feedburner:origLink></item>
		<item>
		<title>Run Visual Studio 2012 as administrator every time</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/iQrxXPamtrU/</link>
		<comments>http://www.debugrelease.com/2013/03/14/run-visual-studio-2012-as-administrator-always/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 03:40:47 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio 2012]]></category>

		<guid isPermaLink="false">http://www.thereforesystems.com/?p=1781</guid>
		<description><![CDATA[As a developer I spend my life inside Visual Studio. Since I installed Windows 8, I was having trouble opening web projects. Turns out that I need to run Visual &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/03/14/run-visual-studio-2012-as-administrator-always/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>As a developer I spend my life inside Visual Studio. Since I installed Windows 8, I was having trouble opening web projects. Turns out that I need to run Visual Studio as an administrator. </p>
<p>Rather than right clicking the shortcut every time and another click to run as administrator, I found a permanent solution. For the lazy me, it saves two extra clicks. </p>
<p>Open properties of the shortcut to Visual Studio 2012, go to Shortcut tab. </p>
<p><img title="SNAGHTML3dd4943" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTML3dd4943" src="http://www.debugrelease.com/wp-content/uploads/2013/03/SNAGHTML3dd4943.png" width="377" height="516"></p>
<p>Click on Advanced and then check Run as administrator checkbox. </p>
<p><img title="SNAGHTML3ddcf34" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTML3ddcf34" src="http://www.debugrelease.com/wp-content/uploads/2013/03/SNAGHTML3ddcf34.png" width="394" height="301"></p>
<img src="http://feeds.feedburner.com/~r/take37/~4/OsSFGBaRL9I" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/iQrxXPamtrU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/03/14/run-visual-studio-2012-as-administrator-always/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/03/14/run-visual-studio-2012-as-administrator-always/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/OsSFGBaRL9I/</feedburner:origLink></item>
		<item>
		<title>Unable to access IIS Metabase on Windows 8</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/zdgEeJpFo_k/</link>
		<comments>http://www.debugrelease.com/2013/03/14/unable-to-access-iis-metabase-on-windows-8/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 03:34:50 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://www.thereforesystems.com/?p=1778</guid>
		<description><![CDATA[After installing Windows 8, I found that my ASP.NET MVC projects won’t open in Visual Studio. This is the error thrown by Visual Studio 2012. My first reaction was to &#8230; <a class="readmore" href="http://www.debugrelease.com/2013/03/14/unable-to-access-iis-metabase-on-windows-8/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>After installing Windows 8, I found that my ASP.NET MVC projects won’t open in Visual Studio. This is the error thrown by Visual Studio 2012.</p>
<p><img title="SNAGHTML3d25f90" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTML3d25f90" src="http://www.debugrelease.com/wp-content/uploads/2013/03/SNAGHTML3d25f90.png" width="492" height="185"></p>
<p>My first reaction was to execute aspnet_regiis –i command. That did not work.</p>
<p><img title="SNAGHTML3d4c20a" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTML3d4c20a" src="http://www.debugrelease.com/wp-content/uploads/2013/03/SNAGHTML3d4c20a.png" width="677" height="343"></p>
<p>This was a WTF moment. It turns out that I should be running Visual Studio 2012 as an administrator. After running Visual Studio 2012 as admin, the error went away and life once again seemed a bit normal.</p>
<img src="http://feeds.feedburner.com/~r/take37/~4/MaJ4NUH4Iss" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/zdgEeJpFo_k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2013/03/14/unable-to-access-iis-metabase-on-windows-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2013/03/14/unable-to-access-iis-metabase-on-windows-8/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/MaJ4NUH4Iss/</feedburner:origLink></item>
		<item>
		<title>Hadoop Word Count Revised</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/U50M7bmBk8k/</link>
		<comments>http://www.debugrelease.com/2012/07/11/hadoop-word-count-revised/#comments</comments>
		<pubDate>Tue, 10 Jul 2012 22:55:42 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Big Data]]></category>
		<category><![CDATA[Hadoop]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.thereforesystems.com/?p=1764</guid>
		<description><![CDATA[This is a follow up to my last post in which I showed you how to write a word count MapReduce job. Have a look at that earlier post before &#8230; <a class="readmore" href="http://www.debugrelease.com/2012/07/11/hadoop-word-count-revised/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>This is a follow up to my <a href="http://www.debugrelease.com/yet-another-hadoop-word-count-tutorial/">last post</a> in which I showed you how to write a word count MapReduce job. Have a look at <a href="http://www.debugrelease.com/yet-another-hadoop-word-count-tutorial/">that earlier post</a> before reading on. It will put things into perspective. </p>
<p>As you saw we implemented our map and reduce methods in their own classes by extending Mapper and Reducer class from Hadoop framework. It turns out that there is a way to implement a word count example without doing that. Hadoop framework already ships with two classes which can be used as our mapper and reducer. They are TokenCounterMapper from org.apache.hadoop.mapreduce.lib.map package and IntSumReducer from org.apache.hadoop.mapreduce.lib.reduce package. </p>
<p>Here is a revised word count which uses built-in TokenCounterMapper and IntSumReducer classes.</p>
<p></p><pre class="crayon-plain-tag">package com.thereforesystems.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.map.TokenCounterMapper;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.reduce.IntSumReducer;
import org.apache.hadoop.util.GenericOptionsParser;

public class HadoopWordCountRevised {

    public static void main(String[] args) throws Exception {
        
        Configuration config = new Configuration();
        String[] otherArgs = 
            new GenericOptionsParser(config, args).getRemainingArgs();
        
        Job job = new Job(config, "Word Count Tutorial");
        job.setJarByClass(HadoopWordCountRevised.class);
        job.setMapperClass(TokenCounterMapper.class);
        job.setReducerClass(IntSumReducer.class);
        
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        
        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
        
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}</pre><p></p>
<img src="http://feeds.feedburner.com/~r/take37/~4/6ZEmxiNH9NA" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/U50M7bmBk8k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2012/07/11/hadoop-word-count-revised/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2012/07/11/hadoop-word-count-revised/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/6ZEmxiNH9NA/</feedburner:origLink></item>
		<item>
		<title>Yet Another Hadoop Word Count Tutorial</title>
		<link>http://feedproxy.google.com/~r/ThereforeSystems/~3/Igl9Pg0cjbE/</link>
		<comments>http://www.debugrelease.com/2012/07/10/yet-another-hadoop-word-count-tutorial/#comments</comments>
		<pubDate>Tue, 10 Jul 2012 01:23:02 +0000</pubDate>
		<dc:creator>Deepak</dc:creator>
				<category><![CDATA[Hadoop]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Net Beans]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[BigData]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://www.thereforesystems.com/?p=1527</guid>
		<description><![CDATA[Here is another Word Count count Hadoop tutorial. Why? You ask. It is a learning exercise for me. I am writing it out so that I can refer to it &#8230; <a class="readmore" href="http://www.debugrelease.com/2012/07/10/yet-another-hadoop-word-count-tutorial/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>Here is another Word Count count Hadoop tutorial. Why? You ask. It is a learning exercise for me. I am writing it out so that I can refer to it in future. Also, rather than just copying the example already available with Hadoop installation, I will try to fix some shortcomings of the word count program. Before I do that, let’s just write a stock-standard one. </p>
<p>For this walkthrough if you want to call it that, I have Hadoop running on a single node setup on Ubuntu 11.10. My preferred IDE is Netbeans.</p>
<p>Here it goes.</p>
<h3>Create a project</h3>
<p>First of all create a Java project in Netbeans. Call it HadoopWordCountTutorial. I also like to use proper package names so my class HadoopWordCountTutorial is in package com.thereforesystems.hadoop.</p>
<p><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2012/07/image.png" width="640" height="398"></p>
<p>&nbsp;</p>
<h3>Add Libraries</h3>
<p>Next thing we need to do is add some libraries. Here is a list of libraries required to compile our Hadoop project.</p>
<p><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2012/07/image1.png" width="459" height="261"></p>
<p>These jars can be found in your Hadoop folders. An easy way to find where things are is by using locate command. For example to locate hadoop-core-0.20.2-cdh3u4.jar execute the command in terminal.</p>
<p><font color="#0000ff">locate hadoop-core-0.20.2-cdh3u4.jar</font></p>
<p>On my machine the file is located in </p>
<p>/usr/lib/hadoop-0.20/</p>
<p>Once we have added required libraries, we are all set to write some code. </p>
<h3>Writing code</h3>
<p>Hadoop is a framework which provides us plumbing to write MapReduce operations (This is such an understatement). Here is a <a href="http://code.google.com/edu/parallel/mapreduce-tutorial.html">good tutorial on MapReduce</a>. If you are not familiar with MapReduce then I suggest that you read it before continuing with this tutorial. </p>
<p>There are two operations we will write. One is the mapper and the other is reducer. Our objective is to count words in a file or many files and write the results to an output location. We will start with our mapper.</p>
<h3>Mapper</h3>
<p>Mapper in Hadoop is implemented by extending Mapper class found in org.apache.hadoop.mapreduce. This class implements a map method in which we will write our logic. Here is the code for our class.</p>
<p></p><pre class="crayon-plain-tag">public static class WordCountMapper extends Mapper<Object /* KEYIN */, 
            Text /* VALUEIN */, 
            Text /* KEYOUT */, 
            IntWritable /* VALUEOUT */> {

    private Text word = new Text();
    private final static IntWritable numberOne = new IntWritable(1);

    public void map(Object key, Text value, Context context) 
        throws IOException, InterruptedException {

        StringTokenizer tokenizer = new StringTokenizer(value.toString());
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            context.write(word, numberOne);
             
        }
    }
}</pre><p></p>
<p>Let’s look at the map method. The map method tokenizes the text passed in. What gets passed in is handled by Hadoop. Keep in mind that text for the entire file may not be passed in to the mapper. And this is a good thing. Imagine if the file was many gigabytes in size, Hadoop will take care of splitting the file into blocks and will spin off <em>n</em> number of mappers to handle the chunked file.</p>
<h3>Reducer</h3>
<p>The reducer is implemented in a class which extends Reducer. Here is the code for Reducer.</p>
<p></p><pre class="crayon-plain-tag">public static class WordCountReducer extends Reducer<Text /* KEYIN */, 
            IntWritable /* VALUEIN */, 
            Text /* KEYOUT */, 
            IntWritable /* VALUEOUT */> {
        
    public void reduce(Text key, Iterable<IntWritable> values, Context context) 
        throws IOException, InterruptedException {
        
        int sum = 0;
        for(IntWritable val : values){
            sum += val.get();
        }
            
        context.write(key, new IntWritable(sum));
    }
}</pre><p></p>
<p>The method of interest here is reduce() which receives a list of IntWritable objects for a key. In our example a key will be a word. For example the word could be “Imagine” which occurs many times in our file. After Mapper is done, Reducer will be called for key “Imagine” and values [1, 2, 1, 1]. Within our reduce method we sum the values up for each key and write it out. Writing out part is handled by the Context for us.</p>
<h3>Main method</h3>
<p>Main method is where it all get’s tied up. Let’s look at the main method.</p>
<p></p><pre class="crayon-plain-tag">public static void main(String[] args) 
    throws IOException, InterruptedException, ClassNotFoundException {
        
    Configuration config = new Configuration();
    String[] otherArgs = new GenericOptionsParser(config, args).getRemainingArgs();
        
    Job job = new Job(config, "Word Count Tutorial");
    job.setJarByClass(HadoopWordCountTutorial.class);
    job.setMapperClass(WordCountMapper.class);
    job.setReducerClass(WordCountReducer.class);
        
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
        
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
        
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}</pre><p></p>
<p>The first thing we do is create an instance of Configuration object. This returns us the default configuration for our installation.&nbsp; Next we parse arguments passed in. These arguments for the purpose of this example are input-directory and output-directory. Note that Hadoop will create output directory for us and it should not already exist.</p>
<p>We then create an instance of Job object by passing in the configuration instance and a name for our job. Next three lines tell Hadoop about our Jar file, the mapper it should use and the reducer it should use for the job.</p>
<p>After this we call setOutputKeyClass and setOutputValueClass on the job instance. This tells Hadoop about data types we expect it to deal with.</p>
<p>Finally we set the locations for input directory and output directory. </p>
<h3>Running the job</h3>
<p>We are all set to run this job. I executed this job by pointing it to a directory which contains only one file. This file is lyrics for Imagine by John Lennon. </p>
<p>On my machine I executed the job with this command.</p>
<p><font color="#0000ff">java -jar /home/deepak/NetBeansProjects/HadoopWordCountTutorial/dist/HadoopWordCountTutorial.jar /home/deepak/temp/HadoopWordCountTutorial/input /home/deepak/temp/HadoopWordCountTutorial/output</font></p>
<p>After the job is run, the output shows me how many times a particular word occured in the file. Here is partial output.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2012/07/image2.png" width="134" height="460"></p>
<p>What is wrong with this output? Take a look at the partial output above, you will notice that “A” has been counted as 1 and “a” is counted as 2. To resolve this issue we can tell our StringTokenizer to ignore certain characters.</p>
<p></p><pre class="crayon-plain-tag">StringTokenizer tokenizer = 
    new StringTokenizer(value.toString(), " tnrf,.:;?[]'(),~!@#%^&*()_");</pre><p></p>
<p>Also when we all word.set we can call toLowerCase method. This will make all our keys lowercase and provide expected ouput.</p>
<p></p><pre class="crayon-plain-tag">word.set(tokenizer.nextToken().toLowerCase());</pre><p></p>
<p>Here is the output after making two minor changes. We now have the count for “a” as 3. This is what we expected.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.debugrelease.com/wp-content/uploads/2012/07/image3.png" width="127" height="310"></p>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>This concludes the post. I hope you learned a thing or two here. These days I am spending more and more time with Hadoop and most importantly I am enjoying my time with it. Stay tuned for more ramblings as I make my way through this massive framework.</p>
<img src="http://feeds.feedburner.com/~r/take37/~4/fDlGdyL3Cpg" height="1" width="1"/><img src="http://feeds.feedburner.com/~r/ThereforeSystems/~4/Igl9Pg0cjbE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.debugrelease.com/2012/07/10/yet-another-hadoop-word-count-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.debugrelease.com/2012/07/10/yet-another-hadoop-word-count-tutorial/</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/take37/~3/fDlGdyL3Cpg/</feedburner:origLink></item>
	</channel>
</rss>
