<?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>Code On A Stick</title>
	<atom:link href="http://www.codeonastick.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.codeonastick.com</link>
	<description>Code that works and ... doesn't</description>
	<pubDate>Wed, 02 Dec 2009 15:50:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GWT - Unicode Characters</title>
		<link>http://www.codeonastick.com/?p=76</link>
		<comments>http://www.codeonastick.com/?p=76#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:39:46 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[GWT]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=76</guid>
		<description><![CDATA[Sometimes simple 1 minute tasks make you stop and spend 20 minutes figuring solution out.
I&#8217;ve got a request to replace the label &#8220;Up&#8221; by this arrow &#8220;&#9650;&#8221; . What could be simpler? I quickly replaced &#8220;Up&#8221; by &#8220;&#9650;&#8221; in my Java source code. Then I tried to save my code and got the Eclipse error &#8220;Some characters [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes simple 1 minute tasks make you stop and spend 20 minutes figuring solution out.</p>
<p>I&#8217;ve got a request to replace the label &#8220;Up&#8221; by this arrow &#8220;&#9650;&#8221; . What could be simpler? I quickly replaced &#8220;Up&#8221; by &#8220;&#9650;&#8221; in my Java source code. Then I tried to save my code and got the Eclipse error &#8220;Some characters cannot be mapped using &#8220;Cp1252&#8243; character encoding&#8221;&#8230;</p>
<p>The <strong>solution </strong>is simple. I used a nice <strong>online converter </strong><a href="http://people.w3.org/rishida/scripts/uniview/conversion.php">http://people.w3.org/rishida/scripts/uniview/conversion.php</a> to get the Unicode code for the arrow character and then pasted it in my Java code like this:</p>
<p><strong>String upArrrow = &#8220;\u25B2&#8243;;</strong></p>
<p style="TEXT-ALIGN: right">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=76</wfw:commentRss>
		</item>
		<item>
		<title>GWT - best practices</title>
		<link>http://www.codeonastick.com/?p=73</link>
		<comments>http://www.codeonastick.com/?p=73#comments</comments>
		<pubDate>Thu, 08 Oct 2009 14:27:43 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[GWT]]></category>

		<category><![CDATA[Google App Engine]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=73</guid>
		<description><![CDATA[GWT tutorials is a good way to learn basics and even to build simple prototypes, but it&#8217;s certainly not enough information to start building real life application. That&#8217;s why I was so glad to find this video from Google I/O 2009 which describes best practices for architectecting GWT application.
-=Oleg=-
]]></description>
			<content:encoded><![CDATA[<p>GWT tutorials is a good way to learn basics and even to build simple prototypes, but it&#8217;s certainly not enough information to start building real life application. That&#8217;s why I was so glad to find <a href="http://code.google.com/events/io/sessions/GoogleWebToolkitBestPractices.html" target="_blank">this video</a> from Google I/O 2009 which describes best practices for architectecting GWT application.</p>
<p style="text-align: right;">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=73</wfw:commentRss>
		</item>
		<item>
		<title>New Direction - Google App Engine</title>
		<link>http://www.codeonastick.com/?p=68</link>
		<comments>http://www.codeonastick.com/?p=68#comments</comments>
		<pubDate>Fri, 02 Oct 2009 16:58:43 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[Google App Engine]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[App Engine]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=68</guid>
		<description><![CDATA[As it often happened in developers life, as soon as you become an expert in something, the life throws you a new project which requires you to learn brand new  languages, platforms, frameworks, technologies, etc&#8230; Suddenly your work day routine changes from 80% coding and 20% research to 99% of learning and researching.
Only six month ago I started [...]]]></description>
			<content:encoded><![CDATA[<p>As it often happened in developers life, as soon as you become an expert in something, the life throws you a new project which requires you to learn brand new  languages, platforms, frameworks, technologies, etc&#8230; Suddenly your work day routine changes from 80% coding and 20% research to 99% of learning and researching.</p>
<p>Only six month ago I started working with Silverlight. We had some fun playing with new power tool, we&#8217;ve built the a series of prototypes&#8230; and that was the end of Silverlight journey.</p>
<p>New mission is Google App Engine.  Our language of choice is Java. My experience with Java - none. So far looking at zillions of Java frameworks makes me dizzy. After spending 2 days on learning Struts 2 I&#8217;ve realized that the learning curve is expected to be very deep. I&#8217;m diving in&#8230; - wish me good luck.</p>
<p style="text-align: right;">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=68</wfw:commentRss>
		</item>
		<item>
		<title>More about IIS performance</title>
		<link>http://www.codeonastick.com/?p=66</link>
		<comments>http://www.codeonastick.com/?p=66#comments</comments>
		<pubDate>Mon, 24 Aug 2009 18:55:07 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[IIS]]></category>

		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=66</guid>
		<description><![CDATA[One more article about IIS performance from trusted source i.e. from Microsoft:
http://blogs.technet.com/mscom/archive/2008/06/09/microsoft-com-operations-performance-analysis-of-iis-7-0-windows-server-2008.aspx
-=Oleg=-
]]></description>
			<content:encoded><![CDATA[<p>One more article about IIS performance from trusted source i.e. from Microsoft:</p>
<p><a href="http://blogs.technet.com/mscom/archive/2008/06/09/microsoft-com-operations-performance-analysis-of-iis-7-0-windows-server-2008.aspx">http://blogs.technet.com/mscom/archive/2008/06/09/microsoft-com-operations-performance-analysis-of-iis-7-0-windows-server-2008.aspx</a></p>
<p style="text-align: right;">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=66</wfw:commentRss>
		</item>
		<item>
		<title>SVN Rollback - restoring deleted files and folders</title>
		<link>http://www.codeonastick.com/?p=63</link>
		<comments>http://www.codeonastick.com/?p=63#comments</comments>
		<pubDate>Mon, 24 Aug 2009 18:50:26 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[SVN]]></category>

		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=63</guid>
		<description><![CDATA[Preface
I&#8217;m not an expert in SVN version control and I don&#8217;t like using command line. I&#8217;m regular Windows user and so it was easy for me to learn how to use &#8220;Commit&#8221; and &#8220;Update&#8221; buttons in TortoiseSVN. It was easy until one day when I had to figure out how to restore delete folders.
A day when [...]]]></description>
			<content:encoded><![CDATA[<h3>Preface</h3>
<p>I&#8217;m not an expert in SVN version control and I don&#8217;t like using command line. I&#8217;m regular Windows user and so it was easy for me to learn how to use &#8220;Commit&#8221; and &#8220;Update&#8221; buttons in TortoiseSVN. It was easy until one day when I had to figure out how to restore delete folders.</p>
<h3>A day when sources disappeared</h3>
<p>One beautiful morning I checked out my sources from SVN and discovered that the most of the files and folders are gone. Apparently the night before one of the developers was cleaning SVN working folder on his machine and &#8230; Well, if you don&#8217;t know what that big red button is for it might be not a good idea to press it&#8230;</p>
<p>So, if don&#8217;t know what to do - ask Google. Google said - don&#8217;t worry, it&#8217;s impossible to lose anything in SVN, just do the reverse merge using following command line params&#8230; </p>
<p>The problem is I didn&#8217;t want to use command line. I wanted to use beautiful TortoiseSVN UI for that. So, I found &#8220;Revert to this revision&#8221; and &#8220;Revert changes from this revision&#8221; and thought my problem is solved, but for some reason SVN was failing this task with an error &#8220;<em>&#8216;/svn/sources/!svn/bc/373/Test&#8217; path not found</em>&#8220;. Finally, after asking an SVN expert, I figured that there was a small detail which I was missing. The revision of your working copy has to be a &#8220;HEAD&#8221;.</p>
<h3>Steps to recover deleted files or undo the submit in SVN:</h3>
<ol>
<li>Get the HEAD revision from SVN it to your <strong>working folder. </strong>Working folder is the key word here. (I suggest using temporary folder)</li>
<li>Click on Show Log</li>
<li>In the Log window, select revision you want to undo and click on the &#8220;Revert changes from this version&#8221; in the popup menu. This will execute the merge command of the corresponding revisions.</li>
<li>Wait for SVN to update your working folder. Working folder is the key word again. SVN updates your working folder first, so you can review the change before you commit it to SVN.</li>
<li>Make sure your sources merged correctly and then commit the change to SVN.</li>
</ol>
<p>Best luck recovering your sources!</p>
<p style="text-align: right;">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=63</wfw:commentRss>
		</item>
		<item>
		<title>IIS Performance</title>
		<link>http://www.codeonastick.com/?p=60</link>
		<comments>http://www.codeonastick.com/?p=60#comments</comments>
		<pubDate>Tue, 28 Jul 2009 15:40:09 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=60</guid>
		<description><![CDATA[Yesterday we had a little debate in the office about the max number or requests IIS can handle per second. So I did a little research and found that majority of the people are not able to go higher than 300-600 requests/sec, however some claim they were able to get 20000 req/sec. I guess it [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday we had a little debate in the office about the max number or requests IIS can handle per second. So I did a little research and found that majority of the people are not able to go higher than 300-600 requests/sec, <span style="line-height: 115%; font-family: &quot;Georgia&quot;,&quot;serif&quot;; color: black; font-size: 10pt; mso-ansi-language: EN-CA; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">however </span>some claim they were able to get 20000 req/sec. I guess it depends on how much processing work your request does i.e. if IIS is simply returning a HTML page or if it processes ASP.NET page doing <span style="line-height: 115%; font-family: &quot;Georgia&quot;,&quot;serif&quot;; color: black; font-size: 10pt; mso-ansi-language: EN-CA; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">authentication</span>, making database requests and constructs the HTML page at the end.</p>
<p>Anyhow, I discovered that IIS 7  has some interesting features wich I was not aware of <a href="http://blogs.iis.net/bills/archive/2007/05/07/iis-vs-apache.aspx">http://blogs.iis.net/bills/archive/2007/05/07/iis-vs-apache.aspx</a>. I especially like the one that allows you to Troubleshooting Failed Requests Using Tracing in IIS 7.0 <a href="http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis-70/">http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis-70/</a>.</p>
<p style="text-align: right;">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=60</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight Styling</title>
		<link>http://www.codeonastick.com/?p=56</link>
		<comments>http://www.codeonastick.com/?p=56#comments</comments>
		<pubDate>Tue, 14 Jul 2009 15:31:16 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=56</guid>
		<description><![CDATA[Changing the styling of the Silverlight controls is simple. It’s somewhat similar to CSS, but it&#8217;s more robust and syntax is completely different. What is different in Silverlight and WPF is that you can completely re-define control’s UI and behavior using styles. It took me about 20 minutes from absolute zero to the “Aha!” moment and [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt">Changing the styling of the Silverlight controls is simple. It’s somewhat similar to CSS, but it&#8217;s more robust and syntax is completely different. What is different in Silverlight and WPF is that you can completely re-define control’s UI and behavior using styles. It took me about 20 minutes from absolute zero to the “Aha!” moment and become an expert in styling WPF and Silverlight applications. Here are the 3 links that helped me to clear the mistery behind Silverlight styles:</p>
<p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1">1.       <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx" target="_blank">Using Style Elements to Better Encapsulate Look and Feel</a> – a good example of how to change control’s properties using styles</p>
<p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1">2.       <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx" target="_blank">Using Control Templates to Customize a Control&#8217;s Look and Feel</a> – a step further that shows how to make control look anyway you want. In other words how to draw control’s UI from scratch or combine several controls into one. All using styles! Pretty amazing yet simple.</p>
<p style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 10pt 36pt; mso-list: l0 level1 lfo1">3.       <a href="http://msdn.microsoft.com/en-us/library/cc189093(VS.95).aspx" target="_blank">MSDN: Customizing the Appearance of an Existing Control by Using a ControlTemplate</a> – the final piece of puzzle is about how to make control to react on events like Pressed or Disabled and change its appearance. Just few more words about this. Basically every control has a list of pre-defined events (they called states in Silverlight) which can be referenced by ControlTemplate. The list of states differs for each control. This information is available in MSDN on control’s Class page as a list of TemplateVisualStateAttribute attributes applied to the class.</p>
<p style="text-align: right; text-indent: -18pt; margin: 0cm 0cm 10pt 36pt; mso-list: l0 level1 lfo1;">-=Oleg=-<span style="font-family: Calibri;"><span style="font-size: small;"></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=56</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight 3 has been released</title>
		<link>http://www.codeonastick.com/?p=55</link>
		<comments>http://www.codeonastick.com/?p=55#comments</comments>
		<pubDate>Fri, 10 Jul 2009 13:14:38 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=55</guid>
		<description><![CDATA[Long awaited Silverlight 3 has been released. Here is the download link:
http://www.microsoft.com/silverlight/get-started/install/default.aspx
New features:
Media: New codec support (H.264, AAC, MPEG-4), raw bitstream Audio/Video API, and improved logging for media analytics
Graphics: GPU Acceleration and hardware compositing, perspective 3D, bitmap and pixel API, pixel shader effects, and Deep Zoom improvements
SEO: Deep linking
Application development: multi-touch support, 60+ controls available, and library [...]]]></description>
			<content:encoded><![CDATA[<p>Long awaited Silverlight 3 has been released. Here is the download link:</p>
<p><a href="http://www.microsoft.com/silverlight/get-started/install/default.aspx">http://www.microsoft.com/silverlight/get-started/install/default.aspx</a></p>
<p>New features:</p>
<li><strong>Media</strong>: New codec support (H.264, AAC, MPEG-4), raw bitstream Audio/Video API, and improved logging for media analytics</li>
<li><strong>Graphics</strong>: GPU Acceleration and hardware compositing, perspective 3D, bitmap and pixel API, pixel shader effects, and Deep Zoom improvements</li>
<li><strong>SEO: </strong>Deep linking</li>
<li><strong>Application development</strong>: multi-touch support, 60+ controls available, and library caching support</li>
<li><strong>Data</strong>: Data-binding improvements, validation error templates, server data push improvements, binary XML networking support, and multi-tier REST data support</li>
<p style="text-align: right;">-=Oleg=-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=55</wfw:commentRss>
		</item>
		<item>
		<title>How to serialize / deserialize ANY object using XmlSerializer</title>
		<link>http://www.codeonastick.com/?p=52</link>
		<comments>http://www.codeonastick.com/?p=52#comments</comments>
		<pubDate>Tue, 30 Jun 2009 21:09:14 +0000</pubDate>
		<dc:creator>Oleg</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[Serialization]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=52</guid>
		<description><![CDATA[There is a lot to say about object serialization. I just want to cover the gray area when you need to serialize object which has references to other objects, but references are not strongly typed. For example, if you have your classes structured like that:
    public class MainClass
    {
        public object Data { get; set; [...]]]></description>
			<content:encoded><![CDATA[<p><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">There is a lot to say about object serialization. I just want to cover the gray area when you need to serialize object which has references to other objects, but references are not strongly typed. For example, if you have your classes structured like that:</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">MainClass</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">public</span> <span style="color: blue;">object</span> Data { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ChildClass1</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">//some properties</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ChildClass2</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">//some properties</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="font-size: small;"><span style="font-family: Calibri;"><span style="mso-ansi-language: EN-US;" lang="EN-US">where Child Classes can be assigned to Data property of the MainClass and if you construct </span>XmlSerializer object like this </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 10pt; padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Calibri;">new XmlSerializer(typeof(MainClass));</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="font-size: small;"><span style="font-family: Calibri;"><span style="mso-ansi-language: EN-US;" lang="EN-US">Then both serialization and deserialization will fail throwing an error saying that it has no knowledge of ChildClass1 or ChildClass2 classes. To resolve this error you need to provide </span>XmlSerializer with additional class types which serializer may meet on its way when parsing XML string. Here is how to do that:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 10pt; padding-left: 30px;"><span style="font-family: Calibri; font-size: small;">new XmlSerializer(typeof(MainClass), new Type[] { typeof(<span style="mso-ansi-language: EN-US;" lang="EN-US">ChildClass1</span>), typeof(<span style="mso-ansi-language: EN-US;" lang="EN-US">ChildClass2</span>) });</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 10pt;"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">Here is the set of functions I use to serialize / deserialize my objects:</span></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">string</span> SerializeToString(<span style="color: blue;">object</span> aObject)</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">return</span> SerializeToString(aObject, <span style="color: blue;">null</span>);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">string</span> SerializeToString(<span style="color: blue;">object</span> aObject, <span style="color: #2b91af;">Type</span>[] extraTypes)</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; color: green; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: #2b91af;">XmlSerializer</span> aSerializer;</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">if</span> (extraTypes == <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>aSerializer = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlSerializer</span>(aObject.GetType());</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">else</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>aSerializer = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlSerializer</span>(aObject.GetType(), extraTypes);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: #2b91af;">MemoryStream</span> aMemoryStream = <span style="color: blue;">new</span> <span style="color: #2b91af;">MemoryStream</span>();</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: #2b91af;">StreamReader</span> aStreamReader = <span style="color: blue;">new</span> <span style="color: #2b91af;">StreamReader</span>(aMemoryStream);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: #2b91af;">XmlWriterSettings</span> aXMLWriterSettings = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlWriterSettings</span>();</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>aXMLWriterSettings.Encoding = <span style="color: blue;">new</span> <span style="color: #2b91af;">UTF8Encoding</span>(<span style="color: blue;">false</span>);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>aXMLWriterSettings.ConformanceLevel = <span style="color: #2b91af;">ConformanceLevel</span>.Document;</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: #2b91af;">XmlWriter</span> aXMLWriter = <span style="color: #2b91af;">XmlWriter</span>.Create(aMemoryStream, aXMLWriterSettings);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>aSerializer.Serialize(aXMLWriter, aObject);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>aXMLWriter.Flush();</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>aXMLWriter.Close();</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>aMemoryStream.Position = 0;</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">return</span> aStreamReader.ReadToEnd();</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">object</span> DeserializeFromString(<span style="color: blue;">string</span> aMessage, System.<span style="color: #2b91af;">Type</span> aType)</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">return</span> DeserializeFromString(aMessage, aType, <span style="color: blue;">null</span>);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">object</span> DeserializeFromString(<span style="color: blue;">string</span> aMessage, System.<span style="color: #2b91af;">Type</span> aType, <span style="color: #2b91af;">Type</span>[] extraTypes)</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>{</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: #2b91af;">XmlSerializer</span> aXMLSerializer;</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">if</span> (extraTypes == <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>aXMLSerializer = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlSerializer</span>(aType);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">else</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>aXMLSerializer = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlSerializer</span>(aType, extraTypes);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>System.IO.<span style="color: #2b91af;">StringReader</span> aStringReader = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringReader</span>(aMessage);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">return</span> aXMLSerializer.Deserialize(aStringReader);</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span>}</span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="text-align: right; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-family: &quot;Courier New&quot;; font-size: 8pt; mso-no-proof: yes;">-= Oleg =-</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=52</wfw:commentRss>
		</item>
		<item>
		<title>My experiences with LINQ (basic use with C#)</title>
		<link>http://www.codeonastick.com/?p=40</link>
		<comments>http://www.codeonastick.com/?p=40#comments</comments>
		<pubDate>Thu, 25 Jun 2009 14:46:23 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.codeonastick.com/?p=40</guid>
		<description><![CDATA[So here&#8217;s how it started:
&#8220;Fill an object that consists of lists of other objects that consist of lists of other objects from the database&#8221;
Meaning, I have to retrieve data from 4-5 different tables, efficiently and bring it in to my app. My first idea: Iterate through the object and write separate queries that will populate [...]]]></description>
			<content:encoded><![CDATA[<p>So here&#8217;s how it started:</p>
<p>&#8220;Fill an object that consists of lists of other objects that consist of lists of other objects from the database&#8221;</p>
<p>Meaning, I have to retrieve data from 4-5 different tables, efficiently and bring it in to my app. My first idea: Iterate through the object and write separate queries that will populate each list, and than iterate through each object in the list and fill that one in turn. The number of transactions would be huge&#8230; so not such a great idea. Finally I came to the conclusion that an XML record set</p>
<pre style="padding-left: 30px;"> (SELECT
                itemType AS '@type',
                Id AS 'Id'
FROM MyDataTable WHERE Id = @Id
FOR XML PATH('Item'), TYPE)</pre>
<p>with a few of those nested, would be a more sensible approach.</p>
<p>After spending a day linking my tables and selecting which values I need and which are junk, I started with the XML parsing. Of course this can be done in many ways, ranging from straight parsing with XPathNavigator to serialization straight into the object, or even transforming the XML using an XSL transform and than serializing it into an object. All those are fun approaches, but this time I decided that I&#8217;ll use that handy little tool that Microsoft has: LINQ.</p>
<p>Language-integrated Query they call it. Mainly it&#8217;s used for writing XML files, and unfortunately most examples are regarding that. Of course, as with anything new that I do, I browsed the net for some examples, and gave up after about 5 minutes, and just started fiddling around with it&#8230; Here are my discoveries:</p>
<p>The basic statement to use is:</p>
<pre style="padding-left: 30px;">var vComponents = from item in sampleXML.Descendants("component")
             select item;</pre>
<p>this gives you a list of items which you can iterate through with something like:</p>
<pre style="padding-left: 30px;">foreach (var vComponent in vComponents)</pre>
<p>you may notice that this is a generic type (var) which is a LINQ free-form variable. In this case vComponents is a System.Linq.Enumerable and the vComponent is an XML container (the inner workings of LINQ are not my main concern).</p>
<p>To extract a value from the XML container you might want to use something like:</p>
<pre style="padding-left: 30px;">int myValue = int.Parse(vComponent.Element("myValue").Value);
Guid myGuid = new Guid(vComponent.Attribute("id").Value);</pre>
<p>which is pretty straight forward. The fun thing is that you can than take your node vComponent, and use it as you would with any other XML document, so you can say something like:</p>
<pre style="padding-left: 30px;">var vElements = from item in vComponent.Descendants("Element")
              select item;</pre>
<p>or even:</p>
<pre style="padding-left: 30px;">string itemName = vElements.Element("ItemInfo").Element("ItemName").Value;</pre>
<p>Of course, doing stuff like this with XML is risky, because let&#8217;s say one of your JOINS from the database yielded some NULL values, so you might want to first check for the element to not be NULL before you query for the value, like:</p>
<pre style="padding-left: 30px;">if (vElements.Element("ItemInfo").Element("ItemDescription") != null)
    itemDescription = vElements.Element("ItemInfo").Element("ItemDescription").
          Value;</pre>
<p>just in case the description field was left NULL.</p>
<p>Of course, you might want to wrap it all up in some try{ &#8230; } catch { &#8230; } statements just to prevent any other nasty errors from popping up.</p>
<p>In conclusion, I guess all I can say is: &#8220;XML parsing made easy&#8221; using Linq. It&#8217;s good for iterating through multiple nodes of the same type, but I&#8217;d expect some nicer way for it to handle errors (like if a node is non existant, don&#8217;t throw an error just return a NULL value, like serialization does). Hopefully I&#8217;ll find some time and write a bit about serialization as well&#8230;</p>
<p style="text-align: right;">alex~</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeonastick.com/?feed=rss2&amp;p=40</wfw:commentRss>
		</item>
	</channel>
</rss>
