<?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"
	>

<channel>
	<title>Codelog</title>
	<atom:link href="http://codelog.blogial.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codelog.blogial.com</link>
	<description>foreach(Snippet aSnippet in CodeLog){ aSnippet.GetSolution(); }</description>
	<pubDate>Tue, 20 Jul 2010 10:00:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>DoUNo: Whadds up with the Background property of a control</title>
		<link>http://codelog.blogial.com/2010/07/20/douno-whadds-up-with-the-background-property-of-a-control/</link>
		<comments>http://codelog.blogial.com/2010/07/20/douno-whadds-up-with-the-background-property-of-a-control/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 09:48:17 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[Control Template]]></category>

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

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

		<category><![CDATA[Tips 'n' Tricks]]></category>

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

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=521</guid>
		<description><![CDATA[This is weird !! Try to customize the control template of a button,

Place a grid as the base panel (don&#8217;t add any Background property to it)
Add an ellipse and a content presenter to this
Add a Click event handler to the button
Run it and try to click on the white space, the event will not be [...]]]></description>
			<content:encoded><![CDATA[<p>This is weird !! Try to customize the control template of a button,</p>
<ol>
<li>Place a grid as the base panel (don&#8217;t add any Background property to it)</li>
<li>Add an ellipse and a content presenter to this</li>
<li>Add a <em>Click</em> event handler to the button</li>
<li>Run it and try to click on the white space,<strong> the event will not be raised !!!</strong></li>
</ol>
<p>Go back to the template,</p>
<ol>
<li>Add a <strong>Background</strong> property to the grid and set the value to Blue (can be any color other than transparent)</li>
<li>Run it and try to click on the Blue color, <strong>the event will be raised !!!</strong></li>
</ol>
<p>Go back to the template,</p>
<ol>
<li>Set the value of the <strong>Background</strong> Property to <strong>Transparent</strong></li>
<li>Run it and try to click on the white space,<strong> the event will still be raised !!! (WHY ?!?)</strong></li>
</ol>
<p>Looks weird to me thou&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/07/20/douno-whadds-up-with-the-background-property-of-a-control/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ScrollBar control template in wpf</title>
		<link>http://codelog.blogial.com/2010/03/12/scrollbar-control-template-in-wpf/</link>
		<comments>http://codelog.blogial.com/2010/03/12/scrollbar-control-template-in-wpf/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 09:34:53 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[Control Template]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=510</guid>
		<description><![CDATA[Won&#8217;t it be cool to have ones own scroll bar. Felling the same, I did  a quick peek in to msdn and there was a sample scroll bar template. The example is really  good, but it did not talk about the internals of a scroll bar. So i  thought I will write [...]]]></description>
			<content:encoded><![CDATA[<p>Won&#8217;t it be cool to have ones own scroll bar. Felling the same, I did  a quick peek in to msdn and there was a <a href="http://msdn.microsoft.com/en-us/library/ms742173.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">sample scroll bar template.</a> The example is really  good, but it did not talk about the internals of a scroll bar. So i  thought I will write about it.</p>
<p><a href="http://codelog.blogial.com/files/scrollbar__template.png" ><img class="aligncenter size-medium wp-image-511" src="http://codelog.blogial.com/files/scrollbar__template-300x79.png" alt="" width="300" height="79" /></a></p>
<p>The two arrows that you see at the ends are called RepeatButtons. The  middle field (light grayish one) is called Track. The middle, movable  portion in the track is called Thumb and the partitions to the left and  the right of the thumb are two more repeat buttons.</p>
<p>I have named these controls with some number so that it can easily be  related to the code.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">        <span style="color: #ddbb00;">&amp;lt;</span>!-- We are going to alter the vertical scroll bar's template --<span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
        <span style="color: #ddbb00;">&amp;lt;</span>ControlTemplate x:Key=&quot;VerticalScrollBar&quot; TargetType=&quot;{x:Type ScrollBar}&quot;<span style="color: #ddbb00;">&amp;gt;</span>
            <span style="color: #ddbb00;">&amp;lt;</span>!-- First up is the background panel for all the above mentioned controls --<span style="color: #ddbb00;">&amp;gt;</span>
            <span style="color: #ddbb00;">&amp;lt;</span>Grid Background=&quot;Transparent&quot;<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>Grid.RowDefinitions<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>RowDefinition MaxHeight=&quot;50&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>!-- Up arrow row --<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>RowDefinition Height=&quot;0.00001*&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>!-- Track row --<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>RowDefinition MaxHeight=&quot;50&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>!-- Down arrow row --<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>/Grid.RowDefinitions<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>Border Grid.RowSpan=&quot;3&quot; CornerRadius=&quot;2&quot; Background=&quot;DarkGray&quot; Opacity=&quot;1&quot; /<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>!-- Border for the scroll bar --<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>RepeatButton Grid.Row=&quot;0&quot; Command=&quot;ScrollBar.LineUpCommand&quot; Width=&quot;30&quot; Height=&quot;30&quot;<span style="color: #ddbb00;">&amp;gt;</span>Up<span style="color: #ddbb00;">&amp;lt;</span>/RepeatButton<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>!-- Repeat button 1 (up arrow) --<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>Track Name=&quot;PART_Track&quot; Grid.Row=&quot;1&quot; IsDirectionReversed=&quot;true&quot;<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>!-- Track --<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>Track.DecreaseRepeatButton<span style="color: #ddbb00;">&amp;gt;</span>
                        <span style="color: #ddbb00;">&amp;lt;</span>RepeatButton Command=&quot;ScrollBar.PageUpCommand&quot; Opacity=&quot;0&quot; /<span style="color: #ddbb00;">&amp;gt;</span>
                        <span style="color: #ddbb00;">&amp;lt;</span>!-- Repeat button 3 (left partition) --<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>/Track.DecreaseRepeatButton<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>Track.Thumb<span style="color: #ddbb00;">&amp;gt;</span>
                        <span style="color: #ddbb00;">&amp;lt;</span>Thumb Margin=&quot;1,0,1,0&quot; Background=&quot;Transparent&quot; Opacity=&quot;0.3&quot; Width=&quot;20&quot; /<span style="color: #ddbb00;">&amp;gt;</span>
                        <span style="color: #ddbb00;">&amp;lt;</span>!-- Thumb --<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>/Track.Thumb<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>Track.IncreaseRepeatButton<span style="color: #ddbb00;">&amp;gt;</span>
                        <span style="color: #ddbb00;">&amp;lt;</span>RepeatButton Command=&quot;ScrollBar.PageDownCommand&quot; Opacity=&quot;0&quot; /<span style="color: #ddbb00;">&amp;gt;</span>
                        <span style="color: #ddbb00;">&amp;lt;</span>!-- Repeat button 4 (right partition) --<span style="color: #ddbb00;">&amp;gt;</span>
                    <span style="color: #ddbb00;">&amp;lt;</span>/Track.IncreaseRepeatButton<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>/Track<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>RepeatButton Grid.Row=&quot;2&quot; Command=&quot;ScrollBar.LineDownCommand&quot; Width=&quot;30&quot; Height=&quot;30&quot;<span style="color: #ddbb00;">&amp;gt;</span>Down<span style="color: #ddbb00;">&amp;lt;</span>/RepeatButton<span style="color: #ddbb00;">&amp;gt;</span>
                <span style="color: #ddbb00;">&amp;lt;</span>!-- Repeat button 2 (down arrow) --<span style="color: #ddbb00;">&amp;gt;</span>
            <span style="color: #ddbb00;">&amp;lt;</span>/Grid<span style="color: #ddbb00;">&amp;gt;</span>
        <span style="color: #ddbb00;">&amp;lt;</span>/ControlTemplate<span style="color: #ddbb00;">&amp;gt;</span></pre></div></div>

<p>I hope the above snippet is self  explanatory, still a bit of explanation.</p>
<ol>
<li>We start off altering the <strong>ControlTemplate</strong> of the <em>ScrollBar</em>.</li>
<li>We place a grid as the base panel for the scroll bar and we  divide it in to three rows, one for up arrow, one for track and one for  down arrow.</li>
<li>Then we add two repeat buttons to the top and the  bottom most rows (up and down arrows).</li>
<li>Now comes the middle row  for the track. As mentioned earlier, a track is again composed  of two  repeat buttons (actually the partitions are made of buttons; really  don&#8217;t know why) so we create those buttons and assign them the scroll  bar related commands.</li>
<li>We also add a thumb in the middle. Make  sure that you don&#8217;t set any Height for the thumb as this is a vertical  scroll bar (no width for the horizontal scroll bar). Don&#8217;t bother about  the opacity that I have given for these controls. We are free to modify  them.</li>
</ol>
<p>After the control template creation modification, we need to assign  this to our scroll bar.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #ddbb00;">&amp;lt;</span>Style x:Key=&quot;{x:Type ScrollBar}&quot; TargetType=&quot;{x:Type ScrollBar}&quot;<span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
    <span style="color: #ddbb00;">&amp;lt;</span>Setter Property=&quot;SnapsToDevicePixels&quot; Value=&quot;True&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
     <span style="color: #ddbb00;">&amp;lt;</span>Setter Property=&quot;OverridesDefaultStyle&quot; Value=&quot;true&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
     <span style="color: #ddbb00;">&amp;lt;</span>Style.Triggers<span style="color: #ddbb00;">&amp;gt;</span>
         <span style="color: #ddbb00;">&amp;lt;</span>Trigger Property=&quot;Orientation&quot; Value=&quot;Vertical&quot;<span style="color: #ddbb00;">&amp;gt;</span>  <span style="color: #ddbb00;">&amp;lt;</span>!-- Our scroll bar is a vertical one. Thats why --<span style="color: #ddbb00;">&amp;gt;</span>
             <span style="color: #ddbb00;">&amp;lt;</span>Setter Property=&quot;Width&quot; Value=&quot;18&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
            <span style="color: #ddbb00;">&amp;lt;</span>Setter Property=&quot;Height&quot; Value=&quot;Auto&quot; /<span style="color: #ddbb00;">&amp;gt;</span>
            <span style="color: #ddbb00;">&amp;lt;</span>Setter Property=&quot;Template&quot; Value=&quot;{StaticResource VerticalScrollBar}&quot; /<span style="color: #ddbb00;">&amp;gt;</span>
        <span style="color: #ddbb00;">&amp;lt;</span>/Trigger<span style="color: #ddbb00;">&amp;gt;</span>
    <span style="color: #ddbb00;">&amp;lt;</span>/Style.Triggers<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>/Style<span style="color: #ddbb00;">&amp;gt;</span></pre></div></div>

<p><a href="http://codelog.blogial.com/files/customized__scrollbar___template.png" ><img class="aligncenter size-medium wp-image-517" src="http://codelog.blogial.com/files/customized__scrollbar___template-300x10.png" alt="" width="300" height="10" /></a></p>
<p>Thats it. You have successfully altered a scroll  bar.</p>
<p><strong>Update &#8212;  Don&#8217;t try changing the PART_Track. Changing the name will lead to an incomplete scroll bar as that name has been used by .NET WPF framework. </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/03/12/scrollbar-control-template-in-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: XAML gets compiled in to a BAML</title>
		<link>http://codelog.blogial.com/2010/02/01/douno-xaml-gets-compiled-in-to-a-baml/</link>
		<comments>http://codelog.blogial.com/2010/02/01/douno-xaml-gets-compiled-in-to-a-baml/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 04:43:44 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=507</guid>
		<description><![CDATA[What does a xaml file gets compiled in to ? It gets compiled in to a baml (binary xaml). More @ wikipedia.
You can find the .baml file in the \obj\Debug folder.
]]></description>
			<content:encoded><![CDATA[<p>What does a xaml file gets compiled in to ? It gets compiled in to a baml (binary xaml). More @ <a href="http://en.wikipedia.org/wiki/BAML" onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');" target="_blank">wikipedia</a>.</p>
<p>You can find the .baml file in the \obj\Debug folder.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/02/01/douno-xaml-gets-compiled-in-to-a-baml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Transparent background with opaque controls on top of it in wpf</title>
		<link>http://codelog.blogial.com/2010/01/13/transparent-background-with-opaque-controls-on-top-of-it/</link>
		<comments>http://codelog.blogial.com/2010/01/13/transparent-background-with-opaque-controls-on-top-of-it/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 04:04:59 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[Tips 'n' Tricks]]></category>

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

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=491</guid>
		<description><![CDATA[Ever felt like having a transparent window background and still opaque controls inside the window? It can be easily done in wpf.

Set the window&#8217;s AllowsTransparency to True
Set the window&#8217;s Background to Transparent
Add a Rectangle to the parent panel of the window
Set the opacity of the rectangle to some value &#60; 1 (0.7, &#8230;)
Add your controls [...]]]></description>
			<content:encoded><![CDATA[<p>Ever felt like having a transparent window background and still opaque controls inside the window? It can be easily done in wpf.</p>
<ol>
<li>Set the window&#8217;s <strong>AllowsTransparency</strong> to <em>True</em></li>
<li>Set the window&#8217;s <strong>Background</strong> to <em>Transparent</em></li>
<li><strong>Add a Rectangle </strong>to the parent panel of the window</li>
<li>Set the <strong>opacity</strong> of the rectangle to some value <em>&lt; 1 </em>(0.7, &#8230;)</li>
<li><strong>Add your controls </strong>to the parent panel</li>
<li>You are one step away form seeing a transparent background with opaque controls on top of it. Go ahead, run the application now</li>
</ol>
<p>Sample window,</p>
<p>&lt;Window x:Class=&#8221;BackgroundWindow.Transparent.Samples.WPF.Window1&#8243;<br />
xmlns=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;<br />
xmlns:x=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;<br />
Title=&#8221;Window1&#8243; Height=&#8221;300&#8243; Width=&#8221;300&#8243; AllowsTransparency=&#8221;True&#8221; Background=&#8221;Transparent&#8221; WindowStyle=&#8221;None&#8221;&gt;<br />
&lt;Grid&gt;<br />
&lt;Rectangle Fill=&#8221;Gray&#8221; Opacity=&#8221;0.7&#8243; /&gt;<br />
&lt;Button Width=&#8221;100&#8243; Height=&#8221;100&#8243;&gt;Click this on&lt;/Button&gt;<br />
&lt;/Grid&gt;<br />
&lt;/Window&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/01/13/transparent-background-with-opaque-controls-on-top-of-it/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: MDI in WPF</title>
		<link>http://codelog.blogial.com/2010/01/13/douno-mdi-is-missing-in-wpf/</link>
		<comments>http://codelog.blogial.com/2010/01/13/douno-mdi-is-missing-in-wpf/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 03:37:19 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

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

		<category><![CDATA[General Programming]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=488</guid>
		<description><![CDATA[WPF, out of the box doesn&#8217;t have provision for MDI windows. The reason is quite simple, MDI windows are outdated and most of the applications have been using tabbed documents, proving they are really easy to use. Although the framework is flexible enough for you to make such a feature, its better to move to [...]]]></description>
			<content:encoded><![CDATA[<p>WPF, out of the box doesn&#8217;t have provision for MDI windows. The reason is quite simple, MDI windows are outdated and most of the applications have been using tabbed documents, proving they are really easy to use. Although the framework is flexible enough for you to make such a feature, its better to move to tab based interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/01/13/douno-mdi-is-missing-in-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mashing Twitter and FSO</title>
		<link>http://codelog.blogial.com/2009/12/06/mashing-twitter-and-fso/</link>
		<comments>http://codelog.blogial.com/2009/12/06/mashing-twitter-and-fso/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 14:46:59 +0000</pubDate>
		<dc:creator>sup3rkiddo</dc:creator>
		
		<category><![CDATA[General Programming]]></category>

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

		<category><![CDATA[Tips 'n' Tricks]]></category>

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

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

		<category><![CDATA[freesmartphone.org]]></category>

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

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=483</guid>
		<description><![CDATA[

I really love Twitter and it didn’t make any sense to me to shell out a rupee for every tweet sent through my Airtel Mobile. Moreover, I am on one of those monthly booster packs which allows you to send 22000 text messages for free. I simply had to exploit this by setting up my [...]]]></description>
			<content:encoded><![CDATA[<div class="itemtext">
<div class="snap_preview">
<p>I really love Twitter and it didn’t make any sense to me to shell out a rupee for every tweet sent through my Airtel Mobile. Moreover, I am on one of those monthly booster packs which allows you to send 22000 text messages for free. I simply had to exploit this by setting up my own little ‘OC’ twitter forwarder written in python. (I know of smstweet.in service but I am still charged 1.50 for every tweet I send)</p>
<p>Its insanely simple to write such a ‘forwarder’ in python using the services provided by the FSO (<a href="http://wiki.freesmartphone.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.freesmartphone.org');">freesmartphone.org</a>) Framework,</p>
<ol>
<li>Send messages to your old/unused number whose SIM is in the <a href="http://openmoko.com/freerunner.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/openmoko.com');">Freerunner</a> (or any other device supported by the <a href="http://wiki.freesmartphone.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.freesmartphone.org');">FSO</a> framework)</li>
<li>Handle the incoming messages and use <a href="http://code.google.com/p/python-twitter/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">python-twitter</a> API (or) raw urllib2 to post updates. Of course, the device should be connected to the internet, you can <a href="http://wiki.openmoko.org/wiki/Usb_networking" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.openmoko.org');">tether</a> this device to an old unused computer. Simply put, the Freerunner should be able to access the internet.</li>
</ol>
<p>I know this is dumb given cheap GPRS and all, but what the heck; Sundays _are_ reserved for dumb things and I wanted to show off how easy it is to develop and conjure up simple but powerful scripts using open hackable hardware like the Freerunner. So take off your pedantic hats <img class="wp-smiley" src="http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif" alt=";)" /></p>
<p>Here is the actual python code,</p>
<p>–</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># Written By Sudharshan S, http://sudharsh.wordpress.com</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> dbus
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> twitter
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> gobject
<span style="color: #ff7700;font-weight:bold;">from</span> gobject <span style="color: #ff7700;font-weight:bold;">import</span> MainLoop
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> dbus.<span style="color: black;">mainloop</span>.<span style="color: black;">glib</span> <span style="color: #ff7700;font-weight:bold;">import</span> DBusGMainLoop
DBusGMainLoop <span style="color: black;">&#40;</span>set_as_default = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use OAUTH?</span>
USERNAME = <span style="color: #483d8b;">&quot;username&quot;</span>
PASSWORD = <span style="color: #483d8b;">&quot;password&quot;</span>
&nbsp;
log = <span style="color: #dc143c;">logging</span>.<span style="color: black;">getLogger</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;TweetForwarder&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> TweetForwarder:
&nbsp;
   <span style="color: #483d8b;">&quot;&quot;&quot;Process Incoming messages and update twitter status
      if the message startswith 'tweet'
   &quot;&quot;&quot;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, username, password<span style="color: black;">&#41;</span>:
       log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Starting up....&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">twitter_api</span> = twitter.<span style="color: black;">Api</span><span style="color: black;">&#40;</span>username=username, password=password<span style="color: black;">&#41;</span>
&nbsp;
       <span style="color: #808080; font-style: italic;"># Get proxies and add signal handlers</span>
       bus = dbus.<span style="color: black;">SystemBus</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
       _usage = bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;org.freesmartphone.ousaged&quot;</span>,
                               <span style="color: #483d8b;">&quot;/org/freesmartphone/Usage&quot;</span><span style="color: black;">&#41;</span>
       _proxy = bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;org.freesmartphone.ogsmd&quot;</span>, \
                               <span style="color: #483d8b;">&quot;/org/freesmartphone/GSM/Device&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">usage_iface</span> = dbus.<span style="color: black;">Interface</span><span style="color: black;">&#40;</span>_usage, <span style="color: #483d8b;">&quot;org.freesmartphone.Usage&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">usage_iface</span>.<span style="color: black;">RequestResource</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'GSM'</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">sms_iface</span> = dbus.<span style="color: black;">Interface</span> <span style="color: black;">&#40;</span>_proxy, <span style="color: #483d8b;">&quot;org.freesmartphone.GSM.SMS&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">sms_iface</span>.<span style="color: black;">connect_to_signal</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;IncomingMessage&quot;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">onIncomingMessage</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> onIncomingMessage<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, sender, message, kwargs<span style="color: black;">&#41;</span>:
       log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Received SMS from %s:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>sender, message<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
       <span style="color: #808080; font-style: italic;"># We don't ALL messages to this number to be tweeted</span>
       <span style="color: #ff7700;font-weight:bold;">if</span> message.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;tweet &quot;</span><span style="color: black;">&#41;</span>:
           log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Trying to update status : %s&quot;</span> <span style="color: #66cc66;">%</span> message<span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span>:<span style="color: black;">&#93;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
           <span style="color: #008000;">self</span>.<span style="color: black;">twitter_api</span>.<span style="color: black;">PostUpdate</span><span style="color: black;">&#40;</span>message<span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
           log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Updated Status&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
       loop = MainLoop<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
       loop.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #dc143c;">logging</span>.<span style="color: black;">basicConfig</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    server = TweetForwarder<span style="color: black;">&#40;</span>USERNAME, PASSWORD<span style="color: black;">&#41;</span>
    server.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
--</pre></div></div>

<p>Make sure you have python-netclient and python-json installed on your Freerunner. These can be installed using the ‘opkg install’ command.</p>
<p>The script and the accompanying dependency can be downloaded from <a href="http://gitorious.org/dumb-scripts/dumb-scripts/archive-tarball/master" onclick="javascript:pageTracker._trackPageview('/outbound/article/gitorious.org');">here</a>. Just change the USERNAME and PASSWORD accordingly after scp’ing the tarball to your device.</p>
<p>Some useful links,</p>
<p>[1]: <a href="http://git.freesmartphone.org/?p=specs.git;a=tree;f=html;h=bb7b2226c03c13b7c930e119c0df4bd0c91c06bb;hb=2a40169edbec7a2fcb804aa45e496df01aeba782" onclick="javascript:pageTracker._trackPageview('/outbound/article/git.freesmartphone.org');">The FSO API reference</a></p>
<p>[2]: <a href="http://dbus.freedesktop.org/doc/dbus-tutorial.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/dbus.freedesktop.org');">DBus Tutorial</a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/12/06/mashing-twitter-and-fso/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: Popup animation in wpf</title>
		<link>http://codelog.blogial.com/2009/12/03/douno-popup-animation-in-wpf/</link>
		<comments>http://codelog.blogial.com/2009/12/03/douno-popup-animation-in-wpf/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:58:24 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

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

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

		<category><![CDATA[Tips 'n' Tricks]]></category>

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=480</guid>
		<description><![CDATA[Every time I try adding a default animation (Slide, Fade, &#8230;) to a pop up in WPF, I find it not to be working. Today, I went thru&#8217; MSDN (breaking my laziness  ) and found that the popup animation shall work only if the AllowsTransparency of the popup is set to true. Really weird [...]]]></description>
			<content:encoded><![CDATA[<p>Every time I try adding a default animation (Slide, Fade, &#8230;) to a pop up in WPF, I find it not to be working. Today, I went thru&#8217; MSDN (breaking my laziness <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) and found that the popup animation shall work only if the <a href="http://msdn.microsoft.com/en-us/library/ms749018.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank"><em>AllowsTransparency</em> of the popup is set to <em>true</em></a>. Really weird !!</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/12/03/douno-popup-animation-in-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: Setting expectations on nullable type, NMock2</title>
		<link>http://codelog.blogial.com/2009/11/06/douno-setting-expectations-on-nullable-type-nmock2/</link>
		<comments>http://codelog.blogial.com/2009/11/06/douno-setting-expectations-on-nullable-type-nmock2/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 03:38:15 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

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

		<category><![CDATA[General Programming]]></category>

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

		<category><![CDATA[Tips 'n' Tricks]]></category>

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=469</guid>
		<description><![CDATA[Ever had a problem of setting an expectation for nullable objects?
If you wanna return false when .HasValue of a nullable object is called, then you cannot do it with the normal expect statement. Rather, try not returning any values, because NMock2 returns default value of HasValue (False) if nothing is set as return values in [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had a problem of setting an expectation for nullable objects?</p>
<p>If you wanna return false when .HasValue of a nullable object is called, then you cannot do it with the normal expect statement. Rather, try not returning any values, because NMock2 returns default value of HasValue (False) if nothing is set as return values in expect statements.</p>
<p>Here is a sample,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IProduct  <span style="color: #008080; font-style: italic;">//Interface that has a nullable member</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">int</span><span style="color: #008000;">?</span> ProductNo  <span style="color: #008080; font-style: italic;">//Member that I wanna test and I wish to test the scenario in which this will be null</span>
  <span style="color: #000000;">&#123;</span>
    get<span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">IProduct aProduct<span style="color: #008000;">=</span> myMockery.<span style="color: #0000FF;">NewMock</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>IProduct<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//Stub.On(aProduct).GetProperty(&quot;ProductNo&quot;).Will(Return.Value(default(int?));  //this statement produces a runtime exception, so we have to use the following instead</span>
Stub.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>aProduct<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperty</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ProductNo&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">//no return value is set, nmock2 returns false when .HasValue is queries</span></pre></div></div>

<p>Hope this helped you.</p>
<p>Sudarsan Srinivasan<br />
- on behalf of my friends (they found this hack <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/11/06/douno-setting-expectations-on-nullable-type-nmock2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Settings expectations in NMock2</title>
		<link>http://codelog.blogial.com/2009/09/03/settings-expectations-in-nmock2/</link>
		<comments>http://codelog.blogial.com/2009/09/03/settings-expectations-in-nmock2/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 08:54:20 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

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

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

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

		<guid isPermaLink="false">http://codelog.blogial.com/?p=449</guid>
		<description><![CDATA[One of our previous articles would have given an introduction to NMocks. In here, we will try out various methods of setting expectations when we do a unit test.
note &#8212; this article considers that you know the basics of unit testing. check out our previous article if you would like to know the basics of [...]]]></description>
			<content:encoded><![CDATA[<p>One of our <a href="http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/"  target="_blank">previous articles </a>would have given an introduction to NMocks. In here, we will try out various methods of setting expectations when we do a unit test.</p>
<p><span style="color: #808080">note &#8212; this article considers that you know the basics of unit testing. check out our previous article if you would like to know the basics of nmock2</span></p>
<p>In NMock2, you have a wide variety of setting expectations on mocked objects.</p>
<p><strong>Stubs</strong></p>
<p>Stubs are expectations whose occurrences are unknown. We use stubs when we are not sure the number of times it might be called. So generally Stubs are used when expectations needs to be set 0 or more times</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Stub.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockedObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">//Use this only when you are unaware of the occurrences,</span>
                                            <span style="color: #008080; font-style: italic;">//otherwise you end up writing a bad UT</span></pre></div></div>

<p><strong>Expect</strong></p>
<p>We use the Expect class when the number of calls to the method or property of the mock objects are known.</p>
<p><em>For example, </em></p>
<p>If number of occurrences are 7 on the method called, &#8220;<strong>GetName</strong>&#8220;, then use,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Exactly</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p>If the number of occurrence is 1 on the method called, &#8220;<strong>GetName</strong>&#8220;, then use,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Exactly</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p>You can even set negative expectations. For example,<br />
If you are pretty sure that the method &#8220;<strong>GetName</strong>&#8220;, will not/should not be called in your unit test, then use,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Never</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p><strong>Expectation With Parameters</strong></p>
<p>If you are unit testing a method that makes a call to an interface which inturn takes two params and if you know the values of those params, you could set expectation on the mock object for the method with the known params.</p>
<p><em>For example, </em></p>
<p>If &#8220;GetName&#8221; method takes two params and if the param values are &#8220;foo&#8221; and &#8220;bar&#8221; according to the unit test case, then we can write an expectation as,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">With</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;foo&quot;</span>, <span style="color: #666666;">&quot;bar&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p><strong>Expectation On Events</strong></p>
<p>You can add expectation on events of the mock object with the <strong>EventAdd </strong>method.</p>
<p><em>For example, </em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Foo
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler ObjectChanged<span style="color: #008000;">;</span>
  ...
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FooBarBaz
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">private</span> Foo myFoo<span style="color: #008000;">;</span>
  ...
  <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> SomeMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    myFoo.<span style="color: #0000FF;">ObjectChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>Foo__ObjectChanged<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    ...
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you are writing a unit test for the method <strong>SomeMethod</strong>, then you shall add an expectation of the following form,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">EventAdd</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ObjectChanged&quot;</span>, <span style="color: #008000;">Is</span>.<span style="color: #0000FF;">Anything</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>Expecting Exceptions</strong></p>
<p>You could also expect exceprions by adding the attribute, ExpectedException on top of your unit test.</p>
<p><em>For example, </em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#40;</span>Description<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Test case method that will test whether the ArgumentNullException is raised&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#91;</span>ExpectedException<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ArgumentNullException<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> TestExceptionalScenario<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  ...
  <span style="color: #008080; font-style: italic;">//call the method that is supposed to throw the ArgumentNullException</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>These are the commonly used expectations. If you have used something really weird, I <span style="color: #ff6600"><strong>expect </strong>you share it with us     <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />        <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/09/03/settings-expectations-in-nmock2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Accessing Command Prompt from C#</title>
		<link>http://codelog.blogial.com/2009/08/31/accessing-command-prompt-from-c/</link>
		<comments>http://codelog.blogial.com/2009/08/31/accessing-command-prompt-from-c/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 12:14:37 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[General Programming]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=446</guid>
		<description><![CDATA[Recently, I wanted to write a program in c# that should start the command prompt in the background (it should not show the cmd window), give inputs from my C# program and get the results redirected back to my C# application. I was googling around a bit and then came up with a solution.
Its damn [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I wanted to write a program in c# that should start the command prompt in the background (it should not show the cmd window), give inputs from my C# program and get the results redirected back to my C# application. I was googling around a bit and then came up with a solution.</p>
<p>Its damn simple. Usually to start any process from C# applications, we use the <em>Process </em>object. The process object has two properties called <strong>StandardInput </strong>and <strong>StandardOutput</strong>. These properties will allow the C# application to get the input stream of the process that needs to be started. So to mock inputs and outputs, we need to do the following,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Process aProcess <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Process<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
ProcessStartInfo aStartInfo <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProcessStartInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
aStartInfo.<span style="color: #0000FF;">FileName</span> <span style="color: #008000;">=</span> Environment.<span style="color: #0000FF;">GetFolderPath</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">SpecialFolder</span>.<span style="color: #000000;">System</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>cmd.exe&quot;</span><span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">StartInfo</span> <span style="color: #008000;">=</span> aStartInfo<span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">StandardInput</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;dir&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">//will open a cmd process and feed the command &quot;dir&quot; to it</span></pre></div></div>

<p>By this way you could give inputs to a process that you start from C#. What if you wanna see output of the cmd prompt in your own prompt ?? For this we use the <strong>StandardOutput</strong> property. But there is yet another simple way to get the output from the command prompt. This is done by subscribing for the event, <strong>OutputDataReceived</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">aProcess.<span style="color: #0000FF;">OutputDataReceived</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> DataReceivedEventHandler<span style="color: #000000;">&#40;</span>Process_OutputDataReceived<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> Process_OutputDataReceived<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DataReceivedEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  textBox1.<span style="color: #0000FF;">AppendText</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Data</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  textBox1.<span style="color: #0000FF;">AppendText</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">NewLine</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Note: These ways are possible only if, </strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">aProcess.<span style="color: #0000FF;">RedirectStandardOutput</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">UseShellExecute</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">BeginOutputReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>are set to the mentioned values. <strong>BeginOutputReadLine </strong>method will start async read operations from the C# application stream instead of the standard input devices. So next time you wanna clone a command prompt, start the cmd process and give your own look and feel to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/08/31/accessing-command-prompt-from-c/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
