<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:media="http://search.yahoo.com/mrss/" version="2.0">

<channel>
	<title>Ramblings of the Sleepy...</title>
	
	<link>http://tiredblogger.wordpress.com</link>
	<description>For an underpaid web architect and overplayed gamer... there is no such thing as sleep.</description>
	<lastBuildDate>Fri, 06 Nov 2009 14:01:17 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain="tiredblogger.wordpress.com" port="80" path="/?rsscloud=notify" registerProcedure="" protocol="http-post" />
<image>
		<url>http://www.gravatar.com/blavatar/e87df6e5b075c4485671acebd012921a?s=96&amp;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Ramblings of the Sleepy...</title>
		<link>http://tiredblogger.wordpress.com</link>
	</image>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RamblingsOfTheSleepy" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>PowerShell : TGIF Reminder</title>
		<link>http://tiredblogger.wordpress.com/2009/11/06/powershell-tgif-reminder/</link>
		<comments>http://tiredblogger.wordpress.com/2009/11/06/powershell-tgif-reminder/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:01:10 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Workplace]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/11/06/powershell-tgif-reminder/</guid>
		<description><![CDATA[Jeff Hicks&#8217; TGIF post yesterday was a fun way to learn a bit of PowerShell (casting, working with dates, etc) and also add something valuable to your professional toolbelt&#8212;knowing when to go home.  
I tweaked the date output a bit to be more human readable, but also moved it from just a function to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=991&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://bit.ly/3dlfCt" target="_blank">Jeff Hicks&rsquo; TGIF post</a> yesterday was a fun way to learn a bit of PowerShell (casting, working with dates, etc) and also add something valuable to your professional toolbelt&mdash;knowing when to go home. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I tweaked the date output a bit to be more human readable, but also moved it from just a function to part of my UI.&nbsp; I mean, I should ALWAYS know how close I am to quittin&rsquo; time, right? Especially as we joke around our office during our &lsquo;payless weeks&rsquo;.</p>
<blockquote>
<p># Determines if today is the end of friday! (fun function)<br />function get-tgif {<br />&nbsp;$now=Get-Date<br />&nbsp;# If it&#8217;s Saturday or Sunday then Stop! It&#8217;s the weekend!<br />&nbsp;if ([int]$now.DayOfWeek -eq 6 -or [int]$now.DayOfWeek -eq 7)<br />&nbsp;{<br />&nbsp;&nbsp;&#8221;Weekend!&#8221;<br />&nbsp;}<br />&nbsp;else {<br />&nbsp;&nbsp;# Determine when the next quittin&#8217; time is&#8230;<br />&nbsp;&nbsp;[datetime]$TGIF=&#8221;{0:MM/dd/yyyy} 4:30:00 PM&#8221; -f `<br />&nbsp;&nbsp;&nbsp;(($now.AddDays( 5 &#8211; [int]$now.DayOfWeek)) )<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;# Must be Friday, but after quittin&#8217; time, GO HOME!<br />&nbsp;&nbsp;if ((get-date) -ge $TGIF) {<br />&nbsp;&nbsp;&nbsp;&#8221;TGIF has started without you!&#8221;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;else {<br />&nbsp;&nbsp;&nbsp;# Awww, still at work&#8211;how long until <br />&nbsp;&nbsp;&nbsp;# it&#8217;s time to go to the pub?<br />&nbsp;&nbsp;&nbsp;$diff = $($tgif &#8211; (get-date))<br />&nbsp;&nbsp;&nbsp;&#8221;TGIF: $($diff.Days)d $($diff.Hours)h $($diff.Minutes)m&#8221;<br />&nbsp;&nbsp;}<br />&nbsp;}<br />}</p>
</blockquote>
<p><strong>NOTE: </strong>My &ldquo;end time&rdquo; is set to 4:30PM, not 5:00PM&mdash;since that&rsquo;s when I escape.&nbsp; Change as necessary. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The code comments explain most of it.&nbsp; As you can see, I added in one more check&mdash;let me know when it&rsquo;s simply the weekend.&nbsp; I also removed the Write-Host calls, since I simply want to return a String from the function.&nbsp; I could use the function, as necessary, with formatting, and add it to other scripts and such.&nbsp; For example:</p>
<blockquote>
<p>Write-Host $(get-tgif) -fore red</p>
</blockquote>
<p>The next step was tapping into the $Host variable.&nbsp; Since I use <a href="http://bit.ly/3wrzDy" target="_blank">Console2</a>, my PowerShell window is a tab rather than the whole window.&nbsp; Console2 is aware of PowerShell&rsquo;s $Host.UI methods and adheres to the changes.</p>
<p>To add <strong>get-tgif</strong> to my prompt&rsquo;s window title:</p>
<blockquote>
<p>$windowTitle = &#8220;(&#8221; + $(get-tgif) + &#8220;) &#8220;<br />$host.ui.rawui.WindowTitle = $windowTitle</p>
</blockquote>
<p>Easy enough.&nbsp; Now my window title looks like (ignore the path in there for now):</p>
<p><img border="2" hspace="5" alt="TGIF countdown in WindowTitle" vspace="5" src="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=575" /></p>
<p>But that only sets it when you log in&hellip; and I want to update it (and keep that path updated as I traverse through directories).&nbsp; To do that add a function called &lsquo;prompt&rsquo; to your PowerShell Profile.&nbsp; Prompt is processed every time the &ldquo;PS&gt;&rdquo; is generated and allows you a great deal of customization.&nbsp; <a href="http://bit.ly/19aNs8" target="_blank">See the post here</a> for further details on how I&rsquo;ve customized my prompt to handle Git repositories.</p>
<p>So, move those two lines into our&nbsp;prompt function, and our TGIF timer now updates every time our prompt changes&hellip; keeping it pretty close to real time as you work.</p>
<blockquote>
<p>function prompt {<br />&nbsp;$windowTitle = &#8220;(&#8221; + $(get-tgif) + &#8220;) &#8221; + $(get-location).ToString()<br />&nbsp;$host.ui.rawui.WindowTitle = $windowTitle</p>
<p>[&hellip;]</p>
<p>}</p>
</blockquote>
<p dir="ltr">This could be tweaked to any type of countdown.&nbsp; I&rsquo;m sure a few of those around the office would have fun adding retirement countdowns, etc. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p dir="ltr">Happy TGIF!</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/PowerShell">PowerShell</a>, <a rel="tag" href="http://technorati.com/tag/scripting">scripting</a>, <a rel="tag" href="http://technorati.com/tag/fun">fun</a>, <a rel="tag" href="http://technorati.com/tag/Windows7">Windows7</a></div>
Posted in General Development, Microsoft, PowerShell, Windows 7, Workplace  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/991/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/991/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/991/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=991&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/11/06/powershell-tgif-reminder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>

		<media:content url="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=575" medium="image">
			<media:title type="html">TGIF countdown in WindowTitle</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell : Add Recursive Directories to PATH</title>
		<link>http://tiredblogger.wordpress.com/2009/10/19/powershell-add-recursive-directories-to-path/</link>
		<comments>http://tiredblogger.wordpress.com/2009/10/19/powershell-add-recursive-directories-to-path/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 12:50:25 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/10/19/powershell-add-recursive-directories-to-path/</guid>
		<description><![CDATA[As I continue to go script crazy (a bit) with PowerShell, I&#8217;ve noticed that my general scripts directory has grown quite a bit and is becoming a bit unmanagable.&#160; Being a lover of neat and tidy, I wanted to separate &#8216;common&#8217; scripts from &#8216;server-based&#8217; and &#8216;task&#8217; scripts.
Sounds easy enough, but that breaks part of my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=988&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As I continue to go script crazy (a bit) with PowerShell, I&rsquo;ve noticed that my general scripts directory has grown quite a bit and is becoming a bit unmanagable.&nbsp; Being a lover of neat and tidy, I wanted to separate &lsquo;common&rsquo; scripts from &lsquo;server-based&rsquo; and &lsquo;task&rsquo; scripts.</p>
<p>Sounds easy enough, but that breaks part of my PowerShell profile&mdash;the part where I add the scripts directory to the path.&nbsp; Moving those files out of that directory, even if they&rsquo;re in subdirectories, would take them out of the path and I&rsquo;d lose my [a..b]-{tab} goodness.</p>
<p>So, how to add the recursive structure to PATH?</p>
<p>It&rsquo;s easy!</p>
<p>In my Profile, <strong>$scripts</strong> is a variable that contains a path to my &lsquo;standard&rsquo; scripts directory based on whatever computer I&rsquo;m currently logged into.</p>
<p>From there, simply use the built-in features of PowerShell.</p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-size:10pt;"><font face="Calibri">gci $scripts |</font></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-size:10pt;"><font face="Calibri"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>? { $_.psIsContainer } | </font></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-size:10pt;"><font face="Calibri"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>% { [System.Environment]::SetEnvironmentVariable(&#8220;PATH&#8221;, </font></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-size:10pt;"><font face="Calibri"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$Env:Path + &#8220;;&#8221; + $_.FullName, &#8220;Process&#8221;) }</font></span></p>
<p>Verbatim: for each child object in $scripts that is a container, append the full name to PATH.</p>
<p>Exactly what I wanted and works like a champ.&nbsp; Now I can move my scripts around, create new directories, the works&mdash;and each time I restart my console, it&rsquo;ll detect the new directories and simply work&mdash;exactly like a shell should.</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/PowerShell">PowerShell</a></div>
Posted in Microsoft, PowerShell  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/988/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/988/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/988/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/988/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/988/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/988/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/988/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/988/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/988/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/988/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=988&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/10/19/powershell-add-recursive-directories-to-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>
	</item>
		<item>
		<title>Updated: PowerShell “Code-Cat” With Colors and Line Breaks</title>
		<link>http://tiredblogger.wordpress.com/2009/10/13/updated-powershell-code-cat-with-colors-and-line-breaks/</link>
		<comments>http://tiredblogger.wordpress.com/2009/10/13/updated-powershell-code-cat-with-colors-and-line-breaks/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 18:16:53 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/10/13/updated-powershell-code-cat-with-colors-and-line-breaks/</guid>
		<description><![CDATA[Motivated by Jeffery Hicks&#8217; fun with my original &#8220;code-cat&#8221; version, I decided to fill in a few of the original updates&#160;I had floating in my head.
The full code is available here via CodePaste.Net.
First off, I loved the idea of colorizing the comments in a file; however, I wanted to keep my line numbers out of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=986&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Motivated by <a href="http://bit.ly/v9UqJ" target="_blank">Jeffery Hicks&rsquo; fun</a> with my original &ldquo;code-cat&rdquo; version, I decided to fill in a few of the original updates&nbsp;I had floating in my head.</p>
<p><strong>The full code is </strong><a href="http://codepaste.net/ocsymv" target="_blank"><strong>available here</strong></a><strong> via CodePaste.Net.</strong></p>
<p>First off, I loved the idea of colorizing the comments in a file; however, I wanted to keep my line numbers out of the &ldquo;coloring&rdquo; and simply color the comments.&nbsp; To do this, I had to break apart the line numbers from the actual output.</p>
<p><img border="2" hspace="5" alt="Coloring Code Cat Comments" vspace="5" src="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=572" /></p>
<p>Second, I really wanted a cleaner way to wrap lines in my code and to have those lines still lineup with everything else.&nbsp; </p>
<p><img border="2" hspace="5" alt="Line Wraps" vspace="5" src="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=573" /></p>
<p>The full code is available via CodePaste.Net (<a href="http://codepaste.net/ocsymv" target="_blank">click here</a>), but let&rsquo;s step through it and see how things work.</p>
<p><strong><u>SplitString Function</u></strong></p>
<p>You&rsquo;ll notice at the top, I&rsquo;ve included a custom helper function that takes a string and splits it into an array.&nbsp; I use this to break up &ldquo;long&rdquo; strings into window-sized strings.</p>
<blockquote>
<p>function splitString([string]$string, [int]$length)<br />{<br />&nbsp;$lines = @();<br />&nbsp;$stringLength = $string.Length;<br />&nbsp;$position = 0;</p>
<p>&nbsp;while ($position -lt $stringLength)<br />&nbsp;{<br />&nbsp;&nbsp;if (($position + $length) -lt $stringLength)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;$lines += $string.substring($position, $length);<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;else<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;$lines += $string.substring($position);<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;$position += $length;<br />&nbsp;}</p>
<p>&nbsp;return $lines;<br />}</p>
</blockquote>
<p>This method is actually in my PowerShell profile for use in numerous parsing activities.</p>
<p><strong><u>Colors and Window Size</u></strong></p>
<p>Unlike the original method, I&rsquo;ve pulled out the colors into variables so they are easily configured.&nbsp; I am also using the built-in PowerShell $Host object to determine the width of my console window.&nbsp; I&rsquo;ll use this later for the line breaks.</p>
<blockquote>
<p>$codeColor = &#8220;Gray&#8221;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />$counterColor = &#8220;White&#8221;;<br />$commentColor = &#8220;Green&#8221;;<br />$newLineColor = &#8220;Yellow&#8221;;</p>
<p># Window size, minus the counter, spacing, and a bit extra padding.<br />$maxLineSize = $Host.UI.RawUI.WindowSize.Width &#8211; 12;</p>
</blockquote>
<p><strong><u>Parsing The Code File</u></strong></p>
<p>There are a few important points in the $content body, here we go!</p>
<p><strong>Replacing Tabs With Spaces</strong></p>
<p>I found that the Substring and Length functions got really quirkly (is a tab 1 character or five, etc) when they came across several tabs (which, tabbing is pretty common in a code file, especially some SQL files).&nbsp; To remedy this, I replace tabs with five spaces.&nbsp; This also allows me to control the tabs a bit more, so if I wanted to ease my code output to the left, I could use three or four spaces.</p>
<blockquote>
<p># remove tabs, they&#8217;re counted as one character, not five.<br />$currentLine = $_.Replace(&#8220;`t&#8221;, &#8220;&nbsp;&nbsp;&nbsp; &#8220;);</p>
</blockquote>
<p>Setting the Color of Comments</p>
<p>Using Jeffery&rsquo;s example, I&rsquo;m also setting my comments (for PowerShell, C#, and TSQL) to a bright color.</p>
<blockquote>
<p># Color-code comments green (PowerShell, C#, SQL)<br />if ($currentLine.Trim().StartsWith(&#8220;#&#8221;) -or `<br />&nbsp;&nbsp;&nbsp;&nbsp;$currentLine.Trim().StartsWith(&#8220;//&#8221;) -or `<br />&nbsp;&nbsp;&nbsp;&nbsp;$currentLine.Trim().StartsWith(&#8220;&#8211;&#8221;))<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp; $foregroundColor = $commentColor;<br />}</p>
</blockquote>
<p dir="ltr"><strong>Separating&nbsp;Line Numbers From Content</strong></p>
<p dir="ltr">I didn&rsquo;t want my line numbers to show up green for comments and I wanted to treat them with a different color than the rest of the code body, so I&rsquo;m taking advantage of the &ldquo;-nonewline&rdquo; feature of <strong>write-host.</strong> This returns the content without forcing a new line break into the result.&nbsp; Very handy.</p>
<p dir="ltr">write-host (&#8220;{0:d4} | &#8221; -f $counter) -nonewline -foregroundColor $counterColor;</p>
<p dir="ltr"><strong>Checking for Line Breaks and Handling Them</strong></p>
<p dir="ltr">The next bit is in &ldquo;beta&rdquo; for the time being.&nbsp; The gist is that it looks at the length of the current line vs. the maximum line size we specified in the variables.&nbsp; </p>
<p dir="ltr">If the current line is longer, it breaks the line into an array of &ldquo;max line size&rdquo; lines.&nbsp; The first line is output using our normal methods&mdash;we want our counter to show up, right?&nbsp; The &lsquo;overflow&rsquo; lines are output using a fancy arrow &ldquo;\&mdash;&gt;&rdquo; and do not include a counter&mdash;simply because they are not &lsquo;new lines&rsquo;.</p>
<p dir="ltr">Of course, if our line is shorter than our window size, it is simply output.</p>
<blockquote>
<p dir="ltr">if ($currentLine.Length -ge $maxLineSize)<br />{<br />&nbsp;$splitLines = splitString $currentLine $maxLineSize;<br />&nbsp;&nbsp;&nbsp; $countOfLines = $splitLines.Length;<br />&nbsp;for ($i = 0; $i -lt $countOfLines; $i++) <br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;if ($i -eq 0)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;# our first line doesn&#8217;t look any different.<br />&nbsp;&nbsp;&nbsp;write-host (&#8220;{0}&#8221; -f $splitLines[$i]) -foregroundColor $foregroundColor;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;else<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;# next lines are using the fancy arrow.<br />&nbsp;&nbsp;&nbsp;write-host (&#8220;\&#8211;&gt; |&nbsp;&nbsp; &#8220;) -nonewline -foregroundColor $newLineColor;<br />&nbsp;&nbsp;&nbsp;write-host (&#8220;{0}`n&#8221; -f $splitLines[$i]) -nonewline -foregroundColor $foregroundColor;<br />&nbsp;&nbsp;}<br />&nbsp;}<br />}<br />else<br />{<br />&nbsp;write-host (&#8220;{0}&#8221; -f $_) -foregroundColor $foregroundColor;<br />}</p>
</blockquote>
<p dir="ltr">Again, the full code is <a href="http://codepaste.net/ocsymv" target="_blank">available here</a> via CodePaste.Net.</p>
<p dir="ltr">Like all things, a work in progress!</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/powershell">powershell</a>, <a rel="tag" href="http://technorati.com/tag/windows+7">windows+7</a></div>
Posted in PowerShell, Windows 7, Windows Server  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/986/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/986/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/986/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/986/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/986/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/986/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/986/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/986/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/986/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/986/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=986&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/10/13/updated-powershell-code-cat-with-colors-and-line-breaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>

		<media:content url="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=572" medium="image">
			<media:title type="html">Coloring Code Cat Comments</media:title>
		</media:content>

		<media:content url="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=573" medium="image">
			<media:title type="html">Line Wraps</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell – Easy Line Numbers using Cat (Get-Content)</title>
		<link>http://tiredblogger.wordpress.com/2009/10/08/powershell-easy-line-numbers-using-cat-get-content/</link>
		<comments>http://tiredblogger.wordpress.com/2009/10/08/powershell-easy-line-numbers-using-cat-get-content/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 16:01:21 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/10/08/powershell-easy-line-numbers-using-cat-get-content/</guid>
		<description><![CDATA[I often cat out code pages from the prompt when I simply want to see what&#8217;s inside or look for a method.&#160; Cat, of course, is an alias to PowerShell&#8217;s get-content cmdlet, but cat brings me back to days in Unix and makes me feel better.  
One thing that was a bit of a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=984&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I often <strong>cat</strong> out code pages from the prompt when I simply want to see what&rsquo;s inside or look for a method.&nbsp; Cat, of course, is an alias to PowerShell&rsquo;s <strong>get-content </strong>cmdlet, but cat brings me back to days in Unix and makes me feel better. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>One thing that was a bit of a trouble was looking for a specific line of code.</p>
<p>For example: Looking through the debug logs, I see an error occuring at line 40 of some file.&nbsp; That&rsquo;s great, but who wants to count lines?&nbsp; Instead, we open up Visual Studio and look.&nbsp; Well, that&rsquo;s a hassle too.</p>
<p>Here&rsquo;s a quick script that does a simple line count with the line in the file.</p>
<blockquote>
<p>param ([string] $filename)<br />$counter = 0; <br />$content = get-content $filename | <br />&nbsp;% { $counter++; write-host &#8220;$counter`t| $_&#8221; }</p>
</blockquote>
<p dir="ltr">Since the result of get-content becomes an enumerable line-by-line list, it&rsquo;s easy to iterate through and increment a counter.</p>
<p dir="ltr">To call it, just call the method with the file name.&nbsp; For mine, I called it cat-code.ps1, though I&rsquo;ll probably set an alias to &lsquo;cc&rsquo; or something later on.</p>
<blockquote>
<p dir="ltr">.\cat-code.ps1 psake_default.ps1</p>
</blockquote>
<p dir="ltr"><img border="2" hspace="5" alt="Code Cat example." vspace="5" src="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=571" /></p>
<p dir="ltr">From here, you could add in a check to the $Host.UI.RawUI and handle the overflows a bit better, but that&rsquo;s for another day!</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/powershell">powershell</a>, <a rel="tag" href="http://technorati.com/tag/tips">tips</a>, <a rel="tag" href="http://technorati.com/tag/scripts">scripts</a></div>
Posted in Microsoft, PowerShell, Windows 7, Windows Server  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/984/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/984/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/984/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=984&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/10/08/powershell-easy-line-numbers-using-cat-get-content/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>

		<media:content url="http://photos.tiredstudent.com/WebStorageHandler.ashx?tb=false&amp;id=571" medium="image">
			<media:title type="html">Code Cat example.</media:title>
		</media:content>
	</item>
		<item>
		<title>Reusable ‘Controls’ with Sprites, CSS, and Spark Partials</title>
		<link>http://tiredblogger.wordpress.com/2009/10/02/reusable-controls-with-sprites-css-and-spark-partials/</link>
		<comments>http://tiredblogger.wordpress.com/2009/10/02/reusable-controls-with-sprites-css-and-spark-partials/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 15:15:34 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Spark View Engine]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/10/02/reusable-controls-with-sprites-css-and-spark-partials/</guid>
		<description><![CDATA[I came across SilkSprite during some of my work with BluePrintCSS and fell in love.&#160; I&#8217;ve used the FamFamSilk icons for ages and, with a current project, wanted to implement some instant CSS buttons and menu items using those icons.
So, with CSS-fu in hand, here&#8217;s how the button turned out.
First, creating a simple CSS button [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=981&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I came across <a href="http://bit.ly/18stDl" target="_blank">SilkSprite</a> during some of my work with BluePrintCSS and fell in love.&nbsp; I&rsquo;ve used the FamFamSilk icons for ages and, with a current project, wanted to implement some instant CSS buttons and menu items using those icons.</p>
<p>So, with CSS-fu in hand, here&rsquo;s how the button turned out.</p>
<p>First, creating a simple CSS button style:</p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;"><span style="color:#cae682;"></p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;"><span style="color:#cae682;"></p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;"><span style="color:#cae682;">.button</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; display: inline-block;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; font-weight: bold;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; font: bold .85em/2.5em Verdana, Helvetica, sans-serif;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; text-decoration: none;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; text-indent: 10px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; width: 150px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; height: 2.5em;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; color: #555555;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; background-color: #EAEAD7;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; border: #CCCCCC solid 1px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; -moz-border-radius: 5px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; -webkit-border-radius: 5px;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;"><span style="color:#cae682;">.button:hover</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; background-color: #F3F3E9;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; color: #737373;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; cursor: pointer;</p>
<p style="margin:0;">}</p>
</div>
<p><!--EndFragment--></span></div>
<p><!--EndFragment--></span></div>
<p><!--EndFragment--></p>
<p>This button is pretty simple and standard&mdash;nothing fancy.&nbsp; The most important tag in there is <strong>display: inline-block </strong>as this allows our buttons to share the same row and not stack on top of each other (like float:left would cause).</p>
<p>Hover Off: <img border="2" hspace="5" alt="CSS Button - Hover Off" vspace="5" src="http://bit.ly/4jINM3" /></p>
<p>Hover On: <img border="2" hspace="5" alt="CSS Button - Hover On" vspace="5" src="http://bit.ly/ZlrM6" /></p>
<p>Second, because I needed to include the icon INSIDE another container (the button), I modified the original SilkSprite <strong>ss_sprite</strong> and removed a bit of the extra padding.</p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;"><span style="color:#cae682;"></p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;"><span style="color:#cae682;">.sprite</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; display: inline-block;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; overflow: hidden;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; background-repeat: no-repeat;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; background-image: url(/content/img/sprites.png);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; padding-left: 25px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; padding-top: 2px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; height: 16px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; max-height: 16px;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; vertical-align: middle;</p>
<p style="margin:0;">}</p>
</div>
<p><!--EndFragment--></span></div>
<p><!--EndFragment--></p>
<p>The important thing to note here is the <strong>padding-top</strong> and the <strong>height</strong> attributes.&nbsp; Until I&rsquo;m lead into the light and improve my CSS-fu, I&rsquo;m compensating for the font height differences by using padding-top.&nbsp; e.g. I want the icon to truly show up in the &ldquo;middle&rdquo;&hellip; and vertical-align just wasn&rsquo;t pushing it far enough.</p>
<p>We&rsquo;ll come back to actually working with SilkSprite in a moment, let&rsquo;s work up a quick Spark partial view to display our results.&nbsp; Now, you could do this without the partial views&mdash;just replace my Spark variables with the actual text we&rsquo;re passing to them.&nbsp; I&rsquo;ll provide both examples.</p>
<p>Our button needs three elements to be useful:</p>
<ol>
<li>An ID so that we can call it from jQuery or your client-side query engine of choice,</li>
<li>A Sprite Name, such as ss_add, etc.&nbsp; These are provided by SilkSprite.</li>
<li>The button text.</li>
</ol>
<p>So, knowing that, a basic button could be rendered using:</p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;">&lt;<span style="color:#8ac6f2;">div</span> <span style="color:#cae682;">id</span>=&#8221;my-button&#8221; <span style="color:#cae682;">class</span>=&#8221;button&#8221;&gt;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &lt;<span style="color:#8ac6f2;">span</span> <span style="color:#cae682;">class</span>=&#8221;sprite ss_add&#8221; /&gt;Add Activity</p>
<p style="margin:0;">&lt;/<span style="color:#8ac6f2;">div</span>&gt;</p>
</div>
<p><!--EndFragment--></p>
<p>We can simply substitute out the variable elements (id, sprite class, and text) and create a Spark partial view (named _styledButton.spark and located in the /Shared view folder).</p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;">&lt;<span style="color:#8ac6f2;">div</span> <span style="color:#cae682;">id</span>=&#8221;<span style="color:teal;">${</span>id<span style="color:teal;">}</span>&#8221; <span style="color:#cae682;">class</span>=&#8221;button&#8221;&gt;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &lt;<span style="color:#8ac6f2;">span</span> <span style="color:#cae682;">class</span>=&#8221;sprite <span style="color:teal;">${</span>sprite<span style="color:teal;">}</span>&#8220;&gt;&lt;/<span style="color:#8ac6f2;">span</span>&gt;<span style="color:teal;">${</span>text<span style="color:teal;">}</span></p>
<p style="margin:0;">&lt;/<span style="color:#8ac6f2;">div</span>&gt;</p>
</div>
<p><!--EndFragment--></p>
<p>In our views, it&rsquo;s easy to create a button:</p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;">&lt;<span style="color:#8ac6f2;">styledButton</span> <span style="color:#cae682;">text</span>=&#8221;&#8216;<span style="color:#e5786d;">Add Activity</span>&#8216;&#8221; <span style="color:#cae682;">id</span>=&#8221;&#8216;<span style="color:#e5786d;">my-button</span>&#8216;&#8221; <span style="color:#cae682;">sprite</span>=&#8221;&#8216;<span style="color:#e5786d;">ss_page_add</span>&#8216;&#8221; /&gt;</p>
</div>
<p><!--EndFragment--></p>
<p><strong>Note: </strong>You need to surround your text with single quotes (&lsquo;text&rsquo;)&nbsp;to inform the Spark engine that the information contained in your variables is a string.</p>
<p>Now, we have shiny, icon&rsquo;d buttons:</p>
<p>Hover Off: <img border="2" hspace="5" alt="" vspace="5" src="http://bit.ly/Nhd6j" /></p>
<p>Hover On: <img border="2" hspace="5" alt="" vspace="5" src="http://bit.ly/4g0js" /></p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/css+sprites">css+sprites</a>, <a rel="tag" href="http://technorati.com/tag/css">css</a>, <a rel="tag" href="http://technorati.com/tag/blueprint+css">blueprint+css</a>, <a rel="tag" href="http://technorati.com/tag/spark+view+engine">spark+view+engine</a></div>
Posted in HTML, MVC, Spark View Engine  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/981/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/981/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/981/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/981/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/981/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/981/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/981/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/981/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/981/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/981/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=981&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/10/02/reusable-controls-with-sprites-css-and-spark-partials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>

		<media:content url="http://bit.ly/4jINM3" medium="image">
			<media:title type="html">CSS Button - Hover Off</media:title>
		</media:content>

		<media:content url="http://bit.ly/ZlrM6" medium="image">
			<media:title type="html">CSS Button - Hover On</media:title>
		</media:content>

		<media:content url="http://bit.ly/Nhd6j" medium="image" />

		<media:content url="http://bit.ly/4g0js" medium="image" />
	</item>
		<item>
		<title>Automating Extracts Using External .SQL Files and PowerShell</title>
		<link>http://tiredblogger.wordpress.com/2009/09/29/automating-extracts-using-external-sql-files-and-powershell/</link>
		<comments>http://tiredblogger.wordpress.com/2009/09/29/automating-extracts-using-external-sql-files-and-powershell/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 14:58:56 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[Hardware and Software]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/09/29/automating-extracts-using-external-sql-files-and-powershell/</guid>
		<description><![CDATA[Rather than rely on a system task, I wanted to be able to kick off an export of one of our SQL databases on the fly, have it generate a CSV, then email the CSV to one of our developers.
Sounds like a task for PowerShell!
Why PowerShell? Well, frankly, because moving jobs around and such on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=979&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Rather than rely on a system task, I wanted to be able to kick off an export of one of our SQL databases on the fly, have it generate a CSV, then email the CSV to one of our developers.</p>
<p>Sounds like a task for PowerShell!</p>
<p>Why PowerShell? Well, frankly, because moving jobs around and such on our mixed-mash of SQL versions and servers is a bit annoying and I wanted to see if it worked.</p>
<p>So, to start off, I have a file, call it <strong>export_data.sql </strong>that contains all of the logic of my SQL query and the format I require.</p>
<p>I&rsquo;ll also be using the Microsoft SQL query script I discussed in <a href="http://tiredblogger.wordpress.com/2009/08/31/querying-sql-server-using-powershell/" target="_blank">this blog post</a>.</p>
<p>The tricky part is reading in the .sql file as a single &ldquo;entity&rdquo;&mdash;not the array of rows that get-content usually provides.&nbsp; Thankfully, there is an easy way to do it.</p>
<blockquote>
<p><strong>@(gc &lsquo;export_data.sql&rsquo; -readcount 0)</strong></p>
</blockquote>
<p dir="ltr">According to the PowerShell documentation, the <strong>readcount</strong> parameter serves two purposes:&nbsp;one is to set the number of lines to read at a time, the second (when set to zero) is to pull in all of the lines at once.&nbsp; Great, that&rsquo;s exactly what we need.</p>
<p dir="ltr">From there, it&rsquo;s simply feeding our query to the sql-query function I wrote and exporting to CSV.&nbsp; Nice enough, CSV exports are built-in to PowerShell!</p>
<p dir="ltr">The final command looks something like this:</p>
<blockquote>
<p dir="ltr"><strong>@(gc &lsquo;export_data.sql&rsquo; -readcount 0) |&nbsp; <br />&nbsp;&nbsp; % { sql-query server db $_ } | <br />&nbsp;&nbsp; export-csv dump.csv</strong></p>
</blockquote>
<p dir="ltr">I could then add another field to mail the csv using the built-in command <strong>Send-MailMessage</strong>.</p>
<p dir="ltr">&lt;3 PowerShell.</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/powershell">powershell</a>, <a rel="tag" href="http://technorati.com/tag/csv">csv</a>, <a rel="tag" href="http://technorati.com/tag/export">export</a>, <a rel="tag" href="http://technorati.com/tag/sql+server">sql+server</a></div>
Posted in General Development, Hardware and Software, Microsoft, PowerShell, SQL, Windows 7, Windows Server  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/979/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=979&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/09/29/automating-extracts-using-external-sql-files-and-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>
	</item>
		<item>
		<title>Populating Select Lists in ASP.NET MVC and jQuery</title>
		<link>http://tiredblogger.wordpress.com/2009/09/25/populating-select-lists-in-asp-net-mvc-and-jquery/</link>
		<comments>http://tiredblogger.wordpress.com/2009/09/25/populating-select-lists-in-asp-net-mvc-and-jquery/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 15:50:26 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Spark View Engine]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/09/25/populating-select-lists-in-asp-net-mvc-and-jquery/</guid>
		<description><![CDATA[I&#8217;ve been working the last bit to find the best way to create/populate select (option) lists using a mixture of ASP.NET MVC and jQuery.&#160; What I&#8217;ve run into is that the &#8220;key&#8221; and &#8220;value&#8221; tags are not passed along when using Json(data).
Here&#8217;s what I&#8217;m trying to pull off in jQuery: building&#160;a simple select drop down [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=977&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&rsquo;ve been working the last bit to find the best way to create/populate select (option) lists using a mixture of ASP.NET MVC and jQuery.&nbsp; What I&rsquo;ve run into is that the &ldquo;key&rdquo; and &ldquo;value&rdquo; tags are not passed along when using <strong>Json(data)</strong>.</p>
<p>Here&rsquo;s what I&rsquo;m trying to pull off in jQuery: building&nbsp;a simple select drop down list.</p>
<blockquote>
<p>var dd_activities = &#8220;&lt;select id=&#8217;dd_activities&#8217;&gt;&#8221;;<br />var count = data.length;<br />for (var i = 0; i &lt; count; i++) {<br />&nbsp;dd_activities += &#8220;&lt;option value=&#8217;&#8221; + data[i].Key + &#8220;&#8216;&gt;&#8221; + data[i].Value + &#8220;&lt;/option&gt;&#8221;;<br />}<br />dd_activities += &#8220;&lt;/select&gt;&#8221;;</p>
<p>$(&#8220;#activities&#8221;).before(dd_activities);</p>
</blockquote>
<p>Using some very basic key/value data:</p>
<blockquote>
<p>[ <br />&nbsp;{"3","Text Value"},<br />&nbsp;{"4","Another Text Value"},<br />&nbsp;{"1","More boring values..."},<br />&nbsp;{"2","Running out of values"},<br />&nbsp;{"5","Last value..."}<br />]</p>
</blockquote>
<div class="netInfoResponseText netInfoText ">Without any sort of name, I was at a loss on how to access the information, how to get it&rsquo;s length, or anything.&nbsp; FireBug was happy to order it up&hellip; but that didn&rsquo;t help.</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">My first attempt was to use a custom object, but that just felt dirty&mdash;creating NEW objects simply to return Json data.</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">My second attempt matched the mentality of newing new anonymous Json objects and seemed to work like a champ:</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;">[<span style="color:#cae682;">Authorize</span>]</p>
<p style="margin:0;">[<span style="color:#cae682;">CacheFilter</span>(Duration = <span style="color:#e5786d;">20</span>)]</p>
<p style="margin:0;"><span style="color:#8ac6f2;">public</span> <span style="color:#cae682;">ActionResult</span> GetActivitiesList()</p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">try</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">var</span> results = </p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _activityRepository</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .GetAll()</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .OrderBy(x =&gt; x.Target.Name).OrderBy(x =&gt; x.Name)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .Select(x =&gt; <span style="color:#8ac6f2;">new</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Key = x.Id.ToString(), </p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Value = <span style="color:#8ac6f2;">string</span>.Format(<span style="color:#e5786d;">&#8220;[{0}] {1}&#8221;</span>, x.Target.Name, x.Name)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; })</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .ToList();</p>
</div>
<p><!--EndFragment--><!--EndFragment--></div>
</div>
<p><!--EndFragment--></p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">return</span> Json(results);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">catch</span> (<span style="color:#cae682;">Exception</span> ex)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">return</span> Json(ex.Message);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">}</p>
</div>
<p><!--EndFragment--></div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">Well, not beautiful, but returns a sexy Key/Value list that Json expects&mdash;and that populates our select list.</div>
<blockquote>
<div class="netInfoResponseText netInfoText ">[<br />&nbsp;{"Key":"3","Value":"Text Value"},<br />&nbsp;{"Key":"4","Value":"Another Text Value"},<br />&nbsp;{"Key":"1","Value":"More boring values..."},<br />&nbsp;{"Key":"2","Value":"Running out of values"},<br />&nbsp;{"Key":"5","Value":"Last value..."}<br />]</div>
</blockquote>
<div class="netInfoResponseText netInfoText ">The next step was to get that out of the controller and into the data repository&hellip; pushing some of that logic back down to the database.</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;"><span style="color:#8ac6f2;"></p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;"><span style="color:#8ac6f2;"></p>
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;"><span style="color:#8ac6f2;">var</span> criteria =</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; Session.CreateCriteria&lt;<span style="color:#cae682;">Activity</span>&gt;()</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; .CreateAlias(<span style="color:#e5786d;">&#8220;Target&#8221;</span>, <span style="color:#e5786d;">&#8220;Target&#8221;</span>)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; .Add(<span style="color:#cae682;">Restrictions</span>.Eq(<span style="color:#e5786d;">&#8220;IsValid&#8221;</span>, <span style="color:#8ac6f2;">true</span>))</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; .AddOrder(<span style="color:#cae682;">Order</span>.Asc(<span style="color:#e5786d;">&#8220;Target.Name&#8221;</span>))</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; .AddOrder(<span style="color:#cae682;">Order</span>.Asc(<span style="color:#e5786d;">&#8220;Name&#8221;</span>))</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; .SetMaxResults(<span style="color:#e5786d;">100</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;"><span style="color:#8ac6f2;">var</span> data = criteria.List&lt;<span style="color:#cae682;">Activity</span>&gt;();</p>
<p style="margin:0;"><span style="color:#8ac6f2;">var</span> result =</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; data</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .Select(x =&gt; <span style="color:#8ac6f2;">new</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Key = x.Id.ToString(), </p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Value = <span style="color:#8ac6f2;">string</span>.Format(<span style="color:#e5786d;">&#8220;[{0}] {1}&#8221;</span>, x.Target.Name, x.Name)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; })</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .ToList();</p>
<p style="margin:0;">tx.Commit();</p>
<p style="margin:0;"><span style="color:#8ac6f2;">return</span> result;</p>
</div>
<p><!--EndFragment--></span></div>
<p><!--EndFragment--></span><!--EndFragment--></div>
</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">A bit of formatting, restrictions, push the ordering back to the database, and a tidy SQL statement is created.</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">The last touch is the return type.&nbsp; Since we&rsquo;re returning a &ldquo;List&rdquo; of anonymous types, the return type of GetActivitiesList() must be an <strong>IList.</strong></div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">That shrinks down my ActionResult to a single call.</div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">
<div style="font-family:Envy Code R, Consolas, Arial;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;"><span style="color:#8ac6f2;">try</span></p>
<p style="margin:0;">&nbsp;{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">return</span> Json(_activityRepository.GetActivitiesList());</p>
<p style="margin:0;">&nbsp;}</p>
<p style="margin:0;">&nbsp;<span style="color:#8ac6f2;">catch</span> (<span style="color:#cae682;">Exception</span> ex)</p>
<p style="margin:0;">&nbsp;{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#8ac6f2;">return</span> Json(ex.Message);</p>
<p style="margin:0;">&nbsp;}</p>
</div>
<p><!--EndFragment--></div>
<div class="netInfoResponseText netInfoText ">&nbsp;</div>
<div class="netInfoResponseText netInfoText ">That works&hellip; and will work for now.&nbsp; Though, I&rsquo;ve marked it as a HACK in my code.&nbsp; Why?&nbsp; I&rsquo;m honestly not sure yet.&nbsp; Just a feeling.</div>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/asp.net+mvc">asp.net+mvc</a>, <a rel="tag" href="http://technorati.com/tag/jquery">jquery</a>, <a rel="tag" href="http://technorati.com/tag/nhibernate">nhibernate</a></div>
Posted in .net 3.5, AJAX, c#, JavaScript, MVC, NHibernate, Spark View Engine, Visual Studio 2008  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/977/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=977&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/09/25/populating-select-lists-in-asp-net-mvc-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>
	</item>
		<item>
		<title>Html.Grid Rendering as Plain Text?</title>
		<link>http://tiredblogger.wordpress.com/2009/09/23/html-grid-rendering-as-plain-text/</link>
		<comments>http://tiredblogger.wordpress.com/2009/09/23/html-grid-rendering-as-plain-text/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 03:22:43 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Spark View Engine]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/09/23/html-grid-rendering-as-plain-text/</guid>
		<description><![CDATA[Notice: Stupid, stupid moment described ahead.&#160; Proceed with caution.
I spent a good half hour trying to figure out why my MVCContrib Html.Grid&#60;T&#62; wasn&#8217;t rendering.&#160; It wasn&#8217;t throwing an error, it was simply returning the HTML code as Plain Text.

The AutoMapper code looked good,
The Html.Grid&#60;T&#62; code looked good (it&#8217;d be templated off another page anyway and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=975&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Notice: Stupid, stupid moment described ahead.&nbsp; Proceed with caution.</strong></p>
<p>I spent a good half hour trying to figure out why my MVCContrib Html.Grid&lt;T&gt; wasn&rsquo;t rendering.&nbsp; It wasn&rsquo;t throwing an error, it was simply returning the HTML code as Plain Text.</p>
<ul>
<li>The AutoMapper code looked good,</li>
<li>The Html.Grid&lt;T&gt; code looked good (it&rsquo;d be templated off another page anyway and that page was working),</li>
<li>The view model code looked good.</li>
</ul>
<p>So why was I being greeted with garble junk?</p>
<blockquote>
<p>${Html.Grid(Model.Details) .Attributes(Id =&gt; &#8220;RoutineDetails&#8221;) .Columns(column =&gt; { column.For(c =&gt; this.Button(&#8220;EditDetail&#8221;).Value(&#8220;Edit&#8221;).Id(string.Format(&#8220;edit_{0}&#8221;, c.Id))).DoNotEncode(); column.For(c =&gt; c.Activity.Target.Name).Named(&#8220;Target Area&#8221;); column.For(c =&gt; c.Activity.Name).Named(&#8220;Activity&#8221;); column.For(c =&gt; c.Sets); column.For(c =&gt; c.Weight); column.For(c =&gt; c.Repetitions); column.For(c =&gt; c.Duration); })}</p>
</blockquote>
<p>Html.Grid that is not&hellip; well, at least not properly.</p>
<p>Encoding issue? Maybe. Data issue? Perhaps.</p>
<p>No, the issue was typing too quick and not paying attention.</p>
<div style="font-family:Consolas, Tahoma, Helvetica;background:#242424;color:#e8f3f6;font-size:10pt;">
<p style="margin:0;"><span style="color:#8ac6f2;">public</span> <span style="color:#cae682;">ActionResult</span> New()</p>
<p style="margin:0;">&nbsp;{</p>
<p style="margin:0;">&nbsp;&nbsp; &nbsp; <span style="color:#8ac6f2;">var</span> viewModel = BuildRoutineNewViewModel(<span style="color:#8ac6f2;">new</span> <span style="color:#cae682;">Routine</span>());</p>
<p style="margin:0;">&nbsp;&nbsp; &nbsp; <span style="color:#8ac6f2;">return</span> View();</p>
<p style="margin:0;">&nbsp;}</p>
</div>
<p><!--EndFragment--></p>
<p>Yeah, that&rsquo;s the problem&hellip; right there.&nbsp; I&rsquo;d forgotten to pass the view model into the View.&nbsp; Apparently the Html.Grid&lt;T&gt; helper simply panics if the model you&rsquo;re reading from is empty or null&mdash;rather than throwing an error.</p>
<p>Oddly enough, this is one of those times I&rsquo;d wish the screen would have lit up red.&nbsp; Lessons learned.</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/mvccontrib">mvccontrib</a>, <a rel="tag" href="http://technorati.com/tag/spark+view+engine">spark+view+engine</a>, <a rel="tag" href="http://technorati.com/tag/asp.net+mvc">asp.net+mvc</a></div>
Posted in .net 3.5, AJAX, c#, MVC, Spark View Engine  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/975/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/975/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/975/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/975/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/975/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/975/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/975/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/975/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/975/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/975/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=975&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/09/23/html-grid-rendering-as-plain-text/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Development Server From ‘Here’ in PowerShell</title>
		<link>http://tiredblogger.wordpress.com/2009/09/09/asp-net-development-server-from-here-in-powershell/</link>
		<comments>http://tiredblogger.wordpress.com/2009/09/09/asp-net-development-server-from-here-in-powershell/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 16:52:21 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[.net 2.0]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[General Development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/09/09/asp-net-development-server-from-here-in-powershell/</guid>
		<description><![CDATA[Long title&#8230; almost longer than the code.
I used to have an old registry setting that started up the ASP.NET Development Server from the current path; however, since I rarely open up Explorer&#8212;and then opening up FireFox was even more painful&#8212;I needed a script.
What does it do?
The script starts up the ASP.NET Development server with a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=973&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Long title&hellip; almost longer than the code.</p>
<p>I used to have an old registry setting that started up the ASP.NET Development Server from the current path; however, since I rarely open up Explorer&mdash;and then opening up FireFox was even more painful&mdash;I needed a script.</p>
<p><strong>What does it do?</strong></p>
<p>The script starts up the ASP.NET Development server with a random port (so you can run multiples&hellip;) at your current location.&nbsp; It then activates your machine&rsquo;s <strong><u>DEFAULT BROWSER</u></strong> and browses to the site.&nbsp; FireFox user?&nbsp; No problem.&nbsp; Works like a champ!</p>
<p><strong>The Script (<a href="http://codepaste.net/feftuu" target="_blank">Full Code</a>)</strong></p>
<blockquote>
<p>$path = resolve-path .<br />$rand = New-Object system.random<br />$port = $rand.next(2048,10240)<br />$path_to_devserver = &#8220;C:\\Program Files (x86)\\Common Files\\microsoft shared\\DevServer\\9.0\\Webdev.WebServer.exe&#8221;</p>
<p>&amp; $path_to_devserver /port:$port /path:$path<br />(new-object -com shell.application).ShellExecute(&#8220;http:\\localhost:$port&#8221;)</p>
</blockquote>
<p>The $path_to_devserver can be updated&mdash;depending on 64&ndash;bit vs. 32&ndash;bit machines.&nbsp; Simple, easy, and to the point.&nbsp; Now, no more fumbling around to launch a quick web application!</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/powershell">powershell</a>, <a rel="tag" href="http://technorati.com/tag/asp.net">asp.net</a>, <a rel="tag" href="http://technorati.com/tag/scripts">scripts</a></div>
Posted in .net 2.0, .net 3.5, c#, General Development, Microsoft, PowerShell, Windows 7, Windows Server  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/973/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=973&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/09/09/asp-net-development-server-from-here-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>
	</item>
		<item>
		<title>Ramping up with PSake</title>
		<link>http://tiredblogger.wordpress.com/2009/09/08/ramping-up-with-psake/</link>
		<comments>http://tiredblogger.wordpress.com/2009/09/08/ramping-up-with-psake/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 18:15:24 +0000</pubDate>
		<dc:creator>David Longnecker</dc:creator>
				<category><![CDATA[.net 2.0]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[General Development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://tiredblogger.wordpress.com/2009/09/08/ramping-up-with-psake/</guid>
		<description><![CDATA[I&#8217;ve been tetering back and forth with PSake and my trusty NAnt scripts for quite a while now.&#160; For those not familiar with PSake, it&#8217;s build automation that makes you drunk&#8212;but in a good way.  &#160; You can read James Kovacs&#8217; original post here or check out the repository here for the latest bits.
I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=970&subd=tiredblogger&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&rsquo;ve been tetering back and forth with PSake and my trusty NAnt scripts for quite a while now.&nbsp; For those not familiar with PSake, it&rsquo;s build automation that makes you drunk&mdash;but in a good way. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> &nbsp; You can read James Kovacs&rsquo; <a href="http://codebetter.com/blogs/james.kovacs/archive/2008/06/27/introducing-psake.aspx" target="_blank">original post here</a> or check out the <a href="http://code.google.com/p/psake/" target="_blank">repository here</a> for the latest bits.</p>
<p>I originally looked at rake scripts (after exposure working with Fluent NHibernate) as PowerShell is loathed in our organization&mdash;or was.&nbsp; That mindset is slowly changing (being able to show people how to crank out what was originally scoped at a week in two lines of PowerShell script helps out); so I&rsquo;m using PSake as further motivation.</p>
<p>My prior PSake scripts were a bit tame.&nbsp; Launch msbuild, copy a few files.&nbsp; With the latest release of xUnit 1.5 hitting the wires over the weekend (and a much needed x86 version for my poor, cranky Oracle libraries), I decided to bite the bullet and dig in to PSake.</p>
<p>I had two goals:</p>
<ol>
<li>Build a reliable framework &ldquo;default.ps1&rdquo; file that I could drop into almost any project and configure with little or no effort.</li>
<li>Compile, test, and rollout updates from a single PSake command task.</li>
</ol>
<p>I borrowed the basic layout from <a href="http://ayende.com/Blog/archive/2009/08/30/on-psake.aspx" target="_blank">Ayende&rsquo;s Rhino Mocks PSake</a>; however, I couldn&rsquo;t get msbuild to run correctly simply by calling it. </p>
<p>Here&rsquo;s what I ended up with for our internal core library.&nbsp; The core library, isn&rsquo;t so much a &ldquo;utilities&rdquo; container, but just as it sounds&mdash;the framework all of our applications are built on to keep connections to our various applications (HR, student systems, data warehouses, etc) consistant as well as hold our base FNH conventions.</p>
<p><strong>CODE: </strong><a href="http://codepaste.net/qyerqm" target="_blank"><strong>Full code available on CodePaste.NET</strong></a></p>
<h3>Properties</h3>
<p>The properties area holds all of the configuration for the PSake script.&nbsp; For me, it&rsquo;s common to configure $solution_name, $libraries_to_merge, and $libraries_to_copy.&nbsp; With our naming standards, the $test_library should be left unchanged.&nbsp; I also added in the tester information so we could change from XUnit to MBUnit (if Hell froze over or something)).</p>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">properties { </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span># ****************<span>&nbsp; </span>CONFIGURE **************** </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$solution_name = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;Framework&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$test_library = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;$solution_name.Test.dll&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$libraries_to_merge = <span>&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;antlr3.runtime.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;ajaxcontroltoolkit.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;Castle.DynamicProxy2.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;Castle.Core.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;FluentNHibernate.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;log4net.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;system.linq.dynamic.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;xunit.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;nhibernate.caches.syscache2.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;cssfriendly.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;iesi.collections.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;nhibernate.bytecode.castle.dll&#8221;, `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;oracle.dataaccess.dll&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$libraries_to_copy = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;system.data.sqlite.dll&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp; </span>$tester_directory = <span></span>&#8220;j:\shared_libraries\xunit\msbuild&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:Consolas;font-size:10pt;" lang="FR">$tester_executable =<span> </span>&#8220;xunit.console.x86.exe&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;" lang="FR"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:Consolas;font-size:10pt;">$tools_directory = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;$tools&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$base_directory<span>&nbsp; </span>= <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>resolve-path .</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$thirdparty_directory = <span>&nbsp;&nbsp; </span>&#8220;$base_directory\thirdparty&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$build_directory = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;$base_directory\build&#8221; </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$solution_file = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;$base_directory\$solution_name.sln&#8221; </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$release_directory = <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;$base_directory\release&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">} </span></p>
</blockquote>
<p>Clean and easy enough.&nbsp; You&rsquo;ll notice that $libraries_to_merge and $libraries_to_copy are implied string arrays.&nbsp; That works out well since string arrays end up as params when passed to commands&hellip; and our $libraries_to_copy can be iterated over later in the code.</p>
<h3>Tasks &ndash; Default</h3>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task default -depends Release</span></p>
<p>The default task (if just running &lsquo;psake&rsquo; without parameters) runs Release.&nbsp; Easy enough.</p>
<h3>Tasks &#8211; Clean</h3>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Clean { </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span>remove-item -force -recurse $build_directory -ErrorAction SilentlyContinue | Out-Null</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span>remove-item -force -recurse $release_directory -ErrorAction SilentlyContinue | Out-Null</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">} </span></p>
</blockquote>
<p>Clean up those build and release directories.</p>
<h3>Tasks &ndash; Init</h3>
</p>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Init -depends Clean { </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp; </span>new-item $release_directory -itemType directory | Out-Null</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp; </span>new-item $build_directory -itemType directory | Out-Null</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp; </span>cp $tester_directory\*.* $build_directory</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">} </span></p>
</blockquote>
<p>Restore those build and release directories that we cleaned up; then copy in our unit testing framework so we can run our tests (if necessary).</p>
<h3>Tasks &ndash; Compile</h3>
</p>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Compile -depends Init { </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span># from http://poshcode.org/1050 (first lines to get latest versions)</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>[System.Reflection.Assembly]::Load(&#8216;Microsoft.Build.Utilities.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#8217;) | Out-Null</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$msbuild = [Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToDotNetFrameworkFile(&#8220;msbuild.exe&#8221;, &#8220;VersionLatest&#8221;)</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span># adding double slash for directories with spaces. Stupid MSBuild.</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp;$msbuild /verbosity:minimal /p:Configuration=&#8221;Release&#8221; /p:Platform=&#8221;Any CPU&#8221; /p:OutDir=&#8221;$build_directory&#8221;\\ &#8220;$solution_file&#8221; </span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">} </span></p>
</blockquote>
<p>Compile is a bit tricky.&nbsp; As noted in the code, I ended up using a SharePoint example from <a href="http://poshcode.org/1050" target="_blank">PoSH code</a>&nbsp;to get MSBuild to behave.&nbsp; The standard <strong>exec</strong> methodology provided by PSake kept ignoring my parameters.&nbsp; Maybe someone has an good reason.. but this works.</p>
<p>You also see that my OutDir has <strong>TWO slashes</strong>.&nbsp; It seems that directories with spaces require the second.&nbsp; I&rsquo;m sure this will somehow bite me later on, but it seems to be working for now. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><h3>Tasks &ndash; Test</h3>
</p>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Test -depends Compile {</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span>$origin_directory = pwd</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span>cd $build_directory</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span>exec .\$tester_executable &#8220;$build_directory\$test_library&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp; </span>cd $origin_directory<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">}</span></p>
</blockquote>
<p>I want to thank Ayende&nbsp;for the idea to dump the origin directory into a parameter&mdash;brilliant.&nbsp; This&nbsp;one is pretty&nbsp;simple&mdash;just calls the tester and&nbsp;tests.</p>
<p><h3>Tasks &ndash; Merge</h3>
</p>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Merge {</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>$origin_directory = pwd</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cd $build_directory</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>remove-item &#8220;$solution_name.merge.dll&#8221; -erroraction SilentlyContinue</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>rename-item &#8220;$solution_name.dll&#8221; &#8220;$solution_name.merge.dll&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; $tools\ilmerge\ilmerge.exe /out:&#8221;$solution_name.dll&#8221; /t:library /xmldocs /log:&#8221;$solution_name.merge.log&#8221; `</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8220;$solution_name.merge.dll&#8221; $libraries_to_merge</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if ($lastExitCode -ne 0) {</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw &#8220;Error: Failed to merge assemblies!&#8221;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cd $origin_directory</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">}</span></p>
</blockquote>
<p>Merge calls ILMerge and wraps all of my libraries into one.&nbsp; Do I need to do this?&nbsp; Nah, but for the framework, I prefer to keep everything together.&nbsp; I don&rsquo;t want to be chasing mis-versioned libraries around.&nbsp; Again, since $libraries_to_merge is a string array, it passes each &ldquo;string&rdquo; as a separate parameter&mdash;which is exactly what ILMerge wants to see.</p>
<p>I also have ILMerge generate and keep a log of&nbsp;what it did&mdash;just to have.&nbsp; Since the build directory gets blown away between builds (and isn&rsquo;t replicated to source control), then no harm.&nbsp; Space is mostly free. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><h3>Tasks &ndash; Build &amp; Release</h3>
</p>
<blockquote>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Build -depends Compile, Merge {</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span># When I REALLY don&#8217;t want to test&#8230;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">}</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">&nbsp;</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">task Release -depends Test, Merge {</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>copy-item $build_directory\$solution_name.dll $release_directory</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>copy-item $build_directory\$solution_name.xml $release_directory</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span># copy libraries that cannot be merged</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>% { $libraries_to_copy } | %{ copy-item (join-path $build_directory $_) $release_directory }</span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p style="margin:0;" class="MsoNoSpacing"><span style="font-family:Consolas;font-size:10pt;">}</span></p>
</blockquote>
<p>Build provides just that&mdash;building with no testing and no copying to the release directory.&nbsp; This is more for testing out the scripts, but useful in some cases.</p>
<p>Release copies the library and the xml documentation out ot the release directory.&nbsp; It then iterates through the string array of &ldquo;other&rdquo; libraries (non-manged code libraries that can&rsquo;t be merged, etc) and copies them as well.</p>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</p>
<div class="bjtags">Tags: <a rel="tag" href="http://technorati.com/tag/powershell">powershell</a>, <a rel="tag" href="http://technorati.com/tag/msbuild">msbuild</a>, <a rel="tag" href="http://technorati.com/tag/psake">psake</a>, <a rel="tag" href="http://technorati.com/tag/visual+studio">visual+studio</a>, <a rel="tag" href="http://technorati.com/tag/c#">c#</a></div>
Posted in .net 2.0, .net 3.5, c#, General Development, Microsoft, PowerShell, Visual Studio 2008, Windows 7, Windows Server  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tiredblogger.wordpress.com/970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tiredblogger.wordpress.com/970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tiredblogger.wordpress.com/970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tiredblogger.wordpress.com/970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tiredblogger.wordpress.com/970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tiredblogger.wordpress.com/970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tiredblogger.wordpress.com/970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tiredblogger.wordpress.com/970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tiredblogger.wordpress.com/970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tiredblogger.wordpress.com/970/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tiredblogger.wordpress.com&blog=253870&post=970&subd=tiredblogger&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tiredblogger.wordpress.com/2009/09/08/ramping-up-with-psake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/31657c007e961f2f893c8b8ee594754a?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">drlongnecker</media:title>
		</media:content>
	</item>
	</channel>
</rss>
