<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PeterKellner.net &#187; Visual Studio</title>
	<atom:link href="http://peterkellner.net/category/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focused, JavaScript,HTML5 (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 11 May 2012 16:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Microsoft&#8217;s ASP.NET MVC Lite, Building a TextReformatter With JsonResult</title>
		<link>http://peterkellner.net/2012/04/10/microsofts-asp-net-mvc-lite-building-a-textreformatter-with-jsonresult/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=microsofts-asp-net-mvc-lite-building-a-textreformatter-with-jsonresult</link>
		<comments>http://peterkellner.net/2012/04/10/microsofts-asp-net-mvc-lite-building-a-textreformatter-with-jsonresult/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 19:40:18 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Visual Studio 2011 Developer Preview]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1931</guid>
		<description><![CDATA[&#160;
Introduction
&#160;
People often ask me if I use MVC or WebForms for my Microsoft ASP.NET projects.&#160; I always tell them MVC, but I don’t use it in the classic way that most others do.&#160; That is to say, I emit no html from my views, and for that matter really don’t even use views (with the [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>&#160;</p>
<p>People often ask me if I use <a href="http://www.asp.net/mvc">MVC</a> or <a href="http://www.asp.net/web-forms">WebForms</a> for my Microsoft <a href="http://www.asp.net/">ASP.NET</a> projects.&#160; I always tell them <a href="http://www.asp.net/mvc">MVC</a>, but I don’t use it in the classic way that most others do.&#160; That is to say, I emit no html from my views, and for that matter really don’t even use views (with the exception of one view which is essentially my entire app.&#160;&#160; People often refer to this as a SPA or Single-Page-Application. What this basically means is that my entire view is built with JavaScript (in my case <a href="'">Sencha’s</a> <a href="http://www.sencha.com/products/extjs/">ExtJS</a>) and the only interaction with the server is to simply bring down <a href="http://json.org/">Json</a> results.</p>
<p>In this post, I’m going to build a simple app following this principle. It’s purpose will be to take a big pile of text, chop it up into words, then output it in some c# friendly manner.&#160; My motivation for doing this is I happen to need that functionality right now and instead of creating a little <a href="http://en.wikipedia.org/wiki/AWK">awk</a> script to do it, I’m going to right a web site!</p>
<p>&#160;</p>
<p>So, Here is what we will build.&#160; A handy formatter! (and you can run it at:&#160;&#160; <a href="http://reformatter.peterkellner.net/">http://reformatter.peterkellner.net/</a> )</p>
<p>&#160;</p>
<p><a href="http://reformatter.peterkellner.net/app.html"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image4.png" width="510" height="438" /></a></p>
<p><a href="http://reformatter.peterkellner.net/app.html"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image5.png" width="511" height="444" /></a></p>
<p>&#160;</p>
<p>&#160;</p>
<h2>Part I, The Visual Studio Project</h2>
<p>&#160;</p>
<p>Let’s first create the Visual Studio project.&#160; My development these days is actually using the latest Windows 8 Consumer build with the beta of Visual Studio 2011 running on it.&#160; The nice thing about this is because Microsoft added “Round Tripping” to VS2011, I can now use VS2011 to create the project and you, my happy readers, can download the project and open it in Visual Studio 2010.&#160; This has been long in coming and Microsoft has finally done it for the newest version of Visual Studio.&#160; Thank you Microsoft!</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb.png" width="438" height="271" /></a></p>
<p>&#160;</p>
<p>And with an Internet Application with Razor (though I really don’t need all that extra stuff, it does not hurt)</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image1.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb1.png" width="385" height="353" /></a></p>
<p>&#160;</p>
<p>The structure created is as as shown below with a Controller and Views folder and all the proper routing setup.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image2.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb2.png" width="218" height="340" /></a></p>
<p>&#160;</p>
<p>Because I want to make a very simple MVC app that only emits Json, Let’s create our own empty controller called ReformatterController.&#160; We do that by right clicking on the Controller folder and pressing “Add Controller”, then “Add Empty Controller”.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image3.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb3.png" width="352" height="256" /></a></p>
<p>&#160;</p>
<p>Now, let’s create a very very simple controller with just one method that returns a JSON Result.&#160; I’m returning the data in a friendly format to&#160; Sencha’s ExtJS (or SenchaTouch for that matter).&#160; <a href="http://www.webappers.com/2011/02/16/how-to-build-single-page-applications-with-jquery/">JQuery</a> would be similar.&#160; Here is our new controller class (I’m sure my little tokenizer, line maker could be improved, but I’m just doing this to show some real work.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Web;
<span class="kwrd">using</span> System.Web.Mvc;

<span class="kwrd">namespace</span> MvcLiteApp.Controllers
{
    <span class="kwrd">public</span> <span class="kwrd">class</span> ReformatterController : Controller
    {

        <span class="kwrd">public</span> JsonResult ConvertTextToFriendlyText(<span class="kwrd">string</span> inputText)
        {
            <span class="kwrd">const</span> <span class="kwrd">int</span> maxCharactersInLine = 30;
            <span class="kwrd">bool</span> success;
            <span class="kwrd">string</span> messageReturn;
            var outputDataList = <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;();

            <span class="kwrd">try</span>
            {
                var words = inputText.Split(<span class="str">' '</span>).ToList();
                var newLine = <span class="kwrd">new</span> StringBuilder();
                <span class="kwrd">foreach</span> (var word <span class="kwrd">in</span> words)
                {
                    <span class="kwrd">if</span> (newLine.Length + word.Length &lt; maxCharactersInLine &amp;&amp;
                        word.Length &lt; maxCharactersInLine)
                    {
                        newLine.Append(<span class="str">&quot; &quot;</span>);
                        newLine.Append(word);
                    }
                    <span class="kwrd">else</span>
                    {
                        outputDataList.Add(newLine.ToString().Trim());
                        newLine = <span class="kwrd">new</span> StringBuilder();
                        newLine.Append(word);
                    }
                }
                success = <span class="kwrd">true</span>;
                messageReturn = <span class="str">&quot;&quot;</span>;
            }
            <span class="kwrd">catch</span> (Exception e)
            {
                messageReturn = e.ToString();
                success = <span class="kwrd">false</span>;
            }

            <span class="kwrd">return</span> Json(<span class="kwrd">new</span>
            {
                Success = success,
                Data = outputDataList,
                message = messageReturn
            }, JsonRequestBehavior.AllowGet);
        }

    }
}</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, let’s feed it a URL and see what happens.&#160; Here is a sample URL:</p>
<p><a title="http://localhost:3600/Reformatter/ConvertTextToFriendlyText?inputText=Romeo%20Montague%20and%20Juliet%20Capulet%20meet%20and%20fall%20in%20love%20in%20Shakespeare&#39;s%20lyrical%20tale%20of%20%22star-cross&#39;d%22%20lovers." href="http://localhost:3600/Reformatter/ConvertTextToFriendlyText?inputText=Romeo%20Montague%20and%20Juliet%20Capulet%20meet%20and%20fall%20in%20love%20in%20Shakespeare's%20lyrical%20tale%20of%20%22star-cross'd%22%20lovers.">http://localhost:3600/Reformatter/ConvertTextToFriendlyText?inputText=Romeo%20Montague%20and%20Juliet%20Capulet%20meet%20and%20fall%20in%20love%20in%20Shakespeare&#8217;s%20lyrical%20tale%20of%20%22star-cross&#8217;d%22%20lovers.</a></p>
<p>I actually pasted the sentence in to the the browser’s URL line and it added the nice encoded spaces for me.&#160; The output is as follows:</p>
<p>{&quot;Success&quot;:true,&quot;Data&quot;:[&quot;Romeo Montague and Juliet&quot;,&quot;Capulet meet and fall in love&quot;,&quot;in Shakespeare\u0027s lyrical tale&quot;],&quot;message&quot;:&quot;&quot;}</p>
<p>Notice that it created the nice lines formatted as a JavaScript array!</p>
<p>Next step, let’s make a real JavaScript program out of this.</p>
<p>&#160;</p>
<h2>Part 2, Our SPA (Single Page App) That Does Real Work</h2>
<p>&#160;</p>
<p>I’m only going to explain here the part of the Sencha Program that actually consumes the data but first, let’s add a little “properness” to our controller so it responds only to POST.&#160; That is, we add an attribute to the top of the method and we change the behavior attribute on the bottom to say to not allow get.</p>
<pre class="csharpcode">        [HttpPost]
        <span class="kwrd">public</span> JsonResult ConvertTextToFriendlyText(<span class="kwrd">string</span> inputText)
        {
            .......
            <span class="kwrd">return</span> Json(<span class="kwrd">new</span>
            {
                Success = success,
                Data = outputDataList,
                message = messageReturn
            }, JsonRequestBehavior.DenyGet);
        }</pre>
<p>And, the JavaScript in the SPA is very straight forward and is here:</p>
<pre class="csharpcode"><span class="kwrd">var</span> beforeTextAreaComponent = Ext.getCmp(<span class="str">'BeforeFormatTextAreaId'</span>);
textBefore = beforeTextAreaComponent.getValue();

<span class="rem">// how to not pollute global name space here?</span>
<span class="kwrd">var</span> stringbuildervalue = Ext.getCmp(<span class="str">'stringbuilderid'</span>).getValue();
<span class="kwrd">var</span> javascriptarrayvalue = Ext.getCmp(<span class="str">'javascriptarrayid'</span>).getValue();
<span class="kwrd">var</span> noformattingvalue = Ext.getCmp(<span class="str">'noformattingid'</span>).getValue();
<span class="kwrd">var</span> outputwidthvalue = Ext.getCmp(<span class="str">'outputwidthid'</span>).getValue();

Ext.Ajax.request({
    url: <span class="str">'ReFormatter/ConvertTextToFriendlyText'</span>,
    <span class="kwrd">params</span>: {
        inputText: textBefore,
        stringbuilder: stringbuildervalue,
        javascriptarray: javascriptarrayvalue,
        noformatting: noformattingvalue,
        outputwidth: outputwidthvalue
    },
    success: <span class="kwrd">function</span>(response){
        <span class="kwrd">var</span> localData = Ext.JSON.decode(response.responseText).Data;
        <span class="kwrd">var</span> numberRows = localData.length;
        <span class="kwrd">var</span> newData = <span class="str">''</span>;
        <span class="kwrd">for</span> (<span class="kwrd">var</span> i=0;i&lt;numberRows;i++) {
            newData += localData[i] + <span class="str">'\n'</span>;
        }

        <span class="kwrd">var</span> afterTextAreaComponent = Ext.getCmp(<span class="str">'AfterFormatTextAreaId'</span>);
        afterTextAreaComponent.setValue(newData);

    },
    failure: <span class="kwrd">function</span>(error) {
        alert(<span class="str">'error'</span>);
    }

});</pre>
<p>Now, in reality, I’ve added some useful stuff to the controller (and put the project here for your review, comments and suggestions).</p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:279ce901-a751-4b1a-8603-ebda182698cc" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
<p>Visual Studio Project <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/TextReformatter.zip" target="_blank">TextReformatter.zip</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/10/microsofts-asp-net-mvc-lite-building-a-textreformatter-with-jsonresult/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test First Development Walk Through with Visual Studio 2011 Preview</title>
		<link>http://peterkellner.net/2012/03/18/test-first-development-walk-through-with-visual-studio-2011-preview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=test-first-development-walk-through-with-visual-studio-2011-preview</link>
		<comments>http://peterkellner.net/2012/03/18/test-first-development-walk-through-with-visual-studio-2011-preview/#comments</comments>
		<pubDate>Sun, 18 Mar 2012 23:14:10 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Visual Studio 2011 Developer Preview]]></category>
		<category><![CDATA[VSTS]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/18/test-first-development-walk-through-with-visual-studio-2011-preview/</guid>
		<description><![CDATA[Introduction
Many of us know we should be using test first development, however it is hard to break old habits.&#160; I have to admit, I started to solve this particular problem I’m going to use an an example first without test first, then realized what a pickle I was going to be in proving to myself [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Many of us know we should be using test first development, however it is hard to break old habits.&#160; I have to admit, I started to solve this particular problem I’m going to use an an example first without test first, then realized what a pickle I was going to be in proving to myself it worked.&#160; So, I thought, why not blog my experience as I do it.&#160; Using <a href="http://www.microsoft.com/visualstudio/en-us">Visual Studio</a>&#160;<a href="http://msdn.microsoft.com/en-us/library/ms379625(v=vs.80).aspx">unit testing</a> makes this pretty easy.</p>
<p>&#160;</p>
<h2>The Problem</h2>
<p>I’m currently building a multithreaded email processor and part of that process is I have to figure out, for any given use whether they are supposed to have there email server checked.&#160; So, the way I look at it, I need a method that takes in the following parameter.</p>
<ol>
<ol>
<li><strong>Now</strong> – This is actually todays date and time in UTC, but since this method need to be tested, I’m going to pass in now rather just use it directly. </li>
<li><strong>LastActivityOfUserDateTime</strong> – This is the last time we saw any activity for this user. </li>
<li><strong>LastEmailSession</strong> – This is when the email session was last run (server check).</li>
<li><strong>DefaultSecondsForLastActivityTreshold</strong> – This is used to determine weather the user last activity makes that user considered active or inactive.&#160; That is, say this is 60 seconds.&#160; Then, if the user has been active in the last 60 seconds, then this user is considered active. </li>
<li><strong>DefaultSecondsBetweenEmailRetryOutsideThreshold</strong> – If the user is<u> not active</u> (as defined by DefaultSecondsForLastActivityTreshold) then this is the number of seconds we should wait before we should try and contact the users email server again. </li>
<li><strong>DefaultSecondsBetweenEmailRetryInsideThreshold</strong> – If the user is <u>active</u> (as defined by DefaultSecondsForLastActivityTreshold) then this is the number of seconds we should wait before we should try and contact the users email server again. </li>
</ol>
</ol>
<p>Given these 4 parameters, we should write a method that returns a Boolean indicating weather the mail server needs to be rechecked for a given user.</p>
<p>&#160;</p>
<h2>The Method To Test</h2>
<p>So, let’s write a method signature.&#160; We will use this in our real project, then write some tests to see if it works correctly.&#160; We have not written the actual method yet, we are just defining what it does, then first, very important, writing the tests to prove it will work.&#160; This way, as we add all the corner cases, we can keep making sure the original cases we programmed have not broken.</p>
<p>So, here is how I see the class definition:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">bool</span> IsUserReadyToContactEmailServer(DateTime currentDateTime,
            DateTime lastActivityOfUserDateTime,
            DateTime lastEmailSession,
            <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold,
            <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold,
            <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold)
        {
            <span class="kwrd">bool</span> activeUser = IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                                      defaultSecondsForLastActivityTreshold);
            <span class="kwrd">int</span> thresholdForRetrySeconds =
                activeUser
                    ? defaultSecondsBetweenEmailRetryInsideThreshold
                    : defaultSecondsBetweenEmailRetryOutsideThreshold;

            <span class="rem">// this has to be a double because could be huge number if last email send very long ago</span>
            <span class="kwrd">double</span> timeSinceLastEmailSessionSeconds =
                currentDateTime.Subtract(lastEmailSession).TotalSeconds;

           <span class="kwrd">return</span> timeSinceLastEmailSessionSeconds &gt; thresholdForRetrySeconds;
        }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h2>Creating a Test Project In Visual Studio 2011 Preview</h2>
<p>Now that we have our method we want to test, let’s create a test project.&#160; This is very straight forward.&#160; We first just say “File/New Project” then choose “Unit Test Project”.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image11.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb11.png" width="432" height="255" /></a></p>
<p>&#160;</p>
<p>I’m going to simply create a method called TestMethodIsUserReadyToContactEmailServer().</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> Microsoft.VisualStudio.TestTools.UnitTesting;

<span class="kwrd">namespace</span> AEWeb.Tests
{
    [TestClass]
    <span class="kwrd">public</span> <span class="kwrd">class</span> UnitTest1
    {
        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> TestMethodIsUserReadyToContactEmailServer()
        {
        }
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, we need to add some guts.&#160; There is an automated way to create the actual test stubs, but at the moment I can’t seem to find it.&#160; In this case, we really just need to test a bunch of corner cases so let’s code the tests up. Below are the tests I’ve come up with including comments that make them self explanatory.</p>
<p>So, as I’m creating my tests, I realize I need to create an extra class to help this one.&#160; That is specifically, I need to add a method that simply determines if the user is currently active.&#160; I’m going to call that IsCurrentlyActive and have it take three paramaters.&#160; currentDateTime, DefaultSecondsForLastActivityThreshold and usersLastActivityDate.&#160; I realized this because solving the full problem of figuring out if the user is ready to sync email is to complex in one step.</p>
<p>If I were developing this without unit tests, I would have figured the same thing out, but then as I built it, I would not be verifying it’s correctness with testing.</p>
<h2>Creating Stub Classes</h2>
<p>So, my new class I want to test will be this:</p>
<pre class="csharpcode"> <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// This really just a supporting method for the above IsUserReadyToContactEmailServer call</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name=&quot;currentDateTime&quot;&gt;Current datetime (for testing can be anything)&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;usersLastActivityDate&quot;&gt;time user was last seen &lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;defaultSecondsForLastActivityTreshold&quot;&gt;our definition of what makes a user currently active&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">bool</span> IsUserCurrentlyActive(DateTime currentDateTime,
            DateTime usersLastActivityDate,
            <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold
            )
        {

            <span class="kwrd">return</span> <span class="kwrd">true</span>;
        }</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<h2>The Unit Tests Themselves</h2>
<p>So, now is time to actually write the tests.&#160; I’m not going to explain here all the mechanics of testing.&#160; I assume you understand the basics are you right calls to methods, then make assertions for correctness.&#160; If the assertion is wrong, then print that message and of course the test fails.</p>
<p>So, Here are my test cases for just the helper method (IsUserCurrentlyActive).</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> AELib;
<span class="kwrd">using</span> Microsoft.VisualStudio.TestTools.UnitTesting;

<span class="kwrd">namespace</span> AEWeb.Tests
{
    [TestClass]
    <span class="kwrd">public</span> <span class="kwrd">class</span> UnitTestEmailReadyCheck
    {

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestRecentActivity()
        {
            {
                <span class="rem">// a long time ago</span>
                var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
                var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 2, 1, 12, 0, 0);
                <span class="rem">// last activity was a month ago, 2/1/2012 at noon</span>
                <span class="rem">// threshhold for calling a user active</span>
                <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60*15; <span class="rem">// let's call this 15 minute threshhold</span>
                <span class="kwrd">bool</span> isActive = <span class="kwrd">new</span> MailServerReadyCheck().
                    IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                          defaultSecondsForLastActivityTreshold);
                Assert.IsFalse(isActive,
                               <span class="str">&quot;User Should Be Inactive because last activity was 1 month ago and threshhold is 15 minutes&quot;</span>);
            }
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestNoRecentActivity()
        {
            <span class="rem">// a just inside threshold</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 11, 55, 0);
            <span class="rem">// last activity was 5 minutes before noon on 2/1/2012</span>
            <span class="rem">// threshhold for calling a user active</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60*15; <span class="rem">// let's call this 15 minute threshhold</span>
            <span class="kwrd">bool</span> isActive = <span class="kwrd">new</span> MailServerReadyCheck().
                IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                      defaultSecondsForLastActivityTreshold);
            Assert.IsTrue(isActive,
                          <span class="str">&quot;User Should Be active because last activity was 5 minutes ago and threshhold is 15 minutes&quot;</span>);
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestCurrentDateBehindActivity()
        {
            <span class="rem">// impossible cause of last activity being after current time. just need to</span>
            <span class="rem">// make sure it returns true and does not crash</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 18, 0, 0);
            <span class="rem">// last activity was 5 minutes after noon on 2/1/2012</span>
            <span class="rem">// threshhold for calling a user active</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60*15; <span class="rem">// let's call this 15 minute threshhold</span>
            <span class="kwrd">bool</span> isActive = <span class="kwrd">new</span> MailServerReadyCheck().
                IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                      defaultSecondsForLastActivityTreshold);
            Assert.IsTrue(isActive,
                          <span class="str">&quot;User Should Be active because last activity was 5 minutes after current time&quot;</span>);
        }
    }
}</pre>
<p>&#160;</p>
<p>Then, I write the actual method:</p>
<p>&#160;</p>
<pre class="csharpcode">       <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// This really just a supporting method for the above IsUserReadyToContactEmailServer call</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name=&quot;currentDateTime&quot;&gt;Current datetime (for testing can be anything)&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;usersLastActivityDate&quot;&gt;time user was last seen &lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;defaultSecondsForLastActivityTreshold&quot;&gt;our definition of what makes a user currently active&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">bool</span> IsUserCurrentlyActive(DateTime currentDateTime,
            DateTime usersLastActivityDate,
            <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold
            )
        {
            <span class="kwrd">int</span> secondsSinceLastActivity = Convert.ToInt32(currentDateTime.Subtract(usersLastActivityDate).TotalSeconds);
            <span class="kwrd">bool</span> activeStatus = defaultSecondsForLastActivityTreshold &gt; secondsSinceLastActivity;
            <span class="kwrd">return</span> activeStatus;
        }</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>And finally, run the test (skipping a little debugging to make them all work)</p>
<p>Presto!</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image12.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb12.png" width="338" height="263" /></a></p>
<p>&#160;</p>
<p>For completeness, I’m pasting the full unit test for the other main class I’m interested in testing below (as well as the class itself), however I won’t go into all the details.&#160; Everything is basically the same, just more of it</p>
<p>&#160;</p>
<h2>Conclusions and Observations</h2>
<p>Turns out, this was quite a bit of work to generate all these tests.&#160; At first pass, I can hear someone saying it seems like a lot to do just for two fairly simple methods.&#160; My answer is that I struggled trying to get it right until I finally decided to write the tests.&#160; Now, I’m confident it works correctly.&#160; What is more, if there is a bug in my algorithm, or something else comes up I need to include (which is very likely) I now have a great way to prove to myself (and others) that my class works.&#160; Also, this serves as great documentation for what expectations are for this very important function.</p>
<p>&#160;</p>
<h2>
<p>Appendex – Full Unit Test And Class Source</p>
<p>&#160;</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;

<span class="kwrd">namespace</span> AELib
{
    <span class="kwrd">public</span> <span class="kwrd">class</span> MailServerReadyCheck
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// </span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name=&quot;currentDateTime&quot;&gt;This is actually todays date and time in UTC, but since </span>
        <span class="rem">///    this method need to be tested, I’m going to pass in now rather just use it directly&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;lastActivityOfUserDateTime&quot;&gt; This is used to determine weather the user last activity</span>
        <span class="rem">///      makes that user considered active or inactive.  That is, say this is 60 seconds.</span>
        <span class="rem">///      Then, if the user has been active in the last 60 seconds, then this user is considered active.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;lastEmailSession&quot;&gt;When the last email completed for this user&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;defaultSecondsForLastActivityTreshold&quot;&gt;This is used to determine weather the user last activity makes that </span>
        <span class="rem">///      user considered active or inactive.  That is, say this is 60 seconds.  Then, if the user has </span>
        <span class="rem">///      been active in the last 60 seconds, then this user is considered active.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;defaultSecondsBetweenEmailRetryOutsideThreshold&quot;&gt; If the user is not active (as defined by </span>
        <span class="rem">///      DefaultSecondsForLastActivityTreshold) then this is the number of seconds we should wait before </span>
        <span class="rem">///      we should try and contact the users email server again.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;defaultSecondsBetweenEmailRetryInsideThreshold&quot;&gt;If the user is active (as defined by </span>
        <span class="rem">///      DefaultSecondsForLastActivityTreshold) then this is the number of seconds we should wait </span>
        <span class="rem">///      before we should try and contact the users email server again.&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;returns a boolean indicating weather the mail server needs to be rechecked for a given user.&lt;/returns&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">bool</span> IsUserReadyToContactEmailServer(DateTime currentDateTime,
            DateTime lastActivityOfUserDateTime,
            DateTime lastEmailSession,
            <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold,
            <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold,
            <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold)
        {
            <span class="kwrd">bool</span> activeUser = IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                                      defaultSecondsForLastActivityTreshold);
            <span class="kwrd">int</span> thresholdForRetrySeconds =
                activeUser
                    ? defaultSecondsBetweenEmailRetryInsideThreshold
                    : defaultSecondsBetweenEmailRetryOutsideThreshold;

            <span class="rem">// this has to be a double because could be huge number if last email send very long ago</span>
            <span class="kwrd">double</span> timeSinceLastEmailSessionSeconds =
                currentDateTime.Subtract(lastEmailSession).TotalSeconds;

           <span class="kwrd">return</span> timeSinceLastEmailSessionSeconds &gt; thresholdForRetrySeconds;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// This really just a supporting method for the above IsUserReadyToContactEmailServer call</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name=&quot;currentDateTime&quot;&gt;Current datetime (for testing can be anything)&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;usersLastActivityDate&quot;&gt;time user was last seen &lt;/param&gt;</span>
        <span class="rem">/// &lt;param name=&quot;defaultSecondsForLastActivityTreshold&quot;&gt;our definition of what makes a user currently active&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">bool</span> IsUserCurrentlyActive(DateTime currentDateTime,
            DateTime usersLastActivityDate,
            <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold
            )
        {
            <span class="kwrd">int</span> secondsSinceLastActivity = Convert.ToInt32(currentDateTime.Subtract(usersLastActivityDate).TotalSeconds);
            <span class="kwrd">bool</span> activeStatus = defaultSecondsForLastActivityTreshold &gt; secondsSinceLastActivity;
            <span class="kwrd">return</span> activeStatus;
        }
    }
}</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>And the tests…</p>
<p>&#160;</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> AELib;
<span class="kwrd">using</span> Microsoft.VisualStudio.TestTools.UnitTesting;

<span class="kwrd">namespace</span> AEWeb.Tests
{
    [TestClass]
    <span class="kwrd">public</span> <span class="kwrd">class</span> UnitTestEmailReadyCheck
    {

        <span class="rem">///////////////////// IsUserCurrentlyActive follows</span>

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestRecentActivity()
        {
            {
                <span class="rem">// a long time ago</span>
                var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
                var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 2, 1, 12, 0, 0);
                <span class="rem">// last activity was a month ago, 2/1/2012 at noon</span>
                <span class="rem">// threshhold for calling a user active</span>
                <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60*15; <span class="rem">// let's call this 15 minute threshhold</span>
                <span class="kwrd">bool</span> isActive = <span class="kwrd">new</span> MailServerReadyCheck().
                    IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                          defaultSecondsForLastActivityTreshold);
                Assert.IsFalse(isActive,
                               <span class="str">&quot;User Should Be Inactive because last activity was 1 month ago and threshhold is 15 minutes&quot;</span>);
            }
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestNoRecentActivity()
        {
            <span class="rem">// a just inside threshold</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 11, 55, 0);
            <span class="rem">// last activity was 5 minutes before noon on 2/1/2012</span>
            <span class="rem">// threshhold for calling a user active</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60*15; <span class="rem">// let's call this 15 minute threshhold</span>
            <span class="kwrd">bool</span> isActive = <span class="kwrd">new</span> MailServerReadyCheck().
                IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                      defaultSecondsForLastActivityTreshold);
            Assert.IsTrue(isActive,
                          <span class="str">&quot;User Should Be active because last activity was 5 minutes ago and threshhold is 15 minutes&quot;</span>);
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestCurrentDateBehindActivity()
        {
            <span class="rem">// impossible cause of last activity being after current time. just need to</span>
            <span class="rem">// make sure it returns true and does not crash</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 18, 0, 0);
            <span class="rem">// last activity was 5 minutes after noon on 2/1/2012</span>
            <span class="rem">// threshhold for calling a user active</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60*15; <span class="rem">// let's call this 15 minute threshhold</span>
            <span class="kwrd">bool</span> isActive = <span class="kwrd">new</span> MailServerReadyCheck().
                IsUserCurrentlyActive(currentDateTime, lastActivityOfUserDateTime,
                                      defaultSecondsForLastActivityTreshold);
            Assert.IsTrue(isActive,
                          <span class="str">&quot;User Should Be active because last activity was 5 minutes after current time&quot;</span>);
        }

        <span class="rem">///////////////////// IsUserReadyToContactEmailServer follows</span>

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestIsUserReadyToContactEmailServerLongTimeAgoUserInActive()
        {
            <span class="rem">// let's use these parameters for every test</span>

            <span class="rem">// let's call this 30 minute threshhold. no contact within 30 minutes, than user is inactive</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60 * 30;

            <span class="rem">// if active user, check email every 2 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold = 60 * 2;

            <span class="rem">// if inactive user, check email every 20 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold = 60 * 20; 

            <span class="rem">// user checked email 5 hours ago and email has not been run for 3 hours</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastEmailSessionDateTime = <span class="kwrd">new</span> DateTime(2011,3,1,2, 0, 0); <span class="rem">// email session 2am of 1 year ago (very long ago)</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2011, 3, 1, 7, 0, 0); <span class="rem">// user checked email at 7am a year ago</span>

            <span class="kwrd">bool</span> emailSessionNeeded = <span class="kwrd">new</span> MailServerReadyCheck().IsUserReadyToContactEmailServer(currentDateTime,
                lastActivityOfUserDateTime,lastEmailSessionDateTime,defaultSecondsForLastActivityTreshold,
                defaultSecondsBetweenEmailRetryOutsideThreshold,
                defaultSecondsBetweenEmailRetryInsideThreshold);

            Assert.IsTrue(emailSessionNeeded,
                          <span class="str">&quot;user checked email 5 hours ago and email has not been run for 3 hours. Should have needed email session&quot;</span>);
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestIsUserReadyToContactEmailServerLongTimeAgoUserActive()
        {
            <span class="rem">// let's use these parameters for every test</span>
            <span class="rem">// let's call this 30 minute threshhold. no contact within 30 minutes, than user is inactive</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60 * 30;

            <span class="rem">// if active user, check email every 2 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold = 60 * 2;

            <span class="rem">// if inactive user, check email every 20 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold = 60 * 20;

            <span class="rem">// user checked email 1 minute ago and email has not been run for 3 hours</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastEmailSessionDateTime = <span class="kwrd">new</span> DateTime(2011, 3, 1, 2, 0, 0); <span class="rem">// email session 2am of 1 year ago (very long ago)</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 11, 59, 0); <span class="rem">// user checked email 1 minute ago</span>

            <span class="kwrd">bool</span> emailSessionNeeded = <span class="kwrd">new</span> MailServerReadyCheck().IsUserReadyToContactEmailServer(currentDateTime,
                lastActivityOfUserDateTime, lastEmailSessionDateTime, defaultSecondsForLastActivityTreshold,
                defaultSecondsBetweenEmailRetryOutsideThreshold,
                defaultSecondsBetweenEmailRetryInsideThreshold);

            Assert.IsTrue(emailSessionNeeded,
                          <span class="str">&quot;user checked email  1 minute ago and email not been run for 1 year. should have run email again&quot;</span>);
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestIsUserReadyToContactEmailServerRecentlyUserActive()
        {
            <span class="rem">// let's use these parameters for every test</span>
            <span class="rem">// let's call this 30 minute threshhold. no contact within 30 minutes, than user is inactive</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60 * 30;

            <span class="rem">// if active user, check email every 2 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold = 60 * 2;

            <span class="rem">// if inactive user, check email every 20 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold = 60 * 20;

            <span class="rem">// user checked email 1 minute ago and email has not been run for 3 hours</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastEmailSessionDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 11, 50, 0); <span class="rem">// email session 10 minutes ago</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 11, 59, 0); <span class="rem">// user checked email 1 minute ago</span>

            <span class="kwrd">bool</span> emailSessionNeeded = <span class="kwrd">new</span> MailServerReadyCheck().IsUserReadyToContactEmailServer(currentDateTime,
                lastActivityOfUserDateTime, lastEmailSessionDateTime, defaultSecondsForLastActivityTreshold,
                defaultSecondsBetweenEmailRetryOutsideThreshold,
                defaultSecondsBetweenEmailRetryInsideThreshold);

            Assert.IsTrue(emailSessionNeeded,
                          <span class="str">&quot;active user, email checked 10 minutes ago but since active should check again&quot;</span>);
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestIsUserReadyToContactEmailServerRecentlyUserInActive()
        {
            <span class="rem">// let's use these parameters for every test</span>
            <span class="rem">// let's call this 30 minute threshhold. no contact within 30 minutes, than user is inactive</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60 * 30;

            <span class="rem">// if active user, check email every 2 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold = 60 * 2;

            <span class="rem">// if inactive user, check email every 20 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold = 60 * 20;

            <span class="rem">// user checked email 1 minute ago and email has not been run for 3 hours</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastEmailSessionDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 11, 50, 0); <span class="rem">// email session 10 minutes ago</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2011, 3, 1, 11, 59, 0); <span class="rem">// user checked email 1 year ago</span>

            <span class="kwrd">bool</span> emailSessionNeeded = <span class="kwrd">new</span> MailServerReadyCheck().IsUserReadyToContactEmailServer(currentDateTime,
                lastActivityOfUserDateTime, lastEmailSessionDateTime, defaultSecondsForLastActivityTreshold,
                defaultSecondsBetweenEmailRetryOutsideThreshold,
                defaultSecondsBetweenEmailRetryInsideThreshold);

            Assert.IsFalse(emailSessionNeeded,
                          <span class="str">&quot;inactive user, but email checked very recently so should not be checking again&quot;</span>);
        }

        [TestMethod]
        <span class="kwrd">public</span> <span class="kwrd">void</span> UnitTestIsUserReadyToContactEmailServerEmailLastSession10MinutesagoActive()
        {
            <span class="rem">// let's use these parameters for every test</span>
            <span class="rem">// let's call this 30 minute threshhold. no contact within 30 minutes, than user is inactive</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsForLastActivityTreshold = 60 * 30;

            <span class="rem">// if active user, check email every 2 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryInsideThreshold = 60 * 2;

            <span class="rem">// if inactive user, check email every 20 minutes</span>
            <span class="kwrd">const</span> <span class="kwrd">int</span> defaultSecondsBetweenEmailRetryOutsideThreshold = 60 * 20;

            <span class="rem">// user checked email 1 minute ago and email has not been run for 3 hours</span>
            var currentDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 12, 0, 0); <span class="rem">// assume current time is 3/1/2012 at noon</span>
            var lastEmailSessionDateTime = <span class="kwrd">new</span> DateTime(2012, 3, 1, 1, 11, 50); <span class="rem">// email session 10 minutes ago</span>
            var lastActivityOfUserDateTime = <span class="kwrd">new</span> DateTime(2011, 3, 1, 11, 59, 0); <span class="rem">// user checked email 5 minutes ago</span>

            <span class="kwrd">bool</span> emailSessionNeeded = <span class="kwrd">new</span> MailServerReadyCheck().IsUserReadyToContactEmailServer(currentDateTime,
                lastActivityOfUserDateTime, lastEmailSessionDateTime, defaultSecondsForLastActivityTreshold,
                defaultSecondsBetweenEmailRetryOutsideThreshold,
                defaultSecondsBetweenEmailRetryInsideThreshold);

            Assert.IsTrue(emailSessionNeeded,
                          <span class="str">&quot;active user, but email checked very recently so should be checking again&quot;</span>);
        }

    }
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</h2>
<p>&#160;</p>
<p>And the results of all tests running <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/wlEmoticon-smile.png" /></p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image13.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb13.png" width="463" height="279" /></a></p>
<p>&#160;</p>
<p>And, if you are still reading, I’ve got 100% of these two methods covered from these unit tests using <a href="http://msdn.microsoft.com/en-us/library/dd299398(v=vs.90).aspx">Code Coverage</a>.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image14.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb14.png" width="490" height="121" /></a></p>
<p>&#160;</p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<ul>
<li></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/18/test-first-development-walk-through-with-visual-studio-2011-preview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>With Visual Studio 2010 (and vs2011 preview) Fast Launch Not Helpful Often</title>
		<link>http://peterkellner.net/2011/11/12/with-visual-studio-2010-and-vs2011-preview-fast-launch-not-helpful-often/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=with-visual-studio-2010-and-vs2011-preview-fast-launch-not-helpful-often</link>
		<comments>http://peterkellner.net/2011/11/12/with-visual-studio-2010-and-vs2011-preview-fast-launch-not-helpful-often/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 17:06:58 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/11/12/with-visual-studio-2010-and-vs2011-preview-fast-launch-not-helpful-often/</guid>
		<description><![CDATA[&#160;
Let’s say I’ve created two Visual Studio Projects with the same name “WebApp” but reside in different directories as shown below (c:\temp\Proj1 and c:\temp\Proj2).&#160; I often call the project WebApp, however I want to keep the projects totally separate.&#160; Below are the File/New Project dialog examples.
&#160;


&#160;
Now, when I click start (this is with the vs2011 [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>Let’s say I’ve created two Visual Studio Projects with the same name “WebApp” but reside in different directories as shown below (c:\temp\Proj1 and c:\temp\Proj2).&#160; I often call the project WebApp, however I want to keep the projects totally separate.&#160; Below are the File/New Project dialog examples.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image10.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb9.png" width="558" height="145" /></a></p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image11.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb10.png" width="564" height="137" /></a></p>
<p>&#160;</p>
<p>Now, when I click start (this is with the vs2011 preview I’m demonstrating), I see the following:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image12.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb11.png" width="322" height="392" /></a></p>
<p>&#160;</p>
<p>I actually have to hover over each “WebApp.sln” to tell which project is which.&#160; I think that information should be in the pinned app itself, not require a hover over to tell which project it is.</p>
<p>Agree?&#160; Add your comment below and go to the following link to vote up my connect suggestion.</p>
<p><a href="https://connect.microsoft.com/VisualStudio/feedback/details/679081/should-have-vs-launch-shortcuts-inside-vs-recent-projects-because-run-as-admin">https://connect.microsoft.com/VisualStudio/feedback/details/679081/should-have-vs-launch-shortcuts-inside-vs-recent-projects-because-run-as-admin</a></p>
<p>From the comments, Microsoft said they would consider it for the next release, but it looks like it has not made it.&#160; Let’s try and change that!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/11/12/with-visual-studio-2010-and-vs2011-preview-fast-launch-not-helpful-often/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>With VS2010 Debugger, Step Into, From a Windows .Net App Directly into a Windows Azure Web Role Hosting a WCF Service In The Developer Fabric</title>
		<link>http://peterkellner.net/2011/06/07/with-vs2010-debugger-step-into-from-a-windows-net-app-directly-into-a-windows-azure-web-role-hosting-a-wcf-service-in-the-developer-fabric/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=with-vs2010-debugger-step-into-from-a-windows-net-app-directly-into-a-windows-azure-web-role-hosting-a-wcf-service-in-the-developer-fabric</link>
		<comments>http://peterkellner.net/2011/06/07/with-vs2010-debugger-step-into-from-a-windows-net-app-directly-into-a-windows-azure-web-role-hosting-a-wcf-service-in-the-developer-fabric/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 21:52:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Blob Storage]]></category>
		<category><![CDATA[Azure Deployment]]></category>
		<category><![CDATA[Azure Web Role]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/06/07/with-vs2010-debugger-step-into-from-a-windows-net-app-directly-into-a-windows-azure-web-role-hosting-a-wcf-service-in-the-developer-fabric/</guid>
		<description><![CDATA[&#160;
OK, I think this is the longest post title I’ve ever made, but if you understand it, you’ll know why it needs to be so long.&#160; I discovered this totally by accident.&#160; I would never ever have pressed F11 (step into) from a client side proxy and expect to get into anything but a bunch [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>OK, I think this is the longest post title I’ve ever made, but if you understand it, you’ll know why it needs to be so long.&#160; I discovered this totally by accident.&#160; I would never ever have pressed F11 (step into) from a client side proxy and expect to get into anything but a bunch of ugly machine generated proxy code (especially with <a href="http://www.microsoft.com/windowsazure/">Azure</a>).&#160; To my total surprise, I landed right inside my <a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx">WCF</a> service as if I had started the <a href="http://www.microsoft.com/en-us/cloud/developer/resource.aspx?resourceId=what-is-windows-azure&amp;fbid=flWeS4xmu1C&amp;WT.srch=1&amp;WT.mc_id=85C588D4-A353-4E3D-8824-823A9551AA51&amp;CR_SCC=200028978">Windows Azure Developer fabric</a> in debug mode and set a break point.</p>
<p>So, I’ll step through the process an show screen shots on the outside chance I was dreaming and can’t reproduce it. If I can, now I will have proof so I can do it again.&#160; Sorry for the work in progress code you will see.&#160; The point here is really the debugger and not the code I’m showing so try and ignore that.</p>
<p>OK, here we go.</p>
<p>Let’s assume you have a completely configured azure web role that is hosting a simple <a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation">WCF</a> service.&#160; When you start that web role and point at the service, you’ll get something like this: (just a note that I started the app fabric by deploying directly from <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</a> <a href="http://www.microsoft.com/visualstudio/en-us">Visual Studio 2010</a> with the start/run.&#160; I am using a debug profile but am <strong>NOT </strong>running in debug mode.&#160; If I do run the app fabric in debug mode, this does not work.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image_thumb4.png" width="480" height="366" /></a></p>
<p>  <span id="more-1508"></span>
<p>&#160;</p>
<p>OK, now let’s run my app that has a <a href="http://visualstudiomagazine.com/articles/2011/06/01/pcnet_wcf-and-soa.aspx">WCF</a> client configured to connect to this service.&#160; The configuration is the normal “Add Service Reference” you would expect but I’m showing it any how just to be clear.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image_thumb5.png" width="485" height="473" /></a></p>
<p>&#160;</p>
<p>Next, we simply Launch <a href="http://www.microsoft.com/visualstudio/en-us">Visual Studio 2010</a> in <a href="http://msdn.microsoft.com/en-us/library/sc65sadd.aspx">debug</a> mode and put a break point just before we cross over into the WCF service by calling the above proxy code.&#160; Here is what that screen looks like after the break point is hit and I’m about to step INTO.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image6.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image_thumb6.png" width="616" height="198" /></a></p>
<p><font size="6">F11</font></p>
<p>&#160;</p>
<p>and…..</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/06/image_thumb7.png" width="657" height="265" /></a></p>
<p><font size="2"></font></p>
<p>There we are!!! right inside the source code that is my WCF service with everything working as if I had launched the site on it’s own, set a break point and waited.</p>
<p>&#160;</p>
<p>Truly amazing!!!&#160; I have nothing more to say.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/06/07/with-vs2010-debugger-step-into-from-a-windows-net-app-directly-into-a-windows-azure-web-role-hosting-a-wcf-service-in-the-developer-fabric/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another Nice DevExpress CodeRush Refactoring</title>
		<link>http://peterkellner.net/2010/07/04/coderush-factorings-introduce-lambda-using-statements/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=coderush-factorings-introduce-lambda-using-statements</link>
		<comments>http://peterkellner.net/2010/07/04/coderush-factorings-introduce-lambda-using-statements/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 16:42:26 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[CodeRush]]></category>
		<category><![CDATA[Refactor]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/07/04/coderush-factorings-introduce-lambda-using-statements/</guid>
		<description><![CDATA[For the last few days, I’ve been using DevExpress CodeRush and am finding some very useful refactorings.&#160; Many I’m not blogging about, but there are a few that I really like.&#160; In this post, I’m going to show just two of those refactorings that have been making my code much nicer and easier to write.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>For the last few days, I’ve been using <a href="http://devexpress.com/">DevExpress</a> <a href="http://devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/">CodeRush</a> and am finding some very useful refactorings.&#160; Many I’m not blogging about, but there are a few that I really like.&#160; In this post, I’m going to show just two of those refactorings that have been making my code much nicer and easier to write.&#160; One is the “Introduce Using” refactoring, and the other is “Convert to Lambda Expression”.</p>
<p>Before I go into the details, I’d just like to disclose that when I was first writing the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> web site, I was an asp.net and c# newby.&#160; I’m not claiming wizard status now, but I have to admit that when I go back and look at some of the code I wrote back then (including what I’m showing below before the refactoring), it’s a little embarrassing.&#160; Silicon Valley Code Camp for me as “when I’m not doing real work” web site so I don’t really have the time to go back and clean things up.&#160; Now, with CodeRush, it’s easy to clean things up when I see them with very little effort.</p>
<p> <span id="more-1337"></span><br />
<h2>Introduce Using Statement Refactoring</h2>
<p>Here is the code I wrote 5+ years ago:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">SqlConnection conn = <span style="color: #0000ff">new</span> SqlConnection(connectionString);conn.Open();

<span style="color: #008000">// First, make a quick list of counts for each id that is unavailable and show</span><span style="color: #008000">// not be shown</span><span style="color: #0000ff">string</span> selectCount = <span style="color: #006080">@&quot;select VistaSlotsId FROM attendees                      WHERE VistaSlotsId &gt;= 2 AND VistaSlotsId &lt;= 5 Group By VistaSlotsId                      HAVING COUNT(*) &gt;= @MaxPerSlot  &quot;</span>;List&lt;<span style="color: #0000ff">int</span>&gt; unavailableSlotsList = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">int</span>&gt;();SqlDataReader readerUnavailable = <span style="color: #0000ff">null</span>;SqlCommand cmdUnAvailable = <span style="color: #0000ff">new</span> SqlCommand(selectCount, conn);cmdUnAvailable.Parameters.Add(<span style="color: #006080">&quot;@MaxPerSlot&quot;</span>, SqlDbType.Int).Value = maxPerSlot;readerUnavailable = cmdUnAvailable.ExecuteReader();<span style="color: #0000ff">try</span>{    <span style="color: #0000ff">while</span> (readerUnavailable.Read())    {        <span style="color: #0000ff">int</span> id = readerUnavailable.GetInt32(0);        unavailableSlotsList.Add(id);    }}<span style="color: #0000ff">finally</span>{    <span style="color: #0000ff">if</span> (readerUnavailable != <span style="color: #0000ff">null</span>) readerUnavailable.Close();}</pre>
<p></div>
<p>By placing the cursor over the “conn” on the top line of the code above, CodeRush gives us the following result:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AnotherNiceDevExpressCodeRushRefactoring_8873/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AnotherNiceDevExpressCodeRushRefactoring_8873/image_thumb.png" width="507" height="233" /></a> </p>
<p>There are actually quite a few things happening here.</p>
<ol>
<li>It is showing us in the top textbox what the using syntax will be </li>
<li>It is crossing out the lines of code it will change </li>
<li>It is teaching us a little about the using statement </li>
</ol>
<p>If I accept the changes, I get a nice refactoring.&#160; I can continue doing this with “using” for SqlCommand and SqlReader.&#160; I did need to move the SqlReader declaration inside the SqlCommand codeblock for this to work.&#160; Here is the final refactored code that took about 10 seconds.&#160; By hand, I’d say it would have taken me 3 minutes and I may have gotten it wrong which is why I would never do it before.&#160; Now, I’m confident I did not break my code.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (SqlConnection conn = <span style="color: #0000ff">new</span> SqlConnection(connectionString)){    conn.Open();    <span style="color: #008000">// First, make a quick list of counts for each id that is unavailable and show</span>    <span style="color: #008000">// not be shown</span>    <span style="color: #0000ff">string</span> selectCount = <span style="color: #006080">@&quot;select VistaSlotsId FROM attendees                                  WHERE VistaSlotsId &gt;= 2 AND VistaSlotsId &lt;= 5 Group By VistaSlotsId                                  HAVING COUNT(*) &gt;= @MaxPerSlot  &quot;</span>;    List&lt;<span style="color: #0000ff">int</span>&gt; unavailableSlotsList = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">int</span>&gt;();    <span style="color: #0000ff">using</span> (SqlCommand cmdUnAvailable = <span style="color: #0000ff">new</span> SqlCommand(selectCount, conn))    {        cmdUnAvailable.Parameters.Add(<span style="color: #006080">&quot;@MaxPerSlot&quot;</span>, SqlDbType.Int).Value = maxPerSlot;        <span style="color: #0000ff">using</span> (SqlDataReader readerUnavailable = cmdUnAvailable.ExecuteReader())        {            <span style="color: #0000ff">try</span>            {                <span style="color: #0000ff">while</span> (readerUnavailable.Read())                {                    <span style="color: #0000ff">int</span> id = readerUnavailable.GetInt32(0);                    unavailableSlotsList.Add(id);                }            }            <span style="color: #0000ff">finally</span>            {                <span style="color: #0000ff">if</span> (readerUnavailable != <span style="color: #0000ff">null</span>)                    readerUnavailable.Close();            }        }    }</pre>
<p>&#160; </p></div>
<div>
  </div>
<h2>Compress To Lambda Expression Refactoring</h2>
<p>A lot of the Silicon Valley Code Camp web site was written prior to the introduction of Lamba Expressions.&#160; If you recall, I wrote an MSDN article back in 2006 entitled <a href="http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/">Adding Personalization via Profiles to the ObjectDataSource in ASP.NET 2.0.</a>&#160; <a href="http://blogs.tedneward.com/">Ted Neward</a> inspired a construct to cleverly sort the result list using delegates as shown in the screen shot (form that above post).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AnotherNiceDevExpressCodeRushRefactoring_8873/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AnotherNiceDevExpressCodeRushRefactoring_8873/image_thumb_3.png" width="569" height="353" /></a> </p>
<p>&#160;</p>
<p>The code below is similar to the above but not quite the same.&#160; This is how it looks before the refactoring:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">Comparison&lt;DataObjectSessionsOverview&gt; comparison = <span style="color: #0000ff">null</span>;    <span style="color: #0000ff">switch</span> (sortDataBase)    {        <span style="color: #0000ff">case</span> <span style="color: #006080">&quot;Userfirstname&quot;</span>:            comparison = <span style="color: #0000ff">new</span> Comparison&lt;DataObjectSessionsOverview&gt;(               <span style="color: #0000ff">delegate</span>(DataObjectSessionsOverview lhs, DataObjectSessionsOverview rhs)               {                   <span style="color: #0000ff">return</span> lhs.Userfirstname.CompareTo(rhs.Userfirstname);               }             );            <span style="color: #0000ff">break</span>;</pre>
<p></div>
<p>CodeRush suggests:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AnotherNiceDevExpressCodeRushRefactoring_8873/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AnotherNiceDevExpressCodeRushRefactoring_8873/image_thumb_4.png" width="551" height="245" /></a> </p>
<p>Which then give us:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">switch</span> (sortDataBase){   <span style="color: #0000ff">case</span> <span style="color: #006080">&quot;Userfirstname&quot;</span>:       comparison = (lhs, rhs) =&gt; lhs.Userfirstname.CompareTo(rhs.Userfirstname);       <span style="color: #0000ff">break</span>;</pre>
<p></div>
<p>I like it!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/07/04/coderush-factorings-introduce-lambda-using-statements/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Handy Refactoring with CodeRush (InLine Temp)</title>
		<link>http://peterkellner.net/2010/07/02/coderush-refactoring-inline-temp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=coderush-refactoring-inline-temp</link>
		<comments>http://peterkellner.net/2010/07/02/coderush-refactoring-inline-temp/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 14:34:56 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeRush]]></category>
		<category><![CDATA[Refactor]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/07/02/coderush-refactoring-inline-temp/</guid>
		<description><![CDATA[I’ve recently started using CodeRush with Visual Studio 2010 and am so far very impressed with the convenience it adds to coding.&#160; One thing that is very clear is that the creators of CodeRush are real programmers and look very hard for patterns that us developers are constantly doing.&#160; As I run into these things [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve recently started using <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/">CodeRush</a> with <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2010</a> and am so far very impressed with the convenience it adds to coding.&#160; One thing that is very clear is that the creators of <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/">CodeRush</a> are real programmers and look very hard for patterns that us developers are constantly doing.&#160; As I run into these things that get my attention, I plan on blogging them.&#160; Some are just earth shattering, and others, just nice to have.&#160; This particular one is a nice to have.</p>
<p>So, say you have code like this:</p>
<p>&#160;</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">var sessionAttendeeOds =   <span style="color: #0000ff">new</span> SessionAttendeeODS();listSessionAttendees =   sessionAttendeeOds.GetByUsername(Context.User.Identity.Name);</pre>
</div>
<div>&#160;</div>
<p><span id="more-1335"></span></p>
<div>When I first wrote code, I often do it like this thinking that I may have more methods I’m going to call against the instantiated object.&#160; In this case, many years later, I’m looking at the code and want to condense it.&#160; With <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/">CodeRush</a>, it show me three little dots under the variable sessionAttendeeOds as follows.&#160; When I click on these three dots, I get the following screen.</div>
<p><a href="http://peterkellner.net/FilesForWebDownload/AHandyRefactoringwithCodeRushInLineTemp_6A97/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AHandyRefactoringwithCodeRushInLineTemp_6A97/image_thumb.png" width="405" height="156" /></a> </p>
<p>When I chose “InlineTemp”, the code changes to the following, make it easier to read.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">listSessionAttendees =                 <span style="color: #0000ff">new</span> SessionAttendeeODS().GetByUsername(Context.User.Identity.Name);</pre>
<p></div>
<p>Again, this is not a huge deal, but small fixes like this will add up over time and make my code cleaner and more readable.&#160; CodeRush makes it so easy that I’m sure I’ll do this kind of thing more and more.</p>
<p>HTH’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/07/02/coderush-refactoring-inline-temp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A VS2010 Project Made From Post: How to: Host a WCF Service in a Managed Windows Service</title>
		<link>http://peterkellner.net/2010/06/18/wcf-service-in-managed-windows-service-vs2010-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wcf-service-in-managed-windows-service-vs2010-2</link>
		<comments>http://peterkellner.net/2010/06/18/wcf-service-in-managed-windows-service-vs2010-2/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 14:37:33 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Windows Service]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/06/18/wcf-service-in-managed-windows-service-vs2010-2/</guid>
		<description><![CDATA[MSDN has a very nice article on how to create a windows service that hosts a Windows Communication Foundation (WCF) service.&#160; It explains all the details of doing this in a step by step fashion.&#160; One thing that I often find missing from these articles is the actual Visual Studio project that I can download [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/library/ms733069.aspx" target="_blank">MSDN has a very nice article</a> on how to create a windows service that hosts a <a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx" target="_blank">Windows Communication Foundation (WCF)</a> service.&#160; It explains all the details of doing this in a step by step fashion.&#160; One thing that I often find missing from these articles is the actual Visual Studio project that I can download and play with.&#160; What I usually do is put that together myself (which I’m sure is the author’s intent).</p>
<p>To save anyone some time who wants to do the same thing, I’ve created a VS2010 project from the example, added a very simple Windows C# console application that consumes the service, as well as made some small changes in a very nice Windows Presentation Foundation (WPF) <a href="http://code.google.com/p/wpf-mvvm-calculator/" target="_blank">calculator project</a> so that the calculator does it operations inside the windows service rather than in the calculator itself.</p>
<p>In this article, I’ve attached the source code (with my small changes and additions) for you to work with and change as you like.</p>
<p> <span id="more-1332"></span>
<p>First, here is the project: </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:d3a970ab-d487-417a-bf52-fd64c206e6d2" class="wlWriterEditableSmartContent">
<p>Visual Studio 2010 Project <a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/WCFServiceInManagedWindowsService_3.zip" target="_blank">Project Zip Here</a></p>
</div>
<p>Now, let’s talk about the details</p>
<p>&#160;</p>
<h2>The Visual Studio 2010 Solution Itself</h2>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_9.png" width="490" height="381" /></a> </p>
<p>There are three projects in this solution.&#160; The service itself which is called WCFServiceInmanagedWindowsService, Console Application and Calculator.</p>
<p>&#160;</p>
<h3>WCFServiceInManagedWindowsService Project</h3>
<p>&#160;</p>
<p>This project is really what is taken from the <a href="http://msdn.microsoft.com/en-us/library/ms733069.aspx" target="_blank">MSDN article</a>. It’s got almost no change and is primarily created by following the directions in the article.&#160; There are a couple batch files added for creating and deleting the service itself in the root of that project directory, but that’s about it.&#160; All the code is in a file called service.cs.</p>
<p>To Add the service, go to the “Service Reference”/”Add Service” Dialog and enter the address of the service (you can find it in the app.config file).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_10.png" width="408" height="337" /></a> </p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_11.png" width="395" height="85" /></a> </p>
<p><a title="http://localhost:8000/ServiceModelSamples/service" href="http://localhost:8000/ServiceModelSamples/service">http://localhost:8000/ServiceModelSamples/service</a></p>
<p>Notice that the methods exposed are Add/Divide/Multiple and Subtract.</p>
<p>To start the actual service, after rebuilding the project, execute the bat file InstallService.bat in the root directory.&#160; Make sure you build the release version because this script installs the service from the release directory. Once started, you will see it in the services application as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_12.png" width="354" height="178" /></a> </p>
<p>Then, start the service by running the command: “net start WCFWindowsServiceSample”&#160; If you get the error: <em>“No connection could be made because the target machine actively refused it 127.0.0.1:8000”,</em> this likely means you did not start your service.</p>
<p>&#160;</p>
<h3>The Console Application</h3>
<p>The Console application is new and very simple. All you have to do is create a new windows c# console project, use the “Add Service” DialWCFWindowsServiceSampleog and point it at&#160; ( <a title="http://localhost:8000/ServiceModelSamples/service" href="http://localhost:8000/ServiceModelSamples/service">http://localhost:8000/ServiceModelSamples/service</a> ) as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_13.png" width="288" height="317" /></a> </p>
<p>Now, you can simply write a console app with the following code and you will be calling the service correctly.&#160; Here is the code:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">class</span> Program    {        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)        {            var calculatorClient = <span style="color: #0000ff">new</span> CalculatorClient();

            var answer = calculatorClient.Add(5, 4);            Console.WriteLine(<span style="color: #006080">&quot;Answer to Adding 5 + 4: {0}&quot;</span>, answer);            Console.ReadKey();

        }    }</pre>
<p></div>
<p>And, when we run it, now surprise, we get 9!</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_14.png" width="244" height="120" /></a> </p>
<p>…</p>
<h3>The Calculator Application</h3>
<p>Just to show a real life use of the service, I grabbed the codeplex project <a title="http://code.google.com/p/wpf-mvvm-calculator/" href="http://code.google.com/p/wpf-mvvm-calculator/">http://code.google.com/p/wpf-mvvm-calculator/</a>.</p>
<p><a href="http://code.google.com/p/wpf-mvvm-calculator/"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_17.png" width="372" height="157" /></a> </p>
<p>Then, modifying a small section of code inside (after adding the service reference of course, just like we did in the above console project, we now have a calculator that adds by calling a service for the answer.&#160; Here is the modified code:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">try</span>           {               <span style="color: #008000">// Establish the connection to the Service</span>               var calculatorClient = <span style="color: #0000ff">new</span> CalculatorClient();               var firstOperand = Convert.ToDouble(FirstOperand);               var secondOperand = Convert.ToDouble(SecondOperand);

               var stopwatch = <span style="color: #0000ff">new</span> Stopwatch();               stopwatch.Start();

               <span style="color: #0000ff">switch</span> (Operation)               {                   <span style="color: #0000ff">case</span> (<span style="color: #006080">&quot;+&quot;</span>):                       result = calculatorClient.Add(firstOperand, secondOperand).ToString();                       <span style="color: #0000ff">break</span>;

                   <span style="color: #0000ff">case</span> (<span style="color: #006080">&quot;-&quot;</span>):                       result = calculatorClient.Subtract(firstOperand, secondOperand).ToString();                       <span style="color: #0000ff">break</span>;

                   <span style="color: #0000ff">case</span> (<span style="color: #006080">&quot;*&quot;</span>):                       result = calculatorClient.Multiply(firstOperand, secondOperand).ToString();                       <span style="color: #0000ff">break</span>;

                   <span style="color: #0000ff">case</span> (<span style="color: #006080">&quot;/&quot;</span>):                       result = calculatorClient.Divide(firstOperand, secondOperand).ToString();                       <span style="color: #0000ff">break</span>;               }

               stopwatch.Stop();</pre>
<p></div>
<p>And, when we run the calculator, it looks like this:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_18.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AVS2010ProjectMadeFromPostHowtoHostaWCFS_C58D/image_thumb_15.png" width="333" height="232" /></a>&#160;</p>
<p>&#160;</p>
<h2>Conclusions</h2>
<p>In this post, we simply implemented the source as a <a href="http://www.microsoft.com/visualstudio/en-us">Visual Studio 2010</a> project from the MSDN article on how to build a windows service using WCF.&#160; It’s been pointed out that we are better off using named pipes for this kind of application for better performance, but our purpose here was just to elaborate on the existing application.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/06/18/wcf-service-in-managed-windows-service-vs2010-2/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Adding Speakers Page Template With Converters In Visual Studio 2010 Beta2 (Article 5 of 7)</title>
		<link>http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7</link>
		<comments>http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 23:20:35 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/</guid>
		<description><![CDATA[


&#160;
Title Of Each Article
Video Included With Each Post


Part 1
Introduction To RIA Services In Silverlight (This Article)
7 Minutes


Part 2
Basic RIA Services And DataGrid With&#160; VS 2010 Tooling
14 Minutes


Part 3
Adding A DataGrid With Connect The Dots DataBinding in VS 2010
13 Minutes


Part 4
Adding a Navigation Page to a Silverlight Business Application Template
11 Minutes


Part 5
Adding Speakers Page Template With [...]]]></description>
			<content:encoded><![CDATA[<table width="90%">
<tbody>
<tr>
<td width="70">&#160;</td>
<td>Title Of Each Article</td>
<td style="width: 100px" width="150">Video Included With Each Post</td>
</tr>
<tr>
<td width="70">Part 1</td>
<td><a href="http://peterkellner.net/2010/01/20/riaservices-silverlight-4-tutorial-svcc-part1of7-introduction/">Introduction To RIA Services In Silverlight (This Article)</a></td>
<td style="width: 100px" width="150">7 Minutes</td>
</tr>
<tr>
<td width="70">Part 2</td>
<td><a href="http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/">Basic RIA Services And DataGrid With&#160; VS 2010 Tooling</a></td>
<td style="width: 100px" width="150">14 Minutes</td>
</tr>
<tr>
<td width="70">Part 3</td>
<td><a href="http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/">Adding A DataGrid With Connect The Dots DataBinding in VS 2010</a></td>
<td style="width: 100px" width="150">13 Minutes</td>
</tr>
<tr>
<td width="70">Part 4</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/">Adding a Navigation Page to a Silverlight Business Application Template</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 5</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/">Adding Speakers Page Template With Converters In Visual Studio 2010 Beta2</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 6</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-sessions-page-that-includes-a-query-parameter-in-silverlight-vs2010-article-6-of-7/">Adding A Sessions Page That Includes a Query Parameter In Silverlight VS2010 Beta2</a></td>
<td style="width: 100px" width="150">10 Minutes</td>
</tr>
<tr>
<td width="70">Part 7</td>
<td><a href="http://peterkellner.net/2010/01/25/authentication-and-authorization-using-ria-services-article-7-of-7/">Basic Authentication and Authorization In RIA Services</a></td>
<td style="width: 100px" width="150">5 Minutes</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<br /><img src="http://video.peterkellner.net/video/RIAServicesBayNet20090120/P5_AddingSpeakerPageTemplateWithConvertsAndHandler_Thumb.jpg" alt="media" /><br />

<p>&#160;</p>
<p>This article will follow the previous article and go through the process of adding Converter’s for changing both the Id column and the Image column.&#160; Basically, what we saw in the previous article was a DataGrid that was created and looked as follows.&#160; (notice the Id column and the PKID columns which are highlighted.&#160; Then, we will add a a DisplayItemTemplate that will format the page and make it look good.</p>
<p> <span id="more-481"></span>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb.png" width="411" height="354" /></a></p>
<p>&#160;</p>
<p>What we are going to want to do is convert the Id column’s data from something that looks like “777” to “/Sessions?SpeakerId=777”.&#160; We also will change the PKID column to change from showing a value like “222f32f83-8811” to http://localhost:52879/DisplayImage.ashx?sizex=60&amp;PKID=222f32f83-8811”.&#160; Then, we will apply a template that will make the page look like the following:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_3.png" width="268" height="319" /></a></p>
<p>&#160;</p>
<p>So, let’s get started.</p>
<p>&#160;</p>
<p>First, we need to add two converters to the project.&#160; Both are straight forward and I will not give much explanation besides saying they do exactly what was mentioned in the paragraph below the above picture.</p>
<p><span style="text-decoration: underline"></span>&#160;</p>
<p><span style="text-decoration: underline">Image Converter:</span></p>
<p> 
<div class="csharpcode">
<pre class="alt"><span class="kwrd">namespace</span> BusinessApplicationSVCodeCamp</pre>
<pre>{</pre>
<pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> ImageConverter : IValueConverter</pre>
<pre>    {</pre>
<pre class="alt">        <span class="kwrd">public</span> <span class="kwrd">object</span> ConvertBack(<span class="kwrd">object</span> <span class="kwrd">value</span>, Type targetType, <span class="kwrd">object</span> parameter, System.Globalization.CultureInfo culture)</pre>
<pre>        {</pre>
<pre class="alt">            <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();</pre>
<pre>        }</pre>
<pre class="alt">&#160;</pre>
<pre>        <span class="kwrd">public</span> <span class="kwrd">object</span> Convert(<span class="kwrd">object</span> <span class="kwrd">value</span>, Type targetType, <span class="kwrd">object</span> parameter, System.Globalization.CultureInfo culture)</pre>
<pre class="alt">        {</pre>
<pre>            <span class="kwrd">string</span> PKID = <span class="kwrd">value</span>.ToString();</pre>
<pre class="alt">&#160;</pre>
<pre>            var s = Application.Current.Host.Source;</pre>
<pre class="alt">            <span class="kwrd">int</span> horizontalSize = 60;</pre>
<pre>            <span class="kwrd">string</span> path = String.Format(<span class="str">&quot;{0}://{1}:{2}/DisplayImage.ashx?sizex={3}&amp;PKID={4}&quot;</span>,</pre>
<pre class="alt">                s.Scheme, s.Host, s.Port, horizontalSize, PKID);</pre>
<pre>&#160;</pre>
<pre class="alt">            <span class="kwrd">return</span> path;</pre>
<pre>        }</pre>
<pre class="alt">    }</pre>
<pre>}</pre>
</div>
<p></p>
<p><span style="text-decoration: underline">Hyperlink Converter:</span></p>
<pre class="csharpcode"><span class="kwrd"></span>&#160;</pre>
<pre class="csharpcode"><span class="kwrd">namespace</span> BusinessApplicationSVCodeCamp
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// NavigateUri=&quot;/Sessions?SpeakerId=2000&quot; is what we want</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">class</span> HyperLinkSessionsFormatter : IValueConverter
    {
        <span class="kwrd">public</span> <span class="kwrd">object</span> ConvertBack(<span class="kwrd">object</span> <span class="kwrd">value</span>, Type targetType, <span class="kwrd">object</span> parameter, System.Globalization.CultureInfo culture)
        {
            <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
        }

        <span class="kwrd">public</span> <span class="kwrd">object</span> Convert(<span class="kwrd">object</span> <span class="kwrd">value</span>, Type targetType, <span class="kwrd">object</span> parameter, System.Globalization.CultureInfo culture)
        {
            <span class="kwrd">string</span> sessionId = <span class="kwrd">value</span>.ToString();
            <span class="kwrd">string</span> path = String.Format(<span class="str">&quot;/Sessions?SpeakerId={0}&quot;</span>,sessionId);
            <span class="kwrd">return</span> path;
        }

    }
}</pre>
<pre class="csharpcode">&#160;</pre>
<p>Next, we need to add these converters to our Visual Studio 2010 Beta2 project as resources so we can use them in the DataGrid.&#160; To do this, we use a very cool new feature in VS2010.&#160; It’s a little indirect how we do this, but ultimately, it does make sense.&#160; Just not very discoverable.&#160; What we do is we bring up the properties editor for the DataGrid.&#160; Notice below we are showing an icon next to the word “(Collection)”.&#160; This is the icon you click that brings up the Collection Editors: Columns dialog.</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_4.png" width="659" height="465" /></a></p>
<p>&#160;</p>
<p>How on the highlighted “Binding” property of the “idColumn”, you click the databinding icon and you will get the following binding dialog.</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_5.png" width="407" height="244" /></a></p>
<p>&#160;</p>
<p>chose “Apply Data Binding” and you’ll get the following:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_6.png" width="404" height="257" /></a></p>
<p>&#160;</p>
<p>Nothing has to be done to the Source property.&#160; This is already set to the the DomainDataSourceView we want.&#160; The Path is already set to Id, which is also correct.&#160; This all happened when we did the “Connect the dots” databinding with RIA Services.&#160; That is, when we dragged the domain data service on top of the DataGrid.&#160; We will need to set the Converter though so click on the currently unexpanded “Converters&quot; control and you will see:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_7.png" width="464" height="311" /></a></p>
<p>&#160;</p>
<p>What this is telling us is that in the Presentation1 project, we have the two converters available to us.&#160; We will need to add these to the project.&#160; To do that, we have to do it one at a time.&#160; First, click on HyperLinkSessionFormatter and you will see the following dialog.</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_8.png" width="462" height="304" /></a></p>
<p>&#160;</p>
<p>When you press “Create New”, you will get a choice of which xaml to put the resource in as follows:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_9.png" width="461" height="303" /></a></p>
<p>&#160;</p>
<p>By default, it will put it in your current Navigation Page (Speakers.xaml), however, if you look at the drop down:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_10.png" width="244" height="132" /></a></p>
<p>&#160;</p>
<p>you’ll see that you can also put in other xaml files that may make more sense.&#160; In our case, we are putting it in the Speakers.xaml file and when we press “OK”, it creates xaml as follows.</p>
<pre class="csharpcode"><span class="kwrd"></span>&#160;</pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">navigation:Page.Resources</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">my1:HyperLinkSessionsFormatter</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;HyperLinkSessionsFormatter1&quot;</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">navigation:Page.Resources</span><span class="kwrd">&gt;</span></pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>or</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_11.png" width="399" height="269" /></a></p>
<p>&#160;</p>
<p>It also dropped in a namespace definition for us at the top of the file that looks like the following to reference the my1 prefix:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_12.png" width="402" height="317" /></a></p>
<p>&#160;</p>
<p>It seems like quite a few steps, however in practice, it’s very quick.&#160; I won’t go through the same steps again, but you need to add the ImageFormatter converter the same way (see busy screen shot below for all steps combined into one).</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_13.png" width="398" height="245" /></a></p>
<p>&#160;</p>
<p>Now, we’ve got xaml with two converters:</p>
<pre class="csharpcode">&#160;</pre>
<pre class="csharpcode">&lt;navigation:Page.Resources&gt;
        &lt;my1:HyperLinkSessionsFormatter x:Key=<span class="str">&quot;HyperLinkSessionsFormatter1&quot;</span> /&gt;
        &lt;my1:ImageConverter x:Key=<span class="str">&quot;ImageConverter1&quot;</span> /&gt;
&lt;/navigation:Page.Resources&gt;</pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>And, the columns of the DataGrid are bound to them correctly.&#160; The xaml for that looks as follows:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_14.png" width="434" height="183" /></a></p>
<p>&#160;</p>
<p>This is hugely convenient, and not very error prone which as far as I’m concerned is very nice.</p>
<p>&#160;</p>
<p>So, now when we run the page, we get the following:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_15.png" width="829" height="293" /></a></p>
<p>&#160;</p>
<p>Ugly, but you can see where we are headed.&#160; Now, we create a DataTemplate (or we get Michael Scherotter to help us create one) that looks like the following:</p>
<pre class="csharpcode"><span class="kwrd"></span>&#160;</pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;SpeakersItemTemplate&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="kwrd">&gt;</span>
        <span class="rem">&lt;!--&lt;frameworkElement Margin=&quot;left,top,right,bottom  --&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">d:LayoutOverrides</span><span class="kwrd">=&quot;Height&quot;</span> <span class="attr">Margin</span><span class="kwrd">=&quot;68,5,5,5&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;FirstName&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserFirstName}&quot;</span>
                           <span class="attr">Margin</span><span class="kwrd">=&quot;0,0,6,0&quot;</span> <span class="attr">FontFamily</span><span class="kwrd">=&quot;Trebuchet MS&quot;</span> <span class="attr">FontSize</span><span class="kwrd">=&quot;16&quot;</span>
                           <span class="attr">FontWeight</span><span class="kwrd">=&quot;Bold&quot;</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;LastName&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserLastName}&quot;</span>
                           <span class="attr">FontFamily</span><span class="kwrd">=&quot;Trebuchet MS&quot;</span> <span class="attr">FontSize</span><span class="kwrd">=&quot;16&quot;</span> <span class="attr">FontWeight</span><span class="kwrd">=&quot;Bold&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">HyperlinkButton</span>
                <span class="attr">NavigateUri</span><span class="kwrd">=&quot;{Binding Id, Converter={StaticResource HyperLinkSessionsFormatter1}}&quot;</span>
                <span class="attr">Content</span><span class="kwrd">=&quot;Sessions&quot;</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Name</span><span class="kwrd">=&quot;Description&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;{Binding UserBio}&quot;</span>
                       <span class="attr">TextWrapping</span><span class="kwrd">=&quot;Wrap&quot;</span> <span class="attr">FontFamily</span><span class="kwrd">=&quot;Trebuchet MS&quot;</span> <span class="attr">FontSize</span><span class="kwrd">=&quot;12&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Image</span>  <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Left&quot;</span> <span class="attr">Width</span><span class="kwrd">=&quot;60&quot;</span> <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Top&quot;</span>
                <span class="attr">Source</span><span class="kwrd">=&quot;{Binding Path=PKID, Converter={StaticResource ImagePathConverter1}}&quot;</span>  <span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Image</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">HyperlinkButton</span>  <span class="attr">Content</span><span class="kwrd">=&quot;WebSite&quot;</span>  <span class="attr">TargetName</span><span class="kwrd">=&quot;_blank&quot;</span>
                          <span class="attr">NavigateUri</span><span class="kwrd">=&quot;{Binding UserWebSite}&quot;</span> <span class="attr">VerticalAlignment</span><span class="kwrd">=&quot;Top&quot;</span>
                          <span class="attr">HorizontalAlignment</span><span class="kwrd">=&quot;Right&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre>
<p>&#160;</p>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->Then, when we add a listbox, rather than the DataGrid and bind it the same</p>
<pre class="csharpcode"><span class="kwrd"></span>&#160;</pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ListBox</span> <span class="attr">Height</span><span class="kwrd">=&quot;600&quot;</span>
         <span class="attr">ItemsSource</span><span class="kwrd">=&quot;{Binding ElementName=speakersShort2009DomainDataSource, Path=Data}&quot;</span>
         <span class="attr">ItemTemplate</span><span class="kwrd">=&quot;{StaticResource SpeakersItemTemplate}&quot;</span>
         <span class="attr">ScrollViewer</span>.<span class="attr">HorizontalScrollBarVisibility</span><span class="kwrd">=&quot;Disabled&quot;</span><span class="kwrd">/&gt;</span></pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>We get something that looks pretty nice:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingNavigationandImagesUsingVisualStud_C695/image_thumb_16.png" width="383" height="457" /></a></p>
<p>&#160;</p>
<p>That’s it for this article.&#160; In the next article we will actually talk about what happens when the Session hyperlink is pressed.&#160; We know it will take us to the Sessions page, but how it filters the Sessions is worth reading about.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<enclosure url="http://video.peterkellner.net/video/RIAServicesBayNet20090120/P5_AddingSpeakerPageTemplateWithConvertsAndHandler.flv" length="1" type="video/x-flv"/>
	</item>
		<item>
		<title>Adding a Navigation Page to a Silverlight Business Application Template (Article 4 of 7)</title>
		<link>http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7</link>
		<comments>http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 23:16:49 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/</guid>
		<description><![CDATA[


&#160;
Title Of Each Article
Video Included With Each Post


Part 1
Introduction To RIA Services In Silverlight (This Article)
7 Minutes


Part 2
Basic RIA Services And DataGrid With&#160; VS 2010 Tooling
14 Minutes


Part 3
Adding A DataGrid With Connect The Dots DataBinding in VS 2010
13 Minutes


Part 4
Adding a Navigation Page to a Silverlight Business Application Template
11 Minutes


Part 5
Adding Speakers Page Template With [...]]]></description>
			<content:encoded><![CDATA[<table width="90%">
<tbody>
<tr>
<td width="70">&#160;</td>
<td>Title Of Each Article</td>
<td style="width: 100px" width="150">Video Included With Each Post</td>
</tr>
<tr>
<td width="70">Part 1</td>
<td><a href="http://peterkellner.net/2010/01/20/riaservices-silverlight-4-tutorial-svcc-part1of7-introduction/">Introduction To RIA Services In Silverlight (This Article)</a></td>
<td style="width: 100px" width="150">7 Minutes</td>
</tr>
<tr>
<td width="70">Part 2</td>
<td><a href="http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/">Basic RIA Services And DataGrid With&#160; VS 2010 Tooling</a></td>
<td style="width: 100px" width="150">14 Minutes</td>
</tr>
<tr>
<td width="70">Part 3</td>
<td><a href="http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/">Adding A DataGrid With Connect The Dots DataBinding in VS 2010</a></td>
<td style="width: 100px" width="150">13 Minutes</td>
</tr>
<tr>
<td width="70">Part 4</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/">Adding a Navigation Page to a Silverlight Business Application Template</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 5</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/">Adding Speakers Page Template With Converters In Visual Studio 2010 Beta2</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 6</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-sessions-page-that-includes-a-query-parameter-in-silverlight-vs2010-article-6-of-7/">Adding A Sessions Page That Includes a Query Parameter In Silverlight VS2010 Beta2</a></td>
<td style="width: 100px" width="150">10 Minutes</td>
</tr>
<tr>
<td width="70">Part 7</td>
<td><a href="http://peterkellner.net/2010/01/25/authentication-and-authorization-using-ria-services-article-7-of-7/">Basic Authentication and Authorization In RIA Services</a></td>
<td style="width: 100px" width="150">5 Minutes</td>
</tr>
</tbody>
</table>
<p> 
<br /><img src="http://video.peterkellner.net//video/RIAServicesBayNet20090120/P4_AddingNavigationImage_Thumb.jpg" alt="media" /><br />

<p> 
<p>Well, if you have gotten this far in the series, you’ve probably realized I’ve gotten my articles and video’s a little out of sync.&#160; The video attached here goes through the full process of building an application from scratch while adding a navigation page.&#160; The process was somewhat explained in the previous article.&#160; I’ve kept the title the same because that is what the video actually shows. </p>
<p> <span id="more-480"></span>
<p>I won’t go through all the details again, however, what you will get at the end is a new speakers page which is just another tab on the home page that looks like the following.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingaNavigationPagetoaSilverlightBusin_CD03/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AddingaNavigationPagetoaSilverlightBusin_CD03/image_thumb.png" width="404" height="347" /></a></p>
<p>In the next section, we will go through adding a SpeakerPageTemplate to style it and have it show up with actual pictures and hyperlinks.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<enclosure url="http://video.peterkellner.net/video/RIAServicesBayNet20090120/P4_AddingNavigationImage.flv" length="1" type="video/x-flv"/>
	</item>
		<item>
		<title>I Love FinalBuilder from VSoft Technologies!</title>
		<link>http://peterkellner.net/2009/11/02/finalbuilder-review-svn-buildsystems/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=finalbuilder-review-svn-buildsystems</link>
		<comments>http://peterkellner.net/2009/11/02/finalbuilder-review-svn-buildsystems/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 00:47:51 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Build Products]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/11/02/finalbuilder-review-svn-buildsystems/</guid>
		<description><![CDATA[&#160;
For the past couple years, I’ve used a product called FinalBuilder from VSoft Technologies to automate my build processes.&#160; Since I’ve been building web sites (about the past 5 years or so), one of the biggest hassles is maintaining them.&#160; That is, updating the databases, deploying the web site, automating backups, etc.&#160; I’ve used several [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>For the past couple years, I’ve used a product called FinalBuilder from <a href="http://www.finalbuilder.com/home.aspx">VSoft Technologies</a> to automate my build processes.&#160; Since I’ve been building web sites (about the past 5 years or so), one of the biggest hassles is maintaining them.&#160; That is, updating the databases, deploying the web site, automating backups, etc.&#160; I’ve used several products like <a href="http://www.finalbuilder.com/home.aspx">FinalBuilder</a> (including Cruise Control), and to be honest, none of them come close to the quality of FinalBuilder.</p>
<p>Basically, the way the product works is that you create a “project” file using the FinalBuilder IDE.&#160; That project file has “Actions” in it which do things like “ftp” files to servers, rename files, iterate over sql scripts, parse and update files, checkout from source control, as well as hundreds of other convenient functions.&#160; You then execute that “script” file and all the magic happens.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/ILoveFinalBuilderfromVSoftTechnologies_11360/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/ILoveFinalBuilderfromVSoftTechnologies_11360/image_thumb.png" width="244" height="181" /></a></p>
<p> <span id="more-376"></span>
<p>Then, VSoft has another product called FinalBuilder Server, which is really an asp.net web site that you run on your server.&#160; That running web site can take one of your FinalBuilder scripts, and run it through a really nice dashboard (web page). </p>
<p><a href="http://peterkellner.net/FilesForWebDownload/ILoveFinalBuilderfromVSoftTechnologies_11360/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/ILoveFinalBuilderfromVSoftTechnologies_11360/image_thumb_3.png" width="244" height="140" /></a></p>
<p>In my current scenario, I have 5 different web sites I can publish simply by pushing a button.&#160; I log into the web page (dashboard), press “Start Build”, and behind the scenes this is what happens:</p>
<ul>
<li>A new temporary directory is created </li>
<li>All My source code is exported from <a href="http://subversion.org/">subversion</a> into that directory </li>
<li>All My Visual Studio Solutions are built </li>
<li>All the config files (web.config,app.config, etc.) are updated with appropriate parameters (connection strings, etc.) </li>
<li>The Web Site is copied to the correct location </li>
<li>A Backup of the source is created an zipped into an archive directory </li>
<li>The temporary directory and all it’s files are deleted </li>
</ul>
<p>Of course, I really do more than this, but you get the basic idea.&#160; It’s wonderful.&#160; It’s not free, but worth every penny (not to mention the support is awesome).</p>
<p>Hope you get a chance to try it.&#160; Here is a link to their site:</p>
<p><a title="http://www.finalbuilder.com/home.aspx" href="http://www.finalbuilder.com/home.aspx">http://www.finalbuilder.com/home.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/11/02/finalbuilder-review-svn-buildsystems/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 Show All Files Does Not Always Work For Me</title>
		<link>http://peterkellner.net/2009/10/30/visualstudio2008-show-all-files-wifi-gogoinflight/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visualstudio2008-show-all-files-wifi-gogoinflight</link>
		<comments>http://peterkellner.net/2009/10/30/visualstudio2008-show-all-files-wifi-gogoinflight/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 21:30:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/10/30/visualstudio2008-show-all-files-wifi-gogoinflight/</guid>
		<description><![CDATA[&#160;
Not sure how many times I’ve pressed the “Show All Files” menu choice on a Visual Studio 2008 Project and nothing happens.&#160; Well, I think I have finally found the pattern.
My guess is that you actually have to be clicked on the solution itself for the Show All Files to work.&#160; I think I’m usually [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>Not sure how many times I’ve pressed the “Show All Files” menu choice on a <a href="http://www.microsoft.com/visualstudio/en-us/default.mspx">Visual Studio 2008</a> Project and nothing happens.&#160; Well, I think I have finally found the pattern.</p>
<p>My guess is that you actually have to be clicked on the solution itself for the Show All Files to work.&#160; I think I’m usually on a directory inside the project and it doesn’t work. That is, I may be inside the /bin directory and expect that if I click “Show All Files” that I will see all the files in the bin directory (like the .config files).</p>
<p> <span id="more-375"></span>
<p>So, post back if you know more about this.&#160; This is just my best guess.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/VisualStudio2008ShowAllFilesDoesNotAlway_C950/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/VisualStudio2008ShowAllFilesDoesNotAlway_C950/image_thumb.png" width="244" height="163" /></a></p>
<p>By the way, I’m blogging this in turbulence American Airlines flight 16 from San Francisco To New York City (JFK).&#160; <a href="http://www.gogoinflight.com/">Wifi</a> in the air is working great!!!</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/VisualStudio2008ShowAllFilesDoesNotAlway_C950/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/VisualStudio2008ShowAllFilesDoesNotAlway_C950/image_thumb_3.png" width="484" height="228" /></a></p>
<p><a title="http://flightaware.com/live/flight/AAL16" href="http://flightaware.com/live/flight/AAL16">http://flightaware.com/live/flight/AAL16</a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/10/30/visualstudio2008-show-all-files-wifi-gogoinflight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Automate a Simple Deploy Using DataDude (Visual Studio 2008 Database Edition)</title>
		<link>http://peterkellner.net/2009/10/24/datadude-vs2008-deploy-shortcut/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=datadude-vs2008-deploy-shortcut</link>
		<comments>http://peterkellner.net/2009/10/24/datadude-vs2008-deploy-shortcut/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 15:38:15 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/10/24/datadude-vs2008-deploy-shortcut/</guid>
		<description><![CDATA[Not sure why this was hard, but I wanted to make a trivial command file to deploy my database (or any change to it).&#160; For those of you that don’t know the DataDude project, I have to say it’s one of the coolest tools that has come out the Microsoft Visual Studio Team for a [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure why this was hard, but I wanted to make a trivial command file to deploy my database (or any change to it).&#160; For those of you that don’t know the <a href="http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/">DataDude project</a>, I have to say it’s one of the coolest tools that has come out the Microsoft Visual Studio Team for a while.&#160; Basically, in a nutshell, what it does is split’s your database into hundreds of little files.&#160; One for each table, key, foreign key, user, role, etc.&#160; Then, since it is a standard <a href="http://www.microsoft.com/visualstudio/en-us/products/teamsystem/default.mspx">VS2008</a> project, you can keep those files and the project under source control.&#160; The big benefit is that multiple team members can change files and check them in, and everyone’s schema is kept up to date.</p>
<p> <span id="more-372"></span>
<p>So, how does the up to date work?&#160; the way it works is when you get the latest from your version control, you simply right click on the vs2008 project and say “Deploy”.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowtoAutomateaSimpleDeployUsingDataDudeV_777E/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowtoAutomateaSimpleDeployUsingDataDudeV_777E/image_thumb.png" width="358" height="277" /></a></p>
<p>It’s kind of a hassle though because you have to open the project first, the don this.</p>
<p>Here is a simple one line cmd file that you can use to do this task for you.</p>
<pre class="csharpcode">C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe /t:Deploy
  /p:Configuration=<span class="str">&quot;Debug&quot;</span>;Platform=<span class="str">&quot;Any CPU&quot;</span> /v:normal /m
  <span class="str">&quot;data\ThreePLogicDatabase\ThreePLogicDatabase.dbproj&quot;</span>
pause</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode">That’s it!  hope this helps.</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/10/24/datadude-vs2008-deploy-shortcut/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Awesome Scrum Developer Training coming to Silicon Valley Microsoft Campus</title>
		<link>http://peterkellner.net/2009/10/14/scrum-training-course-mountainview-richard-hundhausen/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=scrum-training-course-mountainview-richard-hundhausen</link>
		<comments>http://peterkellner.net/2009/10/14/scrum-training-course-mountainview-richard-hundhausen/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 04:02:34 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/10/14/scrum-training-course-mountainview-richard-hundhausen/</guid>
		<description><![CDATA[Several years ago, I was invited to a special showing of what was going to be the new SqlServer 2008 database in San Francisco.&#160; I had expected a sales demo but was hugely surprised by the quality of the presenter and his deep understanding of issues facing real developers like us.&#160; Over the years, I’ve [...]]]></description>
			<content:encoded><![CDATA[<p>Several years ago, I was invited to a special showing of what was going to be the new SqlServer 2008 database in San Francisco.&#160; I had expected a sales demo but was hugely surprised by the quality of the presenter and his deep understanding of issues facing real developers like us.&#160; Over the years, I’ve gotten to know this presenter (<a href="http://blog.hundhausen.com/">Richard Hundhausen</a>) and the other work he’s been involved in. </p>
<p> <span id="more-365"></span>
<p>Richard has been developing a special training course for the Scrum development team.&#160; He’s giving this course called “Scrum Developer Training” at the Microsoft Technology Center in just a few weeks (11/2-11/6).&#160; If you have the opportunity, I can’t imagine a better thing to do to help improve you skills at being productive working in an engineering team.&#160; You can register at the following URL: </p>
<p><a title="http://www.regonline.com/Checkin.asp?EventId=780690" href="http://www.regonline.com/Checkin.asp?EventId=780690">http://www.regonline.com/Checkin.asp?EventId=780690</a></p>
<p>You can read more about the course here:&#160; <a title="http://www.accentient.com/scrum.aspx" href="http://www.accentient.com/scrum.aspx">http://www.accentient.com/scrum.aspx</a></p>
<p>I hope you can make it!</p>
<p><a href="http://www.accentient.com/scrum.aspx"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/AwesomeScrumDeveloperTrainingcomingtoSil_125F0/image.png" width="389" height="438" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/10/14/scrum-training-course-mountainview-richard-hundhausen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some Really Cool LINQ to Help Performance and Show Line Thickness</title>
		<link>http://peterkellner.net/2009/09/18/linq-groupby-grouplist-uniquesort-mapping/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-groupby-grouplist-uniquesort-mapping</link>
		<comments>http://peterkellner.net/2009/09/18/linq-groupby-grouplist-uniquesort-mapping/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 17:49:55 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/09/18/linq-groupby-grouplist-uniquesort-mapping/</guid>
		<description><![CDATA[I’ve done a bunch of Lat/Long type mapping programs over the years and one of the problems always ends up around performance.&#160; A common problem is that you keep redrawing the same line over and over and over.&#160; The pixels you are drawing don’t get any darker so all you are doing is wasting time.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve done a bunch of Lat/Long type mapping programs over the years and one of the problems always ends up around performance.&#160; A common problem is that you keep redrawing the same line over and over and over.&#160; The pixels you are drawing don’t get any darker so all you are doing is wasting time.&#160; In my current project, we were drawing approximately 1500 lines when we really only had about 150 unique lines.&#160; I’ve always known how to solve this problem with a bunch of thrown together hacked up code, but now, <a href="http://www.hookedonlinq.com/LinqToSQL5MinuteOVerview.ashx">LINQ</a> gives me a very clean way to do it.</p>
<p>So, the problem is you have a record that looks like this:</p>
<pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">class</span> LoadSegmentInfoFlat
        {
            <span class="kwrd">public</span> <span class="kwrd">double</span>? OriginLattitude { get; set; }
            <span class="kwrd">public</span> <span class="kwrd">double</span>? OriginLongitude { get; set; }
            <span class="kwrd">public</span> <span class="kwrd">double</span>? DestinationLattitude { get; set; }
            <span class="kwrd">public</span> <span class="kwrd">double</span>? DestinationLongitude { get; set; }
            <span class="kwrd">public</span> <span class="kwrd">string</span> Color { get; set; }
        }</pre>
<p><span id="more-357"></span></p>
<p>You’ve created a list of these and defined it as follows:</p>
<pre class="csharpcode">var loadSegmentInfoFlats = <span class="kwrd">new</span> List&lt;LoadController.LoadSegmentInfoFlat&gt;();</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, you want to create a unique list of Lattitude, Longitude Origins and Destinations by color.</p>
<p>The LINQ query that does the trick is a simple group by that creates an anonymous result (which is our answer).&#160; Here is the LINQ query (thanks to my friend in the <a href="http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/3846fd8f-7616-4eb2-a024-7b5dda508a04">MSDN LINQ Forums</a>, Lignzhi Sun).</p>
<pre class="csharpcode">var segments = from a <span class="kwrd">in</span> loadSegmentInfoFlats
               group a by
                   <span class="kwrd">new</span>
                       {
                           a.OriginLattitude,
                           a.OriginLongitude,
                           a.DestinationLattitude,
                           a.DestinationLongitude,
                           a.Color
                       }
               into grouplist
                   select
                   <span class="kwrd">new</span>
                       {
                           grouplist.Key.OriginLattitude,
                           grouplist.Key.OriginLongitude,
                           grouplist.Key.DestinationLattitude,
                           grouplist.Key.DestinationLongitude,
                           grouplist.Key.Color,
                           Count = grouplist.Count()
                       };</pre>
<p>&#160;</p>
<p>The resulting segments in Visual Studio 2008 debugger are as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/SomeReallyCoolLINQtoHelpPerformanceandSh_931C/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/SomeReallyCoolLINQtoHelpPerformanceandSh_931C/image_thumb.png" width="492" height="321" /></a></p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/09/18/linq-groupby-grouplist-uniquesort-mapping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Disable Edit/Insert/New Buttons in DetailsView or GridView (ASP.NET 2.0+)</title>
		<link>http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=detailsview-gridview-aspnet-disable-new-edit-delete-buttons</link>
		<comments>http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 00:27:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[DetailsView]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/</guid>
		<description><![CDATA[So, this is kind of embarrassing, that it took me a while to figure this out.&#160; I have not been doing pure asp.net server control programming for a while, but I figure since it took me a while, maybe there is someone else in the same boat.
So, you have a GridView or DetailsView that has [...]]]></description>
			<content:encoded><![CDATA[<p>So, this is kind of embarrassing, that it took me a while to figure this out.&#160; I have not been doing pure asp.net server control programming for a while, but I figure since it took me a while, maybe there is someone else in the same boat.</p>
<p>So, you have a GridView or <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview(VS.80).aspx">DetailsView</a> that has standard “Edit” “Update” “New” type command buttons on them.&#160; The way they get there is by having the declaration something like this:</p>
<p> <span id="more-352"></span>
<pre class="csharpcode"> &lt;asp:DetailsView ID=<span class="str">&quot;DetailsView1&quot;</span> runat=<span class="str">&quot;server&quot;</span> Height=<span class="str">&quot;50px&quot;</span> Width=<span class="str">&quot;125px&quot;</span>
            AllowPaging=<span class="str">&quot;True&quot;</span> AutoGenerateRows=<span class="str">&quot;False&quot;</span> DataKeyNames=<span class="str">&quot;Id&quot;</span>
            DataSourceID=<span class="str">&quot;SqlDataSource1&quot;</span>&gt;
            &lt;Fields&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;Id&quot;</span> HeaderText=<span class="str">&quot;Id&quot;</span> ReadOnly=<span class="str">&quot;True&quot;</span>
                    SortExpression=<span class="str">&quot;Id&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;Name&quot;</span> HeaderText=<span class="str">&quot;Name&quot;</span> SortExpression=<span class="str">&quot;Name&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampStartDate&quot;</span> HeaderText=<span class="str">&quot;CampStartDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampStartDate&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampEndDate&quot;</span> HeaderText=<span class="str">&quot;CampEndDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampEndDate&quot;</span> /&gt;
                &lt;asp:CommandField ShowEditButton=<span class="str">&quot;True&quot;</span> ShowInsertButton=<span class="str">&quot;True&quot;</span> /&gt;
            &lt;/Fields&gt;
&lt;/asp:DetailsView&gt;</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>What you want is to say something like:</p>
<p>“I only want admin’s to be able to add new rows so&#160; want to hide the “new” button based on that”</p>
<p>So, first thing is to convert the field to a template from the following menu.&#160; You do this by using the little helper in the upper right hand corner of the detailsview (in design mode), chose Edit Fields, CommandField, then convert to template (as in the picture below).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowtoDisableEditInsertNewButtonsinDeta.0_F26A/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowtoDisableEditInsertNewButtonsinDeta.0_F26A/image_thumb.png" width="521" height="299" /></a></p>
<p>Then, you will have something like this:</p>
<pre class="csharpcode"> &lt;asp:DetailsView ID=<span class="str">&quot;DetailsView1&quot;</span> runat=<span class="str">&quot;server&quot;</span> Height=<span class="str">&quot;50px&quot;</span> Width=<span class="str">&quot;125px&quot;</span>
            AllowPaging=<span class="str">&quot;True&quot;</span> AutoGenerateRows=<span class="str">&quot;False&quot;</span> DataKeyNames=<span class="str">&quot;Id&quot;</span>
            DataSourceID=<span class="str">&quot;SqlDataSource1&quot;</span>&gt;
            &lt;Fields&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;Id&quot;</span> HeaderText=<span class="str">&quot;Id&quot;</span> ReadOnly=<span class="str">&quot;True&quot;</span>
                    SortExpression=<span class="str">&quot;Id&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;Name&quot;</span> HeaderText=<span class="str">&quot;Name&quot;</span> SortExpression=<span class="str">&quot;Name&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampStartDate&quot;</span> HeaderText=<span class="str">&quot;CampStartDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampStartDate&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampEndDate&quot;</span> HeaderText=<span class="str">&quot;CampEndDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampEndDate&quot;</span> /&gt;
                &lt;asp:TemplateField ShowHeader=<span class="str">&quot;False&quot;</span>&gt;
                    &lt;ItemTemplate&gt;
                        &lt;asp:LinkButton ID=<span class="str">&quot;LinkButton1&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;Edit&quot;</span> Text=<span class="str">&quot;Edit&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                        &amp;nbsp;&lt;asp:LinkButton ID=<span class="str">&quot;LinkButton2&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;New&quot;</span> Text=<span class="str">&quot;New&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                    &lt;/ItemTemplate&gt;
                    &lt;EditItemTemplate&gt;
                        &lt;asp:LinkButton ID=<span class="str">&quot;LinkButton1&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;True&quot;</span>
                            CommandName=<span class="str">&quot;Update&quot;</span> Text=<span class="str">&quot;Update&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                        &amp;nbsp;&lt;asp:LinkButton ID=<span class="str">&quot;LinkButton2&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;Cancel&quot;</span> Text=<span class="str">&quot;Cancel&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                    &lt;/EditItemTemplate&gt;
                    &lt;InsertItemTemplate&gt;
                        &lt;asp:LinkButton ID=<span class="str">&quot;LinkButton1&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;True&quot;</span>
                            CommandName=<span class="str">&quot;Insert&quot;</span> Text=<span class="str">&quot;Insert&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                        &amp;nbsp;&lt;asp:LinkButton ID=<span class="str">&quot;LinkButton2&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;Cancel&quot;</span> Text=<span class="str">&quot;Cancel&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                    &lt;/InsertItemTemplate&gt;
                &lt;/asp:TemplateField&gt;
            &lt;/Fields&gt;
&lt;/asp:DetailsView&gt;</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, you have standard &lt;asp:LinkButton&gt; so you can call the visible property from your codebehind like this:</p>
<pre class="csharpcode"> <span class="kwrd">&lt;</span><span class="html">asp:TemplateField</span> <span class="attr">ShowHeader</span><span class="kwrd">=&quot;False&quot;</span><span class="kwrd">&gt;</span>
                     <span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span>
                         <span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;LinkButton1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span> <span class="attr">Visible</span><span class="kwrd">='&lt;%# GetShowEditButton() %&gt;'</span>
                             <span class="attr">CommandName</span><span class="kwrd">=&quot;Edit&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Edit&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span>
                         <span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;LinkButton2&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span> <span class="attr">Visible</span><span class="kwrd">='&lt;%# GetShowInsertButton() %&gt;'</span>
                             <span class="attr">CommandName</span><span class="kwrd">=&quot;New&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;New&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span>
                         <span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;LinkButton3&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span>
                             <span class="attr">CommandName</span><span class="kwrd">=&quot;Delete&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Delete&quot;</span> <span class="attr">Visible</span><span class="kwrd">='&lt;%# GetShowDeleteButton() %&gt;'</span>     <span class="kwrd">&gt;&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span>
                     <span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">asp:TemplateField</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Then, in your codebehind, you have the following:</p>
<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">bool</span> GetShowEditButton()
    {
        <span class="kwrd">return</span> Roles.IsUserInRole(<span class="str">&quot;Admin&quot;</span>);
    }

    <span class="kwrd">protected</span> <span class="kwrd">bool</span> GetShowInsertButton()
    {
        <span class="kwrd">return</span> Roles.IsUserInRole(<span class="str">&quot;Admin&quot;</span>);
    }
    <span class="kwrd">protected</span> <span class="kwrd">bool</span> GetShowDeleteButton()
    {
        <span class="kwrd">return</span> Roles.IsUserInRole(<span class="str">&quot;Admin&quot;</span>);
    }
}</pre>
<p>Hope you find this before spending a bunch of time reading about more complicated solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>A New Book on Using MSBuild and Team Foundation Server</title>
		<link>http://peterkellner.net/2009/02/12/msbuild-bookreview-tfs-visualstudio-microsoft/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=msbuild-bookreview-tfs-visualstudio-microsoft</link>
		<comments>http://peterkellner.net/2009/02/12/msbuild-bookreview-tfs-visualstudio-microsoft/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 19:03:41 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/02/12/msbuild-bookreview-tfs-visualstudio-microsoft/</guid>
		<description><![CDATA[&#160;
William Bartholomew just published a new book on MSBuild and TFS. There is a great forward by Richard Hundhausen (Famous TFS Author and top MS consultant).&#160; I personally don’t use TFS yet, but I do use MSBuild and plan on using it more extensively for web deployments going forward.&#160; I have not yet read the [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p><a href="http://blog.bartholomew.id.au/">William Bartholomew</a> just published a new book on MSBuild and <a href="http://en.wikipedia.org/wiki/Team_Foundation_Server">TFS</a>. There is a great forward by <a href="www.accentient.com">Richard Hundhausen</a> (Famous TFS Author and top MS consultant).&#160; I personally don’t use TFS yet, but I do use <a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx">MSBuild</a> and plan on using it more extensively for web deployments going forward.&#160; I have not yet read the book, but am anxiously looking forward to.&#160; It is a topic that IMHO has been very under documented.&#160; This should be a big help!</p>
<div class="wlWriterEditableSmartContent" id="scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:8b16b1b3-85f5-44c2-80ce-e8e85835c6db" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<table cellspacing="0" cellpadding="2" width="400" border="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="400">
<p><a title="Inside the Microsoft&reg; Build Engine: Using MSBuild and Team Foundation Build (PRO-Developer): Sayed Ibrahim Hashimi, William Bartholomew: Books" href="http://www.amazon.com/exec/obidos/ASIN/0735626286/petkelsblo-20"><img src="http://images.amazon.com/images/P/0735626286.01.MZZZZZZZ.jpg" border="0" align="left" style="float:left">Inside the Microsoft&reg; Build Engine: Using MSBuild and Team Foundation Build (PRO-Developer): Sayed Ibrahim Hashimi, William Bartholomew: Books</a></p>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/02/12/msbuild-bookreview-tfs-visualstudio-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Experience with Visual Studio 2008 Database Edition, I love it!!!</title>
		<link>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visual-studio-database-edition-review-sqlserver2008</link>
		<comments>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 22:06:11 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/</guid>
		<description><![CDATA[As a developer who has spent much of my life doing DBA type work, I really appreciate the simplicity and elegance of what Microsoft Visual Studio Team has put together with the Database Edition and can be seen for sale here as the 
Microsoft Visual Studio 2010 Premium with MSDN Download &#8211; Download Direct from [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer who has spent much of my life doing DBA type work, I really appreciate the simplicity and elegance of what <a href="http://msdn.microsoft.com/en-us/vsts2008/products/bb933747.aspx">Microsoft Visual Studio Team</a> has put together with the <a href="http://blogs.msdn.com/gertd/archive/2007/11/21/visual-studio-team-system-2008-database-edition.aspx">Database Edition</a> and can be seen for sale here as the </p>
<p><a href="http://click.linksynergy.com/fs-bin/click?id=cLhVEJVzoSE&#038;offerid=166833.737&#038;type=2&#038;subid=0">Microsoft Visual Studio 2010 Premium with MSDN Download &#8211; Download Direct from Microsoft</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=cLhVEJVzoSE&#038;bids=166833.737&#038;type=2&#038;subid=0" ></p>
<p> I&#8217;ll first try and explain in a nutshell what it is.&#160; Then I&#8217;ll go through an example of creating a Visual Studio Database Project out of a site I&#8217;ve been working on to show the steps.&#160; Finally, I&#8217;ll give a short summary reliving the experience and giving you some other pointers that may help you get through the experience.</p>
<h3>What is VS2008 Database Edition?</h3>
<p>Basically, what VS2008 does is to first process your existing schema into hundreds (maybe thousands) of little files.&#160; That is, each file is one database thing. That thing might be a table definition, a stored procedure, a trigger, a constraint, a foreign key, etc.&#160; The beauty of this is that now, each thing can be tracked separately.&#160; Say for example, you want to update just one table and someone else on your team wants to update another table in the same schema.&#160; Since the files are now separate files, it&#8217;s no problem.&#160; When you grab the latest changes from source control, you will get your friends changes and he will get yours.&#160; Very very clean!</p>
<div id='extendedEntryBreak' name='extendedEntryBreak'></div>
<p>Also, it has a very powerful comparison engine.&#160; Say you update your data outside of this project.&#160; VS2008 Database Edition will compare your definitions in all these little files with either a sql script you generate, or it will connect to an external database and compare to that.&#160; Me personally, I like to use a tool called <a href="http://www.sqlmanager.net/en/products/studio/mssql">SqlManager</a> to manage my data.&#160; I can continue to do that, then when I&#8217;ve made my changes, I can simply connect VS2008 Database Edition to my updated development database and it will automatically figure out the changes.</p>
<p>So, you may ask, what version do I need to run this of Visual Studio?&#160; The answer is in this link:&#160; <a title="http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx" href="http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx">http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx</a></p>
<h3>Here We Go, Let&#8217;s do an Example</h3>
<p>So, first, I will open my existing solution which has a web project in it, a data access project as well as other projects.&#160; Then, I create the new Database solution by saying File/Open/New Project/Database Project.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb.png" width="395" height="208" /></a></p>
<p>Then, we follow the wizard&#8230;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_3.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_3.png" width="244" height="182" /></a></p>
<p>Taking defaults&#8230;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_4.png" width="244" height="182" /></a></p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_5.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_5.png" width="244" height="182" /></a></p>
<p>Now, I choose my schema.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_6.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_6.png" width="244" height="182" /></a></p>
<p>Press Start&#8230;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_7.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_7.png" width="244" height="182" /></a></p>
<p>Once you&#8217;ve done that, you&#8217;ll now have your schema spread out across your project in little files.&#160; Below is what the &quot;file based&quot; view of your schema looks like.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_8.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_8.png" width="412" height="295" /></a></p>
<p>Notice that the file we are looking at also includes comments for both the table and the columns using the standard extended property documentation format as follows:</p>
<pre class="csharpcode"><span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> sp_addextendedproperty @name = N<span class="str">'MS_Description'</span>,
@<span class="kwrd">value</span> = N<span class="str">'tracks all changes from each camp

title;link;guid;pubDate;category;description'</span>, @level0type = N<span class="str">'SCHEMA'</span>,
@level0name = N<span class="str">'dbo'</span>, @level1type = N<span class="str">'TABLE'</span>,
@level1name = N<span class="str">'CampFeed'</span>;

<span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> sp_addextendedproperty @name = N<span class="str">'MS_Description'</span>,
@<span class="kwrd">value</span> = N<span class="str">'if true, this is the main news feed from the site.
there should only be one main news feed from any site.  this would
not be feeds like twitter'</span>, @level0type = N<span class="str">'SCHEMA'</span>,
@level0name = N<span class="str">'dbo'</span>,
@level1type = N<span class="str">'TABLE'</span>, @level1name = N<span class="str">'CampFeed'</span>,
@level2type = N<span class="str">'COLUMN'</span>, @level2name = N<span class="str">'PrimaryFeed'</span>;</pre>
<pre class="csharpcode">&#160;</pre>
<pre class="csharpcode">Now, when you actually build the project as follows:</pre>
<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_9.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_9.png" width="242" height="244" /></a> </pre>
<p>it will generate the full script combining all the files back into one again. Here is where it puts it:</p>
<pre class="csharpcode">&#160;</pre>
<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_10.png" width="414" height="332" /></a> </pre>
<pre class="csharpcode">&#160;</pre>
<p>So, that&#8217;s about it for now. I haven&#8217;t gone into any of the ways to compare and update your schema based on external changes, but we can leave that for another post.</p>
<p>To see a great video by <a href="http://blog.hundhausen.com/">Richard Hundhausen</a>, President of <a title="http://www.accentient.com/" href="http://www.accentient.com/">Accentient</a>, a <a href="http://msdn.microsoft.com/en-us/vsts2008/aa718934.aspx">Team Systems</a> Consulting company, go to this link:&#160; <a title="http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx" href="http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx">http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx</a></p>
<p>Also, if you are using Sql Server 2008, make sure you install visual studio 2008 sp1, then go to this link and install the download:&#160; <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en</a></p>
<h3>Conclusions</h3>
<p>From what I can tell, this Visual Studio Database Edition will be a huge help in building database schema&#8217;s and database programs (sp&#8217;s, triggers,etc.) in a collaborative environment.&#160;&#160; If you have the license to use this, I strongly recommend it.&#160; It is definitely going to be part of my tool kit for now on.&#160; Even if I&#8217;m the only author in the project.</p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Logging your Sql with LINQ Update Commands. Simple Logging to your Visual Studio 2008 Debugger Output Console</title>
		<link>http://peterkellner.net/2008/12/04/linq-debug-output-vs2008/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-debug-output-vs2008</link>
		<comments>http://peterkellner.net/2008/12/04/linq-debug-output-vs2008/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 02:13:34 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/12/04/linq-debug-output-vs2008/</guid>
		<description><![CDATA[ So, you want to do an update but are wondering what the hec LINQ is doing.&#160; Turns out it is really easy.&#160; All you have to do is run in the debugger and add the Log option to your data context.
Here is an example:

DataClassesGeneralDataContext db3pLogicContext;
db3pLogicContext.Log = Console.Out;
&#160;
var companyQuery = from tbl in db3pLogicContext.Companies
  [...]]]></description>
			<content:encoded><![CDATA[<p> So, you want to do an update but are wondering what the hec LINQ is doing.&#160; Turns out it is really easy.&#160; All you have to do is run in the debugger and add the Log option to your data context.</p>
<p>Here is an example:</p>
<div class="csharpcode">
<pre class="alt">DataClassesGeneralDataContext db3pLogicContext;</pre>
<pre>db3pLogicContext.Log = Console.Out;</pre>
<pre class="alt">&#160;</pre>
<pre>var companyQuery = from tbl <span class="kwrd">in</span> db3pLogicContext.Companies</pre>
<pre class="alt">                   <span class="kwrd">where</span> tbl.ParentId != 0</pre>
<pre>                   select tbl;</pre>
<pre class="alt">&#160;</pre>
<pre><span class="kwrd">int</span> totalCntParents = companyQuery.Count();</pre>
<pre class="alt"><span class="kwrd">foreach</span> (DBAccess.Company co <span class="kwrd">in</span> companyQuery)</pre>
<pre>{</pre>
<pre class="alt">    co.CreateDate = DateTime.Now;</pre>
<pre>    <span class="kwrd">break</span>;</pre>
<pre class="alt">}</pre>
<pre>&#160;</pre>
<pre class="alt">db3pLogicContext.SubmitChanges();</pre>
</div>
<div class="csharpcode">&#160;</div>
<p><span id="more-192"></span></p>
<p>Now, when you run the code, you can look on your debugger output and see something that looks like this:</p>
<div class="csharpcode"><a href="http://peterkellner.net/blogimages/LoggingyourSqlwithLINQUpdateCommands_FEF2/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/blogimages/LoggingyourSqlwithLINQUpdateCommands_FEF2/image_thumb.png" width="431" height="417" /></a> </div>
<div class="csharpcode">&#160;</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Also, if you want to actually execute select type statements, take a look at the Query Visualizer posted on Scott Guthrie&#8217;s web site:</p>
<p><a title="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx" href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx">http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/12/04/linq-debug-output-vs2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQPad is Totally Awesome at Testing and Writing LINQ Queries</title>
		<link>http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linqpad-sqlserver-linq-interpreter-nutshell</link>
		<comments>http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 02:25:56 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/</guid>
		<description><![CDATA[http://www.linqpad.net/ &#8211; Use with Microsoft .Net for building Query type expressions with LINQ
I&#8217;m not a wizard at writing LINQ expressions so I often find myself in Google looking for something similar to what I want, then I put it into my application and run it. This has worked pretty well, but it takes a couple [...]]]></description>
			<content:encoded><![CDATA[<p><a title="http://www.linqpad.net/" href="http://www.linqpad.net/">http://www.linqpad.net/</a> &#8211; Use with Microsoft .Net for building Query type expressions with LINQ</p>
<p>I&#8217;m not a wizard at writing <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx">LINQ</a> expressions so I often find myself in <a href="http://google.com">Google</a> looking for something similar to what I want, then I put it into my application and run it. This has worked pretty well, but it takes a couple iterations to get it right. It occured to me that someone probably has written a LINQ interpreter so I just guessed the name, <a href="http://www.linqpad.net/">LINQPad</a>, typed it into search, and I find the authors of the book C# 3.0 in a nutshell, <a href="http://www.technosis.com.au/Training.aspx">Joseph Albahari</a> and <a href="http://www.oreillynet.com/pub/au/465">Ben Albahari</a>, (which I like a lot) have written it.</p>
<p> <span id="more-162"></span>
<p>I download it (it&#8217;s an exe file), run it (OK, I trust you guys somehow), and presto, I get a very nice interface that not only has tons of examples built into it with a nice tree view, but lets me make a connection to my database and run LINQ queries against it. It even cancels them when you create one that will run forever (very nice guys!).</p>
<p>So, the query I was going after is I have a huge list of cities that includes states. From that, I just want a unique list of states (this list does not have all the states so I want just the ones contained in it). Below is a screen shot of the <a href="http://www.linqpad.net/">LINQPad</a> with my Query in it. I simply pressed the green triangle (trained by <a href="http://msdn.microsoft.com/en-us/library/aa174466(SQL.80).aspx">Sql Server Enterprise Manager</a>), and presto, my list! Could not be much easier. This tool will be in my box for a long time.</p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="5" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://www.peterkellner.net/FilesForWebDownload/LINQPadistotallyawesomeattestingandwriti_11132/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://www.peterkellner.net/FilesForWebDownload/LINQPadistotallyawesomeattestingandwriti_11132/image_thumb.png" width="436" height="462" /></a></td>
<td valign="top" width="200">
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:f6c31e3c-c91c-488b-9956-0209b5fc625f" class="wlWriterSmartContent">
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<p><a title="Amazon.com: C# 3.0 in a Nutshell" href="http://www.amazon.com/exec/obidos/ASIN/0596527578/petkelsblo-20"><img border="0" align="left" src="http://images.amazon.com/images/P/0596527578.01.MZZZZZZZ.jpg" />Amazon.com: C# 3.0 in a Nutshell</a></p>
</td>
</tr>
</tbody>
</table></div>
</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Grab this now!&#160; It&#8217;s a winner, believe me.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to find your temporary asp.net executing assemblies location</title>
		<link>http://peterkellner.net/2008/08/18/find-temp-aspnet-assembly-executing-reflection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-temp-aspnet-assembly-executing-reflection</link>
		<comments>http://peterkellner.net/2008/08/18/find-temp-aspnet-assembly-executing-reflection/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 19:22:46 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/08/18/find-temp-aspnet-assembly-executing-reflection/</guid>
		<description><![CDATA[Seems, I keep forgetting where the temporary files asp.net uses. The reason it&#8217;s nice to know is sometimes you may want to open them with Reflector to see the generated code.&#160; Also, sometimes, you want to delete those files because asp.net is confused and is reusing old ones.&#160; So, here is the magic lines of [...]]]></description>
			<content:encoded><![CDATA[<p>Seems, I keep forgetting where the temporary files <a href="http://www.asp.net/">asp.net</a> uses. The reason it&#8217;s nice to know is sometimes you may want to open them with <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a> to see the generated code.&#160; Also, sometimes, you want to delete those files because asp.net is confused and is reusing old ones.&#160; So, here is the magic lines of code you need.</p>
<p> <span id="more-136"></span>
<div class="csharpcode">
<pre class="alt">&lt;%@ Page Language=<span class="str">&quot;C#&quot;</span> %&gt;</pre>
<pre>&#160;</pre>
<pre class="alt">&lt;!DOCTYPE html PUBLIC <span class="str">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span class="str">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span>&gt;</pre>
<pre>&#160;</pre>
<pre class="alt">&lt;script runat=<span class="str">&quot;server&quot;</span>&gt;</pre>
<pre>&#160;</pre>
<pre class="alt">    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)</pre>
<pre>    {</pre>
<pre class="alt">        LabelWhere.Text = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();</pre>
<pre>    }</pre>
<pre class="alt">&lt;/script&gt;</pre>
<pre>&#160;</pre>
<pre class="alt">&lt;html xmlns=<span class="str">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</pre>
<pre>&lt;head runat=<span class="str">&quot;server&quot;</span>&gt;</pre>
<pre class="alt">    &lt;title&gt;&lt;/title&gt;</pre>
<pre>&lt;/head&gt;</pre>
<pre class="alt">&lt;body&gt;</pre>
<pre>    &lt;form id=<span class="str">&quot;form1&quot;</span> runat=<span class="str">&quot;server&quot;</span>&gt;</pre>
<pre class="alt">    &lt;div&gt;</pre>
<pre>        &lt;asp:Label ID=<span class="str">&quot;LabelWhere&quot;</span> runat=<span class="str">&quot;server&quot;</span> Text=<span class="str">&quot;Label&quot;</span>&gt;&lt;/asp:Label&gt;</pre>
<pre class="alt">    &lt;/div&gt;</pre>
<pre>    &lt;/form&gt;</pre>
<pre class="alt">&lt;/body&gt;</pre>
<pre>&lt;/html&gt;</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Hope this Helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/08/18/find-temp-aspnet-assembly-executing-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 35/42 queries in 0.013 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-23 00:49:43 -->
