<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Journal of a software dev</title>
	<atom:link href="http://journalofasoftwaredev.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://journalofasoftwaredev.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 00:35:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='journalofasoftwaredev.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Journal of a software dev</title>
		<link>http://journalofasoftwaredev.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://journalofasoftwaredev.wordpress.com/osd.xml" title="Journal of a software dev" />
	<atom:link rel='hub' href='http://journalofasoftwaredev.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Still creating windows services in .NET by hand?</title>
		<link>http://journalofasoftwaredev.wordpress.com/2011/11/14/still-creating-windows-services-in-net-by-hand/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2011/11/14/still-creating-windows-services-in-net-by-hand/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 12:30:58 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[topshelf]]></category>
		<category><![CDATA[windows service]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=455</guid>
		<description><![CDATA[Seriously stop and use Topshelf, why?&#8230; Turns a console application into a windows service which allows much easier debugging Uses a fluent interface to setup your services allowing easy in code setup An instance can be provided at install allowing multiple same services on the same machine (which means you won&#8217;t need to read this) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=455&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Seriously stop and use <a href="http://topshelf-project.com/" target="_blank">Topshelf</a>, why?&#8230;</p>
<ul>
<li>Turns a console application into a windows service which allows <strong>much easier debugging</strong></li>
<li>Uses a fluent interface to setup your services allowing <strong>easy in code setup</strong></li>
<li>An instance can be provided at install allowing <strong>multiple same services on the same machine</strong> (which means you won&#8217;t need to read <a href="http://journalofasoftwaredev.wordpress.com/2008/07/16/multiple-instances-of-same-windows-service/" target="_blank">this</a>)</li>
</ul>
<p>The project site has a good <a href="http://topshelf-project.com/documentation/getting-started/" target="_blank">Getting Started</a> guide, once your ready to install the service, simply run this in a cmd prompt in the same directory as your exe:</p>
<pre>myservice.exe install /instance:test</pre>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/c/'>c#</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/topshelf/'>topshelf</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/windows-service/'>windows service</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/455/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=455&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2011/11/14/still-creating-windows-services-in-net-by-hand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Customizing $.getJSON for a specific loading panel</title>
		<link>http://journalofasoftwaredev.wordpress.com/2011/11/02/customizing-getjson-for-a-specific-loading-panel/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2011/11/02/customizing-getjson-for-a-specific-loading-panel/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 21:11:24 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[getJSON]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[loading]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=453</guid>
		<description><![CDATA[If you want to display a loading image for each ajax call made with jQuery you can hook into the global ajax events however you may have screens that have separate areas where the content is loaded async at the same time in which case you want a separate loading image assigned to each, normally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=453&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you want to display a loading image for each ajax call made with jQuery you can hook into the <a href="http://api.jquery.com/category/ajax/global-ajax-event-handlers/" target="_blank">global ajax events</a> however you may have screens that have separate areas where the content is loaded async at the same time in which case you want a separate loading image assigned to each, normally you would then need to use either the low level <code>$.ajax</code> function or use the callback functions on the returned <code>jqXHR</code> object, so I have created the following jQuery plugin to allow a selector to be passed that will be shown at load and hidden when completed:</p>
<p><pre class="brush: jscript;">
(function($) {
    $.extend({
        getJSON: function(url, loadingSelector, data, callback) {
            if ($.isFunction(data)) {
                callback = data;
                data = null;
            }

            var loadingElement = $(loadingSelector);
            return $.ajax({
                url: url,
                type: 'GET',
                dataType: 'json',
                beforeSend: function() {
                    loadingElement.show();
                },
                complete: function() {
                    loadingElement.hide();
                },
                success: callback,
                data: data
            })
        }
    })
})(jQuery);
</pre></p>
<p>The arguments are the same as the standard function apart from the new <code>loadingSelector </code>argument where you specify the element(s) that should be shown on load and hidden when complete here is an example usage:</p>
<p><pre class="brush: jscript;">
$.getJSON('/customer/list', '#loading', function(response) {
    $('#customers').html(response.content);
});
</pre></p>
<p>This will use the selector &#8216;#loading&#8217; to select the element(s) you can use any jQuery selector, with some tweaks you could also extend <code>$.post</code>.</p>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/javascript/'>javascript</a>, <a href='http://journalofasoftwaredev.wordpress.com/category/javascript/jquery/'>jQuery</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/ajax/'>ajax</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/getjson/'>getJSON</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/javascript/'>javascript</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/jquery/'>jQuery</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/js/'>js</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/json/'>json</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/loading/'>loading</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/453/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=453&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2011/11/02/customizing-getjson-for-a-specific-loading-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Replicating String.Format() in Javascript</title>
		<link>http://journalofasoftwaredev.wordpress.com/2011/10/30/replicating-string-format-in-javascript/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2011/10/30/replicating-string-format-in-javascript/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 21:42:01 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript format]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string.format]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=426</guid>
		<description><![CDATA[One of the annoying issues with Javascript is when it comes to formatting strings with values from variables usually you end up with the following: This ends up being hard to read and also prone to errors when operators/quotes are missed or not matched properly, if this was C# we could do the following: This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=426&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the annoying issues with Javascript is when it comes to formatting strings with values from variables usually you end up with the following:</p>
<p><pre class="brush: jscript;">
var someValue = 100;
var anotherValue = 555;
alert('someValue is ' + someValue + ' and anotherValue is ' + anotherValue);
</pre></p>
<p>This ends up being hard to read and also prone to errors when operators/quotes are missed or not matched properly, if this was C# we could do the following:</p>
<p><pre class="brush: csharp;">
var someValue = 100;
var anotherValue = 555;
Console.WriteLine(String.Format(&quot;someValue is {0} and anotherValue is {1}&quot;, someValue, anotherValue));
</pre></p>
<p>This is much nicer it would be better if we had <a href="http://en.wikipedia.org/wiki/String_interpolation" title="String Interpolation" target="_blank">string interpolation</a> but hey-ho maybe in a future version. </p>
<p>One of the great things about the dynamic nature of Javascript is that you can extend any of it&#8217;s types as they are all objects using the prototype keyword, so we can extend the <code>String </code>object and also make use of the <code>arguments</code> object to allow any number parameters to be passed in:</p>
<p><pre class="brush: jscript;">
String.prototype.format = function()
{
   var content = this;
   for (var i=0; i &lt; arguments.length; i++)
   {
        var replacement = '{' + i + '}';
        content = content.replace(replacement, arguments[i]);  
   }
   return content;
};
</pre></p>
<p>This allows us to replace the first code example with this:</p>
<p><pre class="brush: jscript;">
var someValue = 100;
var anotherValue = 555;
alert('someValue is {0} and anotherValue is {1}'.format(someValue, anotherValue));
</pre></p>
<p>Which I think reads better than the static <code>Format</code> method as C# does not have built-in support for doing the following <code>"test {0}".Format(123)</code>.</p>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/javascript/'>javascript</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/javascript/'>javascript</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/javascript-format/'>javascript format</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/js/'>js</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/prototype/'>prototype</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/string/'>string</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/string-format/'>string.format</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/426/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=426&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2011/10/30/replicating-string-format-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Using dynamic for Stored Procedures</title>
		<link>http://journalofasoftwaredev.wordpress.com/2011/10/21/using-dynamic-for-stored-procedures/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2011/10/21/using-dynamic-for-stored-procedures/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 18:00:06 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ado.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# 4.0]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[sp]]></category>
		<category><![CDATA[stored procedures]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=417</guid>
		<description><![CDATA[It can be quite cumbersome to call an SP with ado.net when you also need to supply parameters, you usually end up with this: There is quite a lot of ceremony in there to make a simple SP call, using a dynamic object we can reduce this down to: As you can see it still [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=417&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It can be quite cumbersome to call an SP with ado.net when you also need to supply parameters, you usually end up with this:</p>
<p><pre class="brush: csharp;">
using (var connection = new SqlConnection(connectionString))
{
    connection.Open();
    var cmd = connection.CreateCommand();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Text = &quot;MyStoredProcedure&quot;;
    var firstParameter = new SqlParameter(&quot;FirstParameter&quot;, value);
    var secondParameter = new SqlParameter(&quot;SecondParameter&quot;, DBNull.Value);
    cmd.Parameters.Add(firstParameter);
    cmd.Parameters.Add(secondParameter);
    var reader = cmd.ExecuteReader();
}
</pre></p>
<p>There is quite a lot of ceremony in there to make a simple SP call, using a dynamic object we can reduce this down to:</p>
<p><pre class="brush: csharp;">
using (var connection = new SqlConnection(connectionString))
{
    connection.Open();
    dynamic myStoredProcedure = new DynamicStoredProcedure(&quot;MyStoredProcedure&quot;);
    myStoredProcedure.FirstParameter = value;
    myStoredProcedure.SecondParameter = null;
    var reader = myStoredProcedure.ExecuteReader(connection);
}
</pre></p>
<p>As you can see it still requires the caller to look after the connection so that it can manage it properly and make sure that it is closed however now using the dynamic keyword we can make calls to properties that don&#8217;t exist but instead are resolved dynamically and treated as a <code>SqlParameter</code> using the name of the property as the name of the parameter and the value is used as the parameter value, also nulls are automatically converted to DBNull.Value as the value for the parameter.</p>
<p>The <code>DynamicStoredProcedure</code> object declaration looks like this:</p>
<p><pre class="brush: csharp;">
public class DynamicStoredProcedure : DynamicObject
{
	protected string m_Name = string.Empty;
	protected IDictionary&lt;string, SqlParameter&gt; m_Parameters = new Dictionary&lt;string, SqlParameter&gt;();
	
	public DynamicStoredProcedure(string storedProcedureName)
	{
		m_Name = storedProcedureName;
	}

	public void AddParameter(SqlParameter parameter)
	{
		if (m_Parameters.ContainsKey(parameter.ParameterName))
		{
			m_Parameters[parameter.ParameterName] = parameter;
		}
		else
		{
			m_Parameters.Add(parameter.ParameterName, parameter);
		}
	}

	public override bool TrySetMember(SetMemberBinder binder, object value)
	{
		var convertedValue = (value == null) ? DBNull.Value : value;

		if (m_Parameters.ContainsKey(binder.Name))
		{
			m_Parameters[binder.Name].Value = convertedValue;
			return true;
		}

		var param = new SqlParameter(binder.Name, convertedValue);
		m_Parameters.Add(binder.Name, param);
		return true;
	}
	
	public SqlDataReader ExecuteReader(SqlConnection connection)
	{
		var cmd = CreateCommand(connection);
		var reader = cmd.ExecuteReader();
		return reader;
	}

	public T ExecuteScalar&lt;T&gt;(SqlConnection connection)
	{
		var cmd = CreateCommand(connection);
		var result = cmd.ExecuteScalar();
		var type = typeof(T);

		if (result.GetType().IsAssignableFrom(type))
			return (T)result;

		throw new InvalidOperationException(string.Format(&quot;Cannot convert result [{0}] to type [{1}]&quot;, result, type));
	}

	public void ExecuteNonQuery(SqlConnection connection)
	{
		var cmd = CreateCommand(connection);
		cmd.ExecuteNonQuery();
	}

	private SqlCommand CreateCommand(SqlConnection connection)
	{
		var cmd = connection.CreateCommand();
		cmd.CommandType = CommandType.StoredProcedure;
		cmd.CommandText = m_Name;
		cmd.Parameters.AddRange(m_Parameters.Values.ToArray());
		return cmd;
	}
}
</pre></p>
<p>I have added the standard <code>Execute</code> methods that you find on <code>SqlCommand</code> There are also times were you need to add a parameter explicitly for instance for output parameters and if you want more control over the configuration of the parameter in this case I have added an explicit <code>AddParameter</code> for these cases.</p>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/net/'>.net</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/ado-net/'>ado.net</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/c/'>c#</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/c-4-0/'>c# 4.0</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/database/'>database</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/dynamic/'>dynamic</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/sp/'>sp</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/stored-procedures/'>stored procedures</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/417/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=417&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2011/10/21/using-dynamic-for-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Calling exe&#8217;s with parameters from powershell</title>
		<link>http://journalofasoftwaredev.wordpress.com/2011/10/07/calling-exes-with-parameters-from-powershell/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2011/10/07/calling-exes-with-parameters-from-powershell/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 17:20:25 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=403</guid>
		<description><![CDATA[I have just spent quite a bit of time trying to get a powershell script to be able to call an external program, I knew about the &#38; operator and I could get it to work by calling the exe with no parameters: But once I tried to add any I kept getting errors, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=403&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have just spent quite a bit of time trying to get a powershell script to be able to call an external program, I knew about the &amp; operator and I could get it to work by calling the exe with no parameters:</p>
<p><pre class="brush: powershell;">
&amp; &quot;c:\foo\MyProgram.exe&quot;
</pre></p>
<p>But once I tried to add any I kept getting errors, I tried various different quotes around the strings in different permutations however I finally got it working by specifying no quotes at all:</p>
<p><pre class="brush: powershell;">
&amp; &quot;c:\foo\MyProgram.exe&quot; -firstParameter $firstParam, -secondParam $secondParam
</pre></p>
<p>Just thought I would share this so that someone else doesn&#8217;t spend their time trying various different quotes.</p>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/powershell/'>powershell</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/powershell/'>powershell</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/403/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=403&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2011/10/07/calling-exes-with-parameters-from-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET MVC 3 HtmlHelper for custom pager</title>
		<link>http://journalofasoftwaredev.wordpress.com/2011/10/02/asp-net-mvc-3-htmlhelper-for-custom-pager/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2011/10/02/asp-net-mvc-3-htmlhelper-for-custom-pager/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 15:23:05 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[htmlhelper]]></category>
		<category><![CDATA[pager]]></category>
		<category><![CDATA[paging]]></category>

		<guid isPermaLink="false">https://journalofasoftwaredev.wordpress.com/2011/10/02/asp-net-mvc-3-htmlhelper-for-custom-pager/</guid>
		<description><![CDATA[For our existing intranet applications written using web forms we have a web control to do our paging like most web controls it uses viewstate to remember what state it is currently in going forward we are now using MVC so I needed to replace the webcontrol with a HtmlHelper method to create a pager. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=406&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For our existing intranet applications written using web forms we have a web control to do our paging like most web controls it uses viewstate to remember what state it is currently in going forward we are now using MVC so I needed to replace the webcontrol with a HtmlHelper method to create a pager.</p>
<p>I had a look round to find an existing one however all the ones I came across work in slightly different way compared to our existing webcontrol below is screenshot of how it looks:</p>
<p><a href="http://journalofasoftwaredev.files.wordpress.com/2011/10/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://journalofasoftwaredev.files.wordpress.com/2011/10/image_thumb.png?w=180&#038;h=34" width="180" height="34" /></a> </p>
</p>
<p>The HtmlHelpers I found seem to work by taking the current page number and populating the page numbers either side so that the page number is always in the middle of the other numbers, our existing web control works by displaying a group of page numbers you can then use the ellipse button to move to the previous/next group of pages, for example:</p>
<p>given the above I can move between all the pages above and the selected will be displayed emboldened, if I want to move to the next group of pages I can either click the ellipse button or if I’m on page 5 I can use the <strong>&gt;</strong> button both will display the next group starting from 6. After racking my brain I came up with an algorithm to support this with no viewstate being available.</p>
<p>Basically we can use the current page number to find the last page number in this current group, i.e. if were displaying groups of 3 and were on page 4 the last number in this group is 6 the first group is 1-3. We can then use this to find the start number for the group by taking this number and take off the group size – 1 (2 in this case). The only thing we need to provision for is that we haven’t gone over the page count which can be done by checking which is minimum between the last page number for the group or the page count. Once we have the boundaries of the group we can work out which buttons to display and which page to display fairly easily.</p>
<p>Here is the code to demonstrate:</p>
<p><pre class="brush: csharp;">  
public static MvcHtmlString Pager(this HtmlHelper helper, int currentPage, int pageSize, int totalItemCount, object routeValues) 
{  	
    // how many pages to display in each page group const  	
    int cGroupSize = 5;  	
    var pageCount = (int)Math.Ceiling(totalItemCount / (double)pageSize);   	
    
    // cleanup any out bounds page number passed  	
    currentPage = Math.Max(currentPage, 1);  	
    currentPage = Math.Min(currentPage, pageCount);  	
    
    var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection);  	
    var container = new TagBuilder(&quot;div&quot;);
    container.AddCssClass(&quot;pager&quot;);  	
    var actionName = helper.ViewContext.RouteData.GetRequiredString(&quot;Action&quot;);   	
    
    // calculate the last page group number starting from the current page  	
    // until we hit the next whole divisible number  	
    var lastGroupNumber = currentPage;  	
    while ((lastGroupNumber % cGroupSize != 0)) lastGroupNumber++;   	
    
    // correct if we went over the number of pages  	
    var groupEnd = Math.Min(lastGroupNumber, pageCount);   	
    
    // work out the first page group number, we use the lastGroupNumber instead of  	
    // groupEnd so that we don't include numbers from the previous group if we went  	
    // over the page count  	
    var groupStart = lastGroupNumber - (cGroupSize - 1);   	
    
    // if we are past the first page  	
    if (currentPage &gt; 1)  	
    {  		
        var previous = new TagBuilder(&quot;a&quot;);  		
        previous.SetInnerText(&quot;&lt;&quot;);  		
        previous.AddCssClass(&quot;previous&quot;);  		
        var routingValues = new RouteValueDictionary(routeValues);  		
        routingValues.Add(&quot;page&quot;, currentPage - 1);  		
        previous.MergeAttribute(&quot;href&quot;, urlHelper.Action(actionName, routingValues));  		
        container.InnerHtml += previous.ToString();  	
    }   	
    
    // if we have past the first page group  	
    if (currentPage &gt; cGroupSize)  	
    {  		
        var previousDots = new TagBuilder(&quot;a&quot;);  		
        previousDots.SetInnerText(&quot;...&quot;);  		
        previousDots.AddCssClass(&quot;previous-dots&quot;);  		
        var routingValues = new RouteValueDictionary(routeValues);  		
        routingValues.Add(&quot;page&quot;, groupStart - cGroupSize);  		
        previousDots.MergeAttribute(&quot;href&quot;, urlHelper.Action(actionName, routingValues));  		
        container.InnerHtml += previousDots.ToString();  	
    }   	
    
    for (var i = groupStart; i &lt;= groupEnd; i++)  	
    {  		
        var pageNumber = new TagBuilder(&quot;a&quot;);  		
        pageNumber.AddCssClass(((i == currentPage)) ? &quot;selected-page&quot; : &quot;page&quot;); 				
        pageNumber.SetInnerText((i).ToString());  		
        var routingValues = new RouteValueDictionary(routeValues);  		
        routingValues.Add(&quot;page&quot;, i);  		
        pageNumber.MergeAttribute(&quot;href&quot;, urlHelper.Action(actionName, routingValues));  		
        container.InnerHtml += pageNumber.ToString();  	
    }   	
    
    // if there are still pages past the end of this page group  	
    if (pageCount &gt; groupEnd)  	
    {  		
        var nextDots = new TagBuilder(&quot;a&quot;);  		
        nextDots.SetInnerText(&quot;...&quot;);  		
        nextDots.AddCssClass(&quot;next-dots&quot;);  		
        var routingValues = new RouteValueDictionary(routeValues);  		
        routingValues.Add(&quot;page&quot;, groupEnd + 1); 
        nextDots.MergeAttribute(&quot;href&quot;, urlHelper.Action(actionName, routingValues));  		
        container.InnerHtml += nextDots.ToString();  	
    }   	
    
    // if we still have pages left to show  	
    if (currentPage &lt; pageCount)  	
    {  		
        var next = new TagBuilder(&quot;a&quot;);  		
        next.SetInnerText(&quot;&gt;&quot;);  		
        next.AddCssClass(&quot;next&quot;);  		
        var routingValues = new RouteValueDictionary(routeValues);  		
        routingValues.Add(&quot;page&quot;, currentPage + 1);  		
        next.MergeAttribute(&quot;href&quot;, urlHelper.Action(actionName, routingValues));  		
        container.InnerHtml += next.ToString();  	
    }   	
    
    return MvcHtmlString.Create(container.ToString());  
}</pre> </p>
<p>To use it from the screen you simply do:</p>
<p>@Html.Pager(Model.Page, 20, Model.TotalItems, new {Model.Description})</p>
<p>Hopefully this will help someone who needs a pager to work this way as opposed to the more common offset implementations.</p>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/aspnet-mvc/'>asp.net mvc</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/aspnet-mvc/'>asp.net mvc</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/htmlhelper/'>htmlhelper</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/pager/'>pager</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/paging/'>paging</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=406&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2011/10/02/asp-net-mvc-3-htmlhelper-for-custom-pager/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>

		<media:content url="http://journalofasoftwaredev.files.wordpress.com/2011/10/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>So you want to learn to play the guitar</title>
		<link>http://journalofasoftwaredev.wordpress.com/2010/02/14/so-you-want-to-learn-to-play-the-guitar/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2010/02/14/so-you-want-to-learn-to-play-the-guitar/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 12:45:43 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[guitar]]></category>
		<category><![CDATA[off topic]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/2010/02/14/so-you-want-to-learn-to-play-the-guitar/</guid>
		<description><![CDATA[I know this a little off-topic and one of the main reasons for not posting for a while, but I thought I would do a post about what my opinions are when learning and some advice I would give other people wanting to learn guitar: Consider buying an electric before an acoustic the reasons being [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=402&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I know this a little off-topic and one of the main reasons for not posting for a while, but I thought I would do a post about what my opinions are when learning and some advice I would give other people wanting to learn guitar:</p>
<p><strong>Consider buying an electric before an acoustic</strong> the reasons being electrics are easier to play (thinner strings, lower action) they are also more adjustable you can also pick really good electric guitars for cheaper price a good example being the Yamaha Pacifica. Acoustics on the other hand are harder to play (thicker strings, higher action) and generally you have to spend quite a lot to get a good sounding and easier to play acoustic. When I first started I was borrowing a cheap acoustic off one of my friends and it was awful to play the action was ridiculously high (ok as a slide guitar!) half an hour and my finger tips looked like canyons!</p>
<p><strong>Take your guitar to a luthier to get setup</strong> when I got round to buying quite an expensive acoustic at the time I thought it was ok to play so carried on learning on it, this was a mistake I took it to a local luthier on the island who did an amazing job of lowering the action right down while having no impact on the sound it was like having a brand new guitar and much easier to play (especially when learning barre chords).</p>
<p><strong>Kit you need to buy</strong> should include:</p>
<ul>
<li>Electric tuner – Time should be spent getting your chord shapes, rhythm, changes etc… down and not spent ages trying to tune manually, until you can get good at the former.</li>
<li>Capo – Seriously worth getting one especially before your barre chords are down or if changing key for singing is necessary.</li>
<li>Picks – plenty of them brand doesn’t matter, make sure to get a range of different thicknesses</li>
</ul>
<p><strong>Don’t buy guitar learning books if they don’t include CD’s, DVD’s</strong> I made the mistake early on of buying a book on learning the guitar but didn’t include a CD or DVD so I couldn’t get any visual or sound feedback to see how I was doing rendering it pretty much useless, so I spent a bit more and got a book which included a CD so I could play along and also get feedback as to how parts should sound.</p>
<p><strong>Learn chord boxes and guitar tab</strong>&#160; as these 2 items are used everywhere from learning guitar books to YouTube guitar lessons so you should spend time to understand what they represent.</p>
<p><strong>Buy Justin Sandercoe’s (<a href="http://www.justinguitar.com">www.justinguitar.com</a>) Beginners Guitar Course</strong> if you can afford to do so if not you can view his lessons from his website but seriously consider making a donation as this is provided by Justin’s goodwill. I wish I had bought this from the beginning as this course has everything you need and following it will get you playing guitar if you put the time in.</p>
<p><strong>Don’t worry about the rhythm</strong> until you have your guitar shapes sorted and are able to switch between them relatively quickly because until you can do this your rhythm sound stuttered.</p>
<p><strong>When learning to use barre chords</strong> I was paranoid that my first finger was not long enough which was why I could not get the bottom E string barred this was of course not the case and was just getting the positioning right and building up strength between my thumb and first finger, this just takes time, it may also be that the guitar action is too high.</p>
<p><strong>Take some time out to learn a riff</strong> or a certain song you have wanted to play by checking YouTube for guitar lessons on it you can quickly establish if it’s within you current ability and makes you feel good once you can play it, for instance after a few month’s in I was on Beatles Rockband and was playing Day Tripper I liked the riff tracked down a guitar lesson and was able to play it after about an hour (slower than the record of course!) I also like Oasis and found that a lot of there songs are great to play as most are open chords. Doing this kind of stuff keeps it fun which keeps you interested.</p>
<p><strong>Singing and playing is difficult</strong> I’m still trying to get to grips with this, as I always find that my rhythm goes to hell once I get passed the first line! I would recommend going slower than the record and picking a song you know inside out.</p>
<p><strong>And the most important…be prepared to put lots of time in</strong> you really need to put the hours in to progress and you want to aim to do a few hours over a few days rather than play for many hours on a single day.</p>
<p>Hopefully this will in some way help others who want to learn to play guitar, I’m really glad I took up playing the guitar it lets me unwind from programming and makes me happy, good luck and enjoy playing.</p>
<br />Filed under: <a href='http://journalofasoftwaredev.wordpress.com/category/guitar/'>guitar</a>, <a href='http://journalofasoftwaredev.wordpress.com/category/off-topic/'>off topic</a> Tagged: <a href='http://journalofasoftwaredev.wordpress.com/tag/guitar/'>guitar</a>, <a href='http://journalofasoftwaredev.wordpress.com/tag/off-topic/'>off topic</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/402/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=402&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2010/02/14/so-you-want-to-learn-to-play-the-guitar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft Sync Framework</title>
		<link>http://journalofasoftwaredev.wordpress.com/2009/09/12/microsoft-sync-framework/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2009/09/12/microsoft-sync-framework/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 18:52:14 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[file replication]]></category>
		<category><![CDATA[file synchronization]]></category>
		<category><![CDATA[FileSyncProvider]]></category>
		<category><![CDATA[microsoft sync framework]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=395</guid>
		<description><![CDATA[I recently had a requirement to move backups from a server&#8217;s local filesystem over to a network location now my first thoughts were of a windows service and a FileSystemWatcher watching the local directory and upon a folder/file being changed copy the file over to the network, however once you start digging into the details [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=395&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently had a requirement to move backups from a server&#8217;s local filesystem over to a network location now my first thoughts were of a windows service and a <code>FileSystemWatcher</code> watching the local directory and upon a folder/file being changed copy the file over to the network, however once you start digging into the details you find it isn&#8217;t as straight forward for one thing if a backup file is deleted on the server to free up space (ony the last month&#8217;s worth for example) this should be reflected on the network end plus there&#8217;s also file renames, locked files etc&#8230;</p>
<p>Anyhow I googled around and found the <a href="http://msdn.microsoft.com/en-us/sync/">MS Sync Framework</a> which is specially created to deal with these scenario&#8217;s and out of the box comes with providers for dealing with file synchronization great stuff! The framework is pretty big as it has extension points to let you do stuff with custom providers (for other transport synchronization), custom data transformation, metadata stored items etc&#8230; however for what I wanted I barely needed to scratch the surface.</p>
<p>In it&#8217;s most basic form you end up with the following code:</p>
<p><pre class="brush: csharp;">
FileSyncProvider sourceProvider = null ;
FileSyncProvider destinationProvider = null ;

try
{
    sourceProvider = new FileSyncProvider(
        sourceReplicaId, sourceReplicaRootPath, filter, options);
    destinationProvider = new FileSyncProvider(
        destinationReplicaId, destinationReplicaRootPath, filter, options);

    destinationProvider.AppliedChange +=
        new EventHandler &lt;AppliedChangeEventArgs&gt;(OnAppliedChange);
    destinationProvider.SkippedChange +=
        new EventHandler &lt;SkippedChangeEventArgs&gt;(OnSkippedChange);

    SyncOrchestrator orchestrator = new SyncOrchestrator ();
    orchestrator.LocalProvider = sourceProvider;
    orchestrator.RemoteProvider = destinationProvider;
    orchestrator.Direction = SyncDirection.Upload; // Sync source to destination

    Console .WriteLine( &quot;Synchronizing changes to replica: &quot; +
        destinationProvider.RootDirectoryPath);
    orchestrator.Synchronize();
}
finally
{
    // Release resources
    if (sourceProvider != null ) sourceProvider.Dispose();
    if (destinationProvider != null ) destinationProvider.Dispose();
}
</pre></p>
<p>There is one gotcha that caught me out, the <a href="http://msdn.microsoft.com/en-us/sync/">MS Sync Framework</a> will not do any of the scheduling of when the synchronization is performed that is completely dealt with by you, so in my case I was back to using a <code>FileSystemWatcher</code> to watch for file changes in the source folder and once a change was detected I would then tell the <code>SyncOrchestrator</code> to synchronize this seemed to work fine and was not that much extra work. The only other step was to wrap this functionality up to be used from a windows service and that was it! Overall I would recommend anyone looking to perform synchronization to take a look to see if either there&#8217;s something out of the box the framework gives you or if it can give you a head start.</p>
<br />Posted in Uncategorized Tagged: file replication, file synchronization, FileSyncProvider, microsoft sync framework <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=395&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2009/09/12/microsoft-sync-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Controls to a Server Control</title>
		<link>http://journalofasoftwaredev.wordpress.com/2009/08/08/adding-controls-to-a-server-control/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2009/08/08/adding-controls-to-a-server-control/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 10:54:08 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code example]]></category>
		<category><![CDATA[server control]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/2009/08/08/adding-controls-to-a-server-control/</guid>
		<description><![CDATA[Usually looks like this: How about this instead: Implemented with this: I think this reads better especially if you end up appending lots of child controls, thoughts or any other solutions? Posted in asp.net, c#, code example Tagged: asp.net, server control<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=389&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Usually looks like this:</p>
<p><pre class="brush: csharp;"> 
var row = new TableRow(); 
var cell = new TableCell()
    { 
         Height = Unit.Pixel(30) 
    }); 
cell.Controls.Add( new Button() 
    { 
        Text = &quot;Go&quot;,
        CommandName = &quot;Go&quot;,
        ID = &quot;btnGo&quot; 
    }); 
row.Controls.Add(cell); 
</pre></p>
<p>How about this instead:</p>
<p><pre class="brush: csharp;"> 
var row = new TableRow(); 
var cell = row.AppendControl&lt;TableCell&gt;(x =&gt; 
                  { 
                      x.Height = Unit.Pixel(30); 
                   });
cell.AppendControl&lt;Button&gt;(x =&gt; 
    { 
        x.Text = &quot;Go&quot;;
        x.CommandName = &quot;Go&quot;;
        x.ID = &quot;btnGo&quot;; 
    });
 </pre></p>
<p>Implemented with this:</p>
<p><pre class="brush: csharp;"> 
public static ControlExtensions 
{ 
    public static TControl AppendControl&lt;TControl&gt;(this TControl control, Action&lt;tcontrol&gt; initialization) 
        where TControl : Control, new() 
    { 
        var controlToAppend = Activator.CreateInstance&lt;TControl&gt;();
        intialization(controlToAppend);
        control.Controls.Add(controlToAppend); 
        return controlToAppend; 
    } 
} </pre></p>
<p>I think this reads better especially if you end up appending lots of child controls, thoughts or any other solutions?</p>
<br />Posted in asp.net, c#, code example Tagged: asp.net, server control <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/389/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=389&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2009/08/08/adding-controls-to-a-server-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>
	</item>
		<item>
		<title>Should we enforce constructor args?!</title>
		<link>http://journalofasoftwaredev.wordpress.com/2009/06/27/should-we-enforce-constructor-args/</link>
		<comments>http://journalofasoftwaredev.wordpress.com/2009/06/27/should-we-enforce-constructor-args/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 10:53:56 +0000</pubDate>
		<dc:creator>Michael Cromwell</dc:creator>
				<category><![CDATA[unit testing]]></category>
		<category><![CDATA[DbC]]></category>

		<guid isPermaLink="false">http://journalofasoftwaredev.wordpress.com/?p=370</guid>
		<description><![CDATA[ Context Say we have a Car object: The code above is used to demonstrate a context wereby we have an object that takes a number of other collabarators which are then delegated to when certain behaviour is required this is a common event in OO, You can see I use a custom assertion class to make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=370&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3> Context</h3>
<p>Say we have a <code>Car</code> object:</p>
<p><pre class="brush: csharp;">
public class Car
{
    protected Engine engine;
    protected Door[] doors;
    protected Wheel[] wheels;

    public Car(Engine engine, Door[] doors, Wheel[] wheels)
    {
        Check.PreCondition(engine != null, &quot;engine must not be null&quot;);
        Check.PreCondition(doors != null, &quot;doors must not be null&quot;);
        Check.PreCondition(wheels != null, &quot;wheels must not be null&quot;);

        this.engine = engine;
        this.doors = doors;
        this.wheels = wheels;
    }

    public void EnableCentralLocking()
    {
        doors.ForEach(door =&gt; door.Lock());
    }

    public void Start()
    {
        engine.TurnOver();
    }
}</pre></p>
<p>The code above is used to demonstrate a context wereby we have an object that takes a number of other collabarators which are then delegated to when certain behaviour is required this is a common event in OO, You can see I use a custom assertion class to make sure the collabarators are not null.</p>
<p>One thing we pick up on is that different behaviours that the <code>Car</code> object is instructed to perform may effect only one collabarator or may effect them all for instance <code>EnableCentralLocking</code> effects the doors collabarating object but has no effect on the <code>wheels</code> or <code>engine</code>.</p>
<h3>Unit testing the above</h3>
<p>Ok so now we want to unit test the <code>Car</code> object:</p>
<p><pre class="brush: csharp;">
[TestFixture]
public class when_central_locking_enabled
{
    [Test]
    public void should_tell_all_doors_to_lock()
    {
        var engine = new Engine();
        var wheels = new Wheel[4];
        var doors = createStubDoors();

        var sut = new Car(engine, doors, wheels);
        sut.EnableCentralLocking();
        doors.All(door =&gt; door.Locked);
    }
}
</pre></p>
<p>Here I use a state based way of testing the doors have all been locked. One thing is apparent in order to create the <code>Car</code> due to the assertion checks at the beginning I have to create all the collabarators now if I was testing a behaviour that required all of them this is a must however to test the central locking the doors is the only collabarator I need, the creation of the others is just a wasted overhead.</p>
<p>Now this is how I currently create my objects that require collabarators and I was ok with this however recently I was told by a friend to check out a blog by <a href="http://misko.hevery.com/" target="_blank">Misko Hevery</a> I was astonished by how well written and the information surrounding good OO and unit testing was, anyhow I came across this <a href="http://misko.hevery.com/2009/02/09/to-assert-or-not-to-assert/" target="_blank">post</a> which made me think about whether we should be asserting the collabarators in the constructor or not.</p>
<p>If we remove the assertions our test becomes:</p>
<p><pre class="brush: csharp;">
[TestFixture]
public class when_central_locking_enabled
{
    [Test]
    public void should_tell_all_doors_to_lock()
    {
        var doors = createStubDoors();
        var sut = new Car(null, doors, null);
        sut.EnableCentralLocking();
        doors.All(door =&gt; door.Locked);
    }
}
</pre></p>
<p><img class="alignright size-medium wp-image-379" title="hmmm..." src="http://journalofasoftwaredev.files.wordpress.com/2009/06/columbo.jpg?w=273&#038;h=300" alt="hmmm..." width="273" height="300" /><br />
We removed the overhead of creating the collabarators not needed for the test however our code is open to <code>NullReferenceException</code>s being thrown if were passed a null collabarator, hmmm&#8230; a real head scratcher! </p>
<h3>What are the options?</h3>
<ol>
<li>Make the responsibility of making sure objects are created be assigned to a factory object or on an IoC container</li>
<li>Initialize the fields with NullObject values, and use a property to access the field so checks can be made (this would not be enforcable)</li>
<li>Keep the assertions but allow your assertion library to be context aware, at runtime in your unit tests allow it to be in a fall through mode</li>
<li>Keep the assertions and accept the overhead, use Test Data Builder pattern / Object Mother to cut down on repeated code</li>
<li>Move the assertions into the methods, this could cause a lot of DRY violation and extra overhead.</li>
</ol>
<p>As with most of these things it&#8217;s a balance between acheiving 100% defence and overhead required in our unit tests, after looking at the options I could come up with I&#8217;m inclined to favour 1 or 3.</p>
<p>What would you use? Do you have any different options about how to balance the 2 out?</p>
<br />Posted in unit testing Tagged: DbC, unit testing <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/journalofasoftwaredev.wordpress.com/370/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/journalofasoftwaredev.wordpress.com/370/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/journalofasoftwaredev.wordpress.com/370/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/journalofasoftwaredev.wordpress.com/370/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/journalofasoftwaredev.wordpress.com/370/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/journalofasoftwaredev.wordpress.com/370/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/journalofasoftwaredev.wordpress.com/370/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/journalofasoftwaredev.wordpress.com/370/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=journalofasoftwaredev.wordpress.com&amp;blog=2567678&amp;post=370&amp;subd=journalofasoftwaredev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://journalofasoftwaredev.wordpress.com/2009/06/27/should-we-enforce-constructor-args/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a779cab73bd28249be3597433f31709a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Mike Cromwell</media:title>
		</media:content>

		<media:content url="http://journalofasoftwaredev.files.wordpress.com/2009/06/columbo.jpg?w=273" medium="image">
			<media:title type="html">hmmm...</media:title>
		</media:content>
	</item>
	</channel>
</rss>
