<?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>Left Lobe Logic</title>
	<atom:link href="http://leftlobed.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://leftlobed.wordpress.com</link>
	<description>Ramblings of a left sided thinker...</description>
	<lastBuildDate>Fri, 16 Sep 2011 23:18:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='leftlobed.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Left Lobe Logic</title>
		<link>http://leftlobed.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://leftlobed.wordpress.com/osd.xml" title="Left Lobe Logic" />
	<atom:link rel='hub' href='http://leftlobed.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Getting to know Entity Framework &#8211; Table Per Type (TPT) Inheritance</title>
		<link>http://leftlobed.wordpress.com/2011/03/02/getting-to-know-entity-framework-table-per-type-tpt-inheritance/</link>
		<comments>http://leftlobed.wordpress.com/2011/03/02/getting-to-know-entity-framework-table-per-type-tpt-inheritance/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 20:58:02 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=72</guid>
		<description><![CDATA[I&#8217;ve been using LINQ to SQL for quite sometime because until recently I&#8217;ve had little need for Entity Framework&#8217;s EDMX mappings because we&#8217;ve generally been content with one-to-one table to entity mappings that LINQ to SQL gives us. However, with the addition of a new module to our project that is close, but not quite [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=72&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using LINQ to SQL for quite sometime because until recently I&#8217;ve had little need for Entity Framework&#8217;s EDMX mappings because we&#8217;ve generally been content with one-to-one table to entity mappings that LINQ to SQL gives us. However, with the addition of a new module to our project that is close, but not quite the same as an existing module we&#8217;ve had to call on Entity Framework to generate a proper inheritance hierarchy.</p>
<h3>What is Table Per Type (TPT) inheritance?</h3>
<p>It&#8217;s the method of defining your SQL schema such that each sub-type will live in it&#8217;s own table and share a primary key column with the parent table via a foreign key. That is, the primary key on the child table will be a one-to-one mapping to the parent table.</p>
<div id="attachment_73" class="wp-caption alignnone" style="width: 249px"><a href="http://leftlobed.files.wordpress.com/2011/03/tpt-sqlschema.jpg"><img class="size-medium wp-image-73" title="Tpt-SqlSchema" src="http://leftlobed.files.wordpress.com/2011/03/tpt-sqlschema.jpg?w=239&#038;h=300" alt="SQL Schema with an Employee joined one-to-one with Contact to demonstrate TPT inheritance" width="239" height="300" /></a><p class="wp-caption-text">Shows how Employee will be related to Contact using a common primary key linked via a foreign key</p></div>
<p>Note: My naming standard is to name primary key&#8217;s &#8220;Id&#8221; and any foreign key&#8217;s with the table name (and potentially a verb) prefixed. E.g. &#8220;ContactId&#8221;.</p>
<h3>Generate your EDMX file</h3>
<p>Start your .edmx (ADO.NET Entity Data Model Designer) as described in many <a title="Generating the School .edmx File" href="http://msdn.microsoft.com/en-us/library/bb399739.aspx" target="_blank">tutorials</a>&#8230;</p>
<p>Initially your tables will come through as associated entities. This is where we&#8217;ll pick up&#8230;</p>
<ol>
<li>From the Toolbox, pickup the &#8220;Inheritance&#8221; and join from Employee to Contact.</li>
<li>Delete the Association joining the two tables.</li>
<li>Now you&#8217;ll find that if you try to compile, you&#8217;ll get:<br />
<blockquote><p>Error 3024: Problem in Mapping Fragment starting at line 79: Must specify mapping for all key properties (Contact.Id) of the EntitySet Contact.</p></blockquote>
<p>The problem here lies in the fact that our Employee&#8217;s ContactId didn&#8217;t auto-map to the Contact&#8217;s Id field.</li>
<li>Click on Employee, open the Mapping Details view and select the Column Mapping for ContactId</li>
<li>Change the mapping using the drop down to &#8220;Id&#8221;. The drop down now includes all properties from Contact as well.
<p><div id="attachment_74" class="wp-caption alignnone" style="width: 310px"><a href="http://leftlobed.files.wordpress.com/2011/03/tpt-mappingcolumns.jpg"><img class="size-medium wp-image-74" title="Tpt-MappingColumns" src="http://leftlobed.files.wordpress.com/2011/03/tpt-mappingcolumns.jpg?w=300&#038;h=258" alt="Mapping Columns in Mapping Details editor" width="300" height="258" /></a><p class="wp-caption-text">Map the Employee&#039;s ContactId column to the Contact&#039;s Id column</p></div></li>
<li>Again, you&#8217;ll find that if you try to compile, you&#8217;ll get:<br />
<blockquote><p>Error 11009: Property &#8216;ContactId&#8217; is not mapped.</p></blockquote>
<p>Wait&#8230; Sure it is! Didn&#8217;t we just map it to the Contact&#8217;s Id column. Ummmm? Well, we won&#8217;t need it anyway. So just delete it from the Employee entity&#8217;s diagram.</p>
<p><div id="attachment_75" class="wp-caption alignnone" style="width: 310px"><a href="http://leftlobed.files.wordpress.com/2011/03/tpt-deletecolumn.jpg"><img class="size-medium wp-image-75" title="Tpt-DeleteColumn" src="http://leftlobed.files.wordpress.com/2011/03/tpt-deletecolumn.jpg?w=300&#038;h=227" alt="Delete an entity field" width="300" height="227" /></a><p class="wp-caption-text">Delete the Employee&#039;s ContactId field</p></div></li>
<li>Compile, and all is finally well!</li>
</ol>
<br />Filed under: <a href='http://leftlobed.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=72&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2011/03/02/getting-to-know-entity-framework-table-per-type-tpt-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>

		<media:content url="http://leftlobed.files.wordpress.com/2011/03/tpt-sqlschema.jpg?w=239" medium="image">
			<media:title type="html">Tpt-SqlSchema</media:title>
		</media:content>

		<media:content url="http://leftlobed.files.wordpress.com/2011/03/tpt-mappingcolumns.jpg?w=300" medium="image">
			<media:title type="html">Tpt-MappingColumns</media:title>
		</media:content>

		<media:content url="http://leftlobed.files.wordpress.com/2011/03/tpt-deletecolumn.jpg?w=300" medium="image">
			<media:title type="html">Tpt-DeleteColumn</media:title>
		</media:content>
	</item>
		<item>
		<title>Problems downloading .vhd from Microsoft</title>
		<link>http://leftlobed.wordpress.com/2009/02/11/problems-downloading-vhd-from-microsoft/</link>
		<comments>http://leftlobed.wordpress.com/2009/02/11/problems-downloading-vhd-from-microsoft/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 01:04:59 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=67</guid>
		<description><![CDATA[Thought I&#8217;d post since this seems to be common enough, but I downloaded the latest SharePoint WSS 3.0 Virtual PC files only to have found I wasted my time since during the extraction I was presented with: Packed data CRC failed in WSS-July2008.vhd And the first bit is common for other VHD downloads too I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=67&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Thought I&#8217;d post since this seems to be common enough, but I downloaded the latest SharePoint WSS 3.0 Virtual PC files only to have found I wasted my time since during the extraction I was presented with:</p>
<blockquote><p>Packed data CRC failed in WSS-July2008.vhd</p></blockquote>
<p>And the first bit is common for other VHD downloads too I believe &#8211; including the CRM VPC download, the MOSS download, and others.</p>
<p>Turns out the problem is downloading the file in resume mode and/or multiple connections. Thus, <span style="color:#ff0000;"><strong>don&#8217;t use a download manager</strong><span style="color:#888888;">!</span></span></p>
<p><span style="color:#ff0000;"><span style="color:#888888;">After I went back and re-downloaded (all 4 GB) using just the native IE download (and being sure to start again after a connection dropped out half way through) I got a clean download and successful rar extraction&#8230;</span></span></p>
<p><span style="color:#ff0000;"><span style="color:#888888;">Hopefully that helps some frustrated soul&#8230;</span></span></p>
<p><span style="color:#ff0000;"><span style="color:#888888;">Love,<br />
Reddog.</span></span></p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=67&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2009/02/11/problems-downloading-vhd-from-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Gotcha &#8211; Implicit sitemap localization resx belong in App_GlobalResources</title>
		<link>http://leftlobed.wordpress.com/2009/01/14/gotcha-implicit-sitemap-localization-resx-belong-in-app_globalresources/</link>
		<comments>http://leftlobed.wordpress.com/2009/01/14/gotcha-implicit-sitemap-localization-resx-belong-in-app_globalresources/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:23:57 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[implicit localization]]></category>
		<category><![CDATA[SiteMap]]></category>
		<category><![CDATA[web.sitemap.resx]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=61</guid>
		<description><![CDATA[When providing a multi-lingual website you&#8217;re likely to want to translate your sitemap files for your menus, footer links, etc. I tend to store most of my translations using implicit localization techniques whereby you would put your resx in a relative App_LocalResources folder. However, when it comes to SiteMap localization don&#8217;t be fooled! They must all go [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=61&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When providing a multi-lingual website you&#8217;re likely to want to translate your sitemap files for your menus, footer links, etc.</p>
<p>I tend to store most of my translations using <a href="http://msdn.microsoft.com/en-us/library/fw69ke6f(VS.80).aspx">implicit localization techniques</a> whereby you would put your resx in a relative <strong>App_LocalResources </strong>folder. However, when it comes to SiteMap localization don&#8217;t be fooled!</p>
<p>They must all go into the site relative <strong>App_GlobalResources</strong>.</p>
<p>[References: tiny type on step 3 of <a title="Localize Site-Map Data" href="http://msdn.microsoft.com/en-us/library/ms178427(vs.80).aspx">How to: Localize Site-Map Data</a> and detailed instructions <a href="http://dreamdotnet.blogspot.com/2007/02/tutorial-localize-websitemap-file.html">Tutorial: Localize a Web.sitemap file</a>]</p>
<br />Posted in ASP.NET, Localization, Tips Tagged: implicit localization, SiteMap, web.sitemap.resx <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=61&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2009/01/14/gotcha-implicit-sitemap-localization-resx-belong-in-app_globalresources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Using validator controls with checkboxes</title>
		<link>http://leftlobed.wordpress.com/2008/11/08/using-validator-controls-with-checkboxes/</link>
		<comments>http://leftlobed.wordpress.com/2008/11/08/using-validator-controls-with-checkboxes/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 01:33:28 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CheckBox]]></category>
		<category><![CDATA[CustomValidator]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Validation Controls]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=35</guid>
		<description><![CDATA[When attempting to set the ControlToValidate property of any of the built-in validator controls (particularly CustomValidator) you&#8217;ll find you get the following runtime error: Control &#8216;agreeTermsCheckBox&#8217; referenced by the ControlToValidate property of &#8216;agreeTermsRequiredTrue&#8217; cannot be validated. In my case, I want to validate a checkbox for my website&#8217;s Terms and Conditions to ensure that it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=35&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When attempting to set the ControlToValidate property of any of the built-in validator controls (particularly CustomValidator) you&#8217;ll find you get the following runtime error:</p>
<blockquote><p>Control &#8216;agreeTermsCheckBox&#8217; referenced by the ControlToValidate property of &#8216;agreeTermsRequiredTrue&#8217; cannot be validated.</p></blockquote>
<p>In my case, I want to validate a checkbox for my website&#8217;s Terms and Conditions to ensure that it&#8217;s been marked as true before creating the account.</p>
<p>It turns out that CheckBox controls (and also HiddenField controls) are not supported by the BaseValidator&#8217;s ControlToValidate field. Presumably, since this is due to the fact that the value cannot be reliably read or distinguished from an empty value.</p>
<p>Thus there are two possible work arounds:</p>
<ol>
<li>Don&#8217;t use the ControlToValidate property and in your CustomValidator&#8217;s ClientValidationFunction and ServerValidate function.</li>
<li>Use an intermediate control to store the checkbox&#8217;s check state and validate against it using a CompareValidator.</li>
<li>Use an intermediate control to be able to get a reference to the checkbox to validate using a CustomValidator.</li>
</ol>
<p>The first is far from ideal  since you&#8217;ll have to use a hardcoded reference to your checkbox&#8217;s ClientID and ID in order to check it. The second is OK, except that you have to add client side events to your checkbox which may be a tiny bit more fiddly to get it functional.</p>
<p>The third is what I ended up doing.</p>
<p>In my case, I added a TextBox to the form whose Text property stores the ClientID of the CheckBox. Ideally I would have used a hidden field, but apparently they&#8217;re not supported either! I hide the TextBox using it&#8217;s CssClass (with display: none and visibility: hidden).</p>
<pre><code>
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">asp:TextBox </span><span style="color:#FF0000;">ID</span><span style="color:#0000FF;">="agreeTermsCheckBoxIdField"</span><span style="color:#FF0000;"> runat</span><span style="color:#0000FF;">="server"</span><span style="color:#FF0000;"> CssClass</span><span style="color:#0000FF;">="hidden"</span><span style="color:#FF0000;"> Text</span><span style="color:#0000FF;">='&lt;%# </span><span style="color:#FF0000;">Container.FindControl("agreeTermsCheckBox").ClientID %</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">' /&gt;</span></div>

</code></pre>
<p>Then I add my CustomValidator with ControlToValidate pointing at this new TextBox.</p>
<pre><code>
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">asp:CustomValidator </span><span style="color:#FF0000;">ID</span><span style="color:#0000FF;">="agreeTermsRequiredTrue"</span><span style="color:#FF0000;"> runat</span><span style="color:#0000FF;">="server"</span><span style="color:#FF0000;"> Text</span><span style="color:#0000FF;">="*"</span><span style="color:#FF0000;"> ControlToValidate</span><span style="color:#0000FF;">="agreeTermsCheckBoxIdField"</span><span style="color:#FF0000;"> EnableClientScript</span><span style="color:#0000FF;">="true"</span><span style="color:#FF0000;"> ClientValidationFunction</span><span style="color:#0000FF;">="ValidateCheckBoxIsTrue"</span><span style="color:#FF0000;"> OnServerValidate</span><span style="color:#0000FF;">="agreeTermsRequiredTrue_ServerValidate"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span></div>

</code></pre>
<p>The great thing about this, is that now the Value property of the validation function&#8217;s arguments will automatically be set to the ClientID of the checkbox making our client side function&#8217;s ability to locate the CheckBox nice and easy!</p>
<pre><code>
<div><span style="color:#0000FF;">function</span><span style="color:#000000;"> ValidateCheckBoxIsTrue(source, clientside_arguments)
{
    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Find the checkbox we're validating</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#008000;">//</span><span style="color:#008000;"> In this case, the client ID of the control is stored in a hidden field</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#008000;">//</span><span style="color:#008000;"> whose value is passed in via the ControlToValidate's property.</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000FF;">var</span><span style="color:#000000;"> checkBoxToValidate </span><span style="color:#000000;">=</span><span style="color:#000000;"> document.getElementById(clientside_arguments.Value);

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Default value - let it pass...</span><span style="color:#008000;">
</span><span style="color:#000000;">    clientside_arguments.IsValid </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Set IsValid according to checkbox state.</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (checkBoxToValidate </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
    {
        clientside_arguments.IsValid </span><span style="color:#000000;">=</span><span style="color:#000000;"> checkBoxToValidate.checked;
        </span><span style="color:#0000FF;">return</span><span style="color:#000000;">;
    }
}</span></div>

</code></pre>
<br />Posted in ASP.NET Tagged: ASP.NET, CheckBox, CustomValidator, Javascript, Validation Controls <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=35&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/11/08/using-validator-controls-with-checkboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency Injection into Pages and UserControls using Unity</title>
		<link>http://leftlobed.wordpress.com/2008/11/08/dependency-injection-into-pages-and-usercontrols-using-unity/</link>
		<comments>http://leftlobed.wordpress.com/2008/11/08/dependency-injection-into-pages-and-usercontrols-using-unity/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 01:17:32 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[WCSF]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[UpdatePanel]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=42</guid>
		<description><![CDATA[Edit (8 Nov 2008): Turns out&#8230; Not so much the async postbacks, and more to do with a FormView not having initialized it&#8217;s controls at the point in time in the page lifecycle (on PostBack only, after Page Init). This can be tested by using a quick watch on the protected Control.ChildControlsCreated property in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=42&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#ff0000;"><strong>Edit (8 Nov 2008): </strong>Turns out&#8230; Not so much the async postbacks, and more to do with a <strong>FormView </strong>not having initialized it&#8217;s controls at the point in time in the page lifecycle (on PostBack only, after Page Init). This can be tested by using a quick watch on the protected Control.ChildControlsCreated property in the debugger. Additionally, by touching the Controls collection of the formview it actually causes the controls from within the template to not be loaded on the postback.</span></p>
<p><span style="color:#ff0000;">The solution (and new rule!): Do NOT touch FormView.Controls at all (to get either Count or iterate) instead test beforehand using Control.HasControls() before iterating. (Note: the case where user controls are inside a FormView template will means those controls won&#8217;t have their dependencies injected on PostBack)<br />
</span></p>
<p><span style="color:#ff0000;">From the original <a href="http://blogs.msdn.com/mpuleio/archive/2008/07/17/proof-of-concept-a-simple-di-solution-for-asp-net-webforms.aspx">source code</a> I replaced the original recursive control tree function with some additional functionality including the fix for HasControls() and to make it more reusable later:</span></p>
<pre><code>
</code>
<div><span style="color:#008000;">//</span><span style="color:#008000;"> Build up each control in the page's control tree</span><span style="color:#008000;">
</span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> OnPageInitComplete(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> sender, EventArgs e)
{
    Page page </span><span style="color:#000000;">=</span><span style="color:#000000;"> (Page)sender;
    IUnityContainer container </span><span style="color:#000000;">=</span><span style="color:#000000;"> IocContainer;

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Lambda delegate for controls to apply BuildUp on
    </span><span style="color:#008000;">//</span><span style="color:#008000;"> and delegate for injection.</span><span style="color:#008000;">
</span><span style="color:#000000;">    Func</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Control, </span><span style="color:#0000FF;">bool</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> shouldApplyFunction </span><span style="color:#000000;">=</span><span style="color:#000000;"> (c </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> (c </span><span style="color:#0000FF;">is</span><span style="color:#000000;"> UserControl </span><span style="color:#000000;">||</span><span style="color:#000000;"> c </span><span style="color:#0000FF;">is</span><span style="color:#000000;"> Page </span><span style="color:#000000;">||</span><span style="color:#000000;"> c </span><span style="color:#0000FF;">is</span><span style="color:#000000;"> MasterPage));
    Action</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Control</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> injectIntoControl </span><span style="color:#000000;">=</span><span style="color:#000000;"> (c </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> container.BuildUp(c.GetType(), c));

    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Recurse tree</span><span style="color:#008000;">
</span><span style="color:#000000;">    RecurseControlTree(page.Controls, injectIntoControl, shouldApplyFunction);
}

</span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RecurseControlTree(ControlCollection controls,
                                Action</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Control</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> actionToApply,
                                Func</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Control, </span><span style="color:#0000FF;">bool</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> shouldApplyActionFunction)
{
    </span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (Control child </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> controls)
    {
        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Iterate children first</span><span style="color:#008000;">
</span><span style="color:#000000;">        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (child.HasControls())
        {
            RecurseControlTree(child.Controls, actionToApply, shouldApplyActionFunction);
        }

        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Apply function</span><span style="color:#008000;">
</span><span style="color:#000000;">        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (shouldApplyActionFunction(child))
        {
            actionToApply(child);
        }
    }
}</span></div>
</pre>
<p><span style="color:#ff0000;">Hope that helps someone!!! (End edit)</span></p>
<p>Having recently started playing with using the <a href="http://www.codeplex.com/unity">Unity framework</a> for dependency (but without going the whole hog and using the <a href="http://www.codeplex.com/websf">WCSF</a> libraries), I was after a HttpModule or Handler of some kind that will deal with the injection of dependencies into my pages, user controls, and master pages.</p>
<p>I found a <a href="http://blogs.msdn.com/mpuleio/archive/2008/07/17/proof-of-concept-a-simple-di-solution-for-asp-net-webforms.aspx">lovely little helper module and pattern</a> by <a href="http://blogs.msdn.com/mpuleio/default.aspx">Espresso Fueled Agile Development</a> that <em>almost</em> did the trick perfectly&#8230; With one exception&#8230; When doing an AJAX postback within an UpdatePanel, things went screwy.</p>
<p>Now, I&#8217;ve no idea why, but the problem actually lies with the attempt to traverse the Controls collection for all controls within the page. It turns out that spmething or other doesn&#8217;t like it&#8217;s ControlCollection to be scrutinized during an AJAX-intiated postback. So don&#8217;t! (As long as you don&#8217;t need any injected dependencies in your handlers!)</p>
<p><span style="text-decoration:line-through;">As far as I&#8217;m aware the only way to know if a postback is from an AJAX control this early in the pipeline you&#8217;ll have to call <strong>ScriptManager</strong>&#8216;s <strong>IsInAsyncPostBack</strong> property.  Thus in the <strong>UnityHttpModule</strong>, replace <strong>OnPageInitComplete</strong> with the following:</span></p>
<pre>
<div><span style="text-decoration:line-through;"><span style="color:#000000;">    </span><span style="color:#008000;">//</span><span style="color:#008000;"> Build up each control in the page's control tree</span><span style="color:#008000;">
</span><span style="color:#000000;">    </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> OnPageInitComplete(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> sender, EventArgs e)
    {
        Page page </span><span style="color:#000000;">=</span><span style="color:#000000;"> (Page)sender;
        IUnityContainer container </span><span style="color:#000000;">=</span><span style="color:#000000;"> IocContainer;
        var currentScriptManager </span><span style="color:#000000;">=</span><span style="color:#000000;"> ScriptManager.GetCurrent(page);
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (currentScriptManager </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">currentScriptManager.IsInAsyncPostBack)
        {
            </span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (Control c </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> GetControlTree(page))
            {
                container.BuildUp(c.GetType(), c);
            }
        }
    }</span></span></div>
</pre>
<p>As a side, another thing to remember is that since it&#8217;s difficult to get a hook into the instantiation of pages, you need to use Dependency declarations on the public properties rather than Injection attributes on constructors.</p>
<p>Love,<br />
Reddog.</p>
<br />Posted in ASP.NET, Unity, WCSF Tagged: AJAX, ASP.NET, Dependency Injection, Unity, UpdatePanel <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=42&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/11/08/dependency-injection-into-pages-and-usercontrols-using-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Gotcha &#8211; Reporting Services reports won&#8217;t page any more</title>
		<link>http://leftlobed.wordpress.com/2008/09/04/gotcha-reporting-services-reports-wont-page-any-more/</link>
		<comments>http://leftlobed.wordpress.com/2008/09/04/gotcha-reporting-services-reports-wont-page-any-more/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 23:12:31 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Paging]]></category>
		<category><![CDATA[ReportViewer]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=32</guid>
		<description><![CDATA[A recent discovery of a &#8220;feature&#8221; in Microsoft Reporting Services reports is that when you toggle visibility for a report element, for example, a table inside a rectangle, then you&#8217;ll find that paging on that element no longer works. This is exactly what happened in a recent report where I toggled visibility of the grid [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=32&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A recent discovery of a &#8220;feature&#8221; in Microsoft Reporting Services reports is that when you toggle visibility for a report element, for example, a table inside a rectangle, then you&#8217;ll find that paging on that element no longer works.</p>
<p>This is exactly what happened in a recent report where I toggled visibility of the grid in the event that there is no data and displayed an alternative friendly message instead from a separate rectangle with the opposing visibility expression. In my case, this became evident when I used the ReportViewer component on the page already heavy with content and it took ages to render a report.</p>
<p>Unfortunately this is something in the box and thus not bypassable. See the thread <a href="http://www.sqlreportingservices.net/Ask/5256.aspx">here</a>.</p>
<p>Thus the only option is to turn off the visibility expression&#8230;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/32/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/32/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=32&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/09/04/gotcha-reporting-services-reports-wont-page-any-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Filter tables and rename associations generated by SqlMetal using Powershell</title>
		<link>http://leftlobed.wordpress.com/2008/08/26/filter-tables-and-rename-associations-generated-by-sqlmetal-using-powershell/</link>
		<comments>http://leftlobed.wordpress.com/2008/08/26/filter-tables-and-rename-associations-generated-by-sqlmetal-using-powershell/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 06:10:27 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[DBML]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[remove table]]></category>
		<category><![CDATA[rename association]]></category>
		<category><![CDATA[rename table]]></category>
		<category><![CDATA[SqlMetal.exe]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=29</guid>
		<description><![CDATA[One of the most irritating features I initially found when using LINQ to SQL diagrams was the all or nothing approach for managing tables and views in a way that allows quick regeneration after database schema changes. Out of the box (VS2008 pre-SP1) you have two options: Build LINQ to SQL dbml mapping files by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=29&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the most irritating features I initially found when using LINQ to SQL diagrams was the all or nothing approach for managing tables and views in a way that allows quick regeneration after database schema changes. <strong>Out of the box</strong> (VS2008 pre-SP1) you have two options:</p>
<ol>
<li>Build LINQ to SQL dbml mapping files by hand &#8211; dragging tables, views, and stored procedures from the Server Explorer onto the designer surface. This works great and has the added bonus of being able to rename tables, columns, associations, and of course remove them all as well. The designer surface entities are based on definitions in a .dbml file, and the entity code is generated into a .designer.cs file.</li>
<li>Use SqlMetal.exe to generate the .dbml and class for you. I typically use two commands and drop them into a &#8220;GenerateDbml.bat&#8221; file so that on a schema change we can just double click and go.</li>
</ol>
<p>My preference definitely lies with the latter since despite the ability to do otherwise the object relation model should be close to the relational database model as possible. On the cosmetic side of things it ensures your naming standards are kept consistent, on the database level it ensures that all column types and foreign key mappings are well thought out and meaningfully names, and on the code level it means that the amount of custom code in the domain model is kept at a minimum.</p>
<p>My GenerateDbml.bat usually does it in two steps and looks like this:</p>
<div id="hlDiv" class="dp-highlighter">
<ol class="dp-rb">
<li class="alt"><span><span>sqlmetal /server:</span><span class="string">&#8220;.&#8221;</span><span> /database:</span><span class="string">&#8220;Northwind&#8221;</span><span> /dbml:NorthwindDb.dbml /context:NorthwindDataContext /namespace:LeftLobeLogic.Northwind.Domain /pluralize   </span></span></li>
<li><span>sqlmetal /code:NorthwindDb.designer.cs NorthwindDb.dbml    </span></li>
<li class="alt"><span>pause   </span></li>
</ol>
</div>
<p>One thing to notice is that the generated .dbml file is XML. Now, XML <a href="http://www.codinghorror.com/blog/archives/001114.html">may not be great</a> but at least it gives developers a tonne off standard API for dealing with it. In this instance we&#8217;re going to leverage it to quickly prune out unwanted tables and relationships before generating our object model and we&#8217;re going to make use of PowerShell to do it!</p>
<p>As <a href="http://ddkonline.blogspot.com/2008/06/using-power-of-powershell-to-configure.html" target="_blank">David blogged recently</a>, I&#8217;ve created a generic .ps1 script to handle our calling of SqlMetal as we did in our .bat file. We&#8217;ll also parameterise the script to help ditch all our Northwind references and help us set up some usual naming conventions. Our settings for cleaning our generated DBML by removing tables, renaming tables, and renaming associations are stored in an XML file.</p>
<p>Now you can simply call it with:</p>
<div id="hlDiv" class="dp-highlighter">
<ol class="dp-rb">
<li class="alt"><span><span>.\Call-SqlMetal.ps1 -database Northwind -cleanerXml </span><span class="string">&#8220;NorthwindCleanSettings.xml&#8221;</span><span>  </span></span></li>
</ol>
</div>
<p>To download the full source code you&#8217;ll find it in <a href="http://leftlobed.googlecode.com" target="_blank">Left Lobe Logic&#8217;s GoogleCode project</a> (it&#8217;s SVN). Note: The code is substantially refactored from that posted by <a href="http://ddkonline.blogspot.com/" target="_blank">Dave</a>.</p>
<p>I&#8217;ll try to share some of the individual learnings from the script in later posts.</p>
<p>Enjoy!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=29&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/08/26/filter-tables-and-rename-associations-generated-by-sqlmetal-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Error while installing SQL Server 2005 &#8211; Native Client cannot be found</title>
		<link>http://leftlobed.wordpress.com/2008/08/26/error-while-installing-sql-server-2005/</link>
		<comments>http://leftlobed.wordpress.com/2008/08/26/error-while-installing-sql-server-2005/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 19:07:10 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[Installing SQL Server 2005]]></category>
		<category><![CDATA[Native Client]]></category>
		<category><![CDATA[sqlncli.msi]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=27</guid>
		<description><![CDATA[Recently while installing SQL Server 2005 Standard Edition on a &#8220;fresh&#8221; server I found that crazy thing just wouldn&#8217;t install! I was getting the following error: &#8220;An installation package for the product Microsoft SQL Server Native Client cannot be found. Try the installation again using a valid copy of the installation package &#8216;sqlncli.msi&#8217;&#8221; Most cryptic&#8230; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=27&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently while installing SQL Server 2005 Standard Edition on a &#8220;fresh&#8221; server I found that crazy thing just wouldn&#8217;t install!</p>
<p>I was getting the following error:</p>
<blockquote><p>&#8220;An installation package for the product Microsoft SQL Server Native Client cannot be found. Try the installation again using a valid copy of the installation package &#8216;sqlncli.msi&#8217;&#8221;</p></blockquote>
<p>Most cryptic&#8230; Considering my installation package is the disc given to me by Microsoft and I&#8217;m positive that the sqlncli.msi file is right there.</p>
<p>However, the actual issue appears to be as simple as an inability to upgrade an old Native Client edition. (Thanks to <a href="http://blogs.artinsoft.net/jose_aguilar_blog/default.aspx">Jose</a> for <a href="http://blogs.artinsoft.net/jose_aguilar_blog/archive/2007/07/04/1467.aspx">pointing it out</a>). To resolve, use the Add / Remove Programs panel to uninstall an existing SQL Server Native Client installation and you should be good to roll.</p>
<p>Note that this appears to be common for other editions of SQL Server 2005 too.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=27&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/08/26/error-while-installing-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell script modularization</title>
		<link>http://leftlobed.wordpress.com/2008/06/10/powershell-script-modularization/</link>
		<comments>http://leftlobed.wordpress.com/2008/06/10/powershell-script-modularization/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 07:31:19 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[dot-sourcing]]></category>
		<category><![CDATA[modularization]]></category>
		<category><![CDATA[Script re-use]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/06/10/powershell-script-modularization/</guid>
		<description><![CDATA[PowerShell has been a sneaky beast whose power is just now starting to creep into my programming psyche. Being the good OO citizen that I am I immediately started wanting to modularize my PowerShell scripts and functions for maximum re-use and easy organisation. There are a number of ways to modularize your PowerShell including (but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=26&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>PowerShell has been a sneaky beast whose power is just now starting to creep into my programming psyche. Being the good OO citizen that I am I immediately started wanting to modularize my PowerShell scripts and functions for maximum re-use and easy organisation.</p>
<p>There are a number of ways to modularize your PowerShell including (but probably not limited to!):</p>
<ul>
<li>(Not recommended) <a href="http://www.powershellpro.com/organizing-powershell-script-code-is-a-snap-in/102/">Breaking down script blocks into functions and organising code consistently</a> within the single .ps1 script file</li>
<li>Organising functions into multiple individual .ps1 script files and dot-sourcing them</li>
<ul>
<li>TIP: <a href="http://leftlobed.wordpress.com/2008/06/04/getting-the-current-script-directory-in-powershell/">Make use of Get-ScriptDirectory function to form relative paths</a> from your current script location</li>
<li>For most effective use, it&#8217;s recommended to <a href="http://www.powershellpro.com/function-calling/144/">keep only functions defined in your dot-sourced scripts and call them individually</a>.</li>
</ul>
<li>Organising repeatable script blocks into multiple individual .ps1 script files that are parameterised and call them using the <strong>Call operator (&amp; )</strong> [See Kirk's link why dot-sourcing should be avoided]</li>
<ul>
<li>Note: I&#8217;m not talking about using functions, rather a normal .ps1 script with inline calls</li>
<li>See Kirk&#8217;s great post <a href="http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/">on invoking or calling scripts within scripts</a></li>
<li>Remember, anything used with the <strong>return</strong> keyword is what is assignable when using call operators (. and &amp; )</li>
<li>Anything that is output to host can be piped into certain host/stream redirection cmdlets (e.g. Out-File, Out-Null, Out-String)</li>
</ul>
<li>Defining functions in your <a href="http://technet.microsoft.com/en-us/library/cc162758(TechNet.10).aspx">user or system profile</a> (Profile.ps1)</li>
<ul>
<li>Remember, this could be a deployment and backup problem</li>
</ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc136004(VS.85).aspx">Writing .NET compiled cmdlets</a></li>
<ul>
<li>Compiled functions written in .NET languages and deployed in specially attributed assemblies and then specifically registered into PowerShell</li>
</ul>
</ul>
<p>Love,<br />Reddog.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=26&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/06/10/powershell-script-modularization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting the current script directory in PowerShell</title>
		<link>http://leftlobed.wordpress.com/2008/06/04/getting-the-current-script-directory-in-powershell/</link>
		<comments>http://leftlobed.wordpress.com/2008/06/04/getting-the-current-script-directory-in-powershell/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 02:10:59 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[$pwd]]></category>
		<category><![CDATA[Get-ScriptDirectory]]></category>
		<category><![CDATA[Powershell Profile]]></category>
		<category><![CDATA[Script Directory]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=24</guid>
		<description><![CDATA[One thing to remember when developing PowerShell scripts is that your current value in $PWD is the process&#8217; current directory not the one where the script was stored. In my desire to break out a few functions into a common file in order to load them &#8220;dot-sourced&#8221; (so that the functions become global) I realised [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=24&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One thing to remember when developing PowerShell scripts is that your current value in $PWD is the process&#8217; current directory not the one where the script was stored.</p>
<p>In my desire to break out a few functions into a common file in order to load them &#8220;<a href="http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx" target="_blank">dot-sourced</a>&#8221; (so that the functions become global) I realised I needed help!</p>
<p>In comes a new function from the <a href="http://blogs.msdn.com/powershell/default.aspx">PowerShell Team Blog</a>. It&#8217;s going straight into my PowerShell Profile: Get-ScriptDirectory. It does exactly as the name says, it <a href="http://blogs.msdn.com/powershell/archive/2007/06/19/get-scriptdirectory.aspx" target="_blank">gets the current directory that script is executed from</a>.</p>
<p>&lt;snip&gt;</p>
<div id="hlDiv" class="dp-highlighter">
<ol class="dp-rb">
<li class="alt"><span><span class="keyword">function</span><span> Get-ScriptDirectory </span></span></li>
<li><span>{ </span></li>
<li class="alt"><span> <span class="variable">$Invocation</span><span> = (</span><span class="builtin">Get-Variable</span><span> MyInvocation -Scope 1).Value </span></span></li>
<li><span> <span class="builtin">Split-Path</span><span> </span><span class="variable">$Invocation</span><span>.MyCommand.Path </span></span></li>
<li class="alt"><span>} </span></li>
</ol>
</div>
<p>&lt;/snip&gt;</p>
<p>So that now from my script that requires the Common-Functions.ps1 (located in the same directory) I can call:</p>
<div id="hlDiv" class="dp-highlighter">
<ol class="dp-rb">
<li class="alt"><span><span class="comment"># Load up our common functions</span><span> </span></span></li>
<li><span><span class="variable">$commons</span><span> = </span><span class="builtin">Join-Path</span><span> (Get-ScriptDirectory) </span><span class="string">&#8220;Common-Functions.ps1&#8243;</span><span>; </span></span></li>
<li class="alt"><span>. <span class="variable">$commons</span><span>; </span></span></li>
</ol>
</div>
<p>Love,<br />
Reddog.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=24&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/06/04/getting-the-current-script-directory-in-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting PowerShell console color when running elevated</title>
		<link>http://leftlobed.wordpress.com/2008/05/31/setting-powershell-console-color-when-running-elevated/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/31/setting-powershell-console-color-when-running-elevated/#comments</comments>
		<pubDate>Fri, 30 May 2008 14:07:22 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Profile.ps1]]></category>
		<category><![CDATA[Run as administrator]]></category>
		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/31/setting-powershell-console-color-when-running-elevated/</guid>
		<description><![CDATA[Recently I&#8217;ve just started delving into Powershell and I&#8217;m really growing fond of it! One tiny feature I missed about classic console (dare I say I miss it!) was how the console foreground color changed to yellow when you are running in elevated mode (through Run As Administrator). Then I stumbled onto the creation of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=23&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve just started delving into Powershell and I&#8217;m really growing fond of it!</p>
<p>One tiny feature I missed about classic console (dare I say I miss it!) was how the console foreground color changed to yellow when you are running in elevated mode (through Run As Administrator).</p>
<p>Then I stumbled onto <a href="http://www.computerperformance.co.uk/powershell/powershell_profile_ps1.htm">the creation of a personal profile.ps1</a> file inside your &lt;Profile Documents&gt;\WindowsPowerShell\profile.ps1. First things first, be sure that you&#8217;ve run Set-ExecutionPolicy to either RemoteSigned or Unrestricted (ironically, in Vista be sure that you&#8217;re elevated with Run as Administrator). Next up create the WindowsPowerShell folder in your user profile&#8217;s My Documents (or Documents in Vista) and create a new text file in there called profile.ps1.</p>
<p>Using code <a href="http://www.nivot.org/2008/02/14/WritingPortableCode.aspx">borrowed and ever so slightly changed from Nivot Ink</a> you can add the following to your profile file:</p>
<p><!-- Stylesheet link --><!-- Code --></p>
<div id="hlDiv" class="dp-highlighter">
<ol class="dp-rb">
<li class="alt"><span><span class="comment"># Returns a boolean indicating whether the passed windows identity is an administrator. </span><span>  </span></span></li>
<li><span class="comment"># Argument defaults to current user. </span><span>  </span></li>
<li class="alt"><span class="keyword">function</span><span> Test-Elevated {   </span></li>
<li><span>  </span><span class="keyword">param</span><span>(   </span></li>
<li class="alt"><span>    </span><span class="variable">$identity</span><span> = [security.principal.windowsidentity]::Getcurrent()   </span></li>
<li><span>  )   </span></li>
<li class="alt"><span>    </span></li>
<li><span>  </span><span class="variable">$principal</span><span> = new-object  security.principal.windowsprincipal </span><span class="variable">$identity</span><span>;   </span></li>
<li class="alt"><span>  </span><span class="variable">$adminsRole</span><span> =  [system.security.principal.securityidentifier]</span><span class="string">&#8220;S-1-5-32-544&#8243;</span><span>;   </span></li>
<li><span>  </span><span class="variable">$principal</span><span>.IsInRole(</span><span class="variable">$adminsRole</span><span>);   </span></li>
<li class="alt"><span>}   </span></li>
<li><span>  </span></li>
<li class="alt"><span class="comment"># Usage:    </span><span>  </span></li>
<li><span class="comment">#    </span><span>  </span></li>
<li class="alt"><span class="comment"># If-Elevated { .. admin code .. } { &#8220;sorry, need admin&#8221; }     </span><span>  </span></li>
<li><span class="comment">#    </span><span>  </span></li>
<li class="alt"><span class="keyword">function</span><span> If-Elevated {      </span></li>
<li><span>  </span><span class="keyword">param</span><span>(      </span></li>
<li class="alt"><span>    [scriptblock]</span><span class="variable">$AsAdmin</span><span> = $(Throw </span><span class="string">&#8220;Missing &#8216;as admin&#8217; script&#8221;</span><span>),      </span></li>
<li><span>    [scriptblock]</span><span class="variable">$AsUser</span><span>= $(Throw </span><span class="string">&#8220;Missing &#8216;as user&#8217; script&#8221;</span><span>)      </span></li>
<li class="alt"><span>  )      </span></li>
<li><span>       </span></li>
<li class="alt"><span>  </span><span class="keyword">if</span><span> (Test-Elevated) {      </span></li>
<li><span>    &amp; </span><span class="variable">$AsAdmin</span><span>     </span></li>
<li class="alt"><span>  } </span><span class="keyword">else</span><span> {      </span></li>
<li><span>    &amp; </span><span class="variable">$AsUser</span><span>     </span></li>
<li class="alt"><span>  }      </span></li>
<li><span>}   </span></li>
<li class="alt"><span>  </span></li>
<li><span class="comment"># Change the foreground color to yellow if admin </span><span>  </span></li>
<li class="alt"><span>If-Elevated { [System.Console]::ForegroundColor = [System.ConsoleColor]::Yellow; } { }   </span></li>
</ol>
</div>
<p>Remember PowerShell has all of .NET at it&#8217;s disposal so that&#8217;s exactly what we&#8217;re using in the Test-Elevated function. Similarly we change the console colour in the same way we would in a normal console application and while there we&#8217;ll also keep the current working directory consistent to the $HOME variable (in elevated mode it defaults to the Windows\System32 directory).</p>
<p>The proof in the pudding:<br />
<a href="http://leftlobed.files.wordpress.com/2008/05/image2.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://leftlobed.files.wordpress.com/2008/05/image-thumb1.png?w=598&#038;h=262" border="0" alt="image" width="598" height="262" /></a></p>
<p>Love,<br />
Reddog.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=23&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/31/setting-powershell-console-color-when-running-elevated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>

		<media:content url="http://leftlobed.files.wordpress.com/2008/05/image-thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>When does a requirement need to quit being a requirement?</title>
		<link>http://leftlobed.wordpress.com/2008/05/22/when-does-a-requirement-need-to-quit-being-a-requirement/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/22/when-does-a-requirement-need-to-quit-being-a-requirement/#comments</comments>
		<pubDate>Thu, 22 May 2008 12:16:59 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Developer Life]]></category>
		<category><![CDATA[Project Management]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/22/when-does-a-requirement-need-to-quit-being-a-requirement/</guid>
		<description><![CDATA[In recent times I&#8217;ve done the unmentionable, the disgusting, the horrifying, the unheard of: I said &#8220;we&#8217;ll just have to change their requirement then&#8221; and &#8220;stuff the requirement, they just didn&#8217;t know what they wanted&#8221;. When you make this sort of statement it almost becomes like the old western movies when the odd looking but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=20&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In recent times I&#8217;ve done the unmentionable, the disgusting, the horrifying, the unheard of: I said &#8220;we&#8217;ll just have to change their requirement then&#8221; and &#8220;stuff the requirement, they just didn&#8217;t know what they wanted&#8221;.</p>
<p>When you make this sort of statement it almost becomes like the <a href="http://www.imdb.com/title/tt0099088/">old western movies</a> when the odd looking but well intentioned guy walks into the bar &#8211; the crowd falls silent, the tumbleweeds roll past outside, there&#8217;s just a faint noise of horses or insects outside and dead silence inside&#8230; Then the tough guy who&#8217;s been drinking at this bar for some time (and is quite possibly drunk on dirty whiskey) gets up from high seat at the bar and says &#8220;them&#8217;s mighty strong words, runt!&#8221;</p>
<p>Like many, in recent times I&#8217;ve been working in a environment following a waterfall-esque development methodology where upon developers are completely shielded from the end user (or perhaps its the other way around) through numerous layers of indirection and obfuscation (aka analysts, management, and expensive &#8220;requirements&#8221; documents). So what&#8217;s a developer meant to do when the gut says &#8220;something smells fishy here&#8221;? What do we do when we stumble onto that magical requirement that flies in the face of the rest of them or just won&#8217;t fit with the architecture that&#8217;s been built up around all the other requirements?</p>
<p>Initially when the feeling of inferiority (and a touch of rage) for having such impure thoughts had subsided I felt compelled to write about the fact that not all of our so called &#8220;requirements&#8221; are to be treated as gospel and to try to explain how certain situations called for developers to take drastic action by simply chucking them out or re-engineering until they were unrecognisable. Finally, it occurred to me that I too was falling into the old <a href="http://www.davenicolette.net/articles/slouching_towards_waterfall.html">waterfall habits of blaming the &#8220;other guy&#8221;</a>; in this case the analyst who wrote the spec. In reality, software development is about an evolution as a team and business toward the end product. It&#8217;s not just about building something to a plan, it&#8217;s about creating something, it&#8217;s about a delicate balance of art and logic. All this means is that if you don&#8217;t have the courage to communicate your problems then the whole team loses.</p>
<h3>Some validation for your courage</h3>
<p>When it comes to trusting the quality of a requirement <a href="http://www.lostechies.com/blogs/chad_myers/default.aspx">Chad Myers</a> makes the point beautifully in his &#8220;<a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/01/26/i-don-t-trust-me.aspx">I don&#8217;t trust me</a>&#8221; development methodology ideal (which is suspiciously agile and TDD) such that when it comes to requirements he says:</p>
<blockquote><p>I don&#8217;t trust the customer or the target consumer for the software we&#8217;re building. I don&#8217;t trust them to know thoroughly what their problem is. I don&#8217;t trust them to be able to communicate effectively to me what picture of a solution they have in their mind. I don&#8217;t trust them to be able to know, beforehand, everything that they would need to have their problem solved to complete satisfaction. They will change their mind, remember things they missed mid-way through the project, remember that what they asked for earlier on was wrong and needs corrected, etc.</p>
</blockquote>
<p>With these (rather cynical) realities in mind, it becomes quite clear that not everything in the precious requirements documents is to be considered gospel. It&#8217;s up to the developer &#8211; who has the most intimate working knowledge of the system to be proactive by seeking a solution that best delivers true value to the project.</p>
<h3>Thinking and talking win-win</h3>
<p>Realising that everyone involved in the team has different viewpoints (some perhaps flawed, invalidated by time, or less intricate than others) it&#8217;s time for you, the courageous one, to communicate your problem and reasoning. If a requirement can&#8217;t be done affordably, doesn&#8217;t fit your current architecture, is contradictory, is futile, or any other reasons then it&#8217;s up to you the developer to be proactive and start the conversation rolling. There are many project management solutions that all offer continuous and potentially cheap alternatives that won&#8217;t suck the soul from the developer who would have otherwise felt like going into battle in an David versus Goliath grudge match that would have resulted in re-estimations, benefit analysis, requirements revisions, or anything else that limits developers from actually being creative. My personal preference are informal communication channels such as a chat over your desk or during a daily stand-up meeting (where you can&#8217;t forget to occasionally invite those <a href="http://en.wikipedia.org/wiki/Scrum_%28development%29#.22Chicken.22_Roles">chickens</a>). However, probably best avoid written media (email, MSN) except as an <a href="http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterEmail.aspx#KnowWhenWhenNottoUseEmail">affirmation of your plan of attack</a>.</p>
<p>Love,<br />Reddog.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=20&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/22/when-does-a-requirement-need-to-quit-being-a-requirement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>How else do we earn l33t respect?</title>
		<link>http://leftlobed.wordpress.com/2008/05/12/how-else-do-we-earn-l33t-respect/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/12/how-else-do-we-earn-l33t-respect/#comments</comments>
		<pubDate>Mon, 12 May 2008 13:58:02 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Developer Life]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/?p=19</guid>
		<description><![CDATA[I want to preface this post with a statement: I don&#8217;t think I&#8217;m l33t (meaning an elite programmer for the less nerdy of us). Having previously worked at a Sydney software consultancy where I can assure you the standard of the young consultants was very high such that I felt constantly in the shadow of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=19&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I want to preface this post with a statement: I don&#8217;t think I&#8217;m <a href="http://en.wikipedia.org/wiki/Leet">l33t</a> (meaning an elite programmer for the less nerdy of us). Having previously worked at a Sydney software consultancy where I can assure you the standard of the young consultants was very high such that I felt constantly in the shadow of an incredible 16 year old prodigy, an organised &#8220;old-timer&#8221; who just knew how to get things done (and fast!), or the respected industry speaker and rule maker&#8230; So the question beckons, how do developer&#8217;s talents get recognised?</p>
<p>I think it&#8217;s fair to say that not all <a href="http://drneil.blogspot.com/2007/12/most-programmers-shouldnt-write-code.html">programmers are equal</a> so what does it take to be considered one of those <a href="http://www.sdtimes.com/(X(1)S(bgt2nf55bylzxdrcmd0pw445))/content/article.aspx?ArticleID=31698&amp;AspxAutoDetectCookieSupport=1">hyper-productive folks</a> that we nerds might call l33t?</p>
<p>In any software development team with more than a few people, you&#8217;re almost guaranteed that your manager is no longer technical&#8230; They used to be, but by the very definition of management they&#8217;ve shifted focus onto broader topics such as staffing, team morale, project delivery, process management, financial risk mitigation, and project funding. So are they a good judge of your development skills?  The way I see it is that they are looking to see if you can do some of the following:</p>
<ul>
<li>Have the ability to d3-l33t1fy your conversations (talk non-technical)</li>
<li>Are seen as a teacher or mentor</li>
<li>Are social with your management team</li>
<li>Can communicate with the big picture in mind</li>
<li>Can understand that development costs money, lots of it</li>
<li>Follow change management, timesheeting, task tracking procedures</li>
<li>Contribute to collaboration and knowledge sharing</li>
<li>Estimate well</li>
<li>Gain industry certifications</li>
<li>(Cynically) Can <a href="http://www.slowleadership.org/blog/2008/05/are-we-rewarding-management-or-melodrama/">spin</a> when things go wrong (which <a href="http://www.codinghorror.com/blog/archives/000588.html">we know will happen a lot</a>!)</li>
</ul>
<p>But how does this correlate with what makes a good developer from another developer&#8217;s point of view? Or even a software quality point of view?</p>
<p>Almost certainly developer&#8217;s opinions of other developers are influenced by the personal, creative, social and technical sides of software development. Perhaps including some of the following:</p>
<ul>
<li>Are social with your coworkers and make them feel happy at work &#8211; you enjoy a good laugh, are fun to be around, you don&#8217;t smell, and you can go to lunch or drinks together</li>
<li>Can put time aside to help when you should
<ul>
<li>We&#8217;ve all been super focused on our task at hand to find someone whom is trying to debug your code asking you a million questions which feel unreasonable, but really they&#8217;re not. You should help them&#8230; Don&#8217;t let them <a href="http://waxtadpole.wordpress.com/about-this-blog/">deplete their life-force</a>.</li>
</ul>
</li>
<li>Document your code where necessary
<ul>
<li>Incidentally, I would typically go for a minimalist approach where code should be <a href="http://en.wikipedia.org/wiki/Self-documenting">self-documenting</a></li>
<li>This mostly includes <a href="http://www.ssw.com.au/ssw/Standards/Rules/RulestoBetterCode.aspx">code organisation and following coding standards</a></li>
</ul>
</li>
<li>Write simple code that uses chosen frameworks to their best intentions
<ul>
<li>They know when to fix vs. when to extend vs. when to roll your own</li>
<li>They use inheritance and polymorphism well</li>
</ul>
</li>
<li>Truly understands all code that they produce and &#8220;<a href="http://en.wikipedia.org/wiki/Copy_and_paste_programming">write</a>&#8220;</li>
<li>Gets things done with a gist for how to do things better in the future
<ul>
<li>Did you ever notice a good coder will often leave many TODO&#8217;s in their code?</li>
</ul>
</li>
<li>Has a broad knowledge of system components, technologies and frameworks
<ul>
<li>Somewhat similar to a good architect in that regard</li>
</ul>
</li>
<li>Continually improving old code with fresh ideas</li>
<li>Isn&#8217;t afraid to throw things out
<ul>
<li>They have a good &#8220;<a href="http://en.wikipedia.org/wiki/Code_smell">code smell</a>&#8221; for dud code and don&#8217;t mind re-engineering if need be</li>
</ul>
</li>
<li>Develops a quick familiarity with new technology rather than a deep understanding</li>
</ul>
<p>The reason I bring these points up is that I recently was chatting with <a href="http://drneil.blogspot.com/">Dr Neil</a> about MS certifications as a resume filler and then stumbled onto thoughts about whom is your best referee when going for a job&#8230; The answer is almost certainly the 360° profile including a manager (for the business smarts), coworkers or peers (for the developer smarts), and possibly system users or peers (for the common sense/usability smarts).</p>
<p>The other question we should ask ourselves once we&#8217;ve settled into a job is whether the way we see ourselves in our own careers is similar to that of our managers and coworkers&#8230; (Remember, you must consider it from their view point rather than your own). Is that a problem? Does that highlight some goals you could set yourself for the next year?</p>
<p>What do you respect in other&#8217;s programmer skills?</p>
<p>Love,<br />
Reddog.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=19&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/12/how-else-do-we-earn-l33t-respect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Which lobe are you?</title>
		<link>http://leftlobed.wordpress.com/2008/05/08/which-lobe-are-you/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/08/which-lobe-are-you/#comments</comments>
		<pubDate>Thu, 08 May 2008 11:56:18 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/08/which-lobe-are-you/</guid>
		<description><![CDATA[Are you left or right lobed? Unexpectedly, I see it clockwise&#8230; Though more worrying was that it took me 30 seconds to remember which way is clockwise!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=18&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shamozzle.com/RightLeftBrainTest.html">Are you left or right lobed</a>?</p>
<p>Unexpectedly, I see it clockwise&#8230; Though more worrying was that it took me 30 seconds to remember which way <em>is </em>clockwise!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=18&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/08/which-lobe-are-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Using SiteMap for external links and additional attributes</title>
		<link>http://leftlobed.wordpress.com/2008/05/08/using-sitemap-for-external-links-and-additional-attributes/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/08/using-sitemap-for-external-links-and-additional-attributes/#comments</comments>
		<pubDate>Thu, 08 May 2008 11:37:22 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[WCSF]]></category>
		<category><![CDATA[not a valid virtual path]]></category>
		<category><![CDATA[SiteMap]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/08/using-sitemap-for-external-links-and-additional-attributes/</guid>
		<description><![CDATA[In a website we are currently developing we are using the WCSF (from the Patterns and Practices group) and we wanted to inject in some links to a few external websites. The WCSF uses a custom SiteMapProvider that is part of its framework. A coworker highlighted how he solved the problem by simply overriding the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=17&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a website we are currently developing we are using the <a href="http://www.codeplex.com/websf">WCSF</a> (from the Patterns and Practices group) and we wanted to inject in some links to a few external websites. The WCSF uses a custom SiteMapProvider that is part of its framework. A <a href="http://waxtadpole.wordpress.com/2008/05/02/sitemap/">coworker</a> highlighted how he solved the problem by simply overriding the URL as part of the TreeView (our menu) databound event handler within a master page.</p>
<p>I wasn&#8217;t especially happy with this solution since it separated the URL information from the code that created the information in the first place.</p>
<p>Since the problem originated a &#8220;not in virtual path&#8221; when the sitemap node has a URL that&#8217;s external to the application, I decided to route the external links through a redirect page (Redirect.aspx). The other important thing is to use HttpUtility.UrlEncode and HttpUtility.UrlDecode to take care of making the URL suitable for a querystring value.</p>
<p>(Note: don&#8217;t use escaped characters in the input string &#8211; e.g. +, %2f, etc. since this makes HttpUtility.UrlEncode assume the string is already encoded).</p>
<p>The redirect page is simply this:</p>
<pre><span style="color:#0000ff;">if </span>(!<span style="color:#2b91af;">String</span>.IsNullOrEmpty(Request.QueryString[<span style="color:#a31515;">"url"</span>]))
{
    <span style="color:#0000ff;">string </span>url = <span style="color:#2b91af;">HttpUtility</span>.UrlDecode(Request.QueryString[<span style="color:#a31515;">"url"</span>]);
    Response.Redirect(url);
}
<span style="color:#0000ff;">else
</span>{
    Response.Redirect(<span style="color:#a31515;">"~/Default.aspx"</span>);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Then when inserting the SiteMapNodeInfo nodes into the collection I instead formatted the URL with:</p>
<pre><span style="color:#0000ff;">string </span>url = <span style="color:#2b91af;">String</span>.Format(<span style="color:#a31515;">"~/Redirect.aspx?url={0}"</span>, <span style="color:#2b91af;">HttpUtility</span>.UrlEncode(<span style="color:#a31515;">"http://www.myexternallink.com"</span>));</pre>
<p>The rest is specific to WCSF SiteMapNodeInfo nodes, but additionally, I wanted the external link to pop-out into a new browser window (target=&#8221;_blank&#8221;) so we need to pass in NameValueCollection with key/values for all the attributes you want converted in the final SiteMapNode instance (in our case we simply need Target):</p>
<pre><span style="color:#2b91af;">NameValueCollection </span>attrs = <span style="color:#0000ff;">new </span><span style="color:#2b91af;">NameValueCollection</span>(1);
attrs.Add(<span style="color:#a31515;">"Target"</span>, <span style="color:#a31515;">"_blank"</span>);
SiteMapNodeInfo externalLinkNode = <span style="color:#0000ff;">new </span>SiteMapNodeInfo(<span style="color:#a31515;">"ExternalLink1"</span>, url, <span style="color:#a31515;">"My External Site"</span>, <span style="color:#a31515;">"Check out the external site"</span>, <span style="color:#0000ff;">null</span>, attrs, <span style="color:#0000ff;">null</span>, <span style="color:#0000ff;">null</span>);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Then as was pointed out earlier, in order to take advantage of those additional attributes within your Menu or TreeView we will have to do so within our master page (or page).</p>
<pre><span style="color:#0000ff;">protected void </span>MainMenu_TreeNodeDataBound(<span style="color:#0000ff;">object </span>sender, <span style="color:#2b91af;">TreeNodeEventArgs </span>e)
{
    Debug.Assert(e.Node.DataItem != <span style="color:#0000ff;">null</span>);
    Debug.Assert(e.Node.DataItem <span style="color:#0000ff;">is </span><span style="color:#2b91af;">SiteMapNode</span>);
    e.Node.Target = (e.Node.DataItem <span style="color:#0000ff;">as </span><span style="color:#2b91af;">SiteMapNode</span>)[<span style="color:#a31515;">"Target"</span>];
}</pre>
<p>You could use the same method using additional attributes on the SiteMapNode used to include little images or icon&#8217;s (e.g. ImageUrl) next to the menu node.</p>
<p>Hope this helps some lost soul&#8230;</p>
<p>Love,<br />
Reddog.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=17&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/08/using-sitemap-for-external-links-and-additional-attributes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Tiny Tip: Use Consolas font pack for Visual Studio</title>
		<link>http://leftlobed.wordpress.com/2008/05/04/tiny-tip-use-consolas-font-pack-for-visual-studio/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/04/tiny-tip-use-consolas-font-pack-for-visual-studio/#comments</comments>
		<pubDate>Sun, 04 May 2008 09:02:14 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/04/tiny-tip-use-consolas-font-pack-for-visual-studio/</guid>
		<description><![CDATA[This one has been often blogged but a good tip came around on email to use Consolas mono-spaced, clear type font inside Visual Studio. I&#8217;ve been using it for a little while and think it looks great. You can download it from MSDN. A good visual comparison between Consolas and the standard Courier is here. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=15&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This one has been often <a href="http://www.csharper.net/blog/visual_studio_2005_optimized_font_family.aspx">blogged</a> but a good tip came around on email to use Consolas mono-spaced, clear type font inside Visual Studio. I&#8217;ve been using it for a little while and think it looks great. You can <a href="http://www.microsoft.com/downloads/details.aspx?familyid=22e69ae4-7e40-4807-8a86-b3d36fab68d3&amp;displaylang=en">download it from MSDN</a>. A good visual comparison between Consolas and the standard Courier is <a href="http://chrison.net/ConsolasFontPackForVisualStudio.aspx">here</a>.</p>
<p>One thing to add is that it&#8217;s optimised as a clear-type font. In Vista all fonts are enabled in clear type by default, but at least on my XP machine they weren&#8217;t. To enable this you need to go to the display properties dialogue (right click -&gt; Properties on the desktop). Then on the Appearance tab, hit the Effects button to find this dialogue to enable it. </p>
<p><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="183" alt="Effects window in Vista" src="http://leftlobed.files.wordpress.com/2008/05/image1.png?w=425&#038;h=183" width="425" border="0"></p>
<p>In Vista you can find this dialogue under Control Panel\Appearance and Personalization\Personalization on the Window Color and Appearance item. Use the link to open the classic properties box.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=15&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/04/tiny-tip-use-consolas-font-pack-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>

		<media:content url="http://leftlobed.files.wordpress.com/2008/05/image1.png" medium="image">
			<media:title type="html">Effects window in Vista</media:title>
		</media:content>
	</item>
		<item>
		<title>Archive: ASP.NET impersonation and SQL Server</title>
		<link>http://leftlobed.wordpress.com/2008/05/03/archive-aspnet-impersonation-and-sql-server/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/03/archive-aspnet-impersonation-and-sql-server/#comments</comments>
		<pubDate>Fri, 02 May 2008 14:44:16 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[ASP.NET Authentication]]></category>
		<category><![CDATA[Impersonation]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/03/archive-aspnet-impersonation-and-sql-server/</guid>
		<description><![CDATA[From: http://blogs.ssw.com.au/andrewweaver/archive/2005/03/11/3968.aspx Its a frequent situation where you want your ASP.NET application to connect to the SQL Server using the integrated security account. For example, you have all of your roles setup on the SQL Server and want your web application (secured via IIS integrated authentication) to get data specific to your role on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=12&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>From: <a href="http://blogs.ssw.com.au/andrewweaver/archive/2005/03/11/3968.aspx">http://blogs.ssw.com.au/andrewweaver/archive/2005/03/11/3968.aspx</a></strong></p>
<p>Its a frequent situation where you want your ASP.NET application to connect to the SQL Server using the integrated security account. For example, you have all of your roles setup on the SQL Server and want your web application (secured via IIS integrated authentication) to get data specific to your role on the server.</p>
<p>In a windows application this is easily achieved by just making your SQL connection string use the integrated account (whichever windows account is running the app). But in a web application, the account that your SQL Server will open the connection under is the \ASPNET [or \Network Service in IIS6] not the account that is used for IIS authentication. To make it use the authenticating account you could turn on impersonation within your web.config file with the following:</p>
<pre><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">authentication </span><span style="color:#ff0000;">mode</span><span style="color:#0000ff;">=</span>"<span style="color:#0000ff;">Windows</span>" <span style="color:#0000ff;">/&gt;
&lt;</span><span style="color:#a31515;">identity </span><span style="color:#ff0000;">impersonate</span><span style="color:#0000ff;">=</span>"<span style="color:#0000ff;">true</span>" <span style="color:#0000ff;">/&gt;</span></pre>
<p>When I ran it with impersonation = true it just seemed to work perfectly (you can run a SQL trace to spot who the connection is coming in as). But be warned it doesn&#8217;t work for all server configurations apparently. I&#8217;ve just formatted and have a fresh install of SQL (running under the local system account) so I would think that I&#8217;ve got a “default” install&#8230;</p>
<p>An <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secmod/html/secmod17.asp">MSDN article sheds some light on why</a> it won&#8217;t always work:</p>
<blockquote><p><strong>Why can&#8217;t I enable impersonation for the Web application, so that I can secure the resources accessed by my Web application using ACLs configured against the original caller?</strong></p>
<p>If you enable impersonation, the impersonated security context will not have network credentials (assuming delegation is not enabled and you are using Integrated Windows authentication). Therefore, the remote call to SQL Server will use a NULL session, which will result in a failed call. With impersonation disabled, the remote request will use the ASP.NET process identity.</p></blockquote>
<p>You will notice that it says that “assuming delegation is not enabled” (which it isn&#8217;t by default) these problems will occur. So obviously we might want to work out how to get this enabled&#8230; <a href="http://pluralsight.com/blogs/keith/default.aspx">Keith Brown</a> wrote an <a href="http://pluralsight.com/blogs/keith/archive/2004/07/08/1586.aspx">article detailing what you need to do to get this enabled</a> &#8211; which should in theory get things working seamlessly.</p>
<p>A key problem with using impersonation is that you might now have security considerations that you weren&#8217;t thinking about, e.g. access to file resources, etc&#8230; Remember that all of your code is now executing as that user &#8211; not the ASPNET account&#8230;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=12&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/03/archive-aspnet-impersonation-and-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Archive: Windows Impersonation in C# &#8211; Handy when debugging with ExOLE DB</title>
		<link>http://leftlobed.wordpress.com/2008/05/03/archive-windows-impersonation-in-c-handy-when-debugging-with-exole-db/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/03/archive-windows-impersonation-in-c-handy-when-debugging-with-exole-db/#comments</comments>
		<pubDate>Fri, 02 May 2008 14:43:12 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[DllImport]]></category>
		<category><![CDATA[Externs]]></category>
		<category><![CDATA[Impersonation]]></category>
		<category><![CDATA[LogonUser]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/03/archive-windows-impersonation-in-c-handy-when-debugging-with-exole-db/</guid>
		<description><![CDATA[From: http://blogs.ssw.com.au/andrewweaver/articles/186.aspx While working on our new product SSW Exchange Reporter, the need to impersonate users (mostly for debugging purposes) arose. The reason being that unlike most of the other OLE providers you can&#8217;t provide login details with the connection string when trying to connect to Exchange with the ExOLEDB provider. For example an SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=11&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>From: <a href="http://blogs.ssw.com.au/andrewweaver/articles/186.aspx">http://blogs.ssw.com.au/andrewweaver/articles/186.aspx</a></strong></p>
<p>While working on our new product <a href="http://www.ssw.com.au/ssw/ExchangeReporter">SSW Exchange Reporter</a>, the need to impersonate users (mostly for debugging purposes) arose. The reason being that unlike most of the other OLE providers you can&#8217;t provide login details with the connection string when trying to connect to Exchange with the ExOLEDB provider. For example an SQL connection string you can have “user=sa; password=xxx; &#8230;.” but you can&#8217;t for an ExOLE connection string. Therefore the ExOLE provider will not do any impersonation for you, it will always run under who ever is executing your application code. That is, whoever your service runs under or whoever is logged on and runs your .exe or whoever you run the .exe as using the &#8216;Run As&#8230;&#8217; context menu item. Additionally the user we run under needed read permissions to all mailboxes.</p>
<p>Use some of the following code to do some impersonation.</p>
<p>Firstly make use of the windows LogonUser() function in advapi32.dll. Note that username and passwords are passed as plain text&#8230;<br />
<code><span style="color:#0000ff;">public const int </span>LOGON32_LOGON_INTERACTIVE = 2;<br />
<span style="color:#0000ff;">public const int </span>LOGON32_LOGON_SERVICE = 3;<br />
<span style="color:#0000ff;">public const int </span>LOGON32_PROVIDER_DEFAULT = 0;</code></p>
<p>[<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">"advapi32.dll"</span>, CharSet = <span style="color:#2b91af;">CharSet</span>.Auto)]<br />
<span style="color:#0000ff;">public static extern bool </span>LogonUser(<span style="color:#2b91af;">String </span>lpszUserName, <span style="color:#2b91af;">String </span>lpszDomain, <span style="color:#2b91af;">String </span>lpszPassword, <span style="color:#0000ff;">int </span>dwLogonType, <span style="color:#0000ff;">int </span>dwLogonProvider, <span style="color:#0000ff;">ref </span><span style="color:#2b91af;">IntPtr </span>phToken);</p>
<p>Then you can call this method to get the handle (the last parameter) for the user and use this to create a WindowsIdentity (in the System.Security.Principle namespace) and then begin impersonation with this handle.</p>
<pre><span style="color:#2b91af;">IntPtr </span>userHandle = <span style="color:#0000ff;">new </span><span style="color:#2b91af;">IntPtr</span>(0);
<span style="color:#0000ff;">bool </span>returnValue = LogonUser(name, machine, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, <span style="color:#0000ff;">ref </span>userHandle);

<span style="color:#0000ff;">if </span>(! returnValue)
    <span style="color:#0000ff;">throw new </span><span style="color:#2b91af;">Exception</span>(<span style="color:#a31515;">"Invalid Username"</span>);

WindowsIdentity newId = <span style="color:#0000ff;">new </span>WindowsIdentity(userHandle);
WindowsImpersonationContext impersonatedUser = newId.Impersonate();</pre>
<p>You would probably wrap all this code, along with some additional verification code into a function called “BeginImpersonate“ or similar that would return both the user handle (so that you can free it later) and the impersonatedUser object so that you can end impersonation later via and “EndImpersonate“ function&#8230; End impersonation with the following code.</p>
<pre>impersonatedUser.Undo();</pre>
<p>Free the userHandle with a call to another windows function.</p>
<pre>[<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">"kernel32.dll"</span>, CharSet = <span style="color:#2b91af;">CharSet</span>.Auto)]
<span style="color:#0000ff;">public extern static bool </span>CloseHandle(<span style="color:#2b91af;">IntPtr </span>handle);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Better examples can be found on the MS .NET documentation on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassImpersonateTopic.asp">WindowsIdentity.Impersonate</a> method, but I hope this helped a little&#8230; In this document they actually duplicate user handles that they use for impersonation, though I don&#8217;t exactly understand why&#8230; You duplicate your handles via:</p>
<pre>[<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">"advapi32.dll"</span>, CharSet = <span style="color:#2b91af;">CharSet</span>.Auto, SetLastError = <span style="color:#0000ff;">true</span>)]
<span style="color:#0000ff;">public extern static bool </span>DuplicateToken(<span style="color:#2b91af;">IntPtr </span>ExistingTokenHandle, <span style="color:#0000ff;">int </span>SECURITY_IMPERSONATION_LEVEL, <span style="color:#0000ff;">ref </span><span style="color:#2b91af;">IntPtr </span>DuplicateTokenHandle);
 </pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=11&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/03/archive-windows-impersonation-in-c-handy-when-debugging-with-exole-db/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Archive: Getting the Date portion of a DateTime type in SQL (T-SQL) &#8211; Use Floats and Floor!</title>
		<link>http://leftlobed.wordpress.com/2008/05/03/archive-getting-the-date-portion-of-a-datetime-type-in-sql-t-sql-use-floats-and-floor/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/03/archive-getting-the-date-portion-of-a-datetime-type-in-sql-t-sql-use-floats-and-floor/#comments</comments>
		<pubDate>Fri, 02 May 2008 14:41:08 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Archive]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Convert]]></category>
		<category><![CDATA[DateTime]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/03/archive-getting-the-date-portion-of-a-datetime-type-in-sql-t-sql-use-floats-and-floor/</guid>
		<description><![CDATA[Update &#8211; 2 May 2008 &#8211; Watch out for SQL Server 2008&#8242;s new Date and Time data types! From: http://blogs.ssw.com.au/andrewweaver/archive/2006/06/19/8262.aspx Something that comes up quite frequently when dealing with reporting and DateTime fields on a data table is grouping by the Date portion only of the field or filtering for a full day of data. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=10&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#ff0000">Update &#8211; 2 May 2008 &#8211; Watch out for SQL Server 2008&#8242;s new </font></strong><a href="http://technet.microsoft.com/en-us/library/ms186724(SQL.100).aspx"><strong><font color="#804040">Date and Time data types</font></strong></a><strong><font color="#ff0000">!</font></strong>
<p><strong>From:</strong> <a href="http://blogs.ssw.com.au/andrewweaver/archive/2006/06/19/8262.aspx">http://blogs.ssw.com.au/andrewweaver/archive/2006/06/19/8262.aspx</a>
<p>Something that comes up quite frequently when dealing with reporting and DateTime fields on a data table is grouping by the Date portion only of the field or filtering for a full day of data.
<p>If you were to filter DateTime values where the actual time portion is used then doing:  <code>SELECT * FROM Sales WHERE Sales.TransactionTime = '19 Jun 06'</code>
<p>Then you will only be getting the sales that were created at midnight!
<p>Often you will see people wanting to only get the date portion by using a string conversion or a convoluted mix of <a href="http://weblogs.sqlteam.com/jeffs/archive/2004/12/02/2954.aspx">SQL DateTime functions</a>. For example:  <code>SELECT * FROM Sales WHERE CONVERT(varchar(10), Sales.TransactionTime, 101) = '2006-06-19'</code>
<p>But this is somewhat slower and more memory intensive than a way in which two co-workers (Mehmet and Mark) have suggested (I don&#8217;t think it was ever posted by them, but I&#8217;m sure its on the net somewhere). They say that you should convert the DateTime field to a float and floor it in order to get the date portion. This is will work as when the DateTime is converted to a float the date portion can be found as the whole number representation of the float, the time is the fractional portion.
<p>For example:
<ol>
<li>
<p>Convert date to a float: SELECT CONVERT( Float, GETDATE())</p>
<li>
<p>Floor (take only whole number value) the float value to get only the date portion: SELECT FLOOR( CONVERT( Float, GETDATE())) </p>
<li>
<p>Convert back to date time (if needed) for display purposes: SELECT CONVERT(DateTime, FLOOR( CONVERT( Float, GETDATE())))</p>
</li>
</ol>
<p>There are <a href="http://www.google.ca/search?hl=en&amp;q=datetime+sql+date+portion+round+float">tonnes of posts regarding this</a>, so checkout a few of them.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=10&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/03/archive-getting-the-date-portion-of-a-datetime-type-in-sql-t-sql-use-floats-and-floor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Archive: TIP: Shrinking / Saving / Compressing your big digital images</title>
		<link>http://leftlobed.wordpress.com/2008/05/03/archive-tip-shrinking-saving-compressing-your-big-digital-images/</link>
		<comments>http://leftlobed.wordpress.com/2008/05/03/archive-tip-shrinking-saving-compressing-your-big-digital-images/#comments</comments>
		<pubDate>Fri, 02 May 2008 14:37:21 +0000</pubDate>
		<dc:creator>reddogaw</dc:creator>
				<category><![CDATA[Archive]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Compress]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[IrfanView]]></category>
		<category><![CDATA[Shrink]]></category>

		<guid isPermaLink="false">http://leftlobed.wordpress.com/2008/05/03/archive-tip-shrinking-saving-compressing-your-big-digital-images/</guid>
		<description><![CDATA[Update &#8211; 3 May 2008 &#8211; IrfanView now has a batch save/edit mode that you can use to achieve a similar result&#8230; From: http://blogs.ssw.com.au/andrewweaver/archive/2004/06/02/234.aspx In order to share (via email or web page etc) your digital photos, you really should compress them (and shrink them a bit too) first. One of the easiest ways is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=9&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color:#ff0000;">Update &#8211; 3 May 2008 &#8211; IrfanView now has a batch save/edit mode that you can use to achieve a similar result&#8230;</span></strong></p>
<p><strong>From: <a title="http://blogs.ssw.com.au/andrewweaver/archive/2004/06/02/234.aspx" href="http://blogs.ssw.com.au/andrewweaver/archive/2004/06/02/234.aspx">http://blogs.ssw.com.au/andrewweaver/archive/2004/06/02/234.aspx</a></strong></p>
<p>In order to share (via email or web page etc) your digital photos, you really should compress them (and shrink them a bit too) first.</p>
<p>One of the easiest ways is to use a freeware application called <a href="http://www.irfanview.com">IrfanView</a>. It&#8217;s great to use for viewing slideshows, and doing basic image editing (such as cropping, resizing, saving to different formats etc). It&#8217;s only like 800 KB so it&#8217;s small as well&#8230;</p>
<p>You can then use it&#8217;s command line options to make a simple bat file, that will take all files in a directory, shrink them a bit, knock down the compression quality and re-save them into a sub directory. I use the following bat file (which you can simply place in any directory that you want to shrink the files in).</p>
<pre>@echo off
set IViewDir=C:\Program Files\IrfanView
set CurDir=%cd%
set OutDir=%CurDir%\web "%IViewDir%\i_view32" "%CurDir%\*.jpg" /resize=(0, 600) /aspectratio /jpgq=75 /convert="%OutDir%\*.jpg"
@echo on</pre>
<p>This will put save all jpeg&#8217;s in a directory into a subdirectory called “web” (same filenames), change the jpeg quality to 75%, and resize the image to 600 pixels high (and width will scale according to the original aspect ratio).</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/leftlobed.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/leftlobed.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leftlobed.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leftlobed.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leftlobed.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leftlobed.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leftlobed.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leftlobed.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leftlobed.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leftlobed.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leftlobed.wordpress.com&amp;blog=3560535&amp;post=9&amp;subd=leftlobed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leftlobed.wordpress.com/2008/05/03/archive-tip-shrinking-saving-compressing-your-big-digital-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84cac0fa5789fee40e1f51b19c30b95c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">reddogaw</media:title>
		</media:content>
	</item>
	</channel>
</rss>
