<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss version="2.0">
    <channel>
        <title>root silver</title>
        <link>http://www.rootsilver.com/</link>
        <description>m i s c e l l a n e a</description>
        <language>en</language>
        <copyright>Copyright 2009</copyright>
        <lastBuildDate>Thu, 28 May 2009 17:45:23 -0500</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RootSilver" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <title>Wpf: Binding to parent property (RelativeSource Ancestor DataContext)</title>
            <description><![CDATA[
This is in the context of <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx">the MVVM pattern for WPF</a>. You can bind to the property of the upper-most datacontext from within a View using RelativeSource and finding the AncestorType=Window's DataContext.<br/>
<br/>

<pre class="prettyprint">
XAML:
&lt;TextBlock Text="{Binding 
RelativeSource={RelativeSource FindAncestor, 
AncestorType={x:Type Window}}, Path=DataContext.Message}" /&gt;	
</pre>
<br/>
<img src=http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=902" alt="Wpf mvvm relativesource ancestor uppermost datacontext" />]]></description>
            <link>http://www.rootsilver.com/2009/05/wpf-relativesource-ancestor-datacontext</link>
            <guid>http://www.rootsilver.com/2009/05/wpf-relativesource-ancestor-datacontext</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">wpf mvvm</category>
            
            <pubDate>Thu, 28 May 2009 17:45:23 -0500</pubDate>
        </item>
        
        <item>
            <title>Derived Decorator: Auto-set Properties (C#)</title>
            <description><![CDATA[Here's an example of auto-setting properties in a pseudo-<a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a> in C#, where the decorator is a derived class that automatically sets properties on its base class. 

<br/><br/>This is somewhere between a decorator and a <a href="http://en.wikipedia.org/wiki/Wrapper_pattern">wrapper</a> or <a href="http://en.wikipedia.org/wiki/Adapter_pattern">facade</a>. For straight forward cases it saves the work of manually setting properties of the base class from the instance passed in on the constructor.<br/>

<pre class="prettyprint">
using System;
using System.Linq;

namespace RootSilver
{
  public class User 
  {
    public string FirstName{ get; set; }
    public string LastName { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public int Zip { get; set; }
    public long Phone1 { get; set; }
    public DateTime SignupDate { get; set; }
  }

  public sealed class DecoratedUser : User 
  {
    public DecoratedUser(User user)
    {
      user.GetType()
        .GetProperties()
        .ToList()
        .ForEach( x => 
          x.SetValue(this,
            user.GetType().GetProperty(x.Name)
              .GetValue(user, null),
       null));
    }

    public void PrintProperties()
    {
      this.GetType().GetProperties().ToList().ForEach( x => 
        Console.WriteLine(x.GetValue(this, null)));
    }
  }

  public class Test
  {
    public static void Main()
    {
      User user = new User
      {
        FirstName = "Bob",
        LastName = "Smith",
        Address1 = "11 Main Street",
        Address2 = "Apt 2",
        City = "Candor",
        State = "New York",
        Zip = 13743,
        Phone1 = 6075551212,
        SignupDate = DateTime.Now
      };

      DecoratedUser decoratedUser = new DecoratedUser(user);

      decoratedUser.PrintProperties(); 

      Console.ReadKey();
    }
  }
}
</pre>]]></description>
            <link>http://www.rootsilver.com/2009/05/decorator-pattern-auto-set-properties</link>
            <guid>http://www.rootsilver.com/2009/05/decorator-pattern-auto-set-properties</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">Patterns</category>
            
            <pubDate>Tue, 26 May 2009 16:33:22 -0500</pubDate>
        </item>
        
        <item>
            <title>Generic Singly Linked List in C#: First Pass</title>
            <description><![CDATA[ <img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=887&g2_serialNumber=1" alt="buoys linked list" />
<br/><br/>
A response to the question <a href="http://stackoverflow.com/questions/365489/questions-every-good-net-developer-should-be-able-to-answer/365556#365556">"Questions every good .NET developer should be able to answer?"</a> on StackOverflow was <br/><a href="http://stackoverflow.com/questions/365489/questions-every-good-net-developer-should-be-able-to-answer/365556#365556">"Write your own linked list class without using the built-in classes"</a>.<br/><br/>
I hadn't done this in quite a while (I'd done it in C++ years ago), so I gave it a try off the top of my head. Here's my first pass, using just the <a href="http://en.wikipedia.org/wiki/Linked_list#Singly-linked_lists">Wikipedia entry</a>, vim, and the compiler. <br/>Yes, I realize there's little practical point to this; I'm sure the person posting the response on StackOverflow does too. It's just an exercise.<br/>
<img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=891&g2_serialNumber=1" alt="singly linked list C#"/><br/>
<pre class="prettyprint">
using System;

namespace RootSilver {

  public class LinkedList&lt;T>  {    
    //Node(data, pointer to next) --> Node(data, null)
    //see http://en.wikipedia.org/wiki/Linked_list
    private class Node<T> {

      public Node&lt;T> Next{ get; set; }

      public T Value{ get; private set;}

      public Node(){}
      public Node(T data) {
        this.Value = data;
      }

    }

    private Node&lt;T> currentNode;
    private Node&lt;T> headNode; //placeholder/anchor

    public bool End() {
      return this.currentNode == null;
    }

    public void Remove(int position) {
      var node = this.headNode;

      //walk the list until we find the postion 
      int i = 0;
      while( i &lt; position - 1 ) {
        node = node.Next;
        ++i;
      }
      node.Next = node.Next.Next ?? null;
    }

    public void Insert(T data, int position) {
      var node = this.headNode;

      int i = 0;
      while( i &lt; position - 1  ) {
        node = node.Next;
        ++i;
      }

      var newNode = new Node<T>(data);
      newNode.Next = node.Next;
      node.Next = newNode;
    }

    public void Add(T data) {
      var node = new Node&lt;T>(data);

      if(this.headNode == null) {
        this.headNode = node;
      } else { 
        this.currentNode.Next = node;
      }
        
      this.currentNode = node;
    }

    public T Value {
      get{ return this.currentNode.Value; } 
    }

    public T First(){
      this.currentNode = this.headNode;
      return this.currentNode.Value;
    }

    public T Next() {
      //stop at last & go no further (I'm stuck!!)
      T data = this.currentNode.Value;  
      this.currentNode = this.currentNode.Next;
      
      return data;
    }
  }

  public class Test {
    public static void Main() {

      var list = new LinkedList<string>();

      for(int i = 0; i < 5; i++)
        list.Add(i.ToString());

      Console.WriteLine("\n--------Output-----------------");
      list.First();
      while( ! list.End() ) {
        Console.WriteLine("Next:" + list.Value.ToString());
        list.Next();
      }

      Console.WriteLine("\n--------Insert Bob at 3 -------");
      list.Insert("bob", 3);

      list.First();
      while( ! list.End() ) {
        Console.WriteLine("Next:" + list.Value.ToString());
        list.Next();
      }

      Console.WriteLine("\n--------Remove-----------------");
      list.Remove(3);
      list.First();
      while( ! list.End() ) {
        Console.WriteLine("Next:" + list.Value.ToString());
        list.Next();
      }
    }
  }
}
</pre>]]></description>
            <link>http://www.rootsilver.com/2009/05/generic-singly-linked-list-csharp</link>
            <guid>http://www.rootsilver.com/2009/05/generic-singly-linked-list-csharp</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
            <pubDate>Wed, 20 May 2009 16:46:22 -0500</pubDate>
        </item>
        
        <item>
            <title>WPF Mvvm: Simple error validation on button click</title>
            <description><![CDATA[<b>Validating user input in WPF is supposed to be simple</b>. Wpf comes with a lot of built in validation functionality. But things stop being simple as soon as you want to validate data somewhere other than a tab-out of a textbox. <br/><br/>

If you've arrived here you've probably been googling for 8 hours trying to get a basic use case working:
<br/><br/>
&nbsp;&nbsp;<b>Validate a group of controls in WPF, all at once, on a button click.</b>
<br/><br/>
That's it! If you can do it with Wpf's out of the box validation facilities, your google-fu is a lot better than mine. I can't seem to make WPF validation do anything meangful outside of the tabbed-out-of-textbox scenario.
<br/><br/>
In short, I wanted something that looked like this:<br/><br/>
<img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=885&g2_serialNumber=1" alt="wpf mvvm validation" /><br/>

Here's a shortcut I came up with that doesn't involve any <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validatesondataerrors.aspx">ValidatesOnDataErrors</a>, 

<a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validatesonexceptions.aspx">ValidatesOnExceptions</a>, 

<a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validationrules.aspx">ValidationRules</a>, 

<a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.notifyonvalidationerror.aspx">NotifyOnValidationError</a>, or 

<a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo.aspx">IDataErrorInfo</a> insanity. Anyone who doesn't get a headache just trying to remember all those is nuts.

In any case, none of these worked for me, and I don't have a lot of time to dive into the depths of nightmares like <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.notifyonvalidationerror.aspx">Binding.NotifyOnValidationError</a>:
<pre class="prettyprint">
&lt;Grid>
  &lt;Grid.BindingGroup>
    &lt;BindingGroup>
      &lt;BindingGroup.NotifyOnValidationError>
      &lt;/BindingGroup.NotifyOnValidationError>
    &lt;/BindingGroup>
    &lt;/Grid.BindingGroup>
&lt;/Grid>
</pre>
<b>Yikes! Run for your life!</b>&nbsp;&nbsp;<i>Not</i> writing a lot of code is important for both my for sanity and maintainability purposes. The code above fails in both cases.<br/>

<br/>Here's a much simpler idea that embraces MVVM + Databinding but doesn't get involved with the IDataErrorInfo insanity:</b>
<h3>Expose a public boolean for "InputInvalid" in your ViewModel. Views will bind to this property and update their display with Style.Triggers.</h3>
That's it. Here's how it looks.<br/>First, the xaml:

<pre class="prettyprint">
&lt;Window x:Class="RootSilver.WpfMvvm.Window1View"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
  &lt;Window.Resources>
    &lt;-- Define a style for your textboxes when there's invalid data. 
The DataTrigger is the InvalidInput boolean in the ViewModel -->
    &lt;Style TargetType="TextBox">
      &lt;Style.Triggers>
        &lt;DataTrigger Binding="{Binding Path=InvalidInput, 
          UpdateSourceTrigger=PropertyChanged}" Value="True">
          &lt;Setter Property="BorderBrush" Value="Red"/>
          &lt;Setter Property="BorderThickness" Value="2"/>
        &lt;/DataTrigger>
        &lt;DataTrigger Binding="{Binding Path=InvalidInput, 
          UpdateSourceTrigger=PropertyChanged}" Value="False">
          &lt;Setter Property="BorderBrush" Value="Black"/>
          &lt;Setter Property="BorderThickness" Value="1"/>
        &lt;/DataTrigger>
      &lt;/Style.Triggers>
    &lt;/Style>
  &lt;/Window.Resources>
  
  &lt;-- The rest is standard Wpf Mvvm: binding textboxes to properties and an ICommand for the button click -->
  &lt;Grid Height="200">
    &lt;Grid.ColumnDefinitions>
      &lt;ColumnDefinition Width="79*">&lt;/ColumnDefinition>
      &lt;ColumnDefinition Width="199*">&lt;/ColumnDefinition>
    &lt;/Grid.ColumnDefinitions>
    &lt;Grid.RowDefinitions>
      &lt;RowDefinition>&lt;/RowDefinition>
      &lt;RowDefinition>&lt;/RowDefinition>
      &lt;RowDefinition>&lt;/RowDefinition>
    &lt;/Grid.RowDefinitions>
    &lt;TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Center">
      User Name&lt;/TextBlock>
    &lt;TextBox Grid.Column="1" Grid.Row="0" Width="150" Height="20" 
         VerticalAlignment="Center" Text="{Binding Path=UserName, Mode=TwoWay, 
      UpdateSourceTrigger=PropertyChanged}"/>
    &lt;TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Center">
      User Name&lt;/TextBlock>
    &lt;TextBox Grid.Column="1" Grid.Row="1"  Width="150" Height="20" 
         VerticalAlignment="Center" Text="{Binding Path=Password, Mode=TwoWay, 
      UpdateSourceTrigger=PropertyChanged}"/>
    &lt;Button Grid.Column="1" Grid.Row="2" Command="{Binding Path=LoginCommand}" >Submit&lt;/Button>
  &lt;/Grid>
&lt;/Window>
</pre>
<br/><br/>
Next, the ViewModel. Notice that the only thing happening here is that we have a standard login routine with some logic. If it fails, we let the view know by changing <b>InvalidInput</b> to false and raising a <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx">PropertyChanged</a> event. We won't go ahead with the login, and we'll leave it up to the view to interpret this information as it chooses.<br/>
<pre class="prettyprint">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;  //INotifyPropertyChanged
using System.Windows.Input;    //ICommand
namespace RootSilver.WpfMvvm
{
  public class Window1ViewModel : INotifyPropertyChanged
  {
    public event PropertyChangedEventHandler PropertyChanged = delegate{};

    public string UserName { get; set; }
    public string Password { get; set; }
    public bool InvalidInput { get; private set; }

    private ICommand loginCommand;
    public virtual ICommand LoginCommand
    {
      get
      {
        return this.loginCommand ??
        (this.loginCommand = new DelegateCommand(() =>
        {
          this.InvalidInput = (this.UserName != "Admin" && this.Password != "password");

          PropertyChanged(this, new PropertyChangedEventArgs("InvalidInput"));

        }));
      }
    }

  }
}
</pre>
<br/>
The <b>DelegateCommand</b> is Microsoft's MVVM/Prism command. Similar to Josh Smith's <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx">RelayCommand</a>.
<h3><a href="/files/RootSilver.WpfMvvm.zip">Download Code</a></h3>
<h2><a href="/files/RootSilver.WpfMvvm.zip>Here's the code</a></h2>
]]></description>
            <link>http://www.rootsilver.com/2009/05/wpf-mvvm-simple-error-validation</link>
            <guid>http://www.rootsilver.com/2009/05/wpf-mvvm-simple-error-validation</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">wpf mvvm</category>
            
            <pubDate>Thu, 14 May 2009 17:37:25 -0500</pubDate>
        </item>
        
        <item>
            <title>IoC with StructureMap: Loading Assemblies</title>
            <description><![CDATA[I had some trouble getting <a href="http://structuremap.sourceforge.net/Default.htm">Structure Map</a> to load concrete instances of an abstract class housed in separate assemblies. 
<br/><br>Here's what I wanted, where Core, PersonBase, Bob, and Betty are each separate assemblies:
<img src="http://img396.imageshack.us/img396/1343/iocuml.jpg" alt="SM Ioc UML"/>
<br/><br/>
I expected this to work with:
<pre class="prettyprint" id="java">
ObjectFactory.Configure(x => x.Scan (
  scan =>
  {
    scan.AssembliesFromPath(Environment.CurrentDirectory);

    scan.WithDefaultConventions(); //doesn't do it
    }
));
</pre>
<br/><br/>
What I needed was a custom scanner:
<br/>
<pre class="prettyprint" id="java">
public class MyScanner : ITypeScanner {
  public void Process(Type type, PluginGraph graph) {

    if(type.BaseType == null) return;

    if(type.BaseType.Equals(typeof(PersonBase))) {
      graph.Configure(x => 
        x.ForRequestedType<PersonBase>()
        .TheDefault.Is.OfConcreteType(type));
    }
  }
}
</pre>
</br>
The full writeup is on <a href="http://stackoverflow.com/questions/809051/ioc-dll-references-and-assembly-scanning">Stack Overflow</a>.]]></description>
            <link>http://www.rootsilver.com/2009/05/ioc-with-structuremap-loading-assemblies</link>
            <guid>http://www.rootsilver.com/2009/05/ioc-with-structuremap-loading-assemblies</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">IoC</category>
            
            <pubDate>Sun, 03 May 2009 01:20:35 -0500</pubDate>
        </item>
        
        <item>
            <title>Updating WPF UI on an Eventhandler: BitmapImage, DependencyObject, and Thread Ownership</title>
            <description><![CDATA[I was having trouble updating the UI of a WPF app on an event handler. 

I could update text, but as soon as I tried anything with <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx">BitmapImage</a> I'd get an <br>
<h3>InvalidOperationException</h3>
<i>The calling thread cannot access this object because a different thread owns it.</i>
<br/><br/>
<img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=883&g2_serialNumber=1" alt="InvalidOperationException"/><br/>
<br/>

A simplified version of the code looks like this:
<br/>

<pre class="prettyprint" id="xml">

&lt;Window x:Class="WpfApplication7.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" &gt;
   
	&lt;StackPanel Orientation="Vertical"&gt;

		&lt;TextBlock Text="{Binding Path=Message, 
                 UpdateSourceTrigger=PropertyChanged}" 
                 FontSize="20" Height="40" Width="300"  
                 Background="AliceBlue"/&gt;

		&lt;Image Source="{Binding
                Path=Image,UpdateSourceTrigger=PropertyChanged}" 
                Height="100" Width="100"/&gt;

	&lt;/StackPanel&gt;
&lt;/Window&gt;
</pre>

<br/>

With the C#:
<br/>
<pre class="prettyprint"  id="java">
using System;
using System.ComponentModel;
using System.Timers;
using System.Windows;
using System.IO;
using System.Windows.Threading;
using System.Windows.Media.Imaging;

namespace WpfApplication7
{
  public partial class Window1 : Window, INotifyPropertyChanged
  {
    public BitmapImage Image { get; private set; }
    public string Message { get; set; }
    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    private Timer timer;
    
    public Window1()
    {
      InitializeComponent();
      this.DataContext = this;

      this.timer = new Timer { Enabled = true, Interval = 100 };

      this.timer.Elapsed += (s, e) =>
      {
        //happy :)
        this.Message = File.ReadAllText(@"c:\windows\win.ini").Substring(0, 20);
        PropertyChanged(this, new PropertyChangedEventArgs("Message"));

	//not happy :(
	this.Image = new BitmapImage(
                          new Uri(@"C:\WINDOWS\Web\Wallpaper\Ascent.jpg"));

	//right here:
	//"The calling thread cannot access this object because a different thread owns it."
		PropertyChanged(this, new PropertyChangedEventArgs("Image"));
      };
    }
  }
}
</pre>
<br/><br/>

The "calling thread" error would lead to you a solution involving threading. Which you can do by managing the UI updates within a Dispatcher.Invoke:

<pre class="prettyprint"  id="java">
 this.timer.Elapsed += (s, e) =>
      {
        this.Message = File.ReadAllText(@"c:\windows\win.ini").Substring(0, 20);
        PropertyChanged(this, new PropertyChangedEventArgs("Message"));

        
        Application.Current.Dispatcher.Invoke(
        DispatcherPriority.Send, new Action(delegate
        {
          this.Image = new BitmapImage(new Uri(@"C:\WINDOWS\Web\Wallpaper\Ascent.jpg"));

          PropertyChanged(this, new PropertyChangedEventArgs("Image"));
        }));
      };
</pre>

<br/><br/>
However, the real point is that <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx">BitmapImage</a> is a DependencyObject. You can see this by going up the inheritance hierarchy:

<pre class="prettyprint">
System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Freezable
        System.Windows.Media.Animation.Animatable
          System.Windows.Media.ImageSource
            System.Windows.Media.Imaging.BitmapSource
              System.Windows.Media.Imaging.BitmapImage
</pre>

<br/>
So the more direct way to handle this is to call Freezable():

<pre class="prettyprint" id="java">
  this.timer.Elapsed += (s, e) =>
      {
        this.Message = File.ReadAllText(@"c:\windows\win.ini").Substring(0, 20);
        PropertyChanged(this, new PropertyChangedEventArgs("Message"));

        this.Image = new BitmapImage(new Uri(@"C:\WINDOWS\Web\Wallpaper\Ascent.jpg"));

	this.Image.Freeze();
        PropertyChanged(this, new PropertyChangedEventArgs("Image"));
        
      };
</pre>
<br/><br/>
Thanks to the answers on <a href="http://stackoverflow.com/questions/794882/wpf-event-bitmapimage-propertychanged-calling-thread-cannot-access">StackOverflow</a> for helping me track this down.
]]></description>
            <link>http://www.rootsilver.com/2009/04/updating-wpf-ui-eventhandler-dependencyobject</link>
            <guid>http://www.rootsilver.com/2009/04/updating-wpf-ui-eventhandler-dependencyobject</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">WPF</category>
            
            <pubDate>Mon, 27 Apr 2009 16:20:27 -0500</pubDate>
        </item>
        
        <item>
            <title>Cruise Control.NET, Apache, Windows</title>
            <description><![CDATA[We have subversion running via https on Apache. <br/><br/>

So when it came time to get continuous builds going, I was left with trying to get <a href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET">CruiseControl.NET</a> running on apache. It's actually easy with mod_aspnet + the right httpd.conf configuration.
<ul>
<li>Download and install mod_aspnet from <a href="http://sourceforge.net/projects/mod-aspdotnet">Sourceforge</a></li>

<li>Edit your httpd.conf file as below. The httpd.conf was pieced together from <a href="http://weblogs.asp.net/israelio/archive/2005/09/11/424852.aspx">here</a> and <a href="http://stackoverflow.com/questions/471276/cruisecontrol-net-dashboard-apache/686134#686134">StackOverflow comments</a></li>
</ul>
<br/>
<pre class="prettyprint" id="xml">
&lt;IfModule mod_aspdotnet.cpp&gt; 

AspNetMount /ccnet "C:/Program Files/CruiseControl.NET/webdashboard"

Alias /ccnet/ "C:/Program Files/CruiseControl.NET/webdashboard/"

#(AliasMatch is all one line)
AliasMatch /ccnet(.*\.aspx.*)  
             "C:/Program Files/CruiseControl.NET/webdashboard/default.aspx" 
AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*)  
             "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"

&lt;Directory "C:/Program Files/CruiseControl.NET/webdashboard"&gt;
		Options FollowSymlinks ExecCGI
		AspNet Files Directories Virtual
		Order allow,deny
		Allow from all
		DirectoryIndex default.aspx
&lt;/Directory&gt;      

&lt;Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles"&gt;
	Options FollowSymlinks
	Order allow,deny
	Allow from all
&lt;/Directory&gt;

&lt;/IfModule&gt;

</pre>]]></description>
            <link>http://www.rootsilver.com/2009/04/cruise-controlnet-apache-windo</link>
            <guid>http://www.rootsilver.com/2009/04/cruise-controlnet-apache-windo</guid>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">Continuous Integration</category>
            
            <pubDate>Wed, 15 Apr 2009 11:47:09 -0500</pubDate>
        </item>
        
        <item>
            <title>Log4net in Windows Service: AssemblyInfo.cs</title>
            <description><![CDATA[ In addition to your log4net configuration (i.e. app.config), don't forget to add the following entry to your AssemblyInfo.cs file. <br/>
When running code as a windows service, Log4Net won't work without it.
<br/><br/>
<img src="http://lh6.ggpht.com/_-5GROjmXLgI/SdJ-nlg1rTI/AAAAAAAAA2U/hgI5DQBjyHM/s576/log4net_assemblyinfo.jpg" alt="Log4net assemblyinfo.cs" />]]></description>
            <link>http://www.rootsilver.com/2009/03/log4net-windows-service</link>
            <guid>http://www.rootsilver.com/2009/03/log4net-windows-service</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
            <pubDate>Tue, 31 Mar 2009 16:28:47 -0500</pubDate>
        </item>
        
        <item>
            <title>Generic functions in C# (Linq, IEnumerable)</title>
            <description><![CDATA[Here's an example of a generic function in C#:

<pre class="prettyprint" id="C#">
using System;
using System.Linq;
using System.Collections.Generic;

public class test{

        public static void Main(){

                //create two random sets of enumerable things
                var list = Enumerable.Range(1,2);
                var list2 = new string[]{"hello_1", "hello_2"};

                PrintList(list);
                PrintList(list2);
        }

        public static void PrintList&lt;T&gt;(IEnumerable&lt;T&gt; entries){
                foreach(T s in entries)
                        Console.WriteLine(s + ":" + typeof(T));
        }
}
</pre>
<br/>
output:
<br/>
<pre id="prettyprint">
1:System.Int32
2:System.Int32
hello_1:System.String
hello_2:System.String
</pre>]]></description>
            <link>http://www.rootsilver.com/2009/03/csharp-generic-function-linq-ienumerable</link>
            <guid>http://www.rootsilver.com/2009/03/csharp-generic-function-linq-ienumerable</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
            <pubDate>Thu, 19 Mar 2009 16:52:41 -0500</pubDate>
        </item>
        
        <item>
            <title>Subway Address 0004</title>
            <description><![CDATA[ <img src="http://lh4.ggpht.com/_-5GROjmXLgI/Sb_GzjymeFI/AAAAAAAAA1U/PNv-SJySocg/s640/img_0117.jpg" alt="NYC Subway Address 0004"/>]]></description>
            <link>http://www.rootsilver.com/2009/03/subway-address-0004</link>
            <guid>http://www.rootsilver.com/2009/03/subway-address-0004</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Places</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Useless Errors</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">NYC</category>
            
            <pubDate>Tue, 17 Mar 2009 11:53:46 -0500</pubDate>
        </item>
        
        <item>
            <title>Using Reflection in C# to get Property Values</title>
            <description><![CDATA[Here is some C# code to extract <b>values</b> from an object instance when you don't know (or care) what properties are available. A possible use case is when you know you want to iterate over / use the properties of an object -- all of them, no matter what they are -- and you don't want to hard code their names. Perhaps you're dealing with an object where the object author regularly adds and updates properties.
</br><br/>
<pre class="prettyprint" id="c#">
//Person.cs: Random test class that exposes some properties
using System;

public class Person{
        public string FirstName { get{return "Jeffrey";} }
        public string LastName { get{return "Knight";} }
        public int Age { get { return 35; } }
}
</pre>
</br>
<br/>
Now here's the main code. Short and sweet:
</br><br/>
<pre class="prettyprint" id="c#">
//Main.cs: code to reflect on a saturated instance of this class to get the values out
using System;
using System.Reflection;

public class Test{
        public static void Main(){

                Person p = new Person();
                Type pType = p.GetType();

                PropertyInfo[] propertyInfo = pType.GetProperties();

                foreach(PropertyInfo prop in propertyInfo){

                        string propName = prop.Name;
                        object propValue = pType.GetProperty(propName).GetValue(p, null);

                        Console.WriteLine(String.Format("{0}:{1}", propName, propValue));
                }
        }
}
</pre>
<br/><br/>
There's a certain poetic beauty to this code -- so often in programming you have to know exactly what you're asking for in a way that's very literal. Here, it's revealing itself to us without us having to know beforehand. There's a sort of Heideggerian "givenness" to it.
<br/><br/>
Output:
<pre class="prettyprint" id="text">
FirstName:Jeffrey
LastName:Knight
Age:35
</pre>]]></description>
            <link>http://www.rootsilver.com/2009/03/using-reflection-in-c-to-get-p</link>
            <guid>http://www.rootsilver.com/2009/03/using-reflection-in-c-to-get-p</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
            <pubDate>Thu, 12 Mar 2009 19:25:45 -0500</pubDate>
        </item>
        
        <item>
            <title>Hello World in Spring from scratch on Linux</title>
            <description><![CDATA[This is a simplified version of the "hello world" from <a href="http://www.manning.com/walls3/">Spring in Action, 2nd Ed.</a> (p 11-12), done all "by hand". The example in the book is straight forward enough, but doing it at the command line from scratch took a me few attempts. I'll run through this from a Linux perspective, but it's nearly identical on Windows.

<h2>1) Get the Spring Framework</h2>
All you need is the spring jar file. If you have netbeans, skip this step -- we'll use the jar file from NetBeans later (i.e. netbeans-6.5/java2/modules/ext/spring/spring-2.5.jar). Otherwise, <a href="http://www.springsource.org/download">download the latest spring framework jar file</a>. You're looking for the spring-x.y.jar file.
<br/>
<h2>2) Create a folder structure</h2>
Create a folder structure for your java source files. For this example, use <i>com/rootsilver/spring</i>. You can create this in one shot with:<br/>
<i>mkdir -p com/rootsilver/spring</i>

<h2>3) Create your Bean (hint: it's just a simple class)</h2>
Don't worry about the "bean" naming nonsense. Create the class com/rootsilver/spring/HelloBean.java:<br/>
<pre class="prettyprint" id="java">
//file: com/rootsilver/spring/HelloBean.java
package com.rootsilver.spring;

public class HelloBean{
        public String greeting;

        public void sayGreeting(){
                System.out.println(this.greeting);
        }
        public void setGreeting(String greeting){
                this.greeting = greeting;
        }
}
</pre>

<h2>4) Create your main class</h2>
Now, create the main class under com/rootsilver/spring/Test.java:<br/>
<pre class="prettyprint" id="java">
//file: com/rootsilver/spring/Test.java
package com.rootsilver.spring;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class Test{
        public static void main(String[] args) throws Exception{

                FileSystemResource resource = new FileSystemResource("hello.xml");
                BeanFactory factory = new XmlBeanFactory(resource);
                HelloBean helloBean = (HelloBean)factory.getBean("HelloBean");
                helloBean.sayGreeting();
        }
}
</pre>
<br/>
We now have a basic class (HelloBean.java) and a main class (Test.java) that <b>leverages Spring to create an instance of our test class</b>. We wire this all together with an XML configuration file.

<h2>5) Create your configuration file</h2>
This XML file, which the main class (Test.java) passes into spring via the XmlBeanFactory, holds the whole thing together:<br/>

//file: hello.xml (in the root of the project)
<pre class="prettyprint" id="xml">
&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
   "http://www.springframework.org/dtd/spring-beans.dtd"&gt;

&lt;beans&gt;
        &lt;bean id="HelloBean" class="com.rootsilver.spring.HelloBean"&gt;
                &lt;property name="greeting"&gt;
                        &lt;value&gt;Hello World&lt;/value&gt;
                &lt;/property&gt;
        &lt;/bean&gt;
&lt;/beans&gt;
</pre>
In the <bean> tag, note that the class is the fully qualified class: package name + class name. This is probably patently obvious to Java folks, but it's something .NET folks tend to miss. Also, in Test.java, notice we're creating the bean using .getBean, referencing the bean by its ID as defined in hello.xml

<h2>6) Compile and run</h2>
This is actually a tricky step if you aren't used to building java apps at the command line. I always mess up the dots and slashes. You need to make sure you've got the spring jar file in your classpath.
<pre class="prettyprint lang-sh">
javac -classpath "/path/to/spring-2.5.jar" com/rootsilver/spring/*.java
</pre>
Spring apparently depends on the commons-logging jar. So to run it, with with spring jar file, commons-logging, and "." in your path, executing com.rootsilver.spring/Test:
<pre class="prettyprint lang-sh">
java -classpath ".:/path/to/spring-2.5.jar:/path/to/commons-logging-1.1.jar" com.rootsilver.spring.Test
</pre>
Results:
<pre class="prettyprint lang-sh">
Feb 16, 2009 11:09:39 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [/home/jknight/code/RandomSampleCode/Spring/hello.xml]
Hello World
</pre>

<h2>7) Download Source</h2>
<a href="/files/Spring.rootsilver.zip">Spring.rootsilver.zip</a>]]></description>
            <link>http://www.rootsilver.com/2009/02/spring-hello-world-from-scratc</link>
            <guid>http://www.rootsilver.com/2009/02/spring-hello-world-from-scratc</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">Java</category>
            
            <pubDate>Mon, 16 Feb 2009 10:34:55 -0500</pubDate>
        </item>
        
        <item>
            <title>[mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a31330] moov atom not found </title>
            <description><![CDATA[If ffmpeg gives you this error when encoding a video:
<br /><br />

<b>moov atom not found</b>
<br/><br/>
Use <a href="http://atomicparsley.sourceforge.net/">AtomicParsley</a> to fix your atoms:
<br/>
<b>AtomicParsley myVideo.mp4 -P</b>
<br/><br/>
The -P flag purges some meta data out of your video that you probably didn't know about or care about. You can also use AtomicParsley to set meta data -- artist, album, etc.
<br/>See:
<b>AtomicParsley --longhelp</b>
<br/>
AtomicParley is a simple to use command line utility. You'll be encoding with ffmpeg in no time.]]></description>
            <link>http://www.rootsilver.com/2009/01/moov-atom-not-found</link>
            <guid>http://www.rootsilver.com/2009/01/moov-atom-not-found</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">ffmpeg atomicparsley</category>
            
            <pubDate>Thu, 22 Jan 2009 16:29:34 -0500</pubDate>
        </item>
        
        <item>
            <title>Syncing music and video on a G3 iPhone with ubuntu linux and gtkpod</title>
            <description><![CDATA[Not to take anything away from pwnplayer, mplayer, and AVPlayer, which all work great on a jailbroken iPhone, but with a little work, you can use gtkpod and linux to add music and video to your iPod library. This works on a G3 iPhone running 2.2 firmware. Here's how, roughly:
<br/>
<ol>
<li>Upgrade you iPhone firmware. You need iTunes for this, unfortunately.</li>
<li><a href="http://www.quickpwn.com/">Jailbreak your iPhone</a></li>
<li>Install Openssh on your iPhone, so you can ssh into your iphone</li>
<li>Install sshfs and gtkpod on your linux machine, i.e. <b>sudo aptitude install sshfs gtkpod-aac</b></li>
<li>Join a local network with your iPhone that's accessible to your computer. Find your iPhone's ip address under "Settings" on your iPhone</li>
<li>Check that you can ssh into your iPhone</li>
<li>Ssh into your iPhone and edit the file <b>/System/Library/Lockdown/Checkpoint.xml</b> as <a href="http://marcansoft.com/blog/2009/01/using-amarok-and-other-itunesdb-compatible-software-with-the-iphone-2x/">described here</a>. You can use vi.</li>
<li>Mount your iPhone via sshfs, i.e. <b>sshfs root@192.168.1.101:/var/mobile/Media tmp</b></li>
<li>Now open gtkpod and add a new ipod, pointing to your sshfs mount point (refer to screenshot below)</li>
</ol>
Thanks for the guys on #gtkpod on freenode for sending me to the <a href="http://marcansoft.com/blog/2009/01/using-amarok-and-other-itunesdb-compatible-software-with-the-iphone-2x/">marcansoft.com link</a>, which is the secret ingredient.
<br/><br/>
<img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=878" alt="g3 iphone gtkpod"/>
<br/>
<img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=881&g2_serialNumber=1" style="border:1px solid black;"/>]]></description>
            <link>http://www.rootsilver.com/2009/01/g3-iphone-gtkpod-linux</link>
            <guid>http://www.rootsilver.com/2009/01/g3-iphone-gtkpod-linux</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Technology</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">linux</category>
            
            <pubDate>Fri, 09 Jan 2009 12:37:34 -0500</pubDate>
        </item>
        
        <item>
            <title>Generic XML Serialization</title>
            <description><![CDATA[
Generic functions to Load and Save saturated objects of any type with XML serialization.

<pre class="prettyprint">
using System;
using System.IO;
using System.Xml.Serialization;

namespace rootsilver.serialization{
	public class Test{
		public static void Main(){
			
			Test test = new Test();	

			Settings settings = new Settings(){ name="test.setting"};

			string filePath = test.Save(settings);

			settings = test.Load&lt;Settings&gt;(filePath);
			
			Console.WriteLine(settings.name);	

			Person person = new Person(){ name="Jeff", age = 34};

			filePath = test.Save(person);

			person = test.Load&lt;Person&gt;(filePath);

			Console.WriteLine(person.age + " " + person.name);
			
		}
		
		public T Load&lt;T&gt;(string filePath) {

			T t = default (T);

			using (Stream stream = File.Open(filePath, FileMode.Open))
			{
				XmlSerializer serializer = new XmlSerializer(typeof(T));

				t = (T)serializer.Deserialize(stream);
			}
			return t;

		}

		public string Save&lt;T&gt;(T t) {

			string filePath = typeof(T).ToString() + ".xml";

			using (Stream stream = File.Open(filePath, FileMode.Create))
			{
				XmlSerializer serializer = new XmlSerializer(typeof(T));

				serializer.Serialize(stream, t);
			}
			return filePath;
		}

	}

	//Some classes to test serialization
	public class Settings{
		public string name{get;set;}
	}

	public class Person{
		public int age{get;set;}
		public string name{get;set;}
	}
}
</pre>

<b>output:</b><br/>

<img src="http://images.rootsilver.com/main.php?g2_view=core.DownloadItem&g2_itemId=716" alt="generic xml serialization" >]]></description>
            <link>http://www.rootsilver.com/2008/12/generic-xml-serialization</link>
            <guid>http://www.rootsilver.com/2008/12/generic-xml-serialization</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">How To</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">C#</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">XML</category>
            
            <pubDate>Thu, 04 Dec 2008 12:26:19 -0500</pubDate>
        </item>
        
    <item><title>Links for 2008-02-14 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-02-14</link><pubDate>Fri, 15 Feb 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-02-14</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.codinghorror.com/blog/archives/001054.html"&gt;Coding Horror: The Years of Experience Myth&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Links for 2008-01-23 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-01-23</link><pubDate>Thu, 24 Jan 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-01-23</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://docutils.sourceforge.net/docs/user/rst/quickstart.html"&gt;A ReStructuredText Primer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Links for 2008-01-20 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-01-20</link><pubDate>Mon, 21 Jan 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-01-20</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://unreasonable.org/node/303"&gt;&amp;quot;white noise&amp;quot; generator with sox for Linux - unreasonable.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Links for 2008-01-19 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-01-19</link><pubDate>Sun, 20 Jan 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-01-19</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.reuters.com/article/marketsNews/idUKN1530426720080117?rpc=44"&gt;Wealthy may be next in line in home crisis | Markets | Markets News | Reuters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.time.com/time/business/article/0,8599,1684910,00.html"&gt;After the Oil Crisis, a Food Crisis? - TIME&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Links for 2008-01-15 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-01-15</link><pubDate>Wed, 16 Jan 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-01-15</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://kishandr.wordpress.com/2007/10/18/medibuntu-non-free-codecs-for-gutsy/"&gt;Medibuntu: non-free-codecs for gutsy &amp;laquo; Kishan&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://home.c-otto.de/ipod/"&gt;Video iPod and Linux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ffmpeg.mplayerhq.hu/hooks.html#SEC4"&gt;Video Hook Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.linuxreviews.org/MPlayer#How_to_merge_a_video_file_with_an_audio_file"&gt;MPlayer - LinuxReviews&lt;/a&gt;&lt;br/&gt;
How to merge a video file with an audio fil&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Links for 2008-01-14 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-01-14</link><pubDate>Tue, 15 Jan 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-01-14</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://kylecordes.com/2007/07/05/pipe-ffmpeg/"&gt;Pipe RGB data to ffmpeg - Kyle Cordes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Links for 2008-01-09 [del.icio.us]</title><link>http://del.icio.us/rootsilver#2008-01-09</link><pubDate>Thu, 10 Jan 2008 00:00:00 PST</pubDate><guid isPermaLink="true">http://del.icio.us/rootsilver#2008-01-09</guid><description>&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.javaworld.com/javaworld/jw-11-2006/jw-1121-thread.html#resources"&gt;Hyper-threaded Java - Java World&lt;/a&gt;&lt;br/&gt;
Java threading&lt;/li&gt;
&lt;/ul&gt;</description></item></channel>
</rss>
