<?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</title>
	<atom:link href="http://peterkellner.net/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>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Leading BOF Session on Building SenchaTouch 2.0 App Coming to Mountain View May 25, 2012</title>
		<link>http://peterkellner.net/2012/05/11/leading-bof-session-on-building-senchatouch-2-0-app-coming-to-mountain-view-may-25-2012/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=leading-bof-session-on-building-senchatouch-2-0-app-coming-to-mountain-view-may-25-2012</link>
		<comments>http://peterkellner.net/2012/05/11/leading-bof-session-on-building-senchatouch-2-0-app-coming-to-mountain-view-may-25-2012/#comments</comments>
		<pubDate>Fri, 11 May 2012 16:43:16 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[SenchaMVC]]></category>
		<category><![CDATA[SenchaTouch]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=2008</guid>
		<description><![CDATA[I’m leading a 3 hour hands on lab titled &#34;MindSource Birds of a Feather 55 (BoF) &#8211; Developing Mobile Applications using SenchaTouch 2.0&#34; on May 23rd in Mountain View California.&#160; This is our first go around this so we are limiting attendance so if you are interested, you’ll need to sign up asap.&#160; The URL [...]]]></description>
			<content:encoded><![CDATA[<p>I’m leading a 3 hour hands on lab titled &quot;<a href="http://www.mindsource.com/">MindSource</a> Birds of a Feather 55 (BoF) &#8211; Developing Mobile Applications using <a href="http://www.sencha.com/products/touch/">SenchaTouch</a> 2.0&quot; on May 23rd in Mountain View California.&#160; This is our first go around this so we are limiting attendance so if you are interested, you’ll need to sign up asap.&#160; The URL to sign up is</p>
<p><a href="http://www.eventbrite.com/event/3491482117/mtup">http://www.eventbrite.com/event/3491482117/mtup</a></p>
<p>We do have a small $20 free to both help cover some costs as well as get a clear picture of what attendance will be.&#160; MindSource will be picking up the additional expenses beyond the $20 paid fees.</p>
<p>Hope to see you there!</p>
<p>Here are the details:</p>
<blockquote><p>Join us for this fast-paced hands-on lab where you will develop your own working mobile application to run on iPad, iPhones, and Android devices. Learn the fundamentals of developing mobile web applications with SenchTouch 2.0 by working in small teams to develop a rudimentary conference scheduling application and explore a number of important Sencha libraries.</p>
<p>The course will start with setting up a developer environment and creating your first “hello” App, cover the theory of mobile app design theory and the basics of MVC design, and progress to building the <a href="http://www.siliconvalley-codecamp.com/">Conference Session Viewer</a>, and create panels for button and toolbars.</p>
<p>After a break, then you will learn how to work create storage facilities and add styling. We will conclude with Q&amp;A.</p>
<p>Bring your own Laptop!&#160;&#160; Each module will take about 25 minutes, and if you get behind, you can take our completed code and move on to the next. This way, everyone will finish!</p>
<p>MindSource is honored to have <strong>Peter Kellner</strong> as our speaker.&#160; <em>Peter is founder and president of 73rd Street Associates and is a seasoned software professional specializing in high quality, scalable and extensible web applications. For the past six years, Peter has worked extensively with Microsoft’s ASP.NET and Sencha’s desktop and mobile developer platforms (ExtJS and SenchaTouch).&#160; Peter delivers production software using these technologies.&#160; Peter lectures regularly on these technologies at international conferences including DevConnections and VSLive as well as many local users groups.&#160; Peter has headed up Silicon Valley Code Camp at Foothill College for seven years and also leads the local Sencha Community Meetup.</em></p>
</blockquote>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/05/11/leading-bof-session-on-building-senchatouch-2-0-app-coming-to-mountain-view-may-25-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Add Paging With a Filter Using Sencha Architect with ExtJS4</title>
		<link>http://peterkellner.net/2012/05/08/how-to-add-paging-with-a-filter-using-sencha-architect-with-extjs4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-add-paging-with-a-filter-using-sencha-architect-with-extjs4</link>
		<comments>http://peterkellner.net/2012/05/08/how-to-add-paging-with-a-filter-using-sencha-architect-with-extjs4/#comments</comments>
		<pubDate>Tue, 08 May 2012 23:38:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[Sencha Architect 2]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=2005</guid>
		<description><![CDATA[&#160;
Sometimes,the simplest things can seem complicated.&#160; Well, in this case, after struggling for a while, it turns out the simplest things can actually be pretty simple.&#160; The application I’m building right now (with Sencha’s ExtJS and ASP.NET) is a simple log viewer.&#160; My server base app uses NLog which does a great job of logging [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>Sometimes,the simplest things can seem complicated.&#160; Well, in this case, after struggling for a while, it turns out the simplest things can actually be pretty simple.&#160; The application I’m building right now (with <a href="http://www.sencha.com/">Sencha’s</a> <a href="http://www.sencha.com/products/extjs/">ExtJS</a> and <a href="http://www.asp.net/">ASP.NET</a>) is a simple log viewer.&#160; My server base app uses <a href="http://nlog-project.org/">NLog</a> which does a great job of logging the errors, but the errors are all on my server and I need to see them.&#160; So, hence I need a simple log viewer.&#160; Here is what it looks like once it’s all done.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/05/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/05/image_thumb.png" width="528" height="460" /></a></p>
<p>&#160;</p>
<p>Notice that we have a toolbar that we can check a box in as well as a field to type some text into.&#160; I’m going to assume that creating the windows, the grid, dropping the toolbars on the page (both paging and top toolbar) are something that you know how to do.&#160; The only thing I’m really going to mention is how you go from a grid panel that pages correctly to one that pages correctly with some parameters being sent to the server.</p>
<p>So, it turns out all you have to do is assign an id to each of the controls on your top toolbar, create a <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.AbstractStore-event-beforeload">beforeload</a> store event where you retrieve the values from your toolbar, then set the store’s proxy <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Connection-cfg-extraParams">extraParams</a> values to be the filter parameters you want passed.&#160; OK, that’s a mouthful so let me show it in steps.</p>
<p>1.&#160; Assign id’s to the toolbar parameters. (screen shot of the checkbox below)</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/05/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/05/image_thumb1.png" width="428" height="302" /></a></p>
<p>&#160;</p>
<p>2.&#160; Create a beforeload event in your store for the gridview and get the components you want</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/05/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/05/image_thumb2.png" width="261" height="341" /></a></p>
<p>&#160;</p>
<p>3.&#160; Put some code in the beforeload even that gets these components, then sets the ExtraParams value associated with the stores proxy.</p>
<pre class="csharpcode"><span class="kwrd">var</span> checkboxerroronly = Ext.getCmp(<span class="str">'checkboxerroronlyid'</span>);
<span class="kwrd">var</span> usernamefilter = Ext.getCmp(<span class="str">'usernamefilterid'</span>).getValue();

<span class="kwrd">var</span> displayErrorOnly = checkboxerroronly.<span class="kwrd">checked</span>;
store.proxy.extraParams.errorsOnly = displayErrorOnly;
store.proxy.extraParams.username = usernamefilter;</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>4. And just run it!&#160; If you look at your network traffic, you will see both the errorsOnly and username parameters passed on every page refresh and page forward and back.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/05/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/05/image_thumb3.png" width="536" height="204" /></a></p>
<p>&#160;</p>
<p>Hope this helps!</p>
<p>(sorry, no source code for this one, just some tips in the middle of a project I’m doing)</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/05/08/how-to-add-paging-with-a-filter-using-sencha-architect-with-extjs4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Desktop Class Versus Windows 8 Metro UI</title>
		<link>http://peterkellner.net/2012/04/25/windows-desktop-class-verses-windows-8-metro/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=windows-desktop-class-verses-windows-8-metro</link>
		<comments>http://peterkellner.net/2012/04/25/windows-desktop-class-verses-windows-8-metro/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 06:21:23 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows 8 Metro]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1993</guid>
		<description><![CDATA[I recently went to a big Microsoft Windows 8 developer event at the Mountain View Microsoft office and I heard for the first time a really good explanation for why Metro is, well the way Metro is.&#160; One of the original UI architects spoke and made this argument that I’ve never heard before.&#160; I’ll try [...]]]></description>
			<content:encoded><![CDATA[<p>I recently went to a big <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</a> <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh868262.aspx">Windows 8</a> developer event at the Mountain View Microsoft office and I heard for the first time a really good explanation for why Metro is, well the way Metro is.&#160; One of the original UI architects spoke and made this argument that I’ve never heard before.&#160; I’ll try to do my best to recall what he said with making too much up so here it goes.</p>
<p>He said that with one of the first Metro UI builds that basically looks like the current Metro interface, Microsoft brought in a bunch of people for a study.&#160; They asked them sit in front of a class Windows Desktop and do a bunch of stuff, then sit in front of a Metro interface and do some stuff.&#160; In other words, basically here is what they were looking at:</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image16.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb14.png" width="244" height="139" /></a></p>
<p>versus</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image17.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb15.png" width="244" height="193" /></a></p>
<p>(sorry about the size differences, that’s not really relevant here)</p>
<p>Microsoft then asked the participants to draw what they remembered from each interface.&#160; For Window classic, they drew the following:</p>
<p>&#160;</p>
<p> <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/Photo-Apr-25-11-06-05-PM.jpg"><img title="Photo Apr 25, 11 06 05 PM" 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="Photo Apr 25, 11 06 05 PM" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/Photo-Apr-25-11-06-05-PM_thumb.jpg" width="244" height="183" /></a>
<p>&#160;</p>
<p>For Metro, they drew this:</p>
<p>&#160;</p>
<p> <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/Photo-Apr-25-11-05-57-PM.jpg"><img title="Photo Apr 25, 11 05 57 PM" 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="Photo Apr 25, 11 05 57 PM" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/Photo-Apr-25-11-05-57-PM_thumb.jpg" width="244" height="183" /></a>
<p>&#160;</p>
<p>Microsoft’s conclusion was that Metro is all about the content and Windows class is all about the stuff around the content.&#160; It seems obvious that the OS should be about the content and not the plumbing.</p>
<p>So, there you have it, with the exception of one thing (which is actually what’s motivating this post).</p>
<p>&#160;</p>
<h2>The Problem</h2>
<p>Unless you have been living under a stone, I think we all know that the Apple OSX operating system has been getting more and more popular.&#160; it’s design is even further away from the windows class desktop.&#160; That is, not only to the launch places have to do with edges and corners, the menu itself is glued to the top no matter what program you are running.</p>
<p>I recently noticed this article posted that showed that in full detail:</p>
<p><a href="http://macwinguy.com/2012/04/where-did-my-menu-go/">http://macwinguy.com/2012/04/where-did-my-menu-go/</a></p>
<p>It shows that the mac window all about edges.</p>
<p><a href="http://macwinguy.com/2012/04/where-did-my-menu-go/"><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/image18.png" width="244" height="235" /></a></p>
<p>So, there you have it.&#160; I’m now perplexed.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/25/windows-desktop-class-verses-windows-8-metro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Details On The ExtJS Application to Build Simple CRUD operation Using Models and Stores</title>
		<link>http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores</link>
		<comments>http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 00:00:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[SenchaMVC]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1973</guid>
		<description><![CDATA[&#160;



Part 1
Basics (mostly server side)


Part 2 (this)
ExtJS Client Side Details



&#160;&#160;
In the first article, a very simple updater was build using Sencha’s ExtJS and Microsoft’s Entity Framework Code First.&#160; The focus was really on the server side while the client side project was included for reference.&#160; The client side app was barely discussed.&#160; In this article, [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<table cellspacing="0" cellpadding="2" width="362" border="1">
<tbody>
<tr>
<td valign="top" width="199">Part 1</td>
<td valign="top" width="161"><a href="http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/">Basics (mostly server side)</a></td>
</tr>
<tr>
<td valign="top" width="219">Part 2 (this)</td>
<td valign="top" width="170"><a href="http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/">ExtJS Client Side Details</a></td>
</tr>
</tbody>
</table>
<p>&#160;&#160;
<p>In the first article, a very simple updater was build using <a href="http://www.sencha.com/">Sencha’s</a> <a href="http://www.sencha.com/products/extjs/">ExtJS</a> and Microsoft’s <a href="http://msdn.microsoft.com/en-us/data/aa937723">Entity Framework</a> <a href="http://blogs.msdn.com/b/adonet/archive/2011/04/11/ef-4-1-released.aspx">Code First</a>.&#160; The focus was really on the server side while the client side project was included for reference.&#160; The client side app was barely discussed.&#160; In this article, we are going to discuss in more detail what is happening on the client side and how the <a href="http://www.sencha.com/products/extjs/">Sencha ExtJS</a> <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> library helps us to implement these updates.</p>
<p>&#160;</p>
<h2>The Basics</h2>
<p>Let’s start out with some basics rather than jump right in to the real project.&#160;&#160; I think we can all assume the displaying of the data is pretty simple. We just create a store, add some fields, hook it up to a <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel">Ext.grid.Panel</a> and set the store to <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.ElementLoader-cfg-autoLoad">autoload</a> and it all just works.&#160; Updating though does add a little more complexity and for that, we are going to add some structure.&#160; So, let’s take a look at the very basics without any UI at all.</p>
<p>Just by way of reminders, we create two simple services in our project.&#160; One that reads and the other that updates.&#160; For the purpose of this article, those are the three (of four) <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> operations we are going to implement (read,insert and update).&#160; Let’s first implement those operations directly.&#160; Below is a very straight forward JavaScript which basically represents a completely working ExtJS app with a single button in the viewport.&#160; Here is the code below.</p>
<pre class="csharpcode">Ext.Loader.setConfig({ enabled: <span class="kwrd">true</span> });
Ext.require(<span class="str">'Ext.container.Viewport'</span>);

Ext.application({
    name: <span class="str">'AM'</span>,

    controllers: [
        <span class="str">'Users'</span>
    ],

    launch: <span class="kwrd">function</span>() {
        Ext.create(<span class="str">'Ext.container.Viewport'</span>, {
            layout: <span class="str">'border'</span>,
            items: [
                {
                    xtype: <span class="str">'button'</span>,
                    region: <span class="str">'center'</span>,
                    text: <span class="str">'Insert a Record'</span>,
                    handler: <span class="kwrd">function</span> () {
                        <span class="kwrd">var</span> writer = <span class="kwrd">new</span> Ext.data.JsonWriter({
                            type: <span class="str">'json'</span>,
                            encode: <span class="kwrd">false</span>,
                            listful: <span class="kwrd">true</span>,
                            writeAllFields: <span class="kwrd">true</span>,
                            returnJson: <span class="kwrd">true</span>
                        });

                        <span class="kwrd">var</span> reader = <span class="kwrd">new</span> Ext.data.JsonReader({
                            totalProperty: <span class="str">'total'</span>,
                            successProperty: <span class="str">'success'</span>,
                            idProperty: <span class="str">'Id'</span>,
                            root: <span class="str">'Data'</span>,
                            messageProperty: <span class="str">'message'</span>
                        });

                        <span class="kwrd">var</span> proxy = <span class="kwrd">new</span> Ext.data.HttpProxy({
                            reader: reader,
                            writer: writer,
                            type: <span class="str">'ajax'</span>,
                            api: {
                                read: <span class="str">'/UserInfo/Get'</span>,
                                create: <span class="str">'/UserInfo/Create'</span>,
                                update: <span class="str">'/UserInfo/Update'</span>,
                                destroy: <span class="str">'/UserInfo/Delete'</span>
                            },
                            headers: {
                                <span class="str">'Content-Type'</span>: <span class="str">'application/json; charset=UTF-8'</span>
                            }
                        });

                        Ext.define(<span class="str">'MyModel'</span>, {
                            extend: <span class="str">'Ext.data.Model'</span>,
                            fields: [<span class="str">'Id'</span>, <span class="str">'Name'</span>, <span class="str">'Email'</span>],
                            proxy: proxy
                        });

                        Ext.define(<span class="str">'MyStore'</span>, {
                            extend: <span class="str">'Ext.data.Store'</span>,
                            model: <span class="str">'MyModel'</span>,
                            autoLoad: <span class="kwrd">true</span>,
                            paramsAsHash: <span class="kwrd">true</span>,
                            proxy: proxy
                        });

                        <span class="kwrd">var</span> myStore = Ext.create(<span class="str">'MyStore'</span>, {
                        });

                        myStore.add({
                            Name: <span class="str">'TestName'</span>,
                            Email: <span class="str">'TestEmail@Test.com'</span>
                        });

                        myStore.sync();
                    }
                }
            ]
        });
    }
});</pre>
<p>Without going into to much detail, basically, what has been done above is a to create a simple <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model">model</a> (myModel) which contains a JsonReader and JsonWriter and proxy of course. This model has a couple fields in it (Id,Name and Email), then a simple <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store">store</a> is created that uses this model called myStore.&#160; Once this store has been created, we simply call the store’s “add” method with a config object that represents the data, then calling sync() on that store forces an insert (or create) to be executed through the proxy.&#160; If I look at Chrome’s JavaScript debugger (network tab), you can see from the picture below that indeed, the servers UserInfo/Create method has been called passing in the parameters Name and Email.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image14.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/04/image_thumb12.png" width="516" height="192" /></a></p>
<p>&#160;</p>
<p>It’s important to understand these steps because we will be using the store and model in a similar way when we update the data in our next section.</p>
<p>&#160;</p>
<h2>Implementation in Grid and Editor Panel</h2>
<p>&#160;</p>
<p>We are using the ExtJS MVC architecture for this app so all our procedural code is in the controller.&#160; For the Ext.grid.Panel, all we have for the view is the following (app/view/List.js).</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image15.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/04/image_thumb13.png" width="322" height="179" /></a></p>
<p>&#160;</p>
<pre class="csharpcode">Ext.define(<span class="str">'AM.view.user.List'</span>, {
    extend: <span class="str">'Ext.grid.Panel'</span>,
    alias: <span class="str">'widget.userlist'</span>,

    title: <span class="str">'All Users'</span>,
    store: <span class="str">'Users'</span>,

    columns: [
    { header: <span class="str">'Name'</span>, dataIndex: <span class="str">'Name'</span>, flex: 1 },
    { header: <span class="str">'Email'</span>, dataIndex: <span class="str">'Email'</span>, flex: 1 }
    ]
});</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 our controller (app/controller/Users.js) we have the working code that actually does the editing and updating of the record.&#160; the code is below:</p>
<pre class="csharpcode">Ext.define(<span class="str">'AM.controller.Users'</span>, {
    extend: <span class="str">'Ext.app.Controller'</span>,
    stores: [<span class="str">'Users'</span>],
    models: [<span class="str">'User'</span>],
    views: [<span class="str">'user.Edit'</span>, <span class="str">'user.List'</span>],
    refs: [
        {
            <span class="kwrd">ref</span>: <span class="str">'usersPanel'</span>,
            selector: <span class="str">'panel'</span>
        }
    ],
    init: <span class="kwrd">function</span>() {
        <span class="kwrd">this</span>.control({
            <span class="str">'viewport &gt; userlist dataview'</span>: {
                itemdblclick: <span class="kwrd">this</span>.editUser
            },
            <span class="str">'useredit button[action=save]'</span>: {
                click: <span class="kwrd">this</span>.updateUser
            }
        });
    },
    editUser: <span class="kwrd">function</span>(grid, record) {
        <span class="kwrd">var</span> edit = Ext.create(<span class="str">'AM.view.user.Edit'</span>).show();

        edit.down(<span class="str">'form'</span>).loadRecord(record);
    },
    updateUser: <span class="kwrd">function</span>(button) {
        <span class="kwrd">var</span> win    = button.up(<span class="str">'window'</span>),
            form   = win.down(<span class="str">'form'</span>),
            record = form.getRecord(),
            values = form.getValues();
        record.set(values);
        win.close();
        <span class="kwrd">this</span>.getUsersStore().sync();
    }
});</pre>
<p>Basically, this follows the exact same method we described above for implementing the CRUD.&#160; Note getUsersStore().sync.&#160; This does the same thing as shown above to force the appropriate call the back end.</p>
<p>&#160;</p>
<h2>Remarks</h2>
<p>Hope this helps give you a little more understanding into updating with the ExtJS library. If you are looking for the source, it’s in part 1 of this series.</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>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Sencha Architect and Previewing a JSON feed For Inclusion In The App</title>
		<link>http://peterkellner.net/2012/04/20/using-sencha-architect-and-previewing-a-json-feed-for-inclusion-in-the-app/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-sencha-architect-and-previewing-a-json-feed-for-inclusion-in-the-app</link>
		<comments>http://peterkellner.net/2012/04/20/using-sencha-architect-and-previewing-a-json-feed-for-inclusion-in-the-app/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 15:52:51 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[Sencha Architect 2]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1971</guid>
		<description><![CDATA[I’ve been on the beta testers for the new version of Sencha Architect (formerly Sencha Designer) for the past few months and have really enjoyed learning it and it’s features (both old and new).&#160; Much of the app is very discoverable (meaning you don’t really need directions to figure something out), however there are some [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been on the beta testers for the new version of <a href="http://www.sencha.com/products/architect">Sencha Architect</a> (formerly Sencha Designer) for the past few months and have really enjoyed learning it and it’s features (both old and new).&#160; Much of the app is very discoverable (meaning you don’t really need directions to figure something out), however there are some parts that are quite hidden or not obvious.&#160; On of these is previewing a <a href="http://json.org/">JSON</a>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:08b7f6ed-c464-4887-868d-29d374167a98" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">Technorati Tags: <a href="http://technorati.com/tags/Sencha+Architect" rel="tag">Sencha Architect</a>,<a href="http://technorati.com/tags/Sencha" rel="tag">Sencha</a>,<a href="http://technorati.com/tags/JavaScript+Designer" rel="tag">JavaScript Designer</a></div>
<p>  feed that you will hook up to either a model or store.&#160; In this post, I’m going to show the steps to do that.&#160; I’m now hooked on it.</p>
<p>I’m using the “Contact&quot;s” example provided for download by <a href="http://www.sencha.com/">Sencha</a>.&#160; Notice that when you load the project, assuming you have your Project URL’s setup correctly (Preferences), the store is automatically loaded.&#160; </p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image11.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_thumb9.png" width="360" height="322" /></a></p>
<p>&#160;</p>
<p>If the store does not automatically load, you can right mouse button on the store and choose “Load Data” as shown in the picture below.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/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/04/image_thumb10.png" width="320" height="124" /></a></p>
<p>&#160;</p>
<p>This will refresh your JSON feed and show the new data.&#160; Finally, to preview the JSON feed itself, click on the icon of an eye as shown in the first picture.&#160; This is the “Preview Feed” command.&#160; When you do that, you will see the following:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/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/04/image_thumb11.png" width="496" height="420" /></a></p>
<p>&#160;</p>
<p>I’m hoping Sencha takes the next step and gives us an option to “Auto Field” this data and simply create fields for every field in a record. That would complement the “Auto Column” feature (for another post) in the GridPanel Sencha Architect Design window.</p>
<p>&#160;</p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/20/using-sencha-architect-and-previewing-a-json-feed-for-inclusion-in-the-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Values In a Form Using the Sencha Architect 2.0 (ExtJS 4.0)</title>
		<link>http://peterkellner.net/2012/04/17/setting-values-in-a-form-using-the-sencha-architect-2-0-extjs-4-0/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-values-in-a-form-using-the-sencha-architect-2-0-extjs-4-0</link>
		<comments>http://peterkellner.net/2012/04/17/setting-values-in-a-form-using-the-sencha-architect-2-0-extjs-4-0/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 00:01:50 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[Sencha Architect 2]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/04/17/setting-values-in-a-form-using-the-sencha-architect-2-0-extjs-4-0/</guid>
		<description><![CDATA[Let’s say you want to make a simple modal window that appears when you double click on a row in a Sencha Grid Panel.&#160; Let’s assume you have the panel created and in the double click event you need to put some code.&#160; You want that code to pass in some values to the window, [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s say you want to make a simple modal window that appears when you <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel-event-itemdblclick">double click</a> on a row in a <a href="http://www.sencha.com/">Sencha</a> <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel">Grid Panel</a>.&#160; Let’s assume you have the panel created and in the double click event you need to put some code.&#160; You want that code to pass in some values to the <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.window.Window">window</a>, then have the window pop up and look something like this:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image7.png"><img title="image" style="display: inline" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb5.png" width="354" height="225" /></a></p>
<p>&#160;</p>
<p>We know we need to create a <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel">form panel</a>, but first, let’s code the double click event in the grid that brings it up.&#160; To do this, we add the DoubleClick event to the Grid Panel and then, using the “record” passed in, we pass that to our new Windows we are about to create.&#160; below is some code I wrote to do this (3 lines).</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image8.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_thumb6.png" width="567" height="201" /></a></p>
<p>&#160;</p>
<p>Next, let’s go into designer and make a simple form that is basically a top level window that has a form panel as a client, then the form panel has a <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.FieldSet">fieldset</a>, and that fieldset has 3 <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text">textfields</a>.&#160; Very straight forward and what you end up getting from SA (<a href="http://www.sencha.com/products/architect">Sencha Architect</a>) looks like the following.&#160; I won’t go through the drag and drops to make it, but it is pretty straight forward.&#160; It took me about 30 seconds.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image9.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_thumb7.png" width="462" height="243" /></a></p>
<p>&#160;</p>
<p>The code it created looks like the following (which also contains the load event I entered myself and is pictured separately below it.</p>
<pre class="csharpcode">Ext.define(<span class="str">'MyApp.view.AddressUpdateWindow'</span>, {
    extend: <span class="str">'Ext.window.Window'</span>,

    height: 250,
    width: 400,
    title: <span class="str">'Address Book Update'</span>,

    initComponent: <span class="kwrd">function</span>() {
        <span class="kwrd">var</span> me = <span class="kwrd">this</span>;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: <span class="str">'form'</span>,
                    bodyPadding: 10,
                    items: [
                        {
                            xtype: <span class="str">'fieldset'</span>,
                            title: <span class="str">'My Fields'</span>,
                            items: [
                                {
                                    xtype: <span class="str">'textfield'</span>,
                                    name: <span class="str">'City'</span>,
                                    fieldLabel: <span class="str">'City'</span>,
                                    anchor: <span class="str">'100%'</span>
                                },
                                {
                                    xtype: <span class="str">'textfield'</span>,
                                    name: <span class="str">'State'</span>,
                                    fieldLabel: <span class="str">'State'</span>,
                                    anchor: <span class="str">'100%'</span>
                                },
                                {
                                    xtype: <span class="str">'textfield'</span>,
                                    name: <span class="str">'Zip'</span>,
                                    fieldLabel: <span class="str">'Zip'</span>,
                                    anchor: <span class="str">'100%'</span>
                                }
                            ]
                        }
                    ],
                    listeners: {
                        afterrender: {
                            fn: me.onFormAfterRender,
                            scope: me
                        }
                    }
                }
            ],
            dockedItems: [
                {
                    xtype: <span class="str">'toolbar'</span>,
                    dock: <span class="str">'bottom'</span>,
                    items: [
                        {
                            xtype: <span class="str">'button'</span>,
                            handler: <span class="kwrd">function</span>(button, <span class="kwrd">event</span>) {
                                debugger;
                            },
                            text: <span class="str">'Save'</span>
                        }
                    ]
                }
            ]
        });

        me.callParent(arguments);
    },

    onFormAfterRender: <span class="kwrd">function</span>(abstractcomponent, options) {

        <span class="kwrd">var</span> recordData =
        abstractcomponent.up().recordData;

        abstractcomponent.getForm().setValues(
        recordData
        );

        <span class="rem">//abstractcomponent.getForm().setValues({</span>
        <span class="rem">//    City: recordData.City,</span>
        <span class="rem">//    State: recordData.State,</span>
        <span class="rem">//    Zip: recordData.Zip</span>
        <span class="rem">//});</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>
<p>Below is the code I wrote which you can see incorporated in the code above.&#160; Notice the lines I commented out.&#160; I just did this to show what is really happening, but I condensed it a little in my real JavaScript.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image10.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_thumb8.png" width="569" height="312" /></a></p>
<p>&#160;</p>
<p>So basically, that’s it.&#160; We created a double click event in a grid panel and from that we opened a pop up form and populated it with data.&#160; Very straight forward.</p>
<p>HTH’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/17/setting-values-in-a-form-using-the-sencha-architect-2-0-extjs-4-0/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>INETA Speaker Gig Last Night at Fresno&#8217;s Central California .Net User Group on Windows 8 JavaScript/HTML5/CSS3 Development</title>
		<link>http://peterkellner.net/2012/04/12/ineta-speaker-gig-last-night-at-fresnos-central-california-net-user-group-on-windows-8-javascripthtml5css3-development/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ineta-speaker-gig-last-night-at-fresnos-central-california-net-user-group-on-windows-8-javascripthtml5css3-development</link>
		<comments>http://peterkellner.net/2012/04/12/ineta-speaker-gig-last-night-at-fresnos-central-california-net-user-group-on-windows-8-javascripthtml5css3-development/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 20:41:25 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows 8 Metro]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/04/12/ineta-speaker-gig-last-night-at-fresnos-central-california-net-user-group-on-windows-8-javascripthtml5css3-development/</guid>
		<description><![CDATA[Let me start by saying three words. “CRASH AND BURN”.&#160; Well, I guess that makes it sound much worse than it really was, however I have to say that I don’t enjoy when create a brand new project, press “Run” and it crashes with a funky license error.&#160; Especially when I’ve come from out of [...]]]></description>
			<content:encoded><![CDATA[<p>Let me start by saying three words. “<strong>CRASH AND BURN</strong>”.&#160; Well, I guess that makes it sound much worse than it really was, however I have to say that I don’t enjoy when create a brand new project, press “Run” and it crashes with a funky license error.&#160; Especially when I’ve come from out of town as an <a href="http://www.ineta.org/">INETA</a> speaker to talk about developing in <a href="http://windows.microsoft.com/en-US/windows-8/consumer-preview">Windows 8</a> with <a href="http://en.wikipedia.org/wiki/HTML5">HTML5</a> / <a href="http://en.wikipedia.org/wiki/CSS3">CSS3</a> and <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> to the <a href="http://www.centralcaldotnet.com/">Central California .Net Users Group</a>.&#160; People have high expectations!&#160; I had done about 10 practice run through on the <a href="http://amtrak.com/">AmTrak</a> train on the way to Fresno and no time did I have an issue.&#160; First time in the actual meeting and the demo gods struck!&#160; Here is the screen I was greeted with:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image6.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_thumb4.png" width="411" height="262" /></a></p>
<p>Or, for the jpg-challenged:</p>
<blockquote><p>Error&#160;&#160;&#160; 2&#160;&#160;&#160; 0xC0020012 : While preparing to install the b5d701c0-28f8-415e-a986-ebae057cc7c5_1.0.0.0_neutral__tp1tpcm9wdwpy package, the system failed to register the windows.licensing extension due to the following error: &lt;Error message string not found&gt;.&#160;&#160;&#160; Application5</p>
</blockquote>
<p></p>
<p>I still don’t know what caused this, but I’m sure I’ll find out.&#160; This is my third time doing this presentation and usually that means there will be a fourth.&#160;&#160; For those that don’t know what I did, basically, I built a Silicon Valley Code Camp Speaker Viewer.&#160; Below is a picture of that running on my Samsung Build Tablet as well as my introduction to the session PowerPoint slide.</p>
<p>Let’s home next time goes smoother.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/2012-04-11-18.25.191.jpg"><img title="2012-04-11 18.25.19" 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="2012-04-11 18.25.19" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/2012-04-11-18.25.19_thumb1.jpg" width="501" height="393" /></a></p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/2012-04-11-18.16.37.jpg"><img title="2012-04-11 18.16.37" 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="2012-04-11 18.16.37" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/2012-04-11-18.16.37_thumb.jpg" width="244" height="184" /></a></p>
<p>&#160;</p>
<p>For those that are interested, here is my PowerPoint slides and my <a href="http://www.microsoft.com/visualstudio/11/en-us">Visual Studio 2011</a> <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211385.aspx">Metro HTML5/CSS3/JavaScript</a> Project.</p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:7b98b60f-35c9-4a34-8978-e6cf4565eb04" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
<p>Download VS2011 Solution: <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/Win8MetroSessionInfo1.zip" target="_blank">Windows 8 Metro VS 2011 Solution Zipped</a></p>
</div>
<p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:555f7713-9fc6-4918-8e14-9397df1a048d" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
<p>PowerPoint Slides <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/win8baynet1.pptx" target="_blank">SessionInfo.pps</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/12/ineta-speaker-gig-last-night-at-fresnos-central-california-net-user-group-on-windows-8-javascripthtml5css3-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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>Gaining Some Control Back From Microsoft&#8217;s Entity Framework Code First, Name Your Own Foreign Keys!</title>
		<link>http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys</link>
		<comments>http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 01:32:18 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/</guid>
		<description><![CDATA[Being a relative newbie to Microsoft’s Entity Framework Code First, there are things that I don’t like, things that I don’t understand, and well, just things that really bug me.&#160; The problem is I often find out that the things that I don’t like and bug me are often lack of knowledge and not lack [...]]]></description>
			<content:encoded><![CDATA[<p>Being a relative newbie to <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft’s</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/hh134698">Code First</a>, there are things that I don’t like, things that I don’t understand, and well, just things that really bug me.&#160; The problem is I often find out that the things that I don’t like and bug me are often lack of knowledge and not lack of product (at least not easily discoverable in the product).&#160; One of those things is that Code First makes up names for foreign keys that don’t happen to be the same name as I would use.&#160; Since there are times when you will need to look at these names (and possibly code with them (for another post)), I would like those names to be my names.</p>
<p>Let’s say you have a simple relationship between two tables.&#160; Let’s call it User and Address.&#160; Let’s just say for simplicity a user has one address.&#160; In CodeFirst, you would model it with tables like the following:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> User
{
        [Key]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Address Address { get; set; }
       <span class="rem">// more details about user, name, etc.</span>
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Address
{
       [Key]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> City {get;set;}
        <span class="rem">// more details about address, state,zip,etc.</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>
<p>Now, you will end up with an Address table that has a column named something like User_Id.&#160;&#160; YUC!!!&#160; Who puts underscores in column names anymore (well, certainly I don’t.</p>
<p>You may think all you need to do to solve this is put a foreign key column and attribute in the Address table as follows:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Address
{
     [Key]
     <span class="kwrd">public</span> <span class="kwrd">long</span> Id {get;set;}

     [ForeignKey]
     <span class="kwrd">public</span> <span class="kwrd">long</span> UserId {get;set;}

     <span class="kwrd">public</span> <span class="kwrd">string</span> City {get;set;}
}</pre>
<p>But, when you do that, you will be greeted with an error that looks like the following:</p>
<blockquote>
<h4><i>System.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role &#8216;EmailAccount_User_Source&#8217; in relationship &#8216;EmailAccount_User&#8217;. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be &#8216;*&#8217;.</i></h4>
</blockquote>
<p>or</p>
<blockquote>
<h4><i>The ForeignKeyAttribute on property &#8216;UserId&#8217; on type &#8216;EFCodeFirstLib.CodeFirstModels.EmailAccount&#8217; is not valid. The navigation property &#8216;User&#8217; was not found on the dependent type &#8216;EFCodeFirstLib.CodeFirstModels.EmailAccount&#8217;. The Name value should be a valid navigation property name.</i></h4>
</blockquote>
<p>&#160;</p>
<p>Pretty clear what to do, huh?</p>
<p>Well, I suppose if you know EF EDMX and a whole bunch of other acronyms, you probably will figure it out, but if you don’t I’ll tell you.&#160; You basically need to include the User property in your Address class.&#160; It should then look like:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Address
{
  [Key]
  <span class="kwrd">public</span> <span class="kwrd">long</span> Id {get;set}

  <span class="kwrd">public</span> User User {get;set;}  <span class="rem">// important!</span>
  [ForeignKey]
  <span class="kwrd">public</span> <span class="kwrd">long</span> UserId {get;set;}

  <span class="kwrd">public</span> <span class="kwrd">string</span> City {get;set;}
}</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 now, you will have a “properly” named foreign key column “UserId” with no underscores!</p>
<p>My 2Cents.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework CodeFirst Important Tip For SQL Execution Efficiency</title>
		<link>http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entity-framework-codefirst-important-tip-for-sql-execution-efficiency</link>
		<comments>http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 18:24:27 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/</guid>
		<description><![CDATA[&#160;
Introduction
&#160;
I’ve now been using Microsoft’s&#160;Entity Framework CodeFirst for a month or two and am very impressed with how easily it is to access data in a type safe way.&#160; I also have noticed that I need to be extra careful about how I form my LINQ or I can accidentally cause the Sql Server to [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>&#160;</p>
<p>I’ve now been using <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft’s</a>&#160;<a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx">Entity Framework</a> <a href="http://blogs.msdn.com/b/adonet/archive/tags/code+first/">CodeFirst</a> for a month or two and am very impressed with how easily it is to access data in a type safe way.&#160; I also have noticed that I need to be extra careful about how I form my LINQ or I can accidentally cause the <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">Sql Server</a> to do tons of extra work (tons meaning lots, not actually tons).</p>
<p>I’ll basically explain this with actual code snippets to demonstrate my point and help you understand what I’m talking about. Let’s say you have a set of classes representing your model that basically have a master record and an associated detail record that contains an reference to a table that hold images.&#160; That is, basically, something like this:</p>
<p>&#160;</p>
<pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">class</span> User
    {
        [Key]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> FirstName { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> ICollection&lt;AddressBookEntry&gt;
                        AddressBookEntries { get; set; }
     }

 <span class="kwrd">public</span> <span class="kwrd">class</span>    AddressBookEntry
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> ImageDetail ImageDetail { get; set; }
    }

<span class="kwrd">public</span> <span class="kwrd">class</span> ImageDetail
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }

        [Required(ErrorMessage = <span class="str">&quot;Image Without Data Means Nothing&quot;</span>)]
        [Column(TypeName = <span class="str">&quot;image&quot;</span>)]
        <span class="kwrd">public</span> <span class="kwrd">byte</span>[] ImageDataBytes { get; set; }
    }</pre>
<h2>The Goal For Your Query</h2>
<p>The goal for your <a href="http://msdn.microsoft.com/en-us/data/aa937723">EF</a> query is you want to create a simple image viewer web page.&#160; That is, you want to get the following information from your query that will list the address book of a given person.&#160; The columns you want back for each address book entry (of a given user) are as follows:</p>
<ul>
<ul>
<li>AddressBookEntry.Id</li>
<li>ImageDetail.Id</li>
</ul>
</ul>
<p>You don’t actually want the blob data itself because you will let the html img tag actually get the data for you.</p>
<p>&#160;</p>
<h2>The Wrong Way</h2>
<p>You are probably tempted to write a query that looks something like this:</p>
<pre class="csharpcode">var userAccount =
       db.Users.Where(a =&gt; a.Id == userIdIWant).
               Include(p =&gt; p.addressBookEntries.Select(o =&gt; o.ImageDetail).
                            FirstOrDefault();</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>The problem with this is if you have 4MB image in your ImageDetail table, it will all come down when you materialize your query.</p>
<p>&#160;</p>
<p>&#160;</p>
<h2>The Right Way</h2>
<p>&#160;</p>
<p>The correct way is to create a resulting anonymous object something like this:</p>
<pre class="csharpcode">var userAccount =
      db.Users.Where(a =&gt; a.Id == userIdIWantd).
              Include(p =&gt; AddressBookEntries.Select(o =&gt; o.ImageDetails).Select(p=&gt;<span class="kwrd">new</span> {
                 p.Id,
                 p.ImageDetails.Id
              }));</pre>
<p>&#160;</p>
<h2>Conclusions</h2>
<p>&#160;</p>
<p>Sorry if the syntax here is not perfect.&#160; I did not actually use these tables, my problem is a little different, but I just wanted to get my point across about how important making anonymous (or staticly typed) result sets are for performance and how easily you can make code that will kill the performance of your server.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why Windows 8 Should Not Abandon the START button</title>
		<link>http://peterkellner.net/2012/03/27/why-windows-8-should-not-abandon-the-start-button/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-windows-8-should-not-abandon-the-start-button</link>
		<comments>http://peterkellner.net/2012/03/27/why-windows-8-should-not-abandon-the-start-button/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 14:45:42 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows 8 Metro]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/27/why-windows-8-should-not-abandon-the-start-button/</guid>
		<description><![CDATA[I don’t often post my opinions on contention issues, however I think in this case, it is more than necessary and appropriate.&#160; Unlike most people who have been publishing there opinions lately, I’ve actually been using Windows 8 as my primary operating system now since February 29th when the latest preview was released.&#160; I’ve been [...]]]></description>
			<content:encoded><![CDATA[<p>I don’t often post my opinions on contention issues, however I think in this case, it is more than necessary and appropriate.&#160; Unlike <a href="http://www.bing.com/news/search?q=start+button+windows+8&amp;qpvt=start+button+windows+8&amp;FORM=EWRE">most people</a> who have been publishing there opinions lately, I’ve actually been using <a href="http://windows.microsoft.com/en-US/windows-8/consumer-preview">Windows 8</a> as my primary operating system now since February 29th when the latest preview was released.&#160; I’ve been to the <a href="http://www.buildwindows.com/">BUILD</a> conference, I’ve watched many of the videos and to a reasonable degree, my opinion is validated with real experience.</p>
<p>Those in favor of eliminating the <a href="http://www.bing.com/news/search?q=start+button+windows+8&amp;qpvt=start+button+windows+8&amp;FORM=EWRE">start button</a> simply say Metro is simply the equivalent of the start button and you should use it the same way.&#160; I could not disagree more.&#160; When you are running in Metro the apps look different, you task switch them differently, just everything about them is different.&#160; To those that say you don’t need a start button, I would say then you should say just as much you don’t need a desktop either.</p>
<p>To Microsoft I say you should give people these two choices (or give them both on the same machine is fine with me also, but don’t mix them up).</p>
<blockquote><p><strong><font size="4">1.&#160; Desktop With Start button</font></strong></p>
<p><strong><font size="4">2.&#160; Metro With No Desktop App</font></strong></p>
</blockquote>
<p>These are clearly two separate worlds.&#160; Microsoft, please, don’t make us run them both at the same time.&#160; If I want to run my Windows 8 tablet, I’m 100% happy having Metro&#160; as the only OS.&#160; The start button gives a really miserable experience on a touch device.&#160; Likewise, if I’m on my desktop, please let me avoid Metro and just use the desktop complete with the start button which does work well.&#160; The flashing back and forth to metro is very disconcerting.&#160; As a workaround, I’ve been slowly adding everything I use to my start bar which seems kind of silly.</p>
<p>My 2 cents</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/27/why-windows-8-should-not-abandon-the-start-button/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building a Simple Window Service Application in Visual Studio 2010 That Runs, Sleeps and Stops</title>
		<link>http://peterkellner.net/2012/03/26/building-a-simple-window-service-application-in-visual-studio-2010-that-runs-sleeps-and-stops/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=building-a-simple-window-service-application-in-visual-studio-2010-that-runs-sleeps-and-stops</link>
		<comments>http://peterkellner.net/2012/03/26/building-a-simple-window-service-application-in-visual-studio-2010-that-runs-sleeps-and-stops/#comments</comments>
		<pubDate>Mon, 26 Mar 2012 18:24:46 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/26/building-a-simple-window-service-application-in-visual-studio-2010-that-runs-sleeps-and-stops/</guid>
		<description><![CDATA[Introduction
The goal is to create a simple Service in Windows 7 (or other similar OS’s) with Visual Studio 2010 that simply starts, sleeps for 15 seconds, then stops.&#160; I realize this is not that useful, but basically, it covers the case of building a service that actually does something and when finished stops.&#160; In my [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>The goal is to create a simple <a href="http://en.wikipedia.org/wiki/Windows_service">Service</a> in <a href="http://windows.microsoft.com/en-us/windows7/products/home">Windows 7</a> (or other similar OS’s) with <a href="http://www.microsoft.com/visualstudio/en-us">Visual Studio 2010</a> that simply starts, sleeps for 15 seconds, then stops.&#160; I realize this is not that useful, but basically, it covers the case of building a service that actually does something and when finished stops.&#160; In my personal case, my thread has a while(true) loop which keeps looking for new work and only completes when certain conditions are met (like a fatal error that is non recoverable).</p>
<p>Microsoft has given us a pretty good set of docs and walk through.&#160; You can find them all here:&#160; <a href="http://msdn.microsoft.com/en-us/library/y817hyb6.aspx">http://msdn.microsoft.com/en-us/library/y817hyb6.aspx</a></p>
<p>&#160;</p>
<h2>The Steps</h2>
<p>Create a new Visual Studio Project of type <a href="http://en.wikipedia.org/wiki/Windows_service">“Windows Service”</a></p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image16.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb15.png" width="383" height="299" /></a></p>
<p>Once the project is created, make sure you have the design surface up for Service1 [Design] and right click on it and say “Add Installer”.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image17.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb16.png" width="458" height="189" /></a></p>
<p>Now, you’ll get to “gear” icons that you can set properties for.&#160; They are “serviceProcessInstaller1” and “serviceInstaller1” as follows:</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image18.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb17.png" width="410" height="283" /></a></p>
<p>Select “serviceProcessInstaller1” and in it’s properties window change the account to “LocalSystem”.&#160; You should have a screen that looks like the following:</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image19.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb18.png" width="329" height="227" /></a></p>
<p>Then, on the other gear “serviceInstaller”, change the nanes as follows.&#160; I’m naming my service “MyDoNothingService”.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image20.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb19.png" width="415" height="338" /></a></p>
<p>Now, rebuild your project and you’ll get an exe file in your /bin/Debug folder.&#160; Open that folder with the Visual Studio Command Prompt (elevated as admin).&#160; To install the service, enter the command:</p>
<p><strong>InstallUtil WindowsServiceCreateSample.exe</strong></p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image21.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb20.png" width="603" height="79" /></a></p>
<p>You should get some messages that end with “The Commit phase completed successfully”, then “The Transaction install has completed”.</p>
<p>Now, you should see that you have the service in your services panel (you can get there by going to control panel / Administrative / Services or simple run “services” from your start button.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image22.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb21.png" width="390" height="142" /></a></p>
<p>(sorry for the rename here to MyServiceTest, but I got distracted and had to come back and rename the project)</p>
<p>So, now we want to add something to this project.&#160; Let’s just add to the OnStart event of Service1.cs something that starts a thread that sleeps for 15 seconds, then stops the thread.&#160; Very simple code as follows:</p>
<pre class="csharpcode">  <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnStart(<span class="kwrd">string</span>[] args)
        {
            <span class="kwrd">new</span> Thread(()
                      =&gt;
            {
                Thread.Sleep(15000); <span class="rem">// sleep 15 seconds</span>
                <span class="kwrd">this</span>.Stop();
            }).Start();
        }</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, before we can install the service, we first need to uninstall it.&#160; Very easy, just add a /u to the end of your install command.</p>
<p><strong>InstallUtil WindowsServiceCreateSample.exe /u</strong></p>
<p>You should be greeted with “The uninstall has completed.”.</p>
<p>Now, when you try and reinstall, sadly, you might get this error: “<strong>Error 1001. The specified service has been marked for deletion”.&#160; </strong>If you do, thanks to a post by <a href="http://www.laxdal.org/node/30">Mr. Laxdel</a>, all you have to do is exit your services dialog and restart the service.</p>
<p>Assuming you left the default autoLog set to true as follows:</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image23.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/2012/03/image_thumb22.png" width="436" height="272" /></a></p>
<p>In your event viewer, you should see you service starting and stopping as follows:</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image24.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/2012/03/image_thumb23.png" width="593" height="193" /></a></p>
<p>&#160;</p>
<p>&#160;</p>
<h2>Conclusions</h2>
<p>That was pretty straight forward.&#160; Hopefully, you can follow along and generate the same thing yourself.&#160; Here is the source code attached for a visual studio 2010 project if for some reason you have trouble recreating it yourself.&#160; HTH’s!</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:2e502815-6df7-416f-bba2-da664c6304ef" class="wlWriterEditableSmartContent">
<p>Visual Studio 2010 Project <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/WindowsServiceCreateSample.zip" target="_blank">Project</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/26/building-a-simple-window-service-application-in-visual-studio-2010-that-runs-sleeps-and-stops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting In San Francisco 3/21/2012 (Wednesday): First Blood With Windows 8 Metro Programming in JavaScript and HTML5/CSS3</title>
		<link>http://peterkellner.net/2012/03/19/presenting-in-san-francisco-tomorrow-wednesday-first-blood-with-windows-8-metro-programming-in-javascript-and-html5css3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=presenting-in-san-francisco-tomorrow-wednesday-first-blood-with-windows-8-metro-programming-in-javascript-and-html5css3</link>
		<comments>http://peterkellner.net/2012/03/19/presenting-in-san-francisco-tomorrow-wednesday-first-blood-with-windows-8-metro-programming-in-javascript-and-html5css3/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 17:23:50 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows 8 Metro]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/19/presenting-in-san-francisco-tomorrow-wednesday-first-blood-with-windows-8-metro-programming-in-javascript-and-html5css3/</guid>
		<description><![CDATA[&#160;

&#160;
http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&#38;mid=49
Microsoft San Francisco Office     835 Market Street, Suite 700      San Francisco, CA 94103
Wednesday, March 21st, 6:30 PM to 9:00 PM   (Check-in begins at 6:00 PM)
Due to tightening of security rules at the Microsoft building, we cannot let people in without an escort. To make [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p><a href="http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&amp;mid=49"><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/image15.png" width="496" height="248" /></a></p>
<p>&#160;</p>
<p><a title="http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&amp;mid=49" href="http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&amp;mid=49">http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&amp;mid=49</a></p>
<p><strong>Microsoft San Francisco Office     <br />835 Market Street, Suite 700      <br />San Francisco, CA 94103</strong></p>
<p>Wednesday, March 21st, 6:30 PM to 9:00 PM   <br />(Check-in begins at 6:00 PM)</p>
<p>Due to tightening of security rules at the Microsoft building, we cannot let people in without an escort. To make sure you get in the meeting without trouble, please try to arrive before 6:30, and kindly ask the security guard to badge you in or call up for an escort.?Thanks for your help!</p>
<p>Pizza will be ordered so be sure to register before 10:30am on the day of the event.</p>
<p>Event registration: <a href="http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&amp;mid=49">http://baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=520&amp;mid=49</a></p>
<p>Event Description</p>
<p>Do you want to know what it would be like to build your first Windows 8 Metro App in HTML5/CSS3 with the BUILD bits distributed by Microsoft last year? Having just submitted an app to the windows 8 app store contest, I (Peter Kellner) will give you a guided tour of the steps I went through. This includes running the preview of Blend (HTML5 only), Visual Studio 2011 Preview, all the sample code Microsoft provides as well as the documentation you will run into if you try to do the same thing. Windows 8 Metro programming is going to be too big for any of us to ignore. If you want to get a jump start on this new way of programming windows programming, come to the presentation and hopefully, save yourself many hours of newby mistakes (like I made). Hope to see you there!</p>
<p>Presenters&#8217; Bio</p>
<p>Peter Kellner, a Microsoft ASP.NET MVP since 2007, is founder and president of ConnectionRoad, and a seasoned software professional specializing in high quality, scalable and extensible .Net web applications. His experience includes building and leading engineering teams both on and off shore. When not working, Peter spends most his free time biking. He has ridden his bike across the globe. Most recently he and his wife, Tammy, rode across the U.S., from California to Georgia, in just 27 days. You can find his blog at peterkellner.net, and follow him on Twitter @pkellner</p>
<p>Agenda</p>
<p>6:00 doors open (pizza and drinks)   <br />6:10 &#8211; 6:25 Lightning talks    <br />6:30 announcements    <br />6:45 &#8211; 8:15 presentation    <br />8:15 &#8211; 8:30 raffle    <br />This event is sponsored by JetBrains and PluralSight.</p>
<p>Bay.NET is a California Nonprofit Corporation operated entirely by volunteers and we are proud of our service to the .NET community of the greater San Francisco Bay Area. We regularly provide world-class speakers at no cost to our members. We offer a full-day &quot;Education Day&quot; once every quarter for a nominal registration fee.</p>
<p>You received this message because you signed up to receive announcements from the Bay.NET User Group.</p>
<p>If you are a member and no longer wish to receive e-mail from us, please login to the website at <a href="http://www.baynetug.org/">http://www.baynetug.org/</a> and go to the Edit User Profile link (in the upper right of the home page). The profile allows you to make changes in your Bay.NET membership record including your email preferences. If you are unable to login or if you feel you received this announcement in error please send an email to webmaster@baynetug.org with the details of the problem.&#160; Please send your message from the same address that this email was sent to.</p>
<p>Bay.NET is committed to respecting your privacy. For specific guidelines, read Bay.NET&#8217;s privacy policy.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/19/presenting-in-san-francisco-tomorrow-wednesday-first-blood-with-windows-8-metro-programming-in-javascript-and-html5css3/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>How To Setup Your Own Pop3/IMAP Email Server for Local Development Testing</title>
		<link>http://peterkellner.net/2012/03/11/how-to-setup-your-own-pop3imap-email-server-for-local-development-testing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-setup-your-own-pop3imap-email-server-for-local-development-testing</link>
		<comments>http://peterkellner.net/2012/03/11/how-to-setup-your-own-pop3imap-email-server-for-local-development-testing/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 18:47:39 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[imap]]></category>
		<category><![CDATA[Mail Server]]></category>
		<category><![CDATA[POP3]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/11/how-to-setup-your-own-pop3imap-email-server-for-local-development-testing/</guid>
		<description><![CDATA[For the past few months, I’ve been working on building an HTML5 email web client.&#160; It’s fundamentally server based for gathering email.&#160; That means, when I test, I need to connect my server software to both POP3 and IMAP servers.&#160; I’ve been abusing public email services (names not mentioned) and it has made life a [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few months, I’ve been working on building an <a href="http://en.wikipedia.org/wiki/HTML5">HTML5</a> email web client.&#160; It’s fundamentally server based for gathering email.&#160; That means, when I test, I need to connect my server software to both <a href="http://en.wikipedia.org/wiki/Post_Office_Protocol">POP3</a> and <a href="http://en.wikipedia.org/wiki/Internet_Message_Access_Protocol">IMAP</a> <a href="http://en.wikipedia.org/wiki/Message_transfer_agent">servers</a>.&#160; I’ve been abusing public email services (names not mentioned) and it has made life a little difficult.&#160; That is also not to mention that I often program away from my office which means I pay hotspot charges that can really mount up quickly.</p>
<p>So, I spent a couple hours this morning setting up a local POP3/IMAP mail server on my windows 7 (OK, actually Windows 8 Preview but the process is the same). </p>
<p>&#160;</p>
<h2>
<p>Install HMailServer</p>
</h2>
<p>Download and install the latest from <a href="http://www.hmailserver.com/index.php?page=download">http://www.hmailserver.com/index.php?page=download</a> (I used V5.4)</p>
<p>Add an entry in your c:\windows\system32\drivers\etc\hosts for your local mail server (127.0.0.1&#160; mail.local)</p>
<p>In hMailServer admin, add a domain called mail.local and make sure it is enabled</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image2.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb2.png" width="244" height="99" /></a></p>
<p>Add some test accounts to hMailServer</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image3.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb3.png" width="244" height="200" /></a></p>
<p>In settings, make sure to enable SMTP,POP3 and IMAP</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image4.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb4.png" width="244" height="137" /></a></p>
<p>On Advanced, put in your default domain</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image5.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb5.png" width="244" height="161" /></a></p>
<p>In advanced smtp make sure to bind to 127.0.0.1</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image6.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb6.png" width="244" height="112" /></a></p>
<p>In Advanced / IP Ranges Put in just your localhost range</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image7.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb7.png" width="244" height="144" /></a></p>
<p>Disable auto-ban in Advanced</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image8.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb8.png" width="244" height="182" /></a></p>
<p>&#160;</p>
<h2>Install Mozilla Thunderbird Email Client</h2>
<p>You need a local client to test with. You can use outlook, or in my case, I used Mozilla’s Thunderbird Email Client.&#160; You can download it from <a href="http://www.mozilla.org/en-US/thunderbird/">http://www.mozilla.org/en-US/thunderbird/</a>.</p>
<p>Simply install and go into account setup and put in your test email (in my case, <a href="mailto:test2@mail.local">test2@mail.local</a>, server mail.local)</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image9.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb9.png" width="244" height="190" /></a></p>
<p>By default, it puts .mail.local into the domain names.&#160; Simply get rid of the leading period for both smtp and pop3 as follows. Push re-test and you will show successful.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image10.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 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_thumb10.png" width="244" height="160" /></a></p>
<p>You can now send and receive mail locally in your mozilla thunderbird email client (or any other email client you install locally)</p>
<p>&#160;</p>
<p>That’s it!&#160; You’ve setup your own mail server that only listens on your localhost port.&#160; You may need to disable your firewall for local connections.&#160; I’m not sure if that is necessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/11/how-to-setup-your-own-pop3imap-email-server-for-local-development-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Built In App Launcher in Windows 8 Consumer</title>
		<link>http://peterkellner.net/2012/03/09/built-in-app-launcher-in-windows-8-consumer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=built-in-app-launcher-in-windows-8-consumer</link>
		<comments>http://peterkellner.net/2012/03/09/built-in-app-launcher-in-windows-8-consumer/#comments</comments>
		<pubDate>Fri, 09 Mar 2012 17:52:23 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows 8 Metro]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/09/built-in-app-launcher-in-windows-8-consumer/</guid>
		<description><![CDATA[There has been multiple posts on then net in the last few days about how to get your start button back when using the latest Windows 8 Consumer preview from Microsoft (release last week). I have to say that initially I wanted it back also but I’m getting very use to not having it.&#160; This [...]]]></description>
			<content:encoded><![CDATA[<p>There has been <a href="http://www.pcworld.com/businesscenter/article/251518/free_tool_restores_start_button_to_windows_8.html" target="_blank">multiple posts</a> on then net in the last few days about how to get your <a href="http://www.guardian.co.uk/technology/blog/2012/mar/09/technology-links-newsbucket" target="_blank">start button back</a> when using the latest <a href="http://windows.microsoft.com/en-US/windows-8/consumer-preview" target="_blank">Windows 8 Consumer preview</a> from Microsoft (release last week). I have to say that initially I wanted it back also but I’m getting very use to not having it.&#160; This morning, I accidentally found an option that gives me a lot of what I was missing from the start button.&#160; Specifically, a listing of all my installed apps without having to either search through the metro interface to find them (by lots of scrolling) or knowing what it is called and just typing it once the metro interface is running.</p>
<p>All you have to do is first, bring the metro interface up by either moving your mouse to the lower left corner of the screen, pressing the windows button, or pressing the tablet button bottom center.&#160; Then, type a single letter indicating you want to search for something, then press the backspace key.&#160; you get the screen below with a nicely organized list of apps.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image1.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/2012/03/image_thumb1.png" width="559" height="378" /></a></p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/09/built-in-app-launcher-in-windows-8-consumer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Developing With Visual Studio 2011 and the Windows 8 Consumer Build With Metro and Two (multiple) Monitors</title>
		<link>http://peterkellner.net/2012/03/04/developing-with-visual-studio-2011-and-the-windows-8-consumer-build-with-metro-and-two-multiple-monitors/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=developing-with-visual-studio-2011-and-the-windows-8-consumer-build-with-metro-and-two-multiple-monitors</link>
		<comments>http://peterkellner.net/2012/03/04/developing-with-visual-studio-2011-and-the-windows-8-consumer-build-with-metro-and-two-multiple-monitors/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 02:27:19 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[VS2011]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows 8 Metro]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/04/developing-with-visual-studio-2011-and-the-windows-8-consumer-build-with-metro-and-two-multiple-monitors/</guid>
		<description><![CDATA[Wow, that’s a long title. Sorry, but I just wanted to be clear what you are getting into if you come here.&#160; In this article, I’m going to talk about what it takes in very simple terms to build and specifically debug a windows 8 metro application using the beta version of Visual Studio 2011.
Here [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, that’s a long title. Sorry, but I just wanted to be clear what you are getting into if you come here.&#160; In this article, I’m going to talk about what it takes in very simple terms to build and specifically debug a <a href="http://msdn.microsoft.com/en-us/windows/apps">windows 8</a> metro application using the beta version of Visual Studio 2011.</p>
<p>Here are the steps:</p>
<p>1.&#160; Install <a href="http://windows.microsoft.com/en-US/windows-8/download?ocid=W_MSC_W8P_DevCenter_MetroApps_EN-US">Windows 8 Metro</a> and <a href="http://www.microsoft.com/visualstudio/11/en-us">Visual Studio 2011 Beta</a></p>
<p>2.&#160; Using display settings (control panel / display) make the monitor that is not your desktop the primary monitor</p>
<p>3.&#160; Launch your desktop on the computer that is your primary monitor</p>
<p>4.&#160; Run Visual Studio 2011 Beta on your desktop</p>
<p>5.&#160; Create a <a href="http://en.wikipedia.org/wiki/Windows_8">Metro</a> style project</p>
<p>6.&#160; Run/Debug from inside Visual Studio</p>
<p>That’s it!&#160; The trick is that you want to be running visual studio from the monitor you are sitting in front of and NOT call that your main monitor.&#160; If you don’t do this, then metro comes up and covers up your Visual Studio session.</p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/04/developing-with-visual-studio-2011-and-the-windows-8-consumer-build-with-metro-and-two-multiple-monitors/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Phone Race For $100 at Windows Store With MVP John from Columbia</title>
		<link>http://peterkellner.net/2012/03/01/phone-race-for-100-at-windows-store-with-mvp-john-from-columbia/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=phone-race-for-100-at-windows-store-with-mvp-john-from-columbia</link>
		<comments>http://peterkellner.net/2012/03/01/phone-race-for-100-at-windows-store-with-mvp-john-from-columbia/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 20:59:51 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Microsoft Store]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/03/01/phone-race-for-100-at-windows-store-with-mvp-john-from-columbia/</guid>
		<description><![CDATA[&#160;
The Contest
Post a picture to facebook with your phone faster than RichartT (with not twitter account) with his windows phone at the Microsoft Store.
&#160;

&#160;
The Players
John (not Juan) @jbocachica&#160; from Columbia, Microsoft SqlServer MVP with his IPhone 
RichartT from the Microsoft store with his Windows Phone.
&#160;
The Event
&#160;
So, here we go.&#160; It seemed almost unfair to put [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>The Contest</h2>
<p>Post a picture to facebook with your phone faster than RichartT (with not twitter account) with his windows phone at the <a href="http://content.microsoftstore.com/store/detail/Bellevue-WA" target="_blank">Microsoft Store</a>.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/03/image_thumb.png" width="356" height="276" /></a></p>
<p>&#160;</p>
<h2>The Players</h2>
<p>John (not Juan) @<a href="http://twitter.com/jbocachica" target="_blank">jbocachica</a>&#160; from Columbia, Microsoft SqlServer MVP with his IPhone </p>
<p>RichartT from the Microsoft store with his Windows Phone.</p>
<p>&#160;</p>
<h2>The Event</h2>
<p>&#160;</p>
<p>So, here we go.&#160; It seemed almost unfair to put up a Microsoft store guy up against a seasoned MVP from Columbia, but hec, it’s a Microsoft contest so why not.&#160; If you watch the video carefully, you’ll see that it was basically a photo finish with the final judgement going to the house (I’m not exactly sure why).</p>
<p>Let me know who you think won in the comments.</p>
<p>&#160;</p>
<p> <iframe height="315" src="http://www.youtube.com/embed/WXSJixmBHXE?rel=0" frameborder="0" width="420" allowfullscreen="allowfullscreen"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/03/01/phone-race-for-100-at-windows-store-with-mvp-john-from-columbia/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Microsoft MVP Summit, GeekGive! (3rd year for me)</title>
		<link>http://peterkellner.net/2012/02/26/microsoft-mvp-summit-geekgive-3rd-year-for-me/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=microsoft-mvp-summit-geekgive-3rd-year-for-me</link>
		<comments>http://peterkellner.net/2012/02/26/microsoft-mvp-summit-geekgive-3rd-year-for-me/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 05:12:29 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Charity]]></category>
		<category><![CDATA[GeekGive]]></category>
		<category><![CDATA[Microsoft MVP Program]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/02/26/microsoft-mvp-summit-geekgive-3rd-year-for-me/</guid>
		<description><![CDATA[For the past two years, a day before the Microsoft MVP Summit a GeekGive has been organized where about 50 or so of us all go to some location and help with community building activities. Three years ago, it was building a house with Habitat for Humanity, Last year and this year its’ been in [...]]]></description>
			<content:encoded><![CDATA[<p>For the past two years, a day before the <a href="http://www.2012mvpsummit.com/">Microsoft MVP Summit</a> a <a href="http://geekgive.org/project/mvpsummit2012.aspx">GeekGive</a> has been organized where about 50 or so of us all go to some location and help with community building activities. Three years ago, it was <a href="http://www.youtube.com/watch?v=U2k165EFIr0">building a house with Habitat for Humanity</a>, <a href="http://geekgive.org/project/mvpsummit2011.aspx">Last year</a> and this year its’ been in Seattle Washington at the <a href="http://www.northwestharvest.org/">NorthWest Harvest</a> Facility where we packed thousands of bags of green beans last year and thousands of bags this year. </p>
<p>Here we all are at the end.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image15.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/2012/02/image_thumb14.png" width="731" height="337" /></a></p>
<p>&#160;</p>
<p>and, here I am celebrating packing our completion, Rocky style.(we packed over 7500 pounds of pin dried beans)</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image16.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/2012/02/image_thumb15.png" width="424" height="375" /></a></p>
<p>&#160;</p>
<p>* pictures courtesy of <a href="www.craigberntson.com/blog">Craig Berntson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/02/26/microsoft-mvp-summit-geekgive-3rd-year-for-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EntityFramework 4.3 CodeFirst Trivial One File Example &#8211; Part 1</title>
		<link>http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entityframework-4-3-codefirst-trivial-one-file-example-part-1</link>
		<comments>http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 18:47:26 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1841</guid>
		<description><![CDATA[&#160;
Introduction
This three part series demonstrates a very simple example of using Entity Framework Code First (Version 4.3) to create a SqlServer Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>This three part series demonstrates a very simple example of using <a href="http://www.asp.net/entity-framework">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">Code First</a> (<a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx">Version 4.3</a>) to create a <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part 3 adds a new column with a default value to a migration enabled code first project.</p>
<p>As it happens, I watched President Obama drive by me in San Francisco yesterday so he will be the star of the post.&#160; The table we will use is called Presidents, and the columns we will add are Year Elected and Current.&#160; We will obviously only have one current president so we will have to have our migration conditionally set CurrentPresident to true for Obama.</p>
<p>&#160;</p>
<p>&#160;</p>
<div>
<div style="float: right">
<p align="center"><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb2.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image_thumb4_thumb2" border="0" alt="image_thumb4_thumb2" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb2_thumb.png" width="244" height="176" /></a>         <br /><em>I need practice with my cell phone camera (obviously)</em>&#160; </p>
</p></div>
<div>
<table border="1" cellspacing="0" cellpadding="2" width="360">
<tbody>
<tr>
<td valign="top" width="224"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Part 1</a></strong></td>
<td valign="top" width="234"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Building a 1 File Console App That Creates a SqlServer Table and Populates it With Data</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Part 2</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Adding Two New Columns To the Customer Table and Populating Data Conditionally using New Migrations Feature (With Upgrade To Code Migrations from Project Without Code Migrations)</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Part 3</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Changing your CodeFirst DataModel with Migrations Enabled</a></strong></td>
</tr>
</tbody>
</table></div>
<div>&#160;</div>
<div>For those wanting the real code, the final visual studio solution after part 3, includes parts 1 and 2 information is here:&#160;
<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:1592ae0a-feab-473c-a58f-1002482b399d" class="wlWriterSmartContent">
<p><a href="file:///C:/Users/pkellner/AppData/Local/Temp/WindowsLiveWriter1286139640/supfiles11F36BE/ConApp[2].zip" target="_blank">VS Solution</a></p>
</p></div>
</p></div>
</p></div>
<div>&#160;</div>
<div>&#160;</div>
<h2>
<p>&#160;</p>
<p>What To Do</p>
</h2>
<div>We simply create a console version with Visual Studio 2010 in c#.&#160; Using nuget package manager console we say “Install-Package EntityFramework”, then replace the primary Program.cs with the following file (you should add a connection string with the name SiteDB also if you want it to create a SqlServer Database.</div>
<div>&#160;</div>
<div>Here is the code:</div>
<div>&#160;</div>
<pre class="csharpcode"><span class="kwrd">namespace</span> ConApp
{
    <span class="kwrd">internal</span> <span class="kwrd">class</span> Program
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Database.SetInitializer&lt;SiteDB&gt;(<span class="kwrd">new</span> SiteDBInitialize());
            <span class="kwrd">using</span> (var myContext = <span class="kwrd">new</span> SiteDB())
            {
                var x = myContext.Presidents.ToList();
            }
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> SiteDB : DbContext
    {
        <span class="kwrd">public</span> DbSet&lt;Presidents&gt; Presidents { get; set; }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> Presidents
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> SiteDBInitialize :
        DropCreateDatabaseIfModelChanges&lt;SiteDB&gt;
    {
        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Seed(SiteDB context)
        {
            context.Presidents.Add(<span class="kwrd">new</span> Presidents { LastName = <span class="str">&quot;Reagan&quot;</span> });
            context.Presidents.Add(<span class="kwrd">new</span> Presidents { LastName = <span class="str">&quot;Bush&quot;</span> });
            context.Presidents.Add(<span class="kwrd">new</span> Presidents { LastName = <span class="str">&quot;Obama&quot;</span> });
            context.SaveChanges();
        }
    }

}</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>I won’t go into details of all the steps because this is all very well documented on the EF site at this url among others:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/gg696189(v=vs.103).aspx">http://msdn.microsoft.com/en-us/library/gg696189(v=vs.103).aspx</a></p>
<p>What is interesting to note is that I am implementing the interface DropCreateDatabaseIfModelChanges.&#160; What stumped me for a while was that in my main console, we always call new SiteDBInitialize), however what that class implments determines the action on creation.&#160; There are three choices.</p>
<ol>
<li><a href="http://msdn.microsoft.com/en-us/library/gg679604(v=vs.103).aspx">DropCreateDatabaseIfModelChanges</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/gg679506(v=vs.103).aspx">DropCreateDatabaseAlways</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/gg679221(v=vs.103).aspx">CreateDatabaseIfNotExists</a> </li>
</ol>
<p>The meaning is self explanatory, you just need to derive from the appropriate class depending on what your intention is.&#160; All the calls can be seen here in the MSDN documentation:&#160; <a href="http://msdn.microsoft.com/en-us/library/gg696142(v=vs.103).aspx">http://msdn.microsoft.com/en-us/library/gg696142(v=vs.103).aspx</a></p>
<p>Hope this helps, read on to part 2 to find out how to add some columns and conditionally populate them.</p>
<p>&#160;</p>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1/feed/</wfw:commentRss>
		<slash:comments>2</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 24/31 queries in 0.020 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-17 04:44:26 -->
