<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Elias Puurunen, @agFinn</title>
	<atom:link href="http://puurunen.ca/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://puurunen.ca/blog</link>
	<description>My thoughts on coding, life, and everything else.</description>
	<lastBuildDate>Sat, 21 Apr 2012 07:51:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>PodTower5 Preview, and a Life Recap!</title>
		<link>http://puurunen.ca/blog/?p=236</link>
		<comments>http://puurunen.ca/blog/?p=236#comments</comments>
		<pubDate>Sat, 21 Apr 2012 07:47:24 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[Aspect-Oriented Programming]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[PodTower]]></category>
		<category><![CDATA[PostSharp]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://puurunen.ca/blog/?p=236</guid>
		<description><![CDATA[Yes, I&#8217;m still around, and yes, I&#8217;m still coding. Things just happened to get a little busy, what with finishing a university degree and everything. I&#8217;ve been slacking a bit on the PodTower side though. I haven&#8217;t abandoned it, I&#8217;ve just needed a small stretch of free time where I felt inspired both from a]]></description>
			<content:encoded><![CDATA[<p>Yes, I&#8217;m still around, and yes, I&#8217;m still coding. Things just happened to get a little busy, what with finishing a university degree and everything. I&#8217;ve been slacking a bit on the PodTower side though. I haven&#8217;t abandoned it, I&#8217;ve just needed a small stretch of free time where I felt inspired both from a coding and design perspective.<span id="more-236"></span> On the design side, I took a nod from Metro (and put my own small twists on it), and redid the entire UI.</p>
<p>For a comparison, let&#8217;s take a look at PodTower over the ages. This screenshot is from May 31, 2010 (holy crap, Batman&#8230; coming up on two years of PodTower?).</p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/PodTower-Next.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/PodTower-Next-300x170.png" alt="" title="PodTower" width="300" height="170" class="aligncenter size-medium wp-image-237" /></a></p>
<p>As you can see, it used the Expression Dark theme. Everything was on one screen &#8211; the list of podcasts, episodes, status, etc. Large margins on everything. It worked, but it wasn&#8217;t ideal. After some more enhancements, within a few days I had this.</p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/image_3.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/image_3-300x181.png" alt="" title="image_3" width="300" height="181" class="aligncenter size-medium wp-image-238" /></a></p>
<p>Even more stuff on the screen, and a huge title to boot! The biggest complaint I heard was that people didn&#8217;t know what the two gray bars did. The one on the right controlled volume, and the left controlled the playback position, the &#8220;scrubber.&#8221; Too busy&#8230; I didn&#8217;t like this layout. But I still continued with it. By August 2010 I had this.</p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/PodTower-1.0.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/PodTower-1.0-300x189.png" alt="" title="PodTower-1.0" width="300" height="189" class="aligncenter size-medium wp-image-239" /></a></p>
<p>This was the pinnacle of PodTower, the first major release. I left it alone for quite a while after this, putting off doing the major recoding. I had started the original version sometime in April 2010, using Web Developer Express on my laptop. Throughout the whole project, from a coding perspective, I was just learning how to use PRISM and the Managed Extensibility Framework. At the same time, in school I was just starting to cover design patterns, improving on the self-taught stuff, making my transformation from code monkey to code craftsman. I&#8217;m certainly not where I want to be yet, but I&#8217;ve learned so much over the last two years.</p>
<p>Back on topic, PodTower was left alone for quite a while. At the end of 2010, I was spending my time in C-land, taking courses on Operating Systems, Algorithms, and Database Management Systems. I was knee-deep in the code, and what an experience it was. After this, I spent the winter working for the National Research Council of Canada, and then returned to Waterloo in May 2011. Sometime through this period, I started the major rewrite. I started with the UI, and came up with&#8230;</p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/PodTower2-Alpha-0004.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/PodTower2-Alpha-0004-300x190.png" alt="" title="PodTower2-Alpha-0004" width="300" height="190" class="aligncenter size-medium wp-image-240" /></a></p>
<p>After sending the preview screenshots off to a few friends and getting feedback (keep in mind, this is around May-June 2011, and I was taking a UI course at the time), I tweaked the design a bit more, and&#8230;</p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/Podtower2-Beta0-0001.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/Podtower2-Beta0-0001-300x190.png" alt="" title="Podtower2-Beta0-0001" width="300" height="190" class="aligncenter size-medium wp-image-241" /></a></p>
<p>&#8230;and that&#8217;s how PodTower has remained since. Almost 10 months completely untouched, a bunch of side-projects, school terms and work terms later, and we find ourselves at today. After playing with the Windows 8 Preview and looking into the Metro designs, I came up with this&#8230; written in Silverlight 5 (and waiting for a Metro port at some point)&#8230;</p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/Capture.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/Capture-300x280.png" alt="" title="Capture" width="300" height="280" class="aligncenter size-medium wp-image-242" /></a></p>
<p>Simple. Elegant. Refined. <em>Finally something I can look at and go, &#8220;Yes, that&#8217;s the design I want.&#8221;</em></p>
<p><a href="http://puurunen.ca/blog/wp-content/uploads/2012/04/Capture0002.png"><img src="http://puurunen.ca/blog/wp-content/uploads/2012/04/Capture0002-300x280.png" alt="" title="Capture0002" width="300" height="280" class="aligncenter size-medium wp-image-243" /></a></p>
<p>So there we go. Almost two years of PodTower, and while it took a long while to do the rewrite of both the underlying code and the UI&#8230; I think it&#8217;s going to be totally worth the wait. Just for the record, this project is being built with Postsharp, and the PRISM libraries. </p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=236</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mapping XML Namespaces to CLR Namespaces</title>
		<link>http://puurunen.ca/blog/?p=233</link>
		<comments>http://puurunen.ca/blog/?p=233#comments</comments>
		<pubDate>Mon, 24 Oct 2011 14:20:48 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[PodTower]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://puurunen.ca/blog/?p=233</guid>
		<description><![CDATA[Over time when working on a Silverlight project, you may end up creating UserControls or custom controls that are in a shared library and referenced in your main application. In order to keep things organized, you may end up refactoring these controls into distinct namespaces that relate to their specific function. After a while, you]]></description>
			<content:encoded><![CDATA[<p>Over time when working on a Silverlight project, you may end up creating UserControls or custom controls that are in a shared library and referenced in your main application. In order to keep things organized, you may end up refactoring these controls into distinct namespaces that relate to their specific function. After a while, you might find that your xmlns declarations at the root of your XAML control become littered, and time is wasted on trying to remember what control exists in which namespace.<span id="more-233"></span></p>
<p>As it turns out, you can add an attribute to your assemblies that maps a given CLR namespace to an XML namespace. The full documentation is <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xmlnsdefinitionattribute%28v=vs.95%29.aspx">on MSDN</a>, but for the impatient, here&#8217;s how to use it.</p>
<ol>
<li>Open Properties/AssemblyInfo.cs</li>
<li>Add a using declaration for System.Windows.Markup</li>
<li>Add the following line: [assembly: XmlnsDefinition("XMLNamespace", "CLRNamespace")], replacing XMLNamespace with the XML namespace you want to use (for example, http://www.puurunen.ca/controls) and CLRNamespace with the corresponding CLR namespace (for example, Podtower.Shared.Controls)</li>
</ol>
<p>Once the project is rebuilt, Intellisense should pick this up in XAML. Note that the XML namespace can be one-to-many &#8211; this means you can map a bunch of different namespaces to one XML namespace! This is how Telerink maps all of their controls to http://schemas.telerik.com/2008/xaml/presentation, for instance.</p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=233</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Snippet &#8211; WCF RIA Services Insert/Update/Delete Methods</title>
		<link>http://puurunen.ca/blog/?p=226</link>
		<comments>http://puurunen.ca/blog/?p=226#comments</comments>
		<pubDate>Wed, 21 Sep 2011 14:18:08 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=226</guid>
		<description><![CDATA[I don&#8217;t know what it is about Microsoft technologies, but it seems like almost every time I use another one, it&#8217;s a reminder of why developing in this space rocks so much. Recently, I&#8217;ve been working on a project that uses WCF RIA Services, and needed a way to add create/update/delete methods for new entities]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know what it is about Microsoft technologies, but it seems like almost every time I use another one, it&#8217;s a reminder of why developing in this space rocks so much. Recently, I&#8217;ve been working on a project that uses WCF RIA Services, and needed a way to add create/update/delete methods for new entities in my domain service. <span id="more-226"></span>So, I created a snippet, since I haven&#8217;t yet sat down and learned how to do the same thing in CodeRush yet.</p>
<p>This snippet assumes you&#8217;re using a domain service that derives from LinqToEntitiesDomainService, and that your entities were pluralized when you generated them using the entity framework. I believe they follow the naming conventions for create/update/delete operations, <a href="http://msdn.microsoft.com/en-us/library/ee707373%28v=vs.91%29.aspx">as outlined at MSDN</a>. The only parameter the snippet expects is the type of entity to be used in the method.</p>
<pre class="brush:xml">
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Define create, update, delete data operations.</Title>
            <Shortcut>cuds</Shortcut>
            <Description>Defines CUD operations for a type. Assumes pluralized.</Description>
            <Author>Elias Puurunen</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Entity Type</ToolTip>
                    <Default>object</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[[Insert]
public void Insert$type$($type$ toInsert)
{
    if ((toInsert.EntityState != EntityState.Detached))
    {
        this.ObjectContext.ObjectStateManager.ChangeObjectState(toInsert, EntityState.Added);
    }
    else
    {
        this.ObjectContext.$type$s.AddObject(toInsert);
    }
}

[Update]
public void Update$type$($type$ toUpdate)
{
    this.ObjectContext.$type$s.AttachAsModified(toUpdate, this.ChangeSet.GetOriginal(toUpdate));
}

[Delete]
public void Delete$type$($type$ toDelete)
{
    if ((toDelete.EntityState != EntityState.Detached))
    {
        this.ObjectContext.ObjectStateManager.ChangeObjectState(toDelete, EntityState.Deleted);
    }
    else
    {
        this.ObjectContext.$type$s.Attach(toDelete);
        this.ObjectContext.$type$s.DeleteObject(toDelete);
    }
}$end$]]&gt;
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=226</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF NetTcpBinding and Silverlight &#8211; &#8220;An existing connection was forcibly closed by the remote host&#8221;</title>
		<link>http://puurunen.ca/blog/?p=223</link>
		<comments>http://puurunen.ca/blog/?p=223#comments</comments>
		<pubDate>Wed, 31 Aug 2011 06:19:24 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=223</guid>
		<description><![CDATA[Over the past few nights, I&#8217;ve been working on an awesome application that uses ASP.NET MVC, .NET 4.0, WCF, and WinAMP all at the same time. One component I wanted to build was a visual equalizer, and I decided that Silverlight would be the best fit for this job. While I was working on the]]></description>
			<content:encoded><![CDATA[<p>Over the past few nights, I&#8217;ve been working on an awesome application that uses ASP.NET MVC, .NET 4.0, WCF, and WinAMP all at the same time. One component I wanted to build was a visual equalizer, and I decided that Silverlight would be the best fit for this job. <span id="more-223"></span>While I was working on the Silverlight application, I added another endpoint in the WCF application on port 4502 so the Silverlight application could access it without requiring elevate privileges, and added the service reference to the Silverlight application. Upon running the application however, every access to the remote service would fail, with the inner exception being explained mysteriously as &#8220;An existing connection was forcibly closed by the remote host.&#8221;</p>
<p>After pouring over the <a href="http://msdn.microsoft.com/en-us/library/cc645027%28v=vs.95%29.aspx">always useful MSDN documentation</a>, I tried modifying my netTcpBinding to include the security mode of &#8220;None.&#8221; Amazingly, this solved the issue!</p>
<pre class="brush:xml">
        <bindings>
            <netTcpBinding>
              <binding name="TCPBinding">
                <security mode="None" />
              </binding>
            </netTcpBinding>
        </bindings>
</pre>
<p>Make sure to set the bindingConfiguration in your service endpoint to the name of the binding, and it should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=223</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Implicit Data Templates in Silverlight 5!</title>
		<link>http://puurunen.ca/blog/?p=217</link>
		<comments>http://puurunen.ca/blog/?p=217#comments</comments>
		<pubDate>Mon, 08 Aug 2011 02:22:23 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Databinding]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=217</guid>
		<description><![CDATA[One of the new features in Silverlight 5 is implicit data templates, which at first glace, sounds about as exciting as a Sunday drive in an electric vehicle-only mode Prius. But you&#8217;d be wrong. The basic premise behind an implicit template is simple. Normally, you would declare a DataTemplate in XAML, then associate it with]]></description>
			<content:encoded><![CDATA[<p>One of the new features in Silverlight 5 is implicit data templates, which at first glace, sounds about as exciting as a Sunday drive in an electric vehicle-only mode Prius. But you&#8217;d be wrong.<span id="more-217"></span> The basic premise behind an implicit template is simple. </p>
<p>Normally, you would declare a DataTemplate in XAML, then associate it with a key, and then set an ItemsControl of some sort to use the named resource. In an implicit template, you don&#8217;t set the ItemsControl&#8217;s ItemTemplate property, and you omit the key on the DataTemplate. Instead, you associate it with a DataType, and at runtime, this template is applied to items matching the specified type of the DataTemplate.</p>
<p>In <a href="http://10rem.net/blog/2011/04/13/silverlight-5-working-with-implicit-templates">Pete Brown&#8217;s article</a> on implicit templates, he demonstrates how to display different Twitter message types by having a base TwitterItem class, then other classes (such as DirectMessage) that derive from this class, ultimately instances of which are added to an ObservableCollection of type TwitterItem. Where the real power shines though, is in the fact that implicit data templates, at least in the Silverlight 5 beta, <strong>are not limited to being applied to ItemsControls!</strong> In fact, they can be used by ContentControls as well. <em>Note &#8211; I couldn&#8217;t get them to work with the TreeView control in the beta, and I&#8217;m not quite sure why.</em></p>
<p>As far as I understand it, resource lookup for implicit templates appear to work as follows &#8211; the control searches for a DataTemplate matching the given DataType in its local resources, then moves up the visual tree to it&#8217;s parent and so on, until it eventually reaches the application level. If it can&#8217;t find a template, it uses the usual ToString() output. </p>
<p>Be careful when defining your DataTemplates &#8211; if you have two DataTemplates in the same ResourceDictionary that correspond to the same DataType, you&#8217;ll get a XamlParseException at runtime. It&#8217;ll look similar to this.<br />
</a><br />
<img src="http://silverfinn.net/blog/wp-content/uploads/2011/08/XamlParseError.png" alt="Display of a XAML parse exception." title="Display of a XAML parse exception." width="455" height="274" class="aligncenter size-full wp-image-219" /></p>
<p>Example code is available <a href="http://silverfinn.net/demo/helloimplicittemplates.zip">for download here</a>. For reference, here&#8217;s the XAML associated with this application. If you want to play with a live demo, <a href="http://silverfinn.net/demo/demo1.html">you can try out the code here.</p>
<pre class="brush:xml">
<UserControl x:Class="HelloImplicitTemplates.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:HelloImplicitTemplates"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400">

    <UserControl.Resources>
        <DataTemplate DataType="local:Person">
            <StackPanel>
                <TextBlock FontWeight="Bold"
                           Margin="3"
                           Text="I'm coming from the usercontrol resources! My name is" />
                <TextBlock Margin="3"
                           Text="{Binding Name}" />
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"
          Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition MinWidth="150" />
        </Grid.ColumnDefinitions>

        <ContentControl Content="{Binding ElementName=peopleList, Path=SelectedItem}"
                        Margin="6">
            <ContentControl.Resources>
                <DataTemplate DataType="local:PointyHairedBoss">
                    <Image HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Source="/HelloImplicitTemplates;component/boss.jpg" />
                </DataTemplate>
            </ContentControl.Resources>
        </ContentControl>

        <ListBox ItemsSource="{Binding}"
                 x:Name="peopleList"
                 Grid.Column="1"
                 Margin="6">
            <ListBox.Resources>
                <DataTemplate DataType="local:OfficeGopher">
                    <StackPanel>
                        <TextBlock FontWeight="Bold"
                                   Margin="3"
                                   Text="Office Gopher" />
                        <TextBlock Margin="3"
                                   Text="{Binding Name}" />
                    </StackPanel>
                </DataTemplate>
                <DataTemplate DataType="local:PointyHairedBoss">
                    <StackPanel>
                        <TextBlock FontWeight="Bold"
                                   Margin="3"
                                   Text="El Bossman" />
                        <TextBlock Margin="3"
                                   Text="{Binding Name}" />
                    </StackPanel>
                </DataTemplate>
                <DataTemplate DataType="local:Programmer">
                    <StackPanel>
                        <TextBlock FontWeight="Bold"
                                   Margin="3"
                                   Text="Elite Programming Guard" />
                        <TextBlock Margin="3"
                                   Text="{Binding Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.Resources>
            <Image />
        </ListBox>
    </Grid>
</UserControl>
</pre>
<p>One last comment &#8211; Visual Studio 2010 will complain that each DataTemplate is Invalid XAML. Ignore this error &#8211; apparently this is a known bug.</p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=217</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refactoring Activities in an Android Application &#8211; Watch your Package</title>
		<link>http://puurunen.ca/blog/?p=215</link>
		<comments>http://puurunen.ca/blog/?p=215#comments</comments>
		<pubDate>Wed, 27 Jul 2011 22:00:51 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile Development]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=215</guid>
		<description><![CDATA[Tonight, while working on an Android application, I ran into a slight difficulty when refactoring my activities. Specifically, I wanted to organize my packages a little more, so I created a subpackage called activities, and moved all of my activities into it. Eclipse renamed and updated all my references properly (or so I thought), and]]></description>
			<content:encoded><![CDATA[<p>Tonight, while working on an Android application, I ran into a slight difficulty when refactoring my activities. Specifically, I wanted to organize my packages a little more, so I created a subpackage called activities, and moved all of my activities into it.<span id="more-215"></span> Eclipse renamed and updated all my references properly (or so I thought), and the whole thing compiled without error. However, as soon as I launched, my application threw an unhandled exception, and I had to force quit it.</p>
<p>It turns out Eclipse didn&#8217;t update the AndroidManifest.xml file for me when it took care of everything else. So, it couldn&#8217;t find the MAIN/LAUNCHER activity. Since my package layout was &#8220;application.android&#8221; and &#8220;application.android.activities&#8221; for the application and activities respectively, I had to append &#8220;.activities.&#8221; to each activity name.</p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=215</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 R2 Database Refactoring Strategy: Optional Stored Procedure Parameters</title>
		<link>http://puurunen.ca/blog/?p=208</link>
		<comments>http://puurunen.ca/blog/?p=208#comments</comments>
		<pubDate>Wed, 13 Jul 2011 17:14:51 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Visual Basic .NET]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=208</guid>
		<description><![CDATA[For the most part, refactoring a relational database sucks. Once it&#8217;s in production, changing any aspect of your schema can result in massive breaking changes. If you use SQL Server 2008 and stored procedures, you can mitigate this pain a slight amount. Like C# and Visual Basic.NET, you can introduce &#8220;optional&#8221; parameters into the sproc]]></description>
			<content:encoded><![CDATA[<p>For the most part, refactoring a relational database sucks. Once it&#8217;s in production, changing any aspect of your schema can result in massive breaking changes. If you use SQL Server 2008 and stored procedures, you can mitigate this pain a slight amount.<span id="more-208"></span></p>
<p>Like C# and Visual Basic.NET, you can introduce &#8220;optional&#8221; parameters into the sproc method signature without disturbing existing calls by adding the optional parameters at the end of the signature. For instance our original procedure looks as follows.</p>
<pre class="lang:sql">
ALTER PROCEDURE [dbo].[sp_sample_proc]
@param1 varchar(50),
AS
BEGIN
   SELECT col1, col2, col3, col4 FROM testTable
   WHERE col2 = @param1
END
</pre>
<p>And our new procedure looks as follows.</p>
<pre class="lang:sql">
ALTER PROCEDURE [dbo].[sp_sample_proc]
@param1 varchar(50),
@paramNew varchar(20) = NULL -- New proc added here.
AS
BEGIN
   SELECT col1, col2, col3, col4 FROM testTable
   WHERE col2 = @param1 AND
   col3 = ISNULL(@paramNew, col3);
END
</pre>
<p>I&#8217;ve added the new parameter, @paramNew, at the end of the signature. Now, to ensure existing queries aren&#8217;t disturbed, I&#8217;ve added a call to ISNULL to return the value of col3 if @paramNew is null, and if not, compare col3 to @paramNew.</p>
<p>Now, existing calls to this sproc remain the same. For instance, the original call
<pre class="lang:sql">EXECUTE sp_sample_proc 'Test Value'</pre>
<p> remains the same. Now, you can make a call to the sproc as follows:
<pre class="lang:sql">EXECUTE sp_sample_proc 'Test Value', 'Value 2'</pre>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=208</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How it Works: Windows Mobile RNDIS</title>
		<link>http://puurunen.ca/blog/?p=202</link>
		<comments>http://puurunen.ca/blog/?p=202#comments</comments>
		<pubDate>Tue, 28 Jun 2011 19:30:51 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Databinding]]></category>
		<category><![CDATA[Mobile Development]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=202</guid>
		<description><![CDATA[Today, I had to do a deep dive into Windows Mobile to figure out how a docked Windows Mobile device, specifically the Motorola MC9090 RFID reader, can access the network(s) of the machine it&#8217;s attached to. This seemed to be a magical, &#8220;it sometimes works&#8221; sort of thing, but I think I&#8217;ve nailed down how]]></description>
			<content:encoded><![CDATA[<p>Today, I had to do a deep dive into Windows Mobile to figure out how a docked Windows Mobile device, specifically the Motorola MC9090 RFID reader, can access the network(s) of the machine it&#8217;s attached to. This seemed to be a magical, &#8220;it sometimes works&#8221; sort of thing, but I think I&#8217;ve nailed down how it works, and how to always make it work.<span id="more-202"></span></p>
<p>First off, I&#8217;ll briefly touch on the technical details as I understand them. <strong>Note:</strong> if you just want to make it work, skip this part.</p>
<p>Based off of the always useful <a href="http://tinyurl.com/msdnrndis">MSDN documentation</a>, here&#8217;s how RNDIS works: When a Windows Mobile device is connected via USB to a computer, the RNDIS (Remote Network Driver Interface Specification) protocol is what allows IP packets to be wrapped and transmitted over the network. On the machine with ActiveSync installed is an extra virtual network card, this is internally used by the machine to transmit packets to and from the device. So essentially, the host machine is acting as a proxy for the mobile device, passing those packets onto the appropriate network interface and vice versa.</p>
<p><strong>Now, here&#8217;s how to make it work.</strong> First off, make sure <a href="http://www.microsoft.com/download/en/details.aspx?id=15">ActiveSync 4.5</a> (for Windows XP/Server 2003 and below) or <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&#038;id=14">Windows Mobile Device Center</a> (for Windows Vista/7/Server 2008) are installed, along with any drivers for your mobile device, if necessary. From my experience, if you install ActiveSync/WMDC these drivers are installed automatically.</p>
<p>Next, for ActiveSync, right-click the taskbar icon and click Connection Settings, as pictured.</p>
<p><img src="http://silverfinn.net/blog/wp-content/uploads/2011/06/ActiveSyncIcon.png" alt="The menu appearing after the ActiveSync icon is right-clicked on the taskbar." title="ActiveSync Menu" width="351" height="163" class="aligncenter size-full wp-image-203" /></p>
<p>Now, this part has <a href="http://silverfinn.net/blog/?p=75">bitten me before</a> &#8211; make sure that if you&#8217;re wanting to do any sort of HTTP requests over the network, that under &#8220;This computer is connected to,&#8221; &#8220;The Internet&#8221; is selected, <em>even if you&#8217;re not connected to the Internet.</em> Otherwise, from what I can tell the Windows Mobile device will refuse to make HTTP requests.</p>
<p>Aside from this, make sure your settings match the following. I have found that allowing connections from DMA makes no difference aside from during development time. You can still allow wireless if you so choose, however I do not know what metric the RNDIS adapter is assigned, however I am investigating this.</p>
<p><img src="http://silverfinn.net/blog/wp-content/uploads/2011/06/ActiveSyncSettings.png" alt="The ActiveSync settings dialog, with &quot;The Internet&quot; selected as the network the computer is connected to." title="ActiveSyncSettings" width="393" height="331" class="aligncenter size-full wp-image-204" /></p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=202</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with Apache Pivot 2.0!</title>
		<link>http://puurunen.ca/blog/?p=192</link>
		<comments>http://puurunen.ca/blog/?p=192#comments</comments>
		<pubDate>Tue, 21 Jun 2011 01:40:29 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Pivot]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=192</guid>
		<description><![CDATA[Over the last few days, I&#8217;ve begun to branch out and begin to learn Java once again. One of the main reasons I&#8217;ve largely ignored Java over the years is due to the lack of a modern UI toolkit. After being spoiled by the power of Windows Presentation Foundation and Silverlight, everything else seems so]]></description>
			<content:encoded><![CDATA[<p><img src="http://silverfinn.net/blog/wp-content/uploads/2011/06/logo1-150x150.png" alt="Apache Pivot Logo" title="logo" width="150" height="150" class="alignleft size-thumbnail wp-image-198" />Over the last few days, I&#8217;ve begun to branch out and begin to learn Java once again. One of the main reasons I&#8217;ve largely ignored Java over the years is due to the lack of a modern UI toolkit. After being spoiled by the power of Windows Presentation Foundation and Silverlight, everything else seems so ancient.<span id="more-192"></span> However, the people at Apache have created a somewhat awesome toolkit called <a href="http://pivot.apache.org/index.html">Pivot</a>. it has the beginnings of an awesome UI toolkit, but does feel rough around the edges at certain points.</p>
<p>The idea behind Pivot is to allow Java 6 developers to create &#8220;installable internet applications,&#8221; or IIAs as they refer to them. While Pivot provides much more than a UI toolkit (including web service methods, collections, etc.), what I&#8217;ll be focusing on here is the UI side of things, or how to quickly create an application that creates a UI from an XML file with a Java codebehind file.</p>
<p>First off, <a href="http://pivot.apache.org/download.cgi#2.0">head over to the Pivot site</a> and download the SDK. Grab the Binary distribution. Next, extract those files to a directory on your machine where you keep common JAR files (For my Linux development machine, they&#8217;re usually under /usr/lib; YMMV). </p>
<p>Now, if you&#8217;re using Eclipse, create a new Java project, and open up the properties dialog. Head over to Java Build Path, and click the Libraries tab. Click Add External JARs, and find where you put the Pivot JARs. Select those, hit OK, and hit OK once more.</p>
<p><a href="http://silverfinn.net/blog/wp-content/uploads/2011/06/HelloPivot0001.png"><img src="http://silverfinn.net/blog/wp-content/uploads/2011/06/HelloPivot0001-300x197.png" alt="Project properties dialog displaying the Pivot SDK path." title="HelloPivot0001" width="300" height="197" class="aligncenter size-medium wp-image-193" /></a></p>
<p>Now, create two packages: helloPivot and helloPivot.ui (do this by right-clicking the src directory, New, Package). Insert two files into the helloPivot package: App.java, and HelloWindow.java. Finally, add a text file to helloPivot.ui called HelloWindow.bxml. For this sample project, I&#8217;ve also downloaded the Apache Pivot logo to display on screen &#8211; place this in helloPivot.ui.</p>
<p>First off, the App.java file. I&#8217;ll present the file, then describe what&#8217;s going on.</p>
<pre class="brush:java">
package helloPivot;

import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.*;
import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.*;

public class App implements Application
{
    private HelloWindow window;

    public static void main(String[] args)
    {
	String[] newArgs = new String[args.length + 1];
	newArgs[newArgs.length - 1] = "helloPivot.App";
	org.apache.pivot.wtk.DesktopApplicationContext.main(newArgs);
    }

    @Override
    public void startup(Display display, Map&lt;String, String&gt; properties)
	    throws Exception

    {
	final App toQuit = this;
	BXMLSerializer bxmlSerializer = new BXMLSerializer();
	window = (HelloWindow) bxmlSerializer.readObject(HelloWindow.class,
		"ui/HelloWindow.bxml");
	window.getWindowStateListeners().add(new WindowStateListener()
	{

	    @Override
	    public Vote previewWindowClose(Window arg0)
	    {
		return Vote.APPROVE;
	    }

	    @Override
	    public void windowCloseVetoed(Window arg0, Vote arg1){}

	    @Override
	    public void windowClosed(Window arg0, Display arg1, Window arg2)
	    {
		System.exit(0);
	    }

	    @Override
	    public void windowOpened(Window arg0){}

	});
	window.open(display);
    }

    @Override
    public boolean shutdown(boolean optional)
    {
	window.close();
	return false;
    }

    @Override
    public void suspend()
    {
    }

    @Override
    public void resume()
    {
    }

}
</pre>
<p>The main method basically calls Pivot and launches the application as a desktop window. I&#8217;m sure there&#8217;s a better way to do this, but it&#8217;s the first way I found. Next, startup() is called &#8211; this loads the bxml file that contains our UI, deserializes it, and then opens our main window. Inside startup we set our window listener as well &#8211; when the window is closed, we call System.exit(0). Next, HelloWindow.java.</p>
<pre class="brush:java">
package helloPivot;

import java.net.URL;

import org.apache.pivot.beans.Bindable;
import org.apache.pivot.collections.Map;
import org.apache.pivot.util.Resources;
import org.apache.pivot.wtk.BoxPane;
import org.apache.pivot.wtk.Button;
import org.apache.pivot.wtk.ButtonPressListener;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.ComponentMouseButtonListener;
import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.MessageType;
import org.apache.pivot.wtk.Mouse;
import org.apache.pivot.wtk.Orientation;
import org.apache.pivot.wtk.Prompt;
import org.apache.pivot.wtk.PushButton;
import org.apache.pivot.wtk.TablePane;
import org.apache.pivot.wtk.Window;

public class HelloWindow extends Window implements Bindable
{
    private PushButton quit;

    @Override
    public void initialize(Map&lt;String, Object&gt; namespace, URL location, Resources resources)
    {
	this.quit = (PushButton)namespace.get("quit");

	final Window toClose = this;
	this.quit.getButtonPressListeners().add(new ButtonPressListener()
	{
	    @Override
	    public void buttonPressed(Button arg0)
	    {
		toClose.close();
	    }
	});
    }
}
</pre>
<p>This class doesn&#8217;t do much, except define a button listener to deal with the button on our UI being clicked. From what I gather, when we initialize a new instance of a custom control/window, the initialize method is called, with namespace containing any objects on that UI that have the bxml:id attribute on it. Let&#8217;s show that UI so it makes some sense.</p>
<pre class="brush:xml">
&lt;local:HelloWindow title="Hello Apache Pivot!" maximized="true"
    xmlns:bxml="http://pivot.apache.org/bxml"
    xmlns:local="helloPivot"
    xmlns="org.apache.pivot.wtk"&gt;

	&lt;BoxPane orientation="vertical" styles="{horizontalAlignment:'center',verticalAlignment:'center'}"&gt;
		&lt;ImageView image="@logo.png" /&gt;
		&lt;BoxPane orientation="horizontal" styles="{horizontalAlignment:'right'}"&gt;
			&lt;PushButton bxml:id="quit" buttonData="Quit" /&gt;
		&lt;/BoxPane&gt;
	&lt;/BoxPane&gt;
&lt;/local:HelloWindow&gt;
</pre>
<p>For those of you coming from the WPF/Silverlight world, the BoxPane is Pivot&#8217;s equivalent to a StackPanel. Notice the root of this XML file is local:HelloWindow. This is for two reasons: HelloWindow extends the Window class, and we want this file to eventually be associated with our underlying object instance (when we deserialize it). The local: namespace refers to the name of the package our class is in.</p>
<p>The final result if you build the project (and everything works)?</p>
<p><a href="http://silverfinn.net/blog/wp-content/uploads/2011/06/HelloPivot0002.png"><img src="http://silverfinn.net/blog/wp-content/uploads/2011/06/HelloPivot0002.png" alt="The final result - Apache Pivot logo in a Pivot UI." title="HelloPivot0002" width="452" height="361" class="aligncenter size-full wp-image-197" /></a></p>
<p><a href="http://silverfinn.net/HelloPivot.zip">You can download the source from here</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=192</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Silverlight 5 &#8211; DoubleClickInvokeCommandBehavior!</title>
		<link>http://puurunen.ca/blog/?p=187</link>
		<comments>http://puurunen.ca/blog/?p=187#comments</comments>
		<pubDate>Fri, 03 Jun 2011 04:05:29 +0000</pubDate>
		<dc:creator>Elias</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Databinding]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://silverfinn.net/blog/?p=187</guid>
		<description><![CDATA[Today, I was working on PodTower a bit more, and needed a way to add items to the new playlist coming in PodTower 2. While I plan on adding drag and drop at a later date, for now I decided that double-clicking on an item in the podcast list will add it to the current]]></description>
			<content:encoded><![CDATA[<p>Today, I was working on PodTower a bit more, and needed a way to add items to the new playlist coming in PodTower 2. While I plan on adding drag and drop at a later date, for now I decided that double-clicking on an item in the podcast list will add it to the current playlist.</p>
<p><span id="more-187"></span></p>
<p>So, I decided to break out a behavior for this task. Using the new ClickCount property provided by the MouseButtonEventArgs class (<a href="http://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs%28v=vs.96%29.aspx">MSDN Documentation here</a>), I was able to count the number of clicks, and if it was equal to 2, invoke a Command. Since Behaviors inherit from DependencyObject, they can participate in the binding system as well. Combine this with the new RelativeSource binding support in Silverlight 5, this opens up a whole new realm of binding possibilities! For PodTower, I have the behavior bound to a property of the DataContext on the main UserControl of the application. This allows me to bind up to the Commands on the viewmodel without having to do horrible back-end hack code.</p>
<p>Without further ado, here&#8217;s the code for the behavior. Note that I&#8217;ve included a conditional symbol called SILVERLIGHT5, so that if you want to use this behavior in Silverlight 4, you can.</p>
<pre class="brush:csharp">
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity;

namespace PodTower
{
    public class DoubleClickInvokeCommandBehavior : Behavior<UIElement>
    {
        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register("Command", typeof(ICommand), typeof(DoubleClickInvokeCommandBehavior), new PropertyMetadata(null));

        public Object CommandParameter
        {
            get { return (Object)GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

        public static readonly DependencyProperty CommandParameterProperty =
            DependencyProperty.Register("CommandParameter", typeof(Object), typeof(DoubleClickInvokeCommandBehavior), new PropertyMetadata(null));

        protected override void OnAttached()
        {
            base.OnAttached();

            this.AssociatedObject.MouseLeftButtonDown += OnClick;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            this.AssociatedObject.MouseLeftButtonDown -= OnClick;
        }

#if !SILVERLIGHT5
        DateTime? _lastClick;
#endif

        void OnClick(object sender, MouseButtonEventArgs e)
        {
#if SILVERLIGHT5
            if (e.ClickCount != 2)
                return;
#else
            if (_lastClick == null)
            {
                _lastClick = DateTime.Now;
                return;
            }
            else
            {
                var now = DateTime.Now;
                var last = _lastClick.Value;
                _lastClick = now;

                if (now.Subtract(last).TotalMilliseconds > 250)
                    return;
            }
#endif
            if (this.Command == null || !this.Command.CanExecute(this.CommandParameter))
                return;

            this.Command.Execute(this.CommandParameter);
        }
    }
}
</pre>
<p>&#8230;and here&#8217;s an example of it used in the PodTower main UI.</p>
<pre class="brush:xml">
<DataTemplate x:Key="PodcastItemTemplate">
            <Grid Background="#00000000">
            	<i:Interaction.Behaviors>
            		<convert:DoubleClickInvokeCommandBehavior Command="{Binding DataContext.MediaPlayer.AddToPlaylistCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
					CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"/>
            	</i:Interaction.Behaviors>
            </Grid>
        </DataTemplate>
</pre>
<p>Feel free to use this behavior in your own applications!</p>
]]></content:encoded>
			<wfw:commentRss>http://puurunen.ca/blog/?feed=rss2&#038;p=187</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

