<?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>The Blog of Zachary Snow &#187; .NET</title>
	<atom:link href="http://zacharysnow.net/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://zacharysnow.net</link>
	<description></description>
	<lastBuildDate>Tue, 20 Dec 2011 19:41:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WinQuakeCon</title>
		<link>http://zacharysnow.net/2011/12/20/winquakecon/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=winquakecon</link>
		<comments>http://zacharysnow.net/2011/12/20/winquakecon/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 19:34:10 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[WinQuakeCon]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[command-shell]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[quake]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[winquakecon]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=471</guid>
		<description><![CDATA[I&#8217;ve always wanted a program that would allow me have a command line that I could slide in and out of view as needed like the console from Quake. I never could find one and so I finally got decided &#8230; <a href="http://zacharysnow.net/2011/12/20/winquakecon/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always wanted a program that would allow me have a command line that I could slide in and out of view as needed like the console from <a href="http://en.wikipedia.org/wiki/Quake_(video_game)">Quake</a>. I never could find one and so I finally got decided to write a tool myself. A picture is below and the source code is on <a href="https://github.com/smack0007/WinQuakeCon">GitHub</a>.</p>
<p>I&#8217;m not putting a download here as I don&#8217;t consider this finished just yet.</p>
<p><a href="http://zacharysnow.net/wp-content/uploads/2011/12/WinQuakeCon.png"><img src="http://zacharysnow.net/wp-content/uploads/2011/12/WinQuakeCon-300x160.png" alt="" title="WinQuakeCon" width="300" height="160" class="alignnone size-medium wp-image-475" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2011/12/20/winquakecon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zune Playlist / SMIL Copier</title>
		<link>http://zacharysnow.net/2011/06/27/zune-playlist-smil-copier/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=zune-playlist-smil-copier</link>
		<comments>http://zacharysnow.net/2011/06/27/zune-playlist-smil-copier/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 19:40:50 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[playlist]]></category>
		<category><![CDATA[smil]]></category>
		<category><![CDATA[windows-media-player]]></category>
		<category><![CDATA[zune]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=411</guid>
		<description><![CDATA[I needed a tool that would copy the contents of a Zune playlist to a given directory. I did a bit of googling and I couldn&#8217;t find anything, so like any good nerd I wrote a tool that did. The &#8230; <a href="http://zacharysnow.net/2011/06/27/zune-playlist-smil-copier/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I needed a tool that would copy the contents of a Zune playlist to a given directory. I did a bit of googling and I couldn&#8217;t find anything, so like any good nerd I wrote a tool that did.</p>
<p><a href="http://zacharysnow.net/images/SMILCopier.png"><img alt="SMILCopier" src="/images/SMILCopier.png" title="SMILCopier" class="alignnone" width="411" height="167" /></a></p>
<p>The format of Zune playlists is a simple XML format known as <a href="http://www.w3.org/AudioVideo/">SMIL</a>. I think Windows Media Player also stores playlists in this format but I haven&#8217;t confirmed that yet.</p>
<p>I wrote the tool very quickly and have only tested it on my machine with my test data, but I&#8217;ll provide the source if you&#8217;d like to modify for yourself. The source is C#.</p>
<p><a href="http://zacharysnow.net/files/SMILCopier.zip">Download Executable</a><br />
<a href="http://zacharysnow.net/files/SMILCopier-src.zip">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2011/06/27/zune-playlist-smil-copier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing basic Dependency Injection using a Service Container</title>
		<link>http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-basic-dependency-injection-using-services-container</link>
		<comments>http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 19:09:14 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dependency-injection]]></category>
		<category><![CDATA[design-patterns]]></category>
		<category><![CDATA[service-continer]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=321</guid>
		<description><![CDATA[By extending your Service Container class, a very basic version of dependency injection can be implemented. We&#8217;ll implement two forms of dependency injection: constructor and property injection. We&#8217;ll start by defining the Injectable attribute. [AttributeUsage(AttributeTargets.Constructor &#124; AttributeTargets.Property, AllowMultiple = false, &#8230; <a href="http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>By extending your Service Container class, a very basic version of dependency injection can be implemented. We&#8217;ll implement two forms of dependency injection: constructor and property injection. </p>
<p><span id="more-321"></span></p>
<p>We&#8217;ll start by defining the <strong>Injectable</strong> attribute. </p>
<pre name="code" class="c#">
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Property,
	AllowMultiple = false, Inherited = true)]
public class InjectableAttribute : Attribute
{
}
</pre>
<p>We&#8217;ll use this attribute to mark our constructors and properties for dependency injection. Next we&#8217;ll define an interface for our dependency injector:</p>
<pre name="code" class="c#">
public interface IDependencyInjector
{
	T Construct&lt;T&gt;();
	void Inject(object instance);
}
</pre>
<p>We&#8217;ll define our service container like so:</p>
<pre name="code" class="c#">
public class ServiceContainer : IDependencyInjector, IServiceProvider
{
	Dictionary&lt;Type, Object&gt; services;

	public ServiceContainer()
		: base()
	{
		this.services = new Dictionary&lt;Type, object&gt;();
	}

	public void AddService(Type type, Object provider)
	{
		if(null == type)
			throw new ArgumentNullException("type");

		if(null == provider)
			throw new ArgumentNullException("provider");

		if(this.services.ContainsKey(type))
			throw new InvalidOperationException("A provider is already registered the type " + type);

		var providerType = provider.GetType();

		if(!type.IsAssignableFrom(providerType))
			throw new InvalidOperationException(providerType + " is not an instance of " + type);

		this.services.Add(type, provider);
	}

	public object GetService(Type type)
	{
		if(null == type)
			throw new ArgumentNullException("type");

		if(this.services.ContainsKey(type))
			return this.services[type];

		return null;
	}

	public void RemoveService(Type type)
	{
		if(null == type)
			throw new ArgumentNullException("type");

		this.services.Remove(type);
	}

	protected object GetInjectableService(Type type)
	{
		if(type == typeof(IDependencyInjector) ||
		   type == typeof(IServiceProvider))
		{
			return this;
		}
		else
		{
			object service = this.GetService(type);

			if(service == null)
				throw new InvalidOperationException("Failed to find " + type + " depenedency.");

			return service;
		}
	}

	public T Construct&lt;T&gt;()
	{
		ConstructorInfo injectableConstructor = null;
		foreach(ConstructorInfo constructor in typeof(T).GetConstructors())
		{
			foreach(Attribute attribute in constructor.GetCustomAttributes(true))
			{
				if(attribute is InjectableAttribute)
				{
					injectableConstructor = constructor;
					break;
				}
			}

			if(injectableConstructor != null)
				break;
		}

		if(injectableConstructor == null)
			throw new InvalidOperationException("No injectable constructor found.");

		var parameters = injectableConstructor.GetParameters();
		var services = new object[parameters.Length];

		int i = 0;
		foreach(ParameterInfo parameter in parameters)
			services[i++] = GetInjectableService(parameter.ParameterType);

		return (T)injectableConstructor.Invoke(services);
	}

	public void Inject(object instance)
	{
		foreach(PropertyInfo property in instance.GetType().GetProperties())
		{
			foreach(Attribute attribute in property.GetCustomAttributes(true))
			{
				if(attribute is InjectableAttribute)
				{
					if(!property.CanWrite)
						throw new InvalidOperationException(property.Name + " is marked as Injectable but not writable.");

					property.SetValue(instance, GetInjectableService(property.PropertyType), null);
				}
			}
		}
	}
}
</pre>
<p>You can now construct new instances and inject dependencies on existing instances. Some usage examples:</p>
<pre name="code" class="c#">
public interface IFoo
{
	int Value { get; }
}

public class Foo : IFoo
{
	public int Value
	{
		get;
		set;
	}

	[Injectable]
	public Foo()
	{
	}

	public void DoIt()
	{
		Console.WriteLine(this.Value);
	}
}

public interface IBar
{
	string Value { get; }
}

public class Bar : IBar
{
	IFoo foo;

	public string Value
	{
		get;
		set;
	}

	[Injectable]
	public Bar(IFoo foo)
	{
		this.foo = foo;
	}

	public void DoIt()
	{
		Console.WriteLine(this.Value + ": " + this.foo.Value);
	}
}

public class Baz
{
	[Injectable]
	public IFoo Foo
	{
		get;
		set;
	}

	[Injectable]
	public IBar Bar
	{
		get;
		set;
	}

	public void DoIt()
	{
		Console.WriteLine(this.Bar.Value + " | " + this.Foo.Value);
	}
}

class Program
{
	static void Main(string[] args)
	{
		var container = new ServiceContainer();

		var foo = container.Construct&lt;Foo&gt;();
		foo.Value = 5;
		container.AddService(typeof(IFoo), foo);

		var bar = container.Construct&lt;Bar&gt;();
		container.AddService(typeof(IBar), bar);
		bar.Value = "Hello World!";
		bar.DoIt();

		var baz = new Baz();
		container.Inject(baz);
		baz.DoIt();
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress Bar in Windows 7 Taskbars</title>
		<link>http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=progress-bars-in-windows-7-taskbars</link>
		<comments>http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 18:00:20 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=308</guid>
		<description><![CDATA[I decided to add progress bar to the Windows 7 Taskbar in my Timer app. I started by downloading and compiling the Windows API Code Pack in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files &#8230; <a href="http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I decided to add progress bar to the Windows 7 Taskbar in my Timer app.</p>
<p><a href="http://zacharysnow.net/wp-content/uploads/2010/06/TimerProgressBar.png"><img src="http://zacharysnow.net/wp-content/uploads/2010/06/TimerProgressBar.png" alt="" title="TimerProgressBar" width="139" height="40" class="alignnone size-full wp-image-309" /></a></p>
<p>I started by downloading and compiling the <a href="http://code.msdn.microsoft.com/WindowsAPICodePack">Windows API Code Pack</a> in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files to the project. After that add the lines:</p>
<pre name="code" class="c#">
using Microsoft.WindowsAPICodePack.Taskbar;
</pre>
<p>to your using statements. When the clock starts running I create the progress bar in the taskbar with:</p>
<pre name="code" class="c#">
// Initialize progress bar
if(TaskbarManager.IsPlatformSupported)
{
	TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
	TaskbarManager.Instance.SetProgressValue(0, (int)this.totalTime.TotalSeconds, this.Handle);
}
</pre>
<p>to stop the progress bar:</p>
<pre name="code" class="c#">
// Stop progress bar
if(TaskbarManager.IsPlatformSupported)
	TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
</pre>
<p>and finally to update the progress bar on each tick:</p>
<pre name="code" class="c#">
// Update progress bar
if(TaskbarManager.IsPlatformSupported)
	TaskbarManager.Instance.SetProgressValue((int)this.totalTime.TotalSeconds - (int)this.time.TotalSeconds, (int)this.totalTime.TotalSeconds, this.Handle);
</pre>
<p><a href="http://zacharysnow.net/files/TimerWin7Taskbar.zip">Download Binary</a><br />
<a href="http://zacharysnow.net/files/TimerWin7TaskbarSrc.zip">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

