<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4398517536448454544</id><updated>2012-01-10T03:14:16.142-08:00</updated><title type='text'>Solid Code</title><subtitle type='html'>A site dedicated to sharing .Net, LINQ, and other coding examples and ideas</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>68</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3004991585269707305</id><published>2010-06-09T16:49:00.000-07:00</published><updated>2010-06-09T16:54:36.932-07:00</updated><title type='text'>PLINQ with the LINQ to Excel Provider</title><content type='html'>In .Net 4.0 there are new extensions methods to take advantage of &lt;a href="http://msdn.microsoft.com/en-us/library/dd460688.aspx"&gt;PLINQ&lt;/a&gt; (Parallel LINQ).  These extension methods can be used quite easily in the LINQ to Excel Provider described in the &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html"&gt;post&lt;/a&gt;.  All you need to do is add the AsParallel method to the end of the LINQ query.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;ExcelProvider&lt;/span&gt; provider = &lt;span class="cSharpClass"&gt;ExcelProvider&lt;/span&gt;.Create(@"c:\deploy\Book1.xls");&lt;br /&gt;&lt;span class="keyword"&gt;foreach&lt;/span&gt; (&lt;span class="cSharpClass"&gt;Person&lt;/span&gt; per &lt;span class="keyword"&gt;in&lt;/span&gt; (&lt;span class="keyword"&gt;from&lt;/span&gt; p &lt;span class="keyword"&gt;in&lt;/span&gt; provider.GetSheet&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class="keyword"&gt;where&lt;/span&gt; p.LastName == "Johnson" &lt;span class="keyword"&gt;select&lt;/span&gt; p).AsParallel())&lt;br /&gt;{&lt;br /&gt;per.LastName = "Smith";&lt;br /&gt;}&lt;br /&gt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt; p = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;Person&lt;/span&gt;();&lt;br /&gt;p.Id = 10.0;&lt;br /&gt;p.FirstName = "Alex";&lt;br /&gt;p.LastName = "Zander";&lt;br /&gt;p.BirthDate = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;DateTime&lt;/span&gt;(1980, 4, 4);&lt;br /&gt;provider.GetSheet&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;() InsertOnSubmit(p);&lt;br /&gt;provider.SubmitChanges();&lt;br /&gt;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("Done");&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3004991585269707305?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3004991585269707305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3004991585269707305' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3004991585269707305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3004991585269707305'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2010/06/plinq-with-linq-to-excel-provider.html' title='PLINQ with the LINQ to Excel Provider'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-2132927983623982708</id><published>2009-12-05T08:57:00.001-08:00</published><updated>2009-12-19T11:06:09.250-08:00</updated><title type='text'>Let Python Speak using COM</title><content type='html'>What I have wanted to try and do is create a .Net assembly, make it COM accessible, and call it from Python through COM with pyWin32. There are plenty examples out on the web getting this to work for a simple math class or to call to Microsoft Excel. What I thought would be more interesting is to create a .Net assembly to expose the SpeechSynthesizer class so you could send string phrases from Python and have them spoken by the computer. I think that is a cooler example than a Microsoft Excel integration.&lt;br /&gt;&lt;br /&gt;Prerequisites:&lt;br /&gt;Python library for Windows: &lt;a href='http://sourceforge.net/projects/pywin32/'&gt;pyWin32&lt;/a&gt; &lt;br /&gt;Visual Studio 2005 or greater (I used Microsoft Visual C# 2008 Express Edition)&lt;br /&gt;&lt;br /&gt;Step 1. Create the .Net interface and class in a .Net Class Library (DLL)&lt;br /&gt;&lt;iframe height="650" src="http://solidcodingarchive.appspot.com/resources/Speech.cs.txt" frameborder="0" width="695"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 2. In the class project be sure to select COM Interop&lt;br /&gt;&lt;iframe height="260" src="http://solidcodingarchive.appspot.com/resources/classproject.jpg" frameborder="0" width="695"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 3. Register the .Net Assembly as a COM component from its build location&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;regasm SolidCode.Speech.dll /tlb: SolidCode.Speech.tlb&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Step 4. Run this simple program from Python.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&gt;&gt;&gt; import win32com.client&lt;br /&gt;&gt;&gt;&gt; speech = win32com.client.Dispatch("SolidCode.Speech")&lt;br /&gt;&gt;&gt;&gt; speech.speak('Hello world');&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Step 5. Enjoy.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-2132927983623982708?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/2132927983623982708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=2132927983623982708' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2132927983623982708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2132927983623982708'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/12/let-python-speak-using-com.html' title='Let Python Speak using COM'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1079796024257252036</id><published>2009-09-15T19:45:00.000-07:00</published><updated>2009-11-29T08:43:50.137-08:00</updated><title type='text'>Age Extension Methods for .Net DateTime Type</title><content type='html'>There is not really a straightforward method to calculate a person’s age using the .Net DateTime type.  Subtracting years is not a correct means.  What is required is to round down a person’s age until that person’s birthday has passed for the given year it is being calculated against.  This is what these simple set of extensions to the .Net DateTime class intend to provide.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/AgeDateTimeExt.cs.txt" frameborder="0" width="695" height="1000"  scrolling="auto"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1079796024257252036?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1079796024257252036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1079796024257252036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1079796024257252036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1079796024257252036'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/09/age-extension-methods-for-net-datetime.html' title='Age Extension Methods for .Net DateTime Type'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3564138079247985251</id><published>2009-09-07T13:47:00.000-07:00</published><updated>2009-09-07T13:57:36.133-07:00</updated><title type='text'>IsNullOrEmpty Extension Method for .Net Collections</title><content type='html'>One of the methods on the string class in .Net framework that was added in .Net 2.0 was the IsNullOrEmpty method.  This was implemented as a shortcut mechanism for what developers had been doing which was something like:&lt;br /&gt;if (str == null || str.length == 0) {&lt;br /&gt; //do something&lt;br /&gt;}&lt;br /&gt;Or probably more often&lt;br /&gt;if(!(str == null || str.length == 0)) {&lt;br /&gt;//do something&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If you think about it the string class in .Net is just a specialized type of collection. I see myself performing that similar pattern for other types of collections in .Net. Why not create an IsNullOrEmpty method to support the .Net collection classes and array types?&lt;br /&gt;&lt;br /&gt;It is a pretty simple extension and I plan on incorporating this function in any new .Net 3.5 work that I do.  It is just a handle shortcut to use.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/IsNullOrEmptyExt.cs.txt" frameborder="0" width="695" height="800"  scrolling="auto"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3564138079247985251?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3564138079247985251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3564138079247985251' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3564138079247985251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3564138079247985251'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/09/isnullorempty-extension-method-for-net.html' title='IsNullOrEmpty Extension Method for .Net Collections'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3623742869189961075</id><published>2009-08-29T19:38:00.000-07:00</published><updated>2009-08-29T20:41:46.838-07:00</updated><title type='text'>.Net Extension Method to Load ASP.Net ListControls from Xml</title><content type='html'>Several months ago I joined a group of developers who were in the middle of development of an enterprise web application.  What the application does is not as important as some of the interesting implementation techniques they used.  One of them was the loading of static, common ASP.Net ListControls from embedded Xml files.  I am talking things such as Yes/No radio lists, a list of states, a list of counties, etc.  You know, for things that are not going to change at all or not very often.&lt;br /&gt;&lt;br /&gt;In browsing through their code, the one thing that caught my attention was that they had developed their own Xml schema to define the items in the lists.  My initial thought was, why not use an Xml schema format that allows one to use the Xml serialization functionality of .Net and not have to go through the effort of performing that translation yourself?&lt;br /&gt;&lt;br /&gt;So that’s my experiment in this post. Create an Xml file format so Xml serialization can be used, and since I am using .Net 3.5, use extensions methods to handle the translation instead of developing a special purpose utility class to handle that for me.&lt;br /&gt;&lt;br /&gt;Here is the extension class used to translate the Xml file into the ListControl.  A ToXml method is provided just as a means to obtain a copy of what the Xml schema will look like for a ListControl.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/ListControlExt.cs.txt" frameborder="0" width="695" height="1150"  scrolling="auto"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;An embedded Xml file that includes a Yes, No and Maybe option with the Maybe option being the defaulted selected item.&lt;br /&gt;&lt;br /&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;ArrayOfListItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;  &amp;lt;ListItem&amp;gt;&lt;br /&gt;    &amp;lt;Text&amp;gt;Yes&amp;lt;/Text&amp;gt;&lt;br /&gt;    &amp;lt;Value&amp;gt;yes&amp;lt;/Value&amp;gt;&lt;br /&gt;  &amp;lt;/ListItem&amp;gt;&lt;br /&gt;  &amp;lt;ListItem&amp;gt;&lt;br /&gt;    &amp;lt;Text&amp;gt;No&amp;lt;/Text&amp;gt;&lt;br /&gt;    &amp;lt;Value&amp;gt;no&amp;lt;/Value&amp;gt;&lt;br /&gt;  &amp;lt;/ListItem&amp;gt;&lt;br /&gt;  &amp;lt;ListItem&amp;gt;&lt;br /&gt;    &amp;lt;Text&amp;gt;Maybe&amp;lt;/Text&amp;gt;&lt;br /&gt;    &amp;lt;Value&amp;gt;maybe&amp;lt;/Value&amp;gt;&lt;br /&gt;    &amp;lt;Selected&amp;gt;true&amp;lt;/Selected&amp;gt;&lt;br /&gt;  &amp;lt;/ListItem&amp;gt;&lt;br /&gt;&amp;lt;/ArrayOfListItem&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This image shows the properties that need to be set to embed an Xml file in a Visual Studio project&lt;br /&gt;&lt;br /&gt;&lt;img src="http://solidcodingarchive.appspot.com/resources/embeddedxml.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;This example shows how to load an embedded Xml file into an ASP.Net ListControl on the Page_Load method of an ASP.Net page&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/DefaultListControl.aspx.txt" frameborder="0" width="695" height="350" scrolling="auto"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3623742869189961075?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3623742869189961075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3623742869189961075' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3623742869189961075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3623742869189961075'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/08/net-extension-method-to-load-aspnet.html' title='.Net Extension Method to Load ASP.Net ListControls from Xml'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-53430750365069511</id><published>2009-06-28T16:22:00.001-07:00</published><updated>2009-10-28T18:36:57.268-07:00</updated><title type='text'>Forth as a Web Service</title><content type='html'>This is my latest iteration of developing a Forth system.  I started with &lt;a href='http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html'&gt;Forth in .Net&lt;/a&gt;, &lt;a href='http://solidcoding.blogspot.com/2008/12/wforth-javascript-forth-interpreter.html'&gt;Forth interpreter in JavaScript&lt;/a&gt;, &lt;a href='http://solidcodingarchive.appspot.com/resources/StreetView.htm'&gt;Forth to script Google Street View&lt;/a&gt; and now Forth as a web service.  This latest work builds upon a &lt;a href='http://solidcoding.blogspot.com/2009/04/simple-python-web-service-framework.html'&gt;Python web service framework&lt;/a&gt; I developed.  It is hosted in the Google App engine and the Forth interpreter is a  Python port form my JavaScript Forth implementation.  &lt;br /&gt;&lt;br /&gt;What I like about this implementation is that I now have a Forth system that is accessible to other systems. Also it stores the state of the Forth interpreter between calls. This allows users to develop Forth programs still using the iterative Forth programming style. It stores state by persisting the stacks, and the user dictionary using the Google App Engine data store.  These structures are pickled using Python to ease storing and retrieval.  Developers can choose to pass in a session value to the web service to identify a Forth interpreter instance to use. This is beneficial so you do not have multiple callers manipulating the state of the same Forth interpreter instance and getting unpredictable responses back.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://pybasicws.appspot.com/apps/ForthConsole.html"&gt;To the Forth Web Service Console&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1419675494&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0976458705&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0966215613&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0911827005&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-53430750365069511?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/53430750365069511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=53430750365069511' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/53430750365069511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/53430750365069511'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/06/forth-as-web-service.html' title='Forth as a Web Service'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3981846617645156912</id><published>2009-05-13T15:49:00.000-07:00</published><updated>2009-06-10T14:57:00.767-07:00</updated><title type='text'>MVP Pattern in JavaScript</title><content type='html'>I have been using the Model View Presenter (MVP) pattern when building some ASP.Net applications and I thought it would be an interesting experiment to try and implement that pattern entirely in JavaScript.&lt;br /&gt;&lt;br /&gt;In this experiment, the JavaScript page would be laid out in the following manner.&lt;br /&gt;&lt;br /&gt;1. The View is a JavaScript class that encapsulates the interaction of the UI components of the JavaScript through the DOM. Usually this is an interface plus a class implementation to do this in programming languages like in .Net. However since JavaScript doesn’t have interfaces, I just went with a straight implementation. Since JavaScript is a dynamic language it worked out the same.&lt;br /&gt;&lt;br /&gt;2. The Model is a web service, a CacheService discussed in this &lt;a href="http://solidcoding.blogspot.com/2009/05/python-web-service-and-google-app.html"&gt;post&lt;/a&gt;, and handles getting and retrieving data from the data store.&lt;br /&gt;&lt;br /&gt;3. The Presenter is a JavaScript class that takes in an instance of the View. It also encapsulates the Ajax logic used to read and write data from the Model.&lt;br /&gt;&lt;br /&gt;Granted this is a very small application, but I really liked the way application ended up being organized. It seemed very clean, easy to follow, and common routines were easily reusable. For example, getting and setting values, and enable or disabling the UI while in the middle of an Ajax call.&lt;br /&gt;&lt;br /&gt;I think the next step is to try this pattern out on a larger more complex JavaScript application.&lt;br /&gt;&lt;br /&gt;&lt;a href='http://pybasicws.appspot.com/apps/CacheEntry.html'&gt;Check out the JavaScript page&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;All the code for the implementation of the MVP pattern is embedded within the page so one can just view the source from the browser.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3981846617645156912?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3981846617645156912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3981846617645156912' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3981846617645156912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3981846617645156912'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/05/mvp-pattern-in-javascript.html' title='MVP Pattern in JavaScript'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-4800707964890798171</id><published>2009-05-10T17:53:00.000-07:00</published><updated>2009-05-13T15:53:30.822-07:00</updated><title type='text'>Calling a Python Web Service from JavaScript</title><content type='html'>This entry is a continuation of a caching web service developed using a Python Web Service Framework discussed in this &lt;a href='http://solidcoding.blogspot.com/2009/05/python-web-service-and-google-app.html'&gt;post&lt;/a&gt;. Here I am experimenting with invoking that web service from JavaScript using Ajax.  I have used Ajax before but never to interact with a web service directly.  The only thing that was really new here was adding logic to parse out the SOAP response and a general routine to discover and interpret SOAP faults.  &lt;br /&gt;&lt;br /&gt;In the JavaScript page you will also notice I have mentioned organizing the JavaScript to conform to the Model View Presenter pattern.  I plan on including an entry in coming days to discuss that aspect of the page further.&lt;br /&gt;&lt;b&gt;Update &lt;/b&gt; Added this entry on 5/13/09. Check it out &lt;a href='http://solidcoding.blogspot.com/2009/05/mvp-pattern-in-javascript.html'&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I didn’t include any source because it is just as easy to view the source of the JavaScript page to see what is going on.&lt;br /&gt;&lt;br /&gt;&lt;a href='http://pybasicws.appspot.com/apps/CacheEntry.html'&gt;On to the JavaScript page!&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-4800707964890798171?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/4800707964890798171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=4800707964890798171' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4800707964890798171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4800707964890798171'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/05/calling-python-web-service-from.html' title='Calling a Python Web Service from JavaScript'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-9139517182099732744</id><published>2009-05-10T17:22:00.000-07:00</published><updated>2009-10-28T18:53:40.805-07:00</updated><title type='text'>Python Web Service and the Google App Engine Data Store</title><content type='html'>In the last post I discussed and provided code for a &lt;a href="http://solidcoding.blogspot.com/2009/04/simple-python-web-service-framework.html"&gt;Basic Python Web Service Framework&lt;/a&gt; for the Google App Engine. This post continues on that work and provides an example of a simple service built in that framework which interacts with the Google App Engine’s data store.&lt;br /&gt;&lt;br /&gt;The service is a caching service. It allows users to store a string value referenced by key; a hash table using the Google App Engine’s data store. The operations allowed on this service are get a value by a key, set a key value pair, and delete a key value pair. Two additional operations are get the key value object as Xml, and get the key value object as JSON. Together all these operations provide an example of each of the CRUD operations on the data store. Further, each one is wrapped in a transaction, so there are examples on how to code for transactions as well. The one thing that is missing is an operation that performs a query using GQL.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/CacheService.py.txt"&gt;Link&lt;/a&gt; to the source for the CacheService&lt;br /&gt;&lt;br /&gt;&lt;a href="http://pybasicws.appspot.com/CacheService"&gt;Link&lt;/a&gt; to the live web service on the Google App Engine&lt;br /&gt;&lt;br /&gt;I have built a simple JavaScript application to call the service. This is why the operations to get the key value object as Xml and as JSON are included in the service. It was a fun experiment to try and call the web service from JavaScript using Ajax. I think it provides a nice simple interface for users to experiment with the service.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;CRON Job&lt;/b&gt;&lt;br /&gt;I have implemented a Google App Engine &lt;a href="http://code.google.com/appengine/docs/python/config/cron.html"&gt;Cron&lt;/a&gt; job to delete entries after a defined period of time in order to add expiration to the service.  All it does is perform a &lt;a href="http://code.google.com/appengine/docs/python/datastore/gqlreference.html"&gt;GQL&lt;/a&gt; query looking for entries that are older than week, via the update_date property, and deletes them.  You can see the logic for it within the expire method on the CacheService.  Should note that method is not exposed as a service call and for the cron job it is getting called directly.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=059680069X&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-9139517182099732744?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/9139517182099732744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=9139517182099732744' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/9139517182099732744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/9139517182099732744'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/05/python-web-service-and-google-app.html' title='Python Web Service and the Google App Engine Data Store'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7791180463396603202</id><published>2009-04-22T17:34:00.000-07:00</published><updated>2009-05-11T15:56:20.736-07:00</updated><title type='text'>Simple Python Web Service Framework</title><content type='html'>This post came about as an effort to combine three things that I have been interested in lately. The “ins and outs” of WSDL and SOAP in web services, Python, and the Google App Engine. I have used web services a fair amount, but have never taken the time to explore the inner workings of WSDL and SOAP messaging. My experience has been with WCF and ASP.Net web services and they both take care of those items for you. To dive into that area I came up with the idea to create a simple web service framework in Python and host it in the Google App Engine.&lt;br /&gt;&lt;br /&gt;This is the list of requirements and goals for the project.&lt;br /&gt;&lt;br /&gt;1. In effort to keep it simple it will only support primitive data types.&lt;br /&gt;&lt;br /&gt;2. Creating a web service class should be easy. Do not want to require inheriting from a special class.&lt;br /&gt;&lt;br /&gt;3. Be able to view the WSDL in a browser by issuing a ?WSDL query to the Http endpoint.&lt;br /&gt;&lt;br /&gt;4. Want to be able to generate a proxy class for the service in .Net based off the WSDL.&lt;br /&gt;&lt;br /&gt;To create a service class in this Python framework is fairly straightforward. There is one unique aspect and that is you need to adorn your class with “attributes” to define, for the framework, which methods are exposed as service calls along with adorning the class itself with a namespace for the service. Python doesn’t have attributes directly (at least that I am aware of) so I used the documentation function ‘__doc__’ to hold the attributes. The attribute for the methods are a simple Xml format describing the input parameters and data types and return data type if there are any. Likewise with the namespace attribute for the class, it is a simple Xml format containing the namespace to uniquely define the service. If you do not define a namespace the framework will default to http://tempuri.org.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;class TestService:&lt;br /&gt;"&amp;lt;namespace&amp;gt;http://solidcoding.blogspot.com&amp;lt;/namespace&amp;gt;"&lt;br /&gt;&lt;br /&gt;def add(self, x,y):&lt;br /&gt;&amp;nbsp;&amp;nbsp;"&amp;lt;op&amp;gt;&amp;lt;name/&amp;gt;&amp;lt;args&amp;gt;&amp;lt;arg type="int"&amp;gt;x&amp;lt;/arg&amp;gt;&amp;lt;arg type="int"&amp;gt;y&amp;lt;/arg&amp;gt;&amp;lt;/args&amp;gt;&amp;lt;ret type="int"/&amp;gt;&amp;lt;/op&amp;gt;"&lt;br /&gt;&amp;nbsp;&amp;nbsp;return x + y&lt;br /&gt;&lt;br /&gt;def divide(self, x,y):&lt;br /&gt;&amp;nbsp;&amp;nbsp;"&amp;lt;op&amp;gt;&amp;lt;name/&amp;gt;&amp;lt;args&amp;gt;&amp;lt;arg type="int"&amp;gt;x&amp;lt;/arg&amp;gt;&amp;lt;arg type="int"&amp;gt;y&amp;lt;/arg&amp;gt;&amp;lt;/args&amp;gt;&amp;lt;ret type="int"/&amp;gt;&amp;lt;/op&amp;gt;"&lt;br /&gt;&amp;nbsp;&amp;nbsp;return x / y&lt;br /&gt;&lt;br /&gt;def getDate(self):&lt;br /&gt;&amp;nbsp;&amp;nbsp;"&amp;lt;op&amp;gt;&amp;lt;name/&amp;gt;&amp;lt;args&amp;gt;&amp;lt;/args&amp;gt;&amp;lt;ret type="dateTime"/&amp;gt;&amp;lt;/op&amp;gt;"&lt;br /&gt;&amp;nbsp;&amp;nbsp;return datetime.utcnow().isoformat()&lt;br /&gt;&lt;br /&gt;def save(self, message):&lt;br /&gt;"&amp;lt;op&amp;gt;&amp;lt;name/&amp;gt;&amp;lt;args&amp;gt;&amp;lt;arg type="string"&amp;gt;message&amp;lt;/arg&amp;gt;&amp;lt;/args&amp;gt;&amp;lt;ret/&amp;gt;&amp;lt;/op&amp;gt;"&lt;br /&gt;&amp;nbsp;&amp;nbsp;return&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Full namespace Xml format (web service class attribute):&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&amp;lt;namespace&amp;gt;your namespace here&amp;lt;/namespace&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Full method Xml format (web service method attribute):&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&amp;lt;op&amp;gt;&amp;lt;name&amp;gt;alternate name for method&amp;lt;/name&amp;gt;&amp;lt;args&amp;gt;&amp;lt;arg type='arg1 data type'&amp;gt;argument 1&amp;lt;/arg&amp;gt;&amp;lt;arg type='arg2 data type'&amp;gt;argument 2&amp;lt;/arg&amp;gt;&amp;lt;/args&amp;gt;&amp;lt;ret type='return data type'/&amp;gt;&amp;lt;/op&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I should note here the data types that you can use in your service calls. They are all Xml data types and are listed below for reference. In the attribute there is no need to add an Xml namespace prefix for these types. The framework will handle those for you.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The data types:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;string&lt;br /&gt;boolean&lt;br /&gt;decimal&lt;br /&gt;float&lt;br /&gt;double&lt;br /&gt;duration&lt;br /&gt;dateTime&lt;br /&gt;time&lt;br /&gt;date&lt;br /&gt;&lt;br /&gt;All the heavy lifting in the framework is performed by the ServiceController class. You just supply it with an instance of your service along with a Request object and Response object. These later two objects are expected to be the Request and Response objects from the webapp Framework in the Google App Engine. I’ll discuss more on integrating this class into the webapp Framework in the next section. Finally, to round out this class, it has two methods on it doPost and doGet which are meant to be called with performing an Http Get or Http Post respectively. I have implemented the doGet method to supply the WSDL definition of the service when the endpoint Url is appended with a ?WSDL query string. If it is not supplied it defaults to rendering an Html page with a description of your service. The doPost has been implemented to receive the SOAP requests, call the method on your service class and send the SOAP responses back to the caller.&lt;br /&gt;&lt;br /&gt;In the webapp Framework, developers implement Http endpoints by creating Python classes that inherit from the webapp RequestHander class. Developers then implement a get and or post method on this class to handle Http requests. It is in these methods that you would create an instance of the ServiceController class, supplying it with an instance of your web service and then calling ‘doGet’ or ‘doPost’ depending on which method for the RequestHandler you are implementing.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generating a Proxy in .Net&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I had hoped to be able to generate a proxy class right within Visual Studio using the Add Service Reference menu item on the Solution Explorer. I couldn’t get that to work. So I left that as is for now and went to ‘Plan B’ which was to use the wsdl.exe in the Microsoft SDK folder to generate a proxy class for me. That worked. I am not sure of an exact default location of where to find wsdl.exe on developers’ machines. My best advice is to just do a search for it.&lt;br /&gt;&lt;br /&gt;Uri of the &lt;a href='http://pybasicws.appspot.com/TestService'&gt;live Test Service&lt;/a&gt; in Google App Engine&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Links to the code&lt;/strong&gt;&lt;br /&gt;An example of the &lt;a href='http://solidcodingarchive.appspot.com/resources/TestService.cs'&gt;.Net Proxy class&lt;/a&gt; I generated to use the Test Service&lt;br /&gt;&lt;a href='http://solidcodingarchive.appspot.com/resources/BasicWebService.py.txt'&gt;Source&lt;/a&gt; for the Python web service framework&lt;br /&gt;&lt;a href='http://solidcodingarchive.appspot.com/resources/TestService.py.txt'&gt;Source&lt;/a&gt; for the TestService Python class&lt;br /&gt;&lt;a href='http://solidcodingarchive.appspot.com/resources/TestServicePage.py.txt'&gt;Source&lt;/a&gt; for the integration of Python Web Service into Google App Engine webapp Framework&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7791180463396603202?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7791180463396603202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7791180463396603202' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7791180463396603202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7791180463396603202'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/04/simple-python-web-service-framework.html' title='Simple Python Web Service Framework'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5682946742659108629</id><published>2009-03-18T15:31:00.000-07:00</published><updated>2009-05-06T22:46:18.029-07:00</updated><title type='text'>Python String Slice as .Net Extension Method</title><content type='html'>I have extended the Python list slicing functionality from this &lt;a href="http://solidcoding.blogspot.com/2008/06/python-list-slicing-in-linq.html"&gt;post&lt;/a&gt; to the .Net string class to allow users a mechanism to "slice and dice" .Net strings like you can in Python.  This is accomplished by providing an extension method, Slice(), to the .Net string class and using LINQ under the covers to zero in on the section of the string we are interested in.&lt;br /&gt;&lt;br /&gt;You may ask, .Net already has a substring method why would you need another?  This one has more functionality (I think at least).  Optional start and stop indexes along with support for counting back from the end of a string provides the user with a more flexible solution.  How to count back from the end of a string?  Provide negative index values for the start and/or stop index arguments.&lt;br /&gt;&lt;br /&gt;Example program showing how to use Slice:&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;static void&lt;/span&gt; Main(&lt;span class="keyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;string&lt;/span&gt; hello = "hello";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("Test word hello");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("Expected on the left, result on the right");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("e == ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(1, 2));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("he == ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(&lt;span class="keyword"&gt;null&lt;/span&gt;, 2));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("llo ==");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(2, &lt;span class="keyword"&gt;null&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("hel == ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(&lt;span class="keyword"&gt;null&lt;/span&gt;, -2));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("lo == ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(-2, &lt;span class="keyword"&gt;null&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("el == ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(-4, -2));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.Write("ell == ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(hello.Slice(1, -1));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("Press Enter to end");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.ReadLine();&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StringSliceExt.cs"&gt;Source Code for the Slice extension method&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5682946742659108629?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5682946742659108629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5682946742659108629' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5682946742659108629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5682946742659108629'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/03/python-string-slice-as-net-extension.html' title='Python String Slice as .Net Extension Method'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-2937645496550887529</id><published>2009-03-16T20:24:00.000-07:00</published><updated>2009-05-07T04:46:32.428-07:00</updated><title type='text'>Objective-C Messaging in .Net</title><content type='html'>First off, I should clarify the title of this post. It really should be “Mimic Basic Objective-C Style Messaging in .Net”. A little history on how this post came to be. I was reading about individual developers creating applications for the iPhone. This got me interested in searching out the iPhone SDK. I found it, read about the XCode development environment and the language used for the iPhone and MaC OS, Objective-C. I had not heard of Objective-C before so I had to find out more.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Objective-C&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Like I said I was not familiar with Objective-C so my first stop was to the &lt;a href="http://en.wikipedia.org/wiki/Objective-C"&gt;Wikipedia article&lt;/a&gt; about it. As I started reading, the area that jumped out to me was the approach Objective-C took to invoke a method. As stated in the article, “in Objective-C you send a message to an object while in C++, C# or Java you call a method”. The receiver of the message can choose to provide an implementation for the message. From my understanding, if the message is not implemented nothing happens and code execution moves on. Interesting. Throw on top of that an object can choose to forward a message to another object; and it just got me thinking that it would be an interesting experiment to try and mimic that behavior in .Net.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Experiment&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;How to implement this? Of course reflection would be needed to dynamically find the method corresponding to the message and then invoke it. The other thing was to figure out how to implement the forwarding of messages.&lt;br /&gt;&lt;br /&gt;What I decided to do was create some .Net extension methods on the Object class to allow for the sending of a message to an object, querying an object to see if it implements the message, and finally querying the object to see if it has implemented message forwarding if need be. In Objective-C forwarding is accomplished by the class overriding the forward method. Of course .Net doesn’t have this. What I decided to do was to look for a forward method on the object that had a signature of the first argument being a string (for the message name) and an object array (for the arguments to the message). I would assume that to be the object’s forwarding implementation. I really didn’t need to provide an interface for this since I am dynamically looking for the forward method at runtime. However, for the experiment I did choose to implement one. It is optional and its only functional purpose is to provide the implementer the signature of what the forward method needs to look like.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Method Outline of the Extension Methods on Object&lt;/b&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;static class&lt;/span&gt; &lt;span class="cSharpClass"&gt;ObjectCExt&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static&lt;/span&gt; T Msg&amp;lt;T&amp;gt;(&lt;span class="keyword"&gt;this object&lt;/span&gt; obj, &lt;span class="keyword"&gt;string&lt;/span&gt; method, &lt;span class="keyword"&gt;params object&lt;/span&gt;[] args)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static object&lt;/span&gt; Msg(&lt;span class="keyword"&gt;this object&lt;/span&gt; obj,&lt;span class="keyword"&gt;string&lt;/span&gt; method, &lt;span class="keyword"&gt;params object&lt;/span&gt;[] args)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static bool&lt;/span&gt; RespondsTo(&lt;span class="keyword"&gt;this object&lt;/span&gt; obj, &lt;span class="keyword"&gt;string&lt;/span&gt; method, &lt;span class="keyword"&gt;params object&lt;/span&gt;[] args)&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Basic Example&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;public class&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathClass&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public int&lt;/span&gt; Add(&lt;span class="keyword"&gt;int&lt;/span&gt; x, &lt;span class="keyword"&gt;int&lt;/span&gt; y)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; x + y;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword"&gt;class&lt;/span&gt; Program&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;static void&lt;/span&gt; Main(&lt;span class="keyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;MathClass&lt;/span&gt; m = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathClass&lt;/span&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;int&lt;/span&gt; result = m.Msg&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;&amp;gt;("Add", 2, 2);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(result.ToString());&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Forwarding Example&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;public class&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathController&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;private&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathClass&lt;/span&gt; math;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathController&lt;/span&gt;()&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;math = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathClass&lt;/span&gt;();&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public object&lt;/span&gt; Forward(&lt;span class="keyword"&gt;string&lt;/span&gt; message, &lt;span class="keyword"&gt;params object&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt; (math.RespondsTo(message, args))&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; math.Msg(message, args);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;return null&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword"&gt;class&lt;/span&gt; Program&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;static void&lt;/span&gt; Main(&lt;span class="keyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;span class="cSharpClass"&gt;MathController&lt;/span&gt; mc = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;MathController&lt;/span&gt;();&lt;br /&gt;&amp;nbsp;result = mc.Msg&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;&amp;gt;("Add", 2, 2);&lt;br /&gt;&amp;nbsp;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(result.ToString());&lt;br /&gt;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/ObjectiveC.cs"&gt;Source Code&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-2937645496550887529?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/2937645496550887529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=2937645496550887529' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2937645496550887529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2937645496550887529'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/03/objective-c-messaging-in-net.html' title='Objective-C Messaging in .Net'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5837029606390100608</id><published>2009-03-07T13:43:00.000-08:00</published><updated>2009-03-09T21:03:15.609-07:00</updated><title type='text'>Compress Byte Arrays in .Net</title><content type='html'>This is some utility code I have been using to compress and decompress byte arrays using the .Net Framework’s compression classes.  There are two compression classes available, GZipStream and DeflateStream, and they are found in the System.IO.Compression namespace. This example uses GZipStream.  I did find a lot of examples on how to use the classes in relation to compressing file streams, but had to do a little more digging and experimenting to make it work with memory stream and byte arrays.  I have found this code to be very useful in compressing items such as images for storage in a database.  Though I haven’t tried it, it should work quite well in messaging scenarios too.&lt;br /&gt;&lt;br /&gt;This example reads in a file, compresses data in memory, decompresses the data in memory and then writes the results out to a new file.  Try your own file in the example.  When it is completed, paste the contents of each file into &lt;a href="http://kjacobso2001.googlepages.com/NetDiff.html"&gt; NetDiff&lt;/a&gt; (a web based diff utility I wrote) to verify the files are identical.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Example:&lt;/b&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; System.IO.Compression;&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword"&gt;namespace&lt;/span&gt; ConsoleZip&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;class&lt;/span&gt; Program&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;void&lt;/span&gt; Main(&lt;span class="keyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;byte&lt;/span&gt;[] data = &lt;span class="cSharpClass"&gt;File&lt;/span&gt;.ReadAllBytes("c:\\test.log");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;byte&lt;/span&gt;[] compressed = Compress(data);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;byte&lt;/span&gt;[] decompressed = Decompress(compressed);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;File&lt;/span&gt;.WriteAllBytes("c:\\test2.log", decompressed);&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;byte&lt;/span&gt;[] Compress(&lt;span class="keyword"&gt;byte&lt;/span&gt;[] input)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;MemoryStream&lt;/span&gt; output = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;MemoryStream&lt;/span&gt;()) &lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;GZipStream&lt;/span&gt; zip = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;GZipStream&lt;/span&gt;(output,&lt;span class="cSharpClass"&gt;CompressionMode&lt;/span&gt;.Compress) ) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;zip.Write(input, 0, input.Length);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; output.ToArray();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;byte&lt;/span&gt;[] Decompress(&lt;span class="keyword"&gt;byte&lt;/span&gt;[] input)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;MemoryStream&lt;/span&gt; output = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;MemoryStream&lt;/span&gt;(input))&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;GZipStream&lt;/span&gt; zip = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;GZipStream&lt;/span&gt;(output, &lt;span class="cSharpClass"&gt;CompressionMode&lt;/span&gt;.Decompress))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;List&lt;/span&gt;&amp;lt;byte&amp;gt; bytes = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;List&lt;/span&gt;&amp;lt;byte&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;int&lt;/span&gt; b = zip.ReadByte();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;while&lt;/span&gt; (b != -1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bytes.Add((byte)b);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;b = zip.ReadByte();&lt;br /&gt;                        &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; bytes.ToArray();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5837029606390100608?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5837029606390100608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5837029606390100608' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5837029606390100608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5837029606390100608'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/03/compress-byte-arrays-in-net.html' title='Compress Byte Arrays in .Net'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-128159534746350052</id><published>2009-03-06T15:02:00.001-08:00</published><updated>2009-03-06T15:02:43.416-08:00</updated><title type='text'>ASP.Net SQL Session State Not Expiring</title><content type='html'>I was debugging an ASP.Net web application that was using SQL Server session state and it wasn’t appearing to timeout.  What I discovered, after some digging online, is that you need to have the SQL Agent service up and running.  It handles the expiration of session states stored in SQL Server and if it is not running your session states will not expire.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-128159534746350052?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/128159534746350052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=128159534746350052' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/128159534746350052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/128159534746350052'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/03/aspnet-sql-session-state-not-expiring.html' title='ASP.Net SQL Session State Not Expiring'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5963979111695489166</id><published>2009-02-28T13:09:00.000-08:00</published><updated>2009-02-28T13:20:40.349-08:00</updated><title type='text'>Set WCF Metadata Exchange in Code</title><content type='html'>I was looking for an example on how to setup a MetadataExchange binding for a WCF ServiceHost in code. I readily found examples how to do it with a configuration setting, but had to do some digging to find how to configure it in code. I am posting what worked for me for others to use and for an easy reference for me to go back to. This example is for a simple MathService to add two integers.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;Uri&lt;/span&gt; baseAddress = &lt;span class="keyword"&gt;new &lt;/span&gt;&lt;span class="cSharpClass"&gt;Uri&lt;/span&gt;("http://localhost:2202/MathService");&lt;br /&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;BasicHttpBinding&lt;/span&gt; binding = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;BasicHttpBinding&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;ServiceHost&lt;/span&gt; myServiceHost = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;ServiceHost&lt;/span&gt;(&lt;span class="keyword"&gt;typeof&lt;/span&gt;(&lt;span class="cSharpClass"&gt;MathService&lt;/span&gt;), baseAddress);&lt;br /&gt;myServiceHost.AddServiceEndpoint(&lt;span class="keyword"&gt;typeof&lt;/span&gt;(&lt;span class="cSharpClass"&gt;IMathService&lt;/span&gt;), binding, baseAddress);&lt;br /&gt;myServiceHost.Description.Behaviors.Add(&lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;ServiceMetadataBehavior&lt;/span&gt;());&lt;br /&gt;myServiceHost.AddServiceEndpoint(&lt;span class="keyword"&gt;typeof&lt;/span&gt;(&lt;span class="cSharpClass"&gt;IMetadataExchange&lt;/span&gt;), &lt;span class="cSharpClass"&gt;MetadataExchangeBindings&lt;/span&gt;.CreateMexHttpBinding(), "MEX");&lt;br /&gt;&lt;br /&gt;myServiceHost.Open(); &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5963979111695489166?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5963979111695489166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5963979111695489166' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5963979111695489166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5963979111695489166'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/02/set-wcf-metadata-exchange-in-code.html' title='Set WCF Metadata Exchange in Code'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8407153787812812202</id><published>2009-02-20T19:58:00.001-08:00</published><updated>2009-05-07T04:47:01.024-07:00</updated><title type='text'>FxCop Double Thunk Rule</title><content type='html'>A few years ago I was working on a project that was converting an enterprise business application from being compiled in unmanaged C++ to compiling it in managed C++. The purpose was to get it running on the CLR to expose it for integration with other .Net projects we were working on that were using C#. One of the issues with converting an existing C++ application to build on the .Net Framework is the problem known as a double thunk. A double thunk occurs when program execution hops from managed code to native code and then back to managed code. Why is it an issue? You take a performance hit each time you switch from managed to unmanaged code or vice versa. And with a double thunk you get hit twice. In managed C++ this happens with function pointers and calling virtual functions. However there is a C++ keyword you can use __clrcall to fix the issue. Check out this &lt;a href="http://www.blogger.com/”http://msdn.microsoft.com/en-us/library/ms235292(VS.80).aspx”"&gt;MSDN article &lt;/a&gt;for more information on it.&lt;br /&gt;&lt;br /&gt;To help track down those issues I developed an FxCop rule to check for these double thunks. This rule works on the FxCop 1.35 version. I have includes a zip file of the source code for this rule and provided a link to it at the bottom of this post. In that project are references to two assemblies from FxCop. So if you decide to upgrade to newer versions of FxCop you would probably need to replace those assemblies. Anyways, assuming FxCop 1.35, once you build the code you just need to copy the resulting assembly to the Rules folder of the FxCop install location. FxCop will then be able to load and use the rule from that location.&lt;br /&gt;&lt;br /&gt;I have verified this rule works with the C++ example in the MSDN article I referred to earlier.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/DoubleThunkRules.zip"&gt;Double Thunk Rule zip file&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8407153787812812202?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8407153787812812202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8407153787812812202' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8407153787812812202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8407153787812812202'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/02/fxcop-double-thunk-rule_20.html' title='FxCop Double Thunk Rule'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-4632043923459504932</id><published>2009-02-13T10:36:00.000-08:00</published><updated>2009-05-12T16:13:02.331-07:00</updated><title type='text'>Sharks and Fish Computer Simulation</title><content type='html'>Back in one of my first C++ programming classes in college we had an assignment to build a computer simulation to model the population dynamics of sharks and fish.  It is based on a Scientific American’s “Computer Recreation” column in 1984.  This is the &lt;a href="http://www.pma.caltech.edu/~physlab/ph21_spring04/assignment-7.pdf"&gt;document&lt;/a&gt; I used to refresh my memory on the topic.  I thought it was a fun assignment then and decided to revisit it now, but this time use JavaScript as the programming language. &lt;br /&gt;&lt;br /&gt;The world the fish and sharks reside in is called ‘Wator’ and there are rules on how the sharks and fish behave and live in this environment.  The basics of the simulation are as follows:&lt;br /&gt;&lt;br /&gt;The sharks and fish live in an ocean represented by a grid.  For this example, our grid is going to be a 20 x 20 Html table.  There are no boundaries in the grid.  Items can move off one side of the grid and reappear on the opposing side.  The sharks and fish can only move in the horizontal or vertical direction and can only move one space in each round of the simulation.&lt;br /&gt;&lt;br /&gt;Rules for Sharks:&lt;br /&gt;1. Each round a shark looks for a fish next to it and it eats it if it finds one.  The shark will then move to that fish’s position in the grid.  Remember, the shark (and fish) can only look north, south, east or west.&lt;br /&gt;&lt;br /&gt;2. If a shark cannot find a fish it then looks for a free cell to swim to.  If none are found, the shark stays where it is.&lt;br /&gt;&lt;br /&gt;3. A shark must eat a fish in certain number of rounds or it will die.  This is a parameter the can be adjusted as part of simulation set up.&lt;br /&gt;&lt;br /&gt;4. A shark, after it lives certain number of rounds, will attempt to breed.  It can only breed it there is room for it to move to a free cell.  The child occupies the cell left by the parent.  If there is no room to move; no action is taken and the shark will attempt to breed again in the next round.&lt;br /&gt;&lt;br /&gt;Rules for Fish:&lt;br /&gt;1. Each round a fish will attempt to swim to a free cell next to it.  If none are found it stays in the same location.&lt;br /&gt;&lt;br /&gt;2. After certain number of rounds the fish will attempt to breed. It follows the same pattern as for the sharks.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Simulation&lt;/b&gt;&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/sim.htm" frameborder="#" width="495" height="625"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-4632043923459504932?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/4632043923459504932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=4632043923459504932' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4632043923459504932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4632043923459504932'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/02/sharks-and-fish-computer-simulation.html' title='Sharks and Fish Computer Simulation'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-2852078327891711724</id><published>2009-01-26T14:32:00.000-08:00</published><updated>2009-05-07T17:43:56.817-07:00</updated><title type='text'>Virtual Florida Keys Vacation with Forth</title><content type='html'>I have been itching to take a vacation to some place warm this winter, but it is just not in the budget this year.  So I decided to use my &lt;a href='http://solidcodingarchive.appspot.com/resources/StreetView.htm'&gt;Script Google Street View with Forth&lt;/a&gt; site and take a little virtual vacation to the Florida Keys.  I have put together 5 panoramic slides of some places I found while “Google vacationing” around the Florida Keys.  I listed out the slides below along with a link to view the slide show. I can’t wait to go back :). Enjoy!&lt;br /&gt;&lt;br /&gt;Slides&lt;br /&gt;1. Over Sea Highway near Middle Key, FL&lt;br /&gt;2. Ocean View at Summerland Key, FL&lt;br /&gt;3. Ocean view Key West, FL&lt;br /&gt;4. Front Street in Key West, FL&lt;br /&gt;5. Beach view in Key West, FL&lt;br /&gt;&lt;br /&gt;To the &lt;a href='http://solidcodingarchive.appspot.com/resources/StreetView.htm?:%20360pan%2010%20pace%20360%200%20do%20i%20yaw%201%20+loop%20100%20pace%20;%20250%20pace%20100%20pace%2024%20702066%20-81%20156971%20latlng%20.%22Over%20Sea%20Highway%22%20cr%20360pan%2024%20644232%20-81%20445487%20latlng%20.%22Ocean%20View%20Summerland%20Key%20FL%22%20cr%20360pan%2024%20552666%20-81%20766142%20latlng%20.%22Ocean%20View%20Key%20West%20FL%22%20cr%20360pan%2024%20558903%20-81%20806599%20latlng%20.%22Front%20Street%20Key%20West%20FL%22%20cr%20360pan%20.%22Take%20a%20stroll%20down%20Front%20St%22%20cr%20500%20pace%2010%200%20do%20next%20loop%20100%20pace%2024%20547208%20-81%207889623%20latlng%20.%22Beach%20View%20Key%20West%20FL%22%20cr%20360pan'&gt;slide show&lt;/a&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Check out this &lt;a href='http://solidcoding.blogspot.com/2009/01/share-google-street-scripts-as.html'&gt;post&lt;/a&gt; for more detail on how to share Google Street View scripts by adding them as a query string to the Url.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-2852078327891711724?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/2852078327891711724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=2852078327891711724' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2852078327891711724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2852078327891711724'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/01/virtual-florida-keys-vacation-with.html' title='Virtual Florida Keys Vacation with Forth'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7513062977782111962</id><published>2009-01-12T13:31:00.000-08:00</published><updated>2009-05-07T17:41:27.924-07:00</updated><title type='text'>Share Google Street Scripts as Hyperlinks</title><content type='html'>&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt;I have created a site that allows users to create scripts to automate the panoramas in Google Street View using the programming language Forth. I am able to use Forth in the browser by using a &lt;a href="http://solidcoding.blogspot.com/2008/12/wforth-javascript-forth-interpreter.html"&gt;JavaScript based Forth interpreter&lt;/a&gt; I developed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sharing a script that you have written is easy.  Just append the script as a query string to the &lt;a href="http://solidcodingarchive.appspot.com/resources/streetview.htm"&gt;Program Google Street View&lt;/a&gt; site and send it to whomever or place it on a page as a hyperlink.  This configuration will cause the site to load the script into the Forth console and execute the program when the site is loaded in a browser.&lt;br /&gt;&lt;br /&gt;Let’s look at an example.  The following program performs a 360 pan of Times Square in New York City.&lt;br /&gt;&lt;br /&gt;100 pace 40 757584 -73 985642 latlng 360 0 do i yaw 5 +loop&lt;br /&gt;&lt;br /&gt;To share this program, create a hyperlink as such:&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.htm?100%20pace%2040%20757584%20-73%20985642%20latlng%20360%200%20do%20i%20yaw%205%20+loop"&gt;http://solidcodingarchive.appspot.com/resources/StreetView.htm?100%20pace%2040%20757584%20-73%20985642%20latlng%20360%200%20do%20i%20yaw%205%20+loop&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have added a new tool to the Program Google Street View site to assist in the creation of these hyperlinks.  To open the tool, click on the ‘Share Script’ button at the bottom center of the page.&lt;br /&gt;&lt;br /&gt;Additional Examples&lt;br /&gt;&lt;br /&gt;Geno’s Steaks,  Philadelphia, PA&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.htm?39%20933588%20-75%201590154%20latlng%2010%20yaw"&gt;http://solidcodingarchive.appspot.com/resources/StreetView.htm?39%20933588%20-75%201590154%20latlng%2010%20yaw&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Sears Tower, Chicago IL&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.htm?41%20877654%20-87%20634887%20latlng%200%20yaw%20next%20next%2090%200%20do%20i%20-1%20*%20%0D%20pitch%205%20+loop"&gt;http://solidcodingarchive.appspot.com/resources/StreetView.htm?41%20877654%20-87%20634887%20latlng%200%20yaw%20next%20next%2090%200%20do%20i%20-1%20*%20%0D%20pitch%205%20+loop&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Empire State Building, New York NY (program includes Forth word definition to look west)&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.htm?:%20west%20270%20yaw%20;%20100%20pace%2040%207483491%20-73%209846147%20latlng%20270%20west%2090%200%20do%20i%20-1%20*%20pitch%205%20+loop"&gt;http://solidcodingarchive.appspot.com/resources/StreetView.htm?:%20west%20270%20yaw%20;%20100%20pace%2040%207483491%20-73%209846147%20latlng%20270%20west%2090%200%20do%20i%20-1%20*%20pitch%205%20+loop&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Grauman's Chinese Theatre, Los Angeles CA&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.htm?100%20pace%2034%201015533%20-118%203409672%20latlng%200%20yaw%20360%200%20do%20i%20yaw%205%20+loop%2045%200%20do%20i%20-1%20*%20pitch%205%20+loop%205%20pitch"&gt;http://solidcodingarchive.appspot.com/resources/StreetView.htm?100%20pace%2034%201015533%20-118%203409672%20latlng%200%20yaw%20360%200%20do%20i%20yaw%205%20+loop%2045%200%20do%20i%20-1%20*%20pitch%205%20+loop%205%20pitch&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7513062977782111962?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7513062977782111962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7513062977782111962' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7513062977782111962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7513062977782111962'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/01/share-google-street-scripts-as.html' title='Share Google Street Scripts as Hyperlinks'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-4956469231652234424</id><published>2009-01-03T06:21:00.000-08:00</published><updated>2009-02-04T12:18:39.911-08:00</updated><title type='text'>Embedding and Extending wForth</title><content type='html'>Recently I had a comment on one of my wForth posts inquiring about how I embedded &lt;a href="http://solidcoding.blogspot.com/2008/12/script-google-street-view-with-forth.html"&gt;wForth with Google Street View&lt;/a&gt;. First, I should probably provide a little background on the wForth implementation.  wForth is built around the ability to dynamically execute JavaScript code using JavaScript’s eval() function.  There are two main JavaScript classes that make up wForth, ForthEngine which is the wForth virtual machine and the Forth class which contains the core Forth words (keywords) that are used to manipulate the wForth virtual machine.  Below I have provided a brief outline of the functionality of each of these classes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;ForthEngine&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;1. It is the virtual machine of wForth&lt;br /&gt;&lt;br /&gt;2. Found in wForth.js&lt;br /&gt;&lt;br /&gt;3. Can be referenced by the global variable, engine, which is initialized when the wForth.js is loaded by the browser.&lt;br /&gt;&lt;br /&gt;4. Manages the stacks, code execution pointers, function call stacks, loop management and console feedback&lt;br /&gt;&lt;br /&gt;5. Includes a system dictionary containing a list of the Forth core words&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a) Stored as a simple dictionary table using the Forth word as the key and the corressponding Forth class function (as a string) as the value. The string value of the Forth class function is executed using the JavaScript eval function&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;b) Can be edited at runtime to add additional Forth words to the system dictionary. This is what I did to intergrate wForth with Google Street View&lt;br /&gt;&lt;br /&gt;6. Maintains the linked list for the user defined Forth words created within the wForth system&lt;br /&gt;&lt;br /&gt;7. There are functions to push, pop, and peek both the parameter stack and return stack. That is what the Forth class uses to interact with the wForth virtual machine&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Forth&lt;/b&gt;&lt;br /&gt;1. Provides a JavaScript function for each of the core set of Forth words found in the system dictionary&lt;br /&gt;&lt;br /&gt;2. Provides it own eval function to allow Forth programs to be entered as a string and translated&lt;br /&gt;&lt;br /&gt;3. Contains the parser to extract Forth words from strings&lt;br /&gt;&lt;br /&gt;4. Loads Forth programs into the wForth virtual machine&lt;br /&gt;&lt;br /&gt;5. Contains the interpret function which executes the next Forth word in the wForth virtual machine&lt;br /&gt;&lt;br /&gt;6. Found in wForth.js&lt;br /&gt;&lt;br /&gt;At its simplest in code, all that needs to be done to run a Forth program in wForth is to call the eval function on the Forth class.  You will not get any feedback without a console, but the program will run.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt; Forth.eval(“ 2 2 +”)   leaves the number 4 on the stack&lt;br /&gt;&lt;br /&gt;There is another eval function as well, Forth.eval_i.  The difference between the two is that the eval() will write output to the console when it finishes executing.  Eval_i() will write output after the execution of each Forth word, if there is any.  So the latter provides more interactive feedback.&lt;br /&gt;&lt;br /&gt;To add a console just supply the wForth virtual machine with a reference to a Html element that you want to use as the console. The engine then has all it needs to write output to the user. To send programs to the wForth virtual machine from the console; just call one of the Forth eval functions when the data is done being entered.&lt;br /&gt;&lt;br /&gt;To add your own Forth words to the system dictionary, which I did with Google Street View integration, you just need to add those words to the system dictionary.  This is done in the wForth virtual machine by adding an entry for each new Forth word and its JavaScript implementation. Remember it is the JavaScript function which is used to interact with the wForth virtual machine and any other system you need to work with. Like in my case the Google Street View API.  The best place to add these new words is on a page load.  As an example, here is code snippet from my Google Street View implementation showing how to intregate wForth with Google Street View.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;    function load() {&lt;br /&gt;        engine.console = document.getElementById('sys');&lt;br /&gt;        document.getElementById('sys').focus();&lt;br /&gt;        inputIndex = document.getElementById('sys').value.length;&lt;br /&gt;        &lt;br /&gt;        //load street view stuff&lt;br /&gt;        streetView = new GStreetviewPanorama(document.getElementById("sv"));&lt;br /&gt;        var goldenGate = new GLatLng(37.818774 ,-122.478415);&lt;br /&gt;        streetView.setLocationAndPOV(goldenGate, null);&lt;br /&gt;       &lt;br /&gt;       //geocoder&lt;br /&gt;       geocoder = new GClientGeocoder();&lt;br /&gt;        &lt;br /&gt;        //add street view Dictionary words to wForth&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("yaw", "yaw();"));&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("latlng", "latlng();"));&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("next", "next();"));&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("wait", "wait();"));&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("+zoom", "plusZoom();"));&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("-zoom", "minusZoom();"));&lt;br /&gt;        engine.systemDic.list.push(new SystemWord("pitch", "pitch();"));&lt;br /&gt;        &lt;br /&gt;        document.getElementById('sys').focus();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function yaw() {&lt;br /&gt;        var arg = engine.pop();&lt;br /&gt;        var pov = streetView.getPOV();&lt;br /&gt;        pov.yaw = arg;&lt;br /&gt;        streetView.setPOV(pov);&lt;br /&gt;        return;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    function plusZoom() {&lt;br /&gt;        var arg = engine.pop();&lt;br /&gt;        var pov = streetView.getPOV();&lt;br /&gt;        pov.zoom = pov.zoom + arg;&lt;br /&gt;        streetView.setPOV(pov);&lt;br /&gt;        return;&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-4956469231652234424?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/4956469231652234424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=4956469231652234424' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4956469231652234424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4956469231652234424'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2009/01/embedding-and-extending-wforth.html' title='Embedding and Extending wForth'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5354354153295112015</id><published>2008-12-14T11:12:00.000-08:00</published><updated>2009-05-07T04:49:06.401-07:00</updated><title type='text'>Add Forth Words to Google Street View Scripts</title><content type='html'>In my last &lt;a href="http://solidcoding.blogspot.com/2008/12/script-google-street-view-with-forth.html"&gt;post&lt;/a&gt; I introduced scripting Google Street View with Forth.  I would like to build on that post by providing some Forth words (subroutines) you can write to handle some common tasks in programming against Google Street View. For example a 360 pan and change the position to face north.  You should be able to paste the following program into the Forth console and have it perform a 360 pan of Times Square in New York and then finish with the view looking to the east. Once pasted in the Forth console, hit enter to execute the program.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.html"&gt;Link&lt;/a&gt; to the Program Google Street View web page IDE.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;: 360pan  360 0 do i yaw loop ;&lt;br /&gt;&lt;br /&gt;: north 0 yaw ;&lt;br /&gt;&lt;br /&gt;: south 180 yaw ;&lt;br /&gt;&lt;br /&gt;: east 90 yaw ;&lt;br /&gt;&lt;br /&gt;: west 270 yaw ;&lt;br /&gt;&lt;br /&gt;: times_sqr 40 757584 -73 985642 latlng ;&lt;br /&gt;&lt;br /&gt;100 pace times_sqr 360pan east&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5354354153295112015?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5354354153295112015/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5354354153295112015' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5354354153295112015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5354354153295112015'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/12/add-forth-words-to-google-street-view.html' title='Add Forth Words to Google Street View Scripts'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-6434742578847364639</id><published>2008-12-09T20:25:00.000-08:00</published><updated>2009-05-07T04:49:23.265-07:00</updated><title type='text'>Script Google Street View with Forth</title><content type='html'>Utilizing wForth, check this &lt;a href="http://solidcoding.blogspot.com/2008/12/wforth-javascript-forth-interpreter.html"&gt;post&lt;/a&gt; for an introduction on it, I have created a customized Forth to Google Street View dictionary that allows programmers to automate manipulating Google Street View using a Forth programming language.&lt;br /&gt;&lt;br /&gt;The wForth console has been improved since my first post.  The console is more interactive with feedback; the results display instantaneously instead at the end of a program execution. Also there is the ability to paste Forth programs into the console window and have them parsed correctly.&lt;br /&gt;&lt;br /&gt;Check out the Google Street View and Forth integration IDE page &lt;a href="http://solidcodingarchive.appspot.com/resources/StreetView.html"&gt;here.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Also checkout my virtual Florida Keys vacation &lt;a href='http://solidcoding.blogspot.com/2009/01/virtual-florida-keys-vacation-with.html'&gt;slide show&lt;/a&gt; I built using this site.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-6434742578847364639?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/6434742578847364639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=6434742578847364639' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6434742578847364639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6434742578847364639'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/12/script-google-street-view-with-forth.html' title='Script Google Street View with Forth'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-6564620043070426892</id><published>2008-12-03T16:36:00.000-08:00</published><updated>2009-10-28T18:36:09.339-07:00</updated><title type='text'>wForth - A JavaScript Forth Interpreter</title><content type='html'>‘wForth’ is a JavaScript based Forth interpreter. It is a simplified version of Forth and doesn’t contain all the functionality of a ANSI Forth system. The main goal of it is to provide a basic web based platform for people to try out programming with Forth. At the same time though, I wanted it flexible enough to allow programmers to write their own JavaScript Forth dictionaries to customize and extend the system. For example, allow wForth to interact with others aspects of the browser or to hook into Ajax calls to interact with servers.&lt;br /&gt;&lt;br /&gt;Why wForth? jForth, jsForth, webForth were all taken. So wForth is for web based Forth.&lt;br /&gt;&lt;br /&gt;What is supported:&lt;br /&gt;&lt;br /&gt;1. New Forth word creation&lt;br /&gt;2. Standard math operators on integer types only&lt;br /&gt;3. Parameter stack manipulation&lt;br /&gt;4. Infinite loops&lt;br /&gt;5. Do loops&lt;br /&gt;6. Pass data to and from the parameter stack to the return stack&lt;br /&gt;7. Conditionals (if. then.else)&lt;br /&gt;&lt;br /&gt;Try it out:&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/wForthConsole.htm" frameborder="#" width="495" height="450"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;b&gt;Future Items:&lt;/b&gt;&lt;br /&gt;Storing user defined Forth word dictionaries in cookies or serializing them to and from JSON format to mimic loading them from a disk.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1419675494&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0976458705&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0966215613&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0911827005&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-6564620043070426892?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/6564620043070426892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=6564620043070426892' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6564620043070426892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6564620043070426892'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/12/wforth-javascript-forth-interpreter.html' title='wForth - A JavaScript Forth Interpreter'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7936494064234177578</id><published>2008-11-11T07:16:00.000-08:00</published><updated>2009-05-23T11:49:34.137-07:00</updated><title type='text'>Netdiff - A  JavaScript Based File Comparison Utility</title><content type='html'>Lately I have been interested in developing an internet application built in pure JavaScript to provide a service that does not rely on post backs to a server to process logic.  The project I have been working on is NetDiff, which is a pure JavaScript based file comparison utility.  &lt;br /&gt;&lt;br /&gt;There are some challenges in doing such an application in JavaScript.  One of the first ones I discovered, because of security considerations, was the finding and loading of the files I wanted to compare. There is no such direct mechanism to do this.  I did find examples and suggestions of using ActiveX to read files, but that would have limited me to Internet Explorer.  I also tried uploading the files using the input file tag with some additional JavaScript hocus pocus. I would use the browse functionality to locate the file and provide the path. Once I located both files, I would click a button which would copy the paths to a set of hidden IFrames and have it load the file contents for me. After it loaded, I would then read the contents of the hidden IFrame and store it in a JavaScript string.  The issue with that was you can only read the contents of those IFrame if the source came from the same location as the main html page. So, it wouldn’t work either.  So I just decided to have the users paste in the contents of the files and compare from there.&lt;br /&gt;&lt;br /&gt;The other issue, I guess it wasn’t that bad, was encoding the lines from the document correctly so it would display in HTML.  That included the common culprits of ‘less than’ and 'greater than’ along with trying to maintain tabs from the original document.&lt;br /&gt;&lt;br /&gt;The core of the algorithm is finding the longest common sequence (LCS) of the files. Once you find that, the files can be aligned along that sequence. After that you move in a recursive manner to find the next LCS above and below the one you just aligned the files on.  I learned about this algorithm from this post:  &lt;a href="http://www.codeproject.com/KB/recipes/DiffQuest.aspx"&gt; A Fast Diff Algorithm in Visual Basic .Net&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I chose Microsoft’s windiff as the model on how to display the file comparison results to the user.  I know some people like it, and others hate it. It was just a fairly simple and familiar model to follow.&lt;br /&gt;&lt;br /&gt;Please follow this link to check out &lt;a href="http://solidcodingarchive.appspot.com/resources/NetDiff.htm"&gt;NetDiff&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7936494064234177578?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7936494064234177578/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7936494064234177578' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7936494064234177578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7936494064234177578'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/11/netdiff-pure-javascript-based-file.html' title='Netdiff - A  JavaScript Based File Comparison Utility'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3830078040578530621</id><published>2008-10-09T09:41:00.000-07:00</published><updated>2008-10-09T09:43:41.788-07:00</updated><title type='text'>Send MSMQ Messages to Biztalk with .NET</title><content type='html'>I had been looking to use an MSMQ to send messages to a Biztalk server from a .NET WSE 3.0 enabled web service. The item of concern for me was how to setup the message correctly in .NET in order for it to be read in Biztalk. The web service was accepting the incoming XML messages as a string and I wanted to keep it in that format to send to Biztalk. It would be just like Biztalk accepting XML files from a file adapter.&lt;br /&gt;&lt;br /&gt;There are resolutions out there on how to do it, but I hadn’t found a code example to show how. That’s what I wanted to provide here. The trick to use MSMQ from .NET to send messages described above, is to skip using the Body property on the Message class or in the constructor and instead write to the BodyStream property. The reason is, if you use the Body property or constructor, it will serialize the message as XML. We don’t need to do that, we just need to send the message as is. That is performed by writing directly to the BodyStream property of the Message class.&lt;br /&gt;&lt;br /&gt;This example shows how to read an XML file and stream it into the Message class. You can easily convert to read from any string you want. You will need to add a reference to System.Messaging.dll and use the System.Messaging namespace.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;MessageQueue&lt;/span&gt; queue = &lt;span class="keyword"&gt;new&lt;/span&gt; MessageQueue(@".\private$\queue1");&lt;br /&gt;&lt;span class="cSharpClass"&gt;Message&lt;/span&gt; msg = new &lt;span class="cSharpClass"&gt;Message&lt;/span&gt;();&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;StreamWriter&lt;/span&gt; writer = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;StreamWriter&lt;/span&gt;(msg.BodyStream))&lt;br /&gt;            {&lt;br /&gt;&amp;nbsp;&amp;nbsp;writer.Write(&lt;span class="cSharpClass"&gt;File&lt;/span&gt;.ReadAllText("example.xml"));&lt;br /&gt;&amp;nbsp;&amp;nbsp;writer.Flush();&lt;br /&gt;&amp;nbsp;&amp;nbsp;queue.Send(msg);&lt;br /&gt;            }&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3830078040578530621?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3830078040578530621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3830078040578530621' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3830078040578530621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3830078040578530621'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/10/send-msmq-messages-to-biztalk-with-net.html' title='Send MSMQ Messages to Biztalk with .NET'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8016479454809492848</id><published>2008-09-16T16:07:00.000-07:00</published><updated>2008-09-17T14:31:11.259-07:00</updated><title type='text'>Full Outer Join in LINQ</title><content type='html'>While I haven’t found any direct support for a right outer join or full outer join in LINQ, I did work out a solution to mimic a fuller outer join. I started by building a left outer join like I did in my post, &lt;a href="http://solidcoding.blogspot.com/2007/12/left-outer-join-in-linq.html"&gt;Left Outer Join in LINQ&lt;/a&gt;, and then union those results with another left outer join LINQ query which swaps the sides of the join from the first query. So in effect what you are doing, using the C# classes from my previous post, is performing a left outer join from Person to PersonAddress and union the results with a second query performing a left outer join from PersonAddress to Person. The key is to make sure to use the same columns in each select like would be required performing a union in SQL. It isn’t pretty, but it seems to work.&lt;br /&gt;&lt;br /&gt;LINQ Query&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;var&lt;/span&gt; query = (&lt;span class="keyword"&gt;from&lt;/span&gt; p &lt;span class="keyword"&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;()&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;join&lt;/span&gt; pa &lt;span class="keyword"&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;PersonAddress&lt;/span&gt;&amp;gt;() &lt;span class="keyword"&gt;on&lt;/span&gt; p.Id &lt;span class="keyword"&gt;equals&lt;/span&gt; pa.PersonId &lt;span class="keyword"&gt;into&lt;/span&gt; tempAddresses&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;from&lt;/span&gt; addresses &lt;span class="keyword"&gt;in&lt;/span&gt; tempAddresses.DefaultIfEmpty()&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;select new&lt;/span&gt; { p.FirstName, p.LastName, addresses.State }).Union(&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;from&lt;/span&gt; pa2 &lt;span class="keyword"&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;PersonAddress&lt;/span&gt;&amp;gt;()&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;join&lt;/span&gt; p2 &lt;span class="keyword"&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class="keyword"&gt;on&lt;/span&gt; pa2.PersonId &lt;span class="keyword"&gt;equals&lt;/span&gt; p2.Id &lt;span class="keyword"&gt;into&lt;/span&gt; tempPersons&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;from&lt;/span&gt; persons &lt;span class="keyword"&gt;in&lt;/span&gt; tempPersons.DefaultIfEmpty()&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;select new&lt;/span&gt; { persons.FirstName, persons.LastName, pa2.State });&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;SQL Translation&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;SELECT [t4].[FirstName], [t4].[LastName], [t4].[value] AS [State]&lt;br /&gt;FROM (&lt;br /&gt;&amp;nbsp;SELECT [t0].[FirstName], [t0].[LastName], [t1].[State] AS [value]&lt;br /&gt;&amp;nbsp;FROM [Person] AS [t0]&lt;br /&gt;&amp;nbsp;LEFT OUTER JOIN [PersonAddress] AS [t1] ON [t0].[Id] = [t1].[PersonId]&lt;br /&gt;&amp;nbsp;UNION&lt;br /&gt;&amp;nbsp;SELECT [t3].[FirstName] AS [value], [t3].[LastName] AS [value2], [t2].[State]&lt;br /&gt;&amp;nbsp;FROM [PersonAddress] AS [t2]&lt;br /&gt;&amp;nbsp;LEFT OUTER JOIN [Person] AS [t3] ON [t2].[PersonId] = [t3].[Id]&lt;br /&gt;&amp;nbsp;) AS [t4]&lt;br /&gt;-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8016479454809492848?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8016479454809492848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8016479454809492848' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8016479454809492848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8016479454809492848'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/09/full-outer-join-in-linq.html' title='Full Outer Join in LINQ'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3002197814552402430</id><published>2008-09-11T14:36:00.000-07:00</published><updated>2009-05-09T17:56:46.335-07:00</updated><title type='text'>Roomba Web Remote</title><content type='html'>This project is a combination of two prior projects with the additional help of JSON serialization and Ajax to provide an interactive web page to start and monitor a Roomba. The &lt;a href="http://solidcoding.blogspot.com/2008/04/python-web-server.html"&gt;Python web server project&lt;/a&gt; is merged with the &lt;a href="http://solidcoding.blogspot.com/2008/07/python-library-for-roomba-sci.html"&gt;Python Roomba SCI project&lt;/a&gt; to provide a web server capable of handling Roomba commands from and providing sensor data to a web page. The current implementation I have allows one to start the clean process and then monitor the sensor data of the robot while it cleans. This latter functionality is achieved by making Ajax calls requesting the sensor information to the web server in a timed loop. The web server forwards the sensor data request to the Roomba and then packages up the result using JSON to send back to the web page. The web page deserializes the sensor data and displays it on the page. Once the clean process is started, there is also functionality to stop the clean process and shut off the Roomba.&lt;br /&gt;&lt;br /&gt;The bottleneck in the application is the wait time getting the sensor information from the robot to the web server. Another issue is when the Roomba gets out of range for my Bluetooth connections causing the sensor information to not get updated in the web page.&lt;br /&gt;&lt;br /&gt;The source for the web server and Roomba integration can be found &lt;a href="http://solidcodingarchive.appspot.com/resources/RoombaServer.py.txt"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you want to see the web page it is &lt;a href="http://solidcodingarchive.appspot.com/resources/RoombaController.htm"&gt;here&lt;/a&gt;. Should note, though, this version isn’t pointing to my web server so it will not actually work. There is a line in the source to point it to your own web server, and that will make it work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3002197814552402430?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3002197814552402430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3002197814552402430' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3002197814552402430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3002197814552402430'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/09/roomba-web-remote.html' title='Roomba Web Remote'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-2170182851941341197</id><published>2008-09-08T11:19:00.000-07:00</published><updated>2008-09-08T11:22:56.028-07:00</updated><title type='text'>Boolean Extension Methods for UI Conversions</title><content type='html'>Recently I was working with a teammate on a user interface project. There was a requirement to display a Yes or No value in a textbox. The data type choice used to record that value in the underlying database was a Boolean value; which makes sense. However, what that forces one to do is provide conversions from the Yes or No value to the text box to a Boolean value and vice versa, from a Boolean to a Yes or No value. That gets cumbersome.&lt;br /&gt;&lt;br /&gt;The solution we chose to consolidate those conversions was to add extension methods to the Boolean data type to handle changing to and from a Yes or No value to a Boolean value.  Also, in this example I added functionality to convert from an int and from an On or Off string. &lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="cSharpClass"&gt;Program&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;span class="keyword"&gt;static void&lt;/span&gt; Main(&lt;span class="keyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;bool&lt;/span&gt; x = &lt;span class="keyword"&gt;false&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;x = x.FromYesNo("yes");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;string&lt;/span&gt; s = x.ToYesNo();&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword"&gt;public static class&lt;/span&gt; &lt;span class="cSharpClass"&gt;BooleanExt&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static string&lt;/span&gt; ToYesNo(&lt;span class="keyword"&gt;this bool&lt;/span&gt; val)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; val ? "Yes" : "No";&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static bool&lt;/span&gt; FromYesNo(&lt;span class="keyword"&gt;this bool&lt;/span&gt; val, &lt;span class="keyword"&gt;string&lt;/span&gt; yesOrNoString)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; yesOrNoString.ToLowerInvariant() == "yes";&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static int&lt;/span&gt; ToInt(&lt;span class="keyword"&gt;this bool&lt;/span&gt; val)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; val ? 1 : 0;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static bool&lt;/span&gt; FromInt(&lt;span class="keyword"&gt;this bool&lt;/span&gt; val, &lt;span class="keyword"&gt;int&lt;/span&gt; value)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; value &gt; 0;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static string&lt;/span&gt; ToOnOff(&lt;span class="keyword"&gt;this bool&lt;/span&gt; val)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; val ? "On" : "Off";&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public static bool&lt;/span&gt; FromOnOff(&lt;span class="keyword"&gt;this bool&lt;/span&gt; val, &lt;span class="keyword"&gt;string&lt;/span&gt; onOffString)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt; onOffString.ToLowerInvariant() == "on";&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-2170182851941341197?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/2170182851941341197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=2170182851941341197' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2170182851941341197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2170182851941341197'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/09/boolean-extension-methods-for-ui.html' title='Boolean Extension Methods for UI Conversions'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-9004268615253215130</id><published>2008-08-19T15:52:00.000-07:00</published><updated>2008-08-19T16:02:25.249-07:00</updated><title type='text'>Host a WCF Service in a Windows Form Application</title><content type='html'>I have been working on a prototype Windows application that is being used to provide a user interface to a WCF service I have been working on. The goal was to quickly get an application up and provide some data entry forms to allow users to interact with the WCF service. My team wanted to get some early feed back from the users on the computations provided by the service.  To ease the implementation, I had the idea to have the Windows applications not only to be the client but to also host the service. &lt;br /&gt;&lt;br /&gt;I initially got the service up and running but I could not get the client portion to work correctly. It was always timing out on me.  I had placed the service host code in the start up form of the application. After some experimenting it seems the location that the service host code needs to be in is in the Main function of the application.  This is easily found in C# in the generated Program.cs file.  There is a little more work involved to get this to work in VB.Net.&lt;br /&gt;&lt;br /&gt;In a VB.Net Windows application, the Main function and all that start up code is hidden from you by default.  However, there are options in the project file that allow you to override this and have a Main function you can manipulate like C#. In a VB.Net Windows application do the following in order to setup your own Main function.&lt;br /&gt;&lt;br /&gt;1. Right click the project folder and select Properties&lt;br /&gt;&lt;br /&gt;2. In the Application tab, uncheck Enable Application Framework&lt;br /&gt;&lt;br /&gt;3. In Start Up Object, select Sub Main&lt;br /&gt;&lt;br /&gt;4. Back in the Solution Explorer, add a new Module file with a Sub named Main&lt;br /&gt;&lt;br /&gt;5. Add the following code to Main, replacing Form1 with your startup form&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Windows.Forms.Application.EnableVisualStyles()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(False)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Windows.Forms.Application.Run(New Form1())&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;To now add the service host what I did was wrap the service host in a using statement and then added the code from above inside the using statement.  It would like the following in VB.Net.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt; Public Sub Main()&lt;br /&gt;&amp;nbsp;Using host As ServiceHost = New ServiceHost(GetType(MyWCFService))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;host.Open()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Windows.Forms.Application.EnableVisualStyles()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(False)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Windows.Forms.Application.Run(New Form1())&lt;br /&gt;&amp;nbsp;End Using&lt;br /&gt; End Sub&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-9004268615253215130?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/9004268615253215130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=9004268615253215130' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/9004268615253215130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/9004268615253215130'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/08/host-wcf-service-in-windows-form.html' title='Host a WCF Service in a Windows Form Application'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8906468791338597596</id><published>2008-08-06T21:11:00.001-07:00</published><updated>2008-10-15T20:17:39.352-07:00</updated><title type='text'>Unit Testing WCF</title><content type='html'>I was working on trying to develop some unit tests for a WCF service I had written using Visual Studio test services and came up with solution to initialize a host and client instance inside the same unit test. In order to generate the proxy classes for the client, I did have to create a temporary console application to host the service. Once the proxy code was in place I copied the relevant service configuration code in the app.config and moved it to the app.config of my unit testing class library. So the app.config in the unit test library contains configuration information for both the client and host. &lt;br /&gt;&lt;br /&gt;In the following unit test example the WCF service is AddService and the client proxy is AddServiceClient.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;[&lt;span class="cSharpClass"&gt;TestMethod&lt;/span&gt;()]&lt;br /&gt;&lt;span class="keyword"&gt;public void&lt;/span&gt; AddTest() {&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;ServiceHost&lt;/span&gt; host = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;ServiceHost&lt;/span&gt;(&lt;span class="keyword"&gt;typeof&lt;/span&gt;(&lt;span class="cSharpClass"&gt;AddService&lt;/span&gt;))) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;host.Open();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;AddServiceClient&lt;/span&gt; client = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;AddServiceClient&lt;/span&gt;()) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Assert&lt;/span&gt;.AreEqual&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;&amp;gt;(4,client.Add(2,2));&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8906468791338597596?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8906468791338597596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8906468791338597596' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8906468791338597596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8906468791338597596'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/08/unit-testing-wcf.html' title='Unit Testing WCF'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8783974933036802972</id><published>2008-07-17T13:13:00.000-07:00</published><updated>2009-05-07T04:51:22.101-07:00</updated><title type='text'>Python Library for the Roomba SCI</title><content type='html'>I had created a &lt;a href="http://solidcoding.blogspot.com/2008/06/net-class-library-for-roomba-sci.html"&gt;.Net library for the Roomba SCI&lt;/a&gt;, so in a quest to learn more about Python, I decided to duplicate that work and create an implementation of the same API using Python. It uses the pyserial module for serial communication which is available for download at &lt;a href="http://pyserial.wiki.sourceforge.net/pySerial"&gt;http://pyserial.wiki.sourceforge.net/pySerial&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;This class library only works with the new RooTooth modules. To work with older RooTooth modules, or direct serial connects, one could overwrite the ‘Connect’ and ‘Wakeup’ functions on the RoombaAPI class.   &lt;br /&gt;&lt;br /&gt;Like the .Net version, all the Roomba SCI commands are methods on the RoombaAPI class with the exception of the sensor information which is available via the sensors property. That property returns an instance of the SensorData class which breaks out each sensor value into its own property or for related sensors as propeties of a sub class off of SensorData. For example the cliff sensors are grouped together in the Cliff class which is available as a property off of the SensorData class.&lt;br /&gt;&lt;br /&gt;The source is available &lt;a href="http://solidcodingarchive.appspot.com/resources/RoombaSCI.py.txt"&gt;here&lt;/a&gt;. Also included in this source is a simple example of using the API to start the robot and send it a few commands and also ask for some sensor information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8783974933036802972?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8783974933036802972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8783974933036802972' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8783974933036802972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8783974933036802972'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/07/python-library-for-roomba-sci.html' title='Python Library for the Roomba SCI'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5539823847808743000</id><published>2008-06-19T10:59:00.000-07:00</published><updated>2009-05-07T04:51:42.075-07:00</updated><title type='text'>Python List Slicing in LINQ</title><content type='html'>I have been working with Python lately and I really like its list slicing functionality. Working with that gave me the idea of trying to incorporate the same functionality into LINQ and also to make it available in LINQ to SQL.&lt;br /&gt;&lt;br /&gt;As a refresher, in Python, you are able to perform the following types of slice operations on a list. Negative numbers indicate counting is beginning from the back of the list (moving right to left). Ex. -1 points to the last item in the list.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&gt;&gt;&gt; li = [“a”,”b”,”c”,”d”,”e”,”f”]&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; print li[0:3]&lt;br /&gt;[“a”,”b”,”c”]&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; print li[1:3]&lt;br /&gt;[“b”,”c”]&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; print li[1:-1]&lt;br /&gt;[“b”,”c”,”d”,”e”]&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; print li[-6:-4]&lt;br /&gt;[“a”,”b”]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The most interesting part in the implementation of this for LINQ and LINQ to SQL is the handling of the negative indexes. Like I stated earlier, it is an indication to count from the back of the list. That means you need to know the number of items in the list. That’s easy with LINQ, but using LINQ to SQL a call to get the count would generate a SQL statement to get the count of items in the underlying table. I wanted to avoid that and try and build one LINQ to SQL statement to get the data. I was able to get it to work in the LINQ case using a combination of Skip, Take, Reverse, Union, and Intersect. However I ran into issues in LINQ to SQL stating the Reverse operator is not supported. So I went back to getting the count and adding the negative indexes to that to get the position of the start and stop. Even though it is two calls to the database, it is probably more efficient than the SQL statement it would have (if it could have) generated. I left the original implementation in place for the LINQ case for those interested in how that worked.&lt;br /&gt;&lt;br /&gt;The source file is available &lt;a href="http://solidcodingarchive.appspot.com/resources/LINQSlicing.cs"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The following is a set of tests run against the LINQ to SQL slice functionality to see what the generated SQL would look like. It shows how the operation is performed in Python, how to perform the same thing in LINQ to SQL, and what the generated SQL statements looks like.&lt;br /&gt;&lt;br /&gt;In the LINQ examples variable dc is an instance of DataContext&lt;br /&gt;&lt;br /&gt;&lt;b&gt; Test 1&lt;/b&gt;&lt;br /&gt;Python Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;li[0:3]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;LINQ Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;(From p In dc.GetTable&amp;lt;Person&amp;gt;.Slice(0, 3)).ToList()&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Generated SQL&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;SELECT TOP (3) [t0].[Id], [t0].[FirstName], [t0].[LastName]&lt;br /&gt;FROM [Person] AS [t0]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt; Test 2&lt;/b&gt;&lt;br /&gt;Python Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;li[1:3]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;LINQ Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;(From p In dc.GetTable&amp;lt;Person&amp;gt;.Slice(1, 3)).ToList()&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Generated SQL&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;SELECT [t2].[Id], [t2].[FirstName], [t2].[LastName]&lt;br /&gt;FROM (&lt;br /&gt;    SELECT [t1].[Id], [t1].[FirstName], [t1].[LastName], [t1].[ROW_NUMBER]&lt;br /&gt;    FROM (&lt;br /&gt;        SELECT ROW_NUMBER() OVER (ORDER BY [t0].[Id], [t0].[FirstName], [t0].[LastName]) AS [ROW_NUMBER], [t0].[Id], [t0].[FirstName], [t0].[LastName]&lt;br /&gt;        FROM [Person] AS [t0]&lt;br /&gt;        ) AS [t1]&lt;br /&gt;    WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1&lt;br /&gt;    ) AS [t2]&lt;br /&gt;ORDER BY [t2].[ROW_NUMBER]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt; Test 3&lt;/b&gt;&lt;br /&gt;Python Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;li[1:-1]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;LINQ Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;(From p In dc.GetTable&amp;lt;Person&amp;gt;.Slice(1, -1)).ToList()&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Generated SQL&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;SELECT COUNT(*) AS [value]&lt;br /&gt;FROM [Person] AS [t0]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT [t2].[Id], [t2].[FirstName], [t2].[LastName]&lt;br /&gt;FROM (&lt;br /&gt;    SELECT [t1].[Id], [t1].[FirstName], [t1].[LastName], [t1].[ROW_NUMBER]&lt;br /&gt;    FROM (&lt;br /&gt;        SELECT ROW_NUMBER() OVER (ORDER BY [t0].[Id], [t0].[FirstName], [t0].[LastName]) AS [ROW_NUMBER], [t0].[Id], [t0].[FirstName], [t0].[LastName]&lt;br /&gt;        FROM [Person] AS [t0]&lt;br /&gt;        ) AS [t1]&lt;br /&gt;    WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1&lt;br /&gt;    ) AS [t2]&lt;br /&gt;ORDER BY [t2].[ROW_NUMBER]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt; Test 4&lt;/b&gt;&lt;br /&gt;Python Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;li[-6:-4]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;LINQ Slice&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;(From p In dc.GetTable&amp;lt;Person&amp;gt;.Slice(-6, -4)).ToList()&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Generated SQL&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;SELECT COUNT(*) AS [value]&lt;br /&gt;FROM [Person] AS [t0]&lt;br /&gt;&lt;br /&gt;SELECT TOP (2) [t0].[Id], [t0].[FirstName], [t0].[LastName]&lt;br /&gt;FROM [Person] AS [t0]&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5539823847808743000?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5539823847808743000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5539823847808743000' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5539823847808743000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5539823847808743000'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/06/python-list-slicing-in-linq.html' title='Python List Slicing in LINQ'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7193620286191803884</id><published>2008-06-12T09:38:00.000-07:00</published><updated>2009-05-07T04:52:10.584-07:00</updated><title type='text'>.Net Class Library for the Roomba SCI</title><content type='html'>This is the class library I have been using to interact with the Roomba. It is a class library written in C# targeting the .Net 3.5 Framework. I have used some LINQ queries to parse out the byte array that is returned when you request sensor information. The main class to work with in the library is the RoombaAPI class. It is used to connect to the Roomba, send commands to it, and retrieve sensor data from the robot.&lt;br /&gt;&lt;br /&gt;I am not sure if others have done this or not, but in my opinion the most usefully part of the library is the parsing out of the sensor information into a set of objects and properties to allow easy access by a user. The way it works is that you ask the Roomba for all the sensor information, 26 bytes, and the information is returned in a class named SensorData. Some of the data such as the cliff sensors are broken out into their own class Cliff which has properties Left, FrontLeft, FrontRight and Right and is accessed via the SensorData’s Cliff property. Other sensor data, such as Temperature is a property of type short on the SensorData class.&lt;br /&gt;&lt;br /&gt;This class library only works with the new RooTooth modules. To work with older RooTooth modules, or direct serial connects, one could override the ‘Connect’ and ‘Wakeup’ functions on the RoombaAPI class.&lt;br /&gt;&lt;br /&gt;To use in your code add a reference to the class library and add the namespace RoombaSCI. All the command functions and the ‘Sensors’ properties are marked as virtual so developers can override as needed. I haven’t gotten around to implementing the Song function to record your own songs. So that would be a good candidate to override and provide an implementation for.&lt;br /&gt;&lt;br /&gt;I also have implemented a “Log” property so you can hookup any log writers you want to the class libray. I have one implemented, DebugWriter, that writes log info out to the debug window in Visual Studio.&lt;br /&gt;&lt;br /&gt;Just the .dll, in a .zip file, is available &lt;a href="http://solidcodingarchive.appspot.com/resources/RoombaSCI_DLL.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A .zip file of the source project is &lt;a href="http://solidcodingarchive.appspot.com/resources/RoombaSCI_Source.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example code to connect to the Roomba, starts the clean sequence, and asks for some sensor data.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;using (RoombaAPI api = new RoombaAPI("COM5",115200))&lt;br /&gt;{&lt;br /&gt;  api.Log = new DebugWriter();&lt;br /&gt;  api.Connect();&lt;br /&gt;  api.Control();&lt;br /&gt;  api.Clean();&lt;br /&gt;  System.Threading.Thread.Sleep(5000);&lt;br /&gt;  Console.WriteLine(api.Sensors.Angle.ToString());&lt;br /&gt;  api.Off();&lt;br /&gt;} &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7193620286191803884?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7193620286191803884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7193620286191803884' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7193620286191803884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7193620286191803884'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/06/net-class-library-for-roomba-sci.html' title='.Net Class Library for the Roomba SCI'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1116493274198965460</id><published>2008-06-02T21:12:00.000-07:00</published><updated>2008-06-02T21:17:19.998-07:00</updated><title type='text'>Wake Up Roomba Using Latest RooTooth</title><content type='html'>I was able to finally figure out the commands needed to ‘wake up’ the Roomba using the new RooTooths based on the Roving Network Bluetooth Module. You need to set the module to command mode and toggle pin GPIO 7.&lt;br /&gt;&lt;br /&gt;Here are the commands that worked for me. The SendToRoomba function is just a wrapper function around the SerialPort.Write(string) function in .Net 3.5.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;SendToRoomba("$$$");&lt;br /&gt;&lt;span class="codecomments"&gt;//Set GPIO 7 as output&lt;/span&gt;&lt;br /&gt;SendToRoomba("S@,8080\n");&lt;br /&gt;&lt;span class="codecomments"&gt;//set GPIO 7 low&lt;/span&gt;&lt;br /&gt;SendToRoomba("S&amp;amp;,8000\n");&lt;br /&gt;System.Threading.Thread.Sleep(500);&lt;br /&gt;&lt;span class="codecomments"&gt;//set GPIO 7 high&lt;/span&gt;&lt;br /&gt;SendToRoomba("S&amp;amp;,8080\n");&lt;br /&gt;&lt;span class="codecomments"&gt;//exit command mode&lt;/span&gt;&lt;br /&gt;SendToRoomba("---\n");&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Also another thing I did was to turn off the config timer so that the command mode is always available.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1116493274198965460?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1116493274198965460/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1116493274198965460' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1116493274198965460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1116493274198965460'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/06/wake-up-roomba-using-latest-rootooth.html' title='Wake Up Roomba Using Latest RooTooth'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-4158723810318567606</id><published>2008-05-22T21:45:00.000-07:00</published><updated>2009-05-12T16:17:51.522-07:00</updated><title type='text'>Voice Controlled Roomba Using .Net 3.5</title><content type='html'>I am developing a C# application that listens for voice commands, translates them to instructions understood by Roomba, and sends the request to the robot. A Bluetooth headset is used to send the voice commands to the application which is using the .Net Framework’s System.Speech.Recognition classes to process the commands. Recognized commands are converted to opcode instructions understood by the Roomba’s Serial Command Interface. Also, those commands are echoed to the screen and spoken using the .Net Framework’s speech synthesizer to provide feedback to the user.  A Bluetooth adaptor on the Roomba, a Rootooth, receives the translated opcodes from the application and passes them through to the Roomba. &lt;br /&gt;&lt;br /&gt;Source code for the voice controller part of the application is available &lt;a href="http://solidcodingarchive.appspot.com/resources/VoiceController.cs" &gt;here&lt;/a&gt;. I am still working on cleaning up the code that communicates with the Roomba. I'll try and post that at a later date.  There is functionality I haven't tested yet such as playing and recording songs that I would like to get implemented.&lt;br /&gt;&lt;br /&gt;I have also included a video demo of the application in action. &lt;br /&gt;&lt;br /&gt;&lt;EMBED SRC="http://solidcodingarchive.appspot.com/resources/Roomba.mov" WIDTH=500 HEIGHT = 300 AUTOPLAY=false CONTROLLER=true LOOP=false PLUGINSPAGE="http://www.apple.com/quicktime/"&gt;&lt;/EMBED&gt;&lt;br /&gt;&lt;br /&gt;Screenshot of the application:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://solidcodingarchive.appspot.com/resources/app_screenshot_cropped.JPG"&gt;&lt;/img&gt;&lt;br /&gt;&lt;br /&gt;5/29/08 -- Doing some more work with the voice commands by adding the ability to query some of the sensors on the Roomba. The video shows, getting the battery temperature, battery charge, and the presence of any virtual walls.&lt;br /&gt;&lt;br /&gt;&lt;EMBED SRC="http://solidcodingarchive.appspot.com/resources/RoombaSensors.mov" WIDTH=500 HEIGHT = 300 AUTOPLAY=false CONTROLLER=true LOOP=false PLUGINSPAGE="http://www.apple.com/quicktime/"&gt;&lt;/EMBED&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-4158723810318567606?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/4158723810318567606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=4158723810318567606' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4158723810318567606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/4158723810318567606'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/05/voice-controlled-roomba-using-net-35.html' title='Voice Controlled Roomba Using .Net 3.5'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5488405235095095403</id><published>2008-05-01T17:06:00.000-07:00</published><updated>2009-05-06T18:10:42.161-07:00</updated><title type='text'>Fuel Cost and Trip Planner</title><content type='html'>I improved the &lt;a href="http://solidcoding.blogspot.com/2008/04/fuel-cost-calculator.html"&gt;original fuel cost calculator&lt;/a&gt; by incorporating it into Google Maps. You can now choose a start and end destination and the calculator will retrieve the distance traveled from the Google Map API. The application will display the route in a Google Map as well as displaying the step by step directions. There is another new feature in the calculator that allows you to state the size of the vehicle’s gas tank. With that information along with the MPG of the vehicle, the calculator can determine how many miles the user can travel on a tank of gas. What it will then do is add markers to the map to inform the user that they may need to refuel at that point in their journey. When the user clicks the marker, a balloon window will contain a link to a GasBuddy.com map which contains fuel stations in that area along with current prices.&lt;br /&gt;&lt;br /&gt;The application can be viewed &lt;a href="http://fuel-cost.appspot.com"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5488405235095095403?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5488405235095095403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5488405235095095403' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5488405235095095403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5488405235095095403'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/05/fuel-cost-and-trip-planner.html' title='Fuel Cost and Trip Planner'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-460720804991648139</id><published>2008-04-29T15:09:00.000-07:00</published><updated>2009-05-06T22:43:06.269-07:00</updated><title type='text'>Python Web Server</title><content type='html'>I have been working with Python recently and it has been really fun getting to learn the language. I had built my own simple web server with C# and I decided to try my hand at building one in Python in an effort to learn the language. There are several examples out there, but the ones I found where really simple and just returned html files or plain text. I wanted one that could serve up several different types of Internet files, such as .html, .gif, .jpg, pdf, .xls, etc.  Also it needed to support a simple virtual directory mechanism.&lt;br /&gt;&lt;br /&gt;I have one up and running that achieves these goals. It has been tested with  .html, .zip, .doc. .pdf, .jpeg and has worked in all those cases. &lt;br /&gt;&lt;br /&gt;The source file can be obtained &lt;a href="http://solidcodingarchive.appspot.com/resources/MyWebServer.py.txt"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This server uses the Python mime type module to map file extensions to mime types. It uses an in memory list of virtual directory mappings and allows a developer to add more directories as needed. However that would then require a restart of the server. It would be very simple to move to a database lookup, but I left it this way so it can easily be tested and used by others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-460720804991648139?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/460720804991648139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=460720804991648139' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/460720804991648139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/460720804991648139'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/04/python-web-server.html' title='Python Web Server'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1309388526898213125</id><published>2008-04-27T13:38:00.000-07:00</published><updated>2009-05-23T11:50:37.174-07:00</updated><title type='text'>Fuel Cost Calculator</title><content type='html'>With fuel prices projected to reach $4.00 a gallon this summer, this fuel cost calculator will allow to determine how much that trip will affect your budget.  Just enter the cost of gas per gallon, the mile per gallon your vehicle gets, and the length of your trip in miles. The calculator will compute how much it costs you per mile to drive your vehicle, the amount of fuel you will you, and the estimated cost to make that trip.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://solidcodingarchive.appspot.com/resources/fuelcostcal.htm" width="500px" height="300px" frameborder="#"&gt;&lt;br /&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0740760025&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0756627346&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1309388526898213125?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1309388526898213125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1309388526898213125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1309388526898213125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1309388526898213125'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/04/fuel-cost-calculator.html' title='Fuel Cost Calculator'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8719066298807008111</id><published>2008-04-19T10:52:00.000-07:00</published><updated>2008-06-11T20:24:12.785-07:00</updated><title type='text'>Forth.Net Update: Source File Support</title><content type='html'>Functionality has been added to compile Forth.Net programs from source files. Previously, Forth.Net programming had to be done interactively in the Forth interpreter or by building Forth words in Visual Studio. To use this feature simply supply the full path of the source file to the Forth.exe on the command line. Any Forth word definitions, variables and constants in the source file are added to the well known assembly ForthWords.dll while Forth words for execution are added to the compiled .Net console application. The name of this console application will be the name of the source file.&lt;br /&gt;&lt;br /&gt;Additional information, along with the source code, on the Forth.Net environment is available &lt;a href="http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8719066298807008111?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8719066298807008111/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8719066298807008111' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8719066298807008111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8719066298807008111'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/04/forthnet-update-source-file-support.html' title='Forth.Net Update: Source File Support'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-364469805558012185</id><published>2008-04-14T08:11:00.000-07:00</published><updated>2009-05-25T14:39:55.841-07:00</updated><title type='text'>Hosting Forth.Net in a Windows Form</title><content type='html'>With gas prices increasing I thought it would be interesting to create a Forth.Net program to calculate the cost per mile to drive my vehicle. The program will take in the price of gas, the miles per gallon of my vehicle and will compute the cost to drive it per mile. For example, if gas is $3.25 and I am getting 17 MPG it is costing me 19 cents per mile to drive my vehicle.&lt;br /&gt;&lt;br /&gt;The twist with the Forth.Net program is the end product will be hosted in a Windows form. First, we will create the Forth words for the program in the Forth.Net compiler. Them we will create a Windows form to hold a textbox for the cost of gas, the miles per gallon and the result of cents per mile. A calculate button will be placed on the form, and the code behind that button will start the Forth program, pass in the inputs, and call the necessary Forth words, and get the result left on the Forth stack placing it in the cents per mile textbox.&lt;br /&gt;&lt;br /&gt;The Forth.Net environment is available &lt;a href="http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Open the Forth.Net compiler, Forth.exe, and implement the following Forth words.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;: ToCents (dollar cents – cents) swap 100 * + ;&lt;br /&gt;&lt;br /&gt;: CentsPerMile (gasdollar gascents mpg -- cents_per_mile)&lt;br /&gt;rot swap ToCents swap / ;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In Visual Studio 2008, create a new Windows Application.&lt;br /&gt;&lt;br /&gt;Add references to ForthAPI.dll and ForthWords.dll. ForthWords.dll contains the Forth words that you just created.&lt;br /&gt;&lt;br /&gt;Setup the UI like the one shown and enter the following code in the button click event&lt;br /&gt;&lt;image src="http://solidcodingarchive.appspot.com/resources/centspermile.jpg"&gt;&lt;/image&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;private void&lt;/span&gt; button1_Click(&lt;span class="keyword"&gt;object&lt;/span&gt; sender, &lt;span class="cSharpClass"&gt;EventArgs&lt;/span&gt; e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="cSharpClass"&gt;Forth&lt;/span&gt; f = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;Forth&lt;/span&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="codecomments"&gt;//f.Lit() is the function to add values to the stack.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="codecomments"&gt;//'Lit' short for literal&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;f.Lit(&lt;span class="cSharpClass"&gt;Convert&lt;/span&gt;.ToInt32(txtDollar.Text));&lt;br /&gt;&amp;nbsp;&amp;nbsp;f.Lit(&lt;span class="cSharpClass"&gt;Convert&lt;/span&gt;.ToInt32(txtCents.Text));&lt;br /&gt;&amp;nbsp;&amp;nbsp; f.Lit(&lt;span class="cSharpClass"&gt;Convert&lt;/span&gt;.ToInt32(txtMPG.Text));&lt;br /&gt;&amp;nbsp;&amp;nbsp;f.Centspermile();&lt;br /&gt;&amp;nbsp;&amp;nbsp;txtCentsPerMile.Text = f.DotGet().ToString();&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The windows application project is available with the Forth words already implemented in the ForthWords.dll &lt;a href="http://solidcodingarchive.appspot.com/resources/CentsPerMile_Source.zip"&gt;here&lt;/a&gt; and the components to just run the application are &lt;a href="http://solidcodingarchive.appspot.com/resources/CentsPerMile.zip"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-364469805558012185?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/364469805558012185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=364469805558012185' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/364469805558012185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/364469805558012185'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/04/hosting-forthnet-in-windows-form.html' title='Hosting Forth.Net in a Windows Form'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-983002231629323211</id><published>2008-04-07T07:48:00.000-07:00</published><updated>2009-05-06T22:40:40.286-07:00</updated><title type='text'>Diff Algorithm with LINQ</title><content type='html'>A year or so ago I wrote a diff application similar to windiff based upon the core algorithm discussed in &lt;a href="http://www.codeproject.com/KB/recipes/DiffQuest.aspx"&gt; A Fast Diff Algorithm in Visual Basic .Net&lt;/a&gt;. Somewhere along the way of upgrading my computer I lost that application.  I decided to go back and recreate that application, but this time focus on using LINQ as much as possible in the implementation. It is probably not the fastest, but it is intended to be an exercise in incorporating LINQ in the implementation of an algorithm.&lt;br /&gt; &lt;br /&gt;What I have at this point is code that will find the longest common sequence (LCS) of two string arrays. An extension method, LCS, is available on any string collections that implements the IEnumerable&lt;string&gt; interface. You start with an original string collection, and pass the LCS function another string collection that you would like to diff against the original. What you are returned is a DiffInfo class which contains the start index of the LCS in the original string collection, the start position of the LCS in the comparing string collection, and finally the length of the LCS. With that information we have a foundation on which to build an application to show the diff of the two string collections. I will build that application in later posts.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;            &lt;span class="keyword"&gt;string&lt;/span&gt;[] org = {"A","A","z", "A"};&lt;br /&gt;            &lt;span class="keyword"&gt;string&lt;/span&gt;[] cmp = {"z", "A", "A", "A", "A"};&lt;br /&gt;            &lt;span class="cSharpClass"&gt;DiffInfo&lt;/span&gt; d = org.LCS(cmp);&lt;br /&gt;            &lt;span class="codecomments"&gt;//index = 0&lt;/span&gt;&lt;br /&gt;            &lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("LCS start in orginal " + d.OriginalStartPos.ToString());&lt;br /&gt;            &lt;span class="codecomments"&gt;//index = 1&lt;/span&gt;&lt;br /&gt;            &lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("LCS start in compared " + d.ComparedStartPos.ToString());&lt;br /&gt;            &lt;span class="codecomments"&gt;// length = 2&lt;/span&gt;&lt;br /&gt;            &lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("Length of LCS " + d.Length);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Code available &lt;a href="http://solidcodingarchive.appspot.com/resources/LinqDiff.cs"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-983002231629323211?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/983002231629323211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=983002231629323211' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/983002231629323211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/983002231629323211'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/04/diff-algorithm-with-linq.html' title='Diff Algorithm with LINQ'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1297311233710593286</id><published>2008-03-12T14:09:00.000-07:00</published><updated>2009-05-06T22:40:03.089-07:00</updated><title type='text'>Roomba Hacking, Forth Style</title><content type='html'>After developing my &lt;a href="http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html"&gt;Forth.Net implementation&lt;/a&gt; I began trying to come up with ideas on how I could use it. About that same time the vacuum motors on our Roomba went down, so we decided we would replace it with a new one. I had been thinking about getting the Roomba Create robot, but with my Roomba Scheduler going down, I decided to hold on to it and try my hand at hacking it instead. It still runs, but it just doesn’t vacuum. I had read about the &lt;a href="http://www.irobot.com/images/consumer/hacker/Roomba_SCI_Spec_Manual.pdf"&gt; Roomba Serial Command Interface (SCI)&lt;/a&gt;, and it looked like it would be a great candidate to try and build a Forth.Net dictionary around. &lt;br /&gt;&lt;br /&gt;So my current Forth.Net project is a Forth.Net to Roomba dictionary. At this stage I am developing a Forth word for each of the commands in the Roomba SCI. The Forth words are being developed as extension methods of the ForthAPI class and are getting compiled into a .Net class library.  C# is the language being used to tie the Forth words to the Roomba SCI. &lt;br /&gt;&lt;br /&gt;The Forth.Net to Roomba dictionary hasn’t been tested yet; I am still working on getting a Bluetooth adaptor, the &lt;a href="http://www.sparkfun.com/commerce/product_info.php?products_id=684"&gt;RooTooth&lt;/a&gt;, from  SparkFun Electronics. I am not sure if my serial port connection implementation is going to work. I am opening and closing the port between each Roomba command. I might need to keep the port open the entire duration that I am sending commands to the Roomba. There are some tricks I can do for that.  &lt;br /&gt;&lt;br /&gt;Anyways, I am putting this out there now to share while I work on getting a RooTooth adaptor. The source code is available &lt;a href='http://solidcodingarchive.appspot.com/resources/ForthRoomba.cs'&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;A simple Forth.Net to Roomba program to start the Roomba cleaning&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;Start Control Clean&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0470072717&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0976458705&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1297311233710593286?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1297311233710593286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1297311233710593286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1297311233710593286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1297311233710593286'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/03/roomba-hacking-forth-style.html' title='Roomba Hacking, Forth Style'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1140530007241037660</id><published>2008-03-10T09:20:00.000-07:00</published><updated>2009-05-06T22:52:01.099-07:00</updated><title type='text'>LINQ to SQL Code Generator</title><content type='html'>Last month I created an online, pure Javascript, &lt;a href="http://solidcoding.blogspot.com/2008/02/linq-to-excel-code-generator_2842.html"&gt;LINQ to Excel code generator&lt;/a&gt; for use with the &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html"&gt;LINQ to Excel provider&lt;/a&gt; that I have developed. I decided to take that code and modify it slightly to create a code generator for LINQ to SQL. This will allow one to easily map a SQL Server table to a .Net LINQ to SQL class. This generator, however, is not able to generate relationships between tables using EntitySet or EntityRef.&lt;br /&gt;&lt;br /&gt;Check it out &lt;a href="http://solidcodingarchive.appspot.com/resources/LINQtoSQLCodeGen.htm"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1140530007241037660?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1140530007241037660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1140530007241037660' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1140530007241037660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1140530007241037660'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/03/linq-to-sql-code-generator.html' title='LINQ to SQL Code Generator'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5623050796057187535</id><published>2008-02-27T14:59:00.001-08:00</published><updated>2008-09-20T13:29:08.822-07:00</updated><title type='text'>LINQ to SQL Multi Tier Example</title><content type='html'>After some experimenting I have come up with what I think is a viable implementation to provide support for multi tier development using LINQ to SQL. One of the major issues with providing multi tier support in LINQ to SQL is how to attach the entity back on the DataContext and have it save the data correctly, or in many instances not to get LINQ to throw an exception.&lt;br /&gt;&lt;br /&gt;Here is what I am doing:&lt;br /&gt;&lt;br /&gt;- Attaching the inbound entity to a data context using the Attach method off the Table object. This object can be found off the DataContext on the GetTable generic method&lt;br /&gt;&lt;br /&gt;- After attaching the inbound entity, I will then refresh it with a copy from the database using the Refresh method on the DataContext. I am using the KeepCurrentValues option which forces a comparison to see and set what has changed with the entity. This allows me to only persist the properties of the entity that have changed,and not update all the properties of the entity.&lt;br /&gt;&lt;br /&gt;- Since I am using the Attach method that takes just one entity, it forces me to define a property on my entity that should be used for version checking. If I don’t do this, I get an exception stating to set the IsVersion property on one of my entity’s properties ColumnAttributes or turn off the update checking. Version checking allows for the ability to determine if the data of an entity has been changed by some else in the database after you had retrieved it. This action is performed when you try to submit changes to the database.  To allow for this, I am going to add a timestamp column to my underlying SQL table that is updated using triggers when a row is updated or inserted. The column will be mapped as a read only property on my entity.&lt;br /&gt;&lt;br /&gt;What is update checking?  It is a technique LINQ uses to determine if the data for an entity instance has been changed since the entity was retrieved from the database. What it does is a build a where clause in the update statement that consists of the original values of all the entity‘s mapped properties. If any of those values have changed the update will fail and LINQ will throw an exception saying the row was deleted or changed. &lt;br /&gt;&lt;br /&gt;Version checking does the same thing but you are setting what property, or maybe even properties (haven’t tried it) is built in that update where clause.&lt;br /&gt;&lt;br /&gt;Here is what my sample entity looks like&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&amp;lt;&lt;span class="cSharpClass"&gt;Table&lt;/span&gt;(Name="Person")&amp;gt;&lt;br /&gt;&lt;span class="keyword"&gt;public class&lt;/span&gt; &lt;span class="cSharpClass"&gt;Person&lt;/span&gt; {&lt;br /&gt;&amp;nbsp;&amp;lt;&lt;span class="cSharpClass"&gt;Column&lt;/span&gt;(Name="Id", Storage="_id", IsPrimaryKey=&lt;span class="keyword"&gt;true&lt;/span&gt;, IsDbGenerated=&lt;span class="keyword"&gt;true&lt;/span&gt;)&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public int&lt;/span&gt; Id {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="codecomments"&gt;//add get set details&lt;/span&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;&lt;span class="cSharpClass"&gt;Column&lt;/span&gt;(Name="FirstName", Storage="_firstName")&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public string&lt;/span&gt; FirstName {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="codecomments"&gt;//add get set details&lt;/span&gt;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;&lt;span class="cSharpClass"&gt;Column&lt;/span&gt;(Name="LastName", Storage="_lastName")&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public string&lt;/span&gt; LastName {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="codecomments"&gt;//add get set details&lt;/span&gt;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;&lt;span class="cSharpClass"&gt;Column&lt;/span&gt;(Name="RowModifiedDate", Storage="_date", IsVersion=&lt;span class="keyword"&gt;true&lt;/span&gt;)&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="cSharpClass"&gt;DateTime&lt;/span&gt; RowModifiedDate {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class="codecomments"&gt;//add get details&lt;/span&gt;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now in the example I am about to show I am going to convert my entity to and from Xml using some extension methods I described in my &lt;a href="http://solidcoding.blogspot.com/2007/11/c-toxml-extension-method.html"&gt;C# ToXml extension method&lt;/a&gt; post. This is just used to mimic sending a message back and forth to another tier of my application.&lt;br /&gt;&lt;br /&gt;Finally the example&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt; outPerson = null;&lt;br /&gt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt; inPerson = null;&lt;br /&gt;&lt;span class="keyword"&gt;string&lt;/span&gt; transport = &lt;span class="keyword"&gt;string&lt;/span&gt;.Empty;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt; (&lt;span class="cSharpClass"&gt;DataContext&lt;/span&gt; dc = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;DataContext&lt;/span&gt;("connectioninfo")) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;outPerson = dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;().First();&lt;br /&gt;}&lt;br /&gt;&lt;span class="codecomments"&gt;//mimic transport to and from another tier of the application&lt;/span&gt;&lt;br /&gt;transport = outPerson.ToXml();&lt;br /&gt;inPerson = transport.FromXml&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;span class="codecomments"&gt;//Force a change to the entity&lt;/span&gt;&lt;br /&gt;inPerson.FirstName = "John";&lt;br /&gt;&lt;br /&gt;&lt;span class="codecomments"&gt;//save the inbound entity back to the database&lt;/span&gt;&lt;br /&gt;&lt;span class="keyword"&gt;using&lt;/span&gt;(&lt;span class="cSharpClass"&gt;DataContext&lt;/span&gt; dc = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;DataContext&lt;/span&gt;("connectioninfo")) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;().Attach(inPerson);&lt;br /&gt;&amp;nbsp;&amp;nbsp;dc.Refresh(&lt;span class="cSharpClass"&gt;RefreshMode&lt;/span&gt;.KeepCurrentValues, inPerson);&lt;br /&gt;&amp;nbsp;&amp;nbsp;dc.SubmitChanges();&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5623050796057187535?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5623050796057187535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5623050796057187535' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5623050796057187535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5623050796057187535'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/02/linq-to-sql-multi-tier-example.html' title='LINQ to SQL Multi Tier Example'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8378812657751671897</id><published>2008-02-22T15:47:00.001-08:00</published><updated>2009-05-06T22:38:33.386-07:00</updated><title type='text'>LINQ to Excel Code Generator</title><content type='html'>I have noticed that there has been some interest in my LINQ to Excel Provider. I thought it might be beneficial and fun to try and build an online code generator to create one’s LINQ to Excel class. This code generator is a pure JavaScript application and it should be pretty straightforward to use.&lt;br /&gt;&lt;br /&gt;The purpose of this generator is to build a .Net class than can be used to interact with my &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html"&gt;LINQ to Excel Provider 2.5&lt;/a&gt; and perform CRUD operations on an Excel sheet.&lt;br /&gt;&lt;br /&gt;To run the generator:&lt;br /&gt;&lt;br /&gt;1. Determine with language you want to use (C# or VB).&lt;br /&gt;2. Supply the name of your .Net class&lt;br /&gt;3. Set the name of the Excel sheet you want to map your .Net class to.&lt;br /&gt;4. Supply the column names and data types from the Excel sheet that you want to incorporate into your .Net class.&lt;br /&gt;5. Click the Generate Code button.&lt;br /&gt;6. Copy the contents of the bottom textbox into a class file in Visual Studio.&lt;br /&gt;7. Refer to &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html"&gt;LINQ to Excel Provider 2.5&lt;/a&gt; for an example on how to interact with your class and read data from Excel.&lt;br /&gt;&lt;br /&gt;Enjoy and if you have any comments or suggestions let me know.&lt;br /&gt;&lt;br /&gt;Check the generator out &lt;a href="http://solidcodingarchive.appspot.com/resources/LINQtoExcelCodeGen.html"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8378812657751671897?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8378812657751671897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8378812657751671897' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8378812657751671897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8378812657751671897'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/02/linq-to-excel-code-generator_2842.html' title='LINQ to Excel Code Generator'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7220931476067364639</id><published>2008-01-30T15:45:00.001-08:00</published><updated>2008-01-30T15:45:50.621-08:00</updated><title type='text'>Microsoft Tech Ed 2008 Registration Open</title><content type='html'>The &lt;a href=”http://www.microsoft.com/events/teched2008/default.mspx”&gt;Microsoft Tech Ed 2008&lt;/a&gt; conference is now open for registration. The conference will be held in Orlando, Florida at the Orange County Convention Center. This year the conference is actually broken down to two conferences, the Developer conference from June 3-6 followed by the IT Professional conference from June 10-13.  Bill Gates will keynote the Developer conference and Bob Muglia, Vice President Server and Tools Business will do likewise for the IT Professional conference. &lt;br /&gt;&lt;br /&gt;Register before April 4 and save $200.  Software, programming, sun, Florida, theme parks; sounds like fun to me&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7220931476067364639?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7220931476067364639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7220931476067364639' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7220931476067364639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7220931476067364639'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/01/microsoft-tech-ed-2008-registration.html' title='Microsoft Tech Ed 2008 Registration Open'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8464318054952214783</id><published>2008-01-29T18:48:00.000-08:00</published><updated>2009-05-06T22:38:06.677-07:00</updated><title type='text'>LINQ to Excel Provider 2.5</title><content type='html'>This version of the provider, evolving from &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-20.html"&gt;LINQ to Excel Provider 2.0&lt;/a&gt;, adds change tracking in order to allow a user to update, insert, and delete Microsoft Excel data from any .Net code. It follows the LINQ to SQL model of change tracking. To track updates in a class the class will need to implement the System.ComponentModel.INotifyPropertyChanged interface. On the property setters, a developer will write code to raise the PropertyChanged event when a new value is set in the property. The example shows how to write a helper method to ease raising this event. To add or delete records one would call either InsertOnSubmit or DeleteOnSubmit on the generic GetSheet method of the provider. When you would like to commit your changes to Excel, simply call SubmitChanges on the provider and all the inserts, updates, and deletes are committed to the Excel spreadsheet.&lt;br /&gt;&lt;br /&gt;The C# source file is available &lt;a href="http://solidcodingarchive.appspot.com/resources/LinqExcelProvider25.cs"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A VB.Net version of the source is available &lt;a href="http://solidcodingarchive.appspot.com/resources/LinqExcelProvider25.vb"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;An online code generator to build the LINQ to Excel class is available &lt;a href="http://solidcodingarchive.appspot.com/resources/LINQtoExcelCodeGen.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="cSharpClass"&gt;ExcelProvider&lt;/span&gt; provider = &lt;span class="cSharpClass"&gt;ExcelProvider&lt;/span&gt;.Create(@"c:\deploy\Book1.xls");&lt;br /&gt;&lt;span class="keyword"&gt;foreach&lt;/span&gt; (&lt;span class="cSharpClass"&gt;Person&lt;/span&gt; per &lt;span class="keyword"&gt;in&lt;/span&gt; (&lt;span class="keyword"&gt;from&lt;/span&gt; p &lt;span class="keyword"&gt;in&lt;/span&gt; provider.GetSheet&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class="keyword"&gt;where&lt;/span&gt; p.LastName == "Johnson" &lt;span class="keyword"&gt;select&lt;/span&gt; p))&lt;br /&gt;{&lt;br /&gt;per.LastName = "Smith";&lt;br /&gt;}&lt;br /&gt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt; p = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;Person&lt;/span&gt;();&lt;br /&gt;p.Id = 10.0;&lt;br /&gt;p.FirstName = "Alex";&lt;br /&gt;p.LastName = "Zander";&lt;br /&gt;p.BirthDate = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;DateTime&lt;/span&gt;(1980, 4, 4);&lt;br /&gt;provider.GetSheet&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;() InsertOnSubmit(p);&lt;br /&gt;provider.SubmitChanges();&lt;br /&gt;&lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine("Done");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;[&lt;span class="cSharpClass"&gt;ExcelSheet&lt;/span&gt;(Name="Sheet1")]&lt;br /&gt;&lt;span class="keyword"&gt;public class&lt;/span&gt; Person: System.ComponentModel.INotifyPropertyChanged&lt;br /&gt;{&lt;br /&gt; &lt;span class="keyword"&gt;private double&lt;/span&gt; id;&lt;br /&gt; &lt;span class="keyword"&gt;private string&lt;/span&gt; fName;&lt;br /&gt; &lt;span class="keyword"&gt;private string&lt;/span&gt; lName;&lt;br /&gt; &lt;span class="keyword"&gt;private&lt;/span&gt; &lt;span class="cSharpClass"&gt;DateTime&lt;/span&gt; bDate;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="keyword"&gt;public event&lt;/span&gt; System.ComponentModel.PropertyChangedEventHandler PropertyChanged;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="keyword"&gt;protected virtual void&lt;/span&gt; SendPropertyChanged(&lt;span class="keyword"&gt;string&lt;/span&gt; propertyName)&lt;br /&gt; {&lt;br /&gt;  System.ComponentModel.PropertyChangedEventHandler handler = PropertyChanged;&lt;br /&gt;  &lt;span class="keyword"&gt;if&lt;/span&gt; (handler != &lt;span class="keyword"&gt;null&lt;/span&gt;)&lt;br /&gt;  {&lt;br /&gt;   handler(&lt;span class="keyword"&gt;this&lt;/span&gt;, &lt;span class="keyword"&gt;new&lt;/span&gt; System.ComponentModel.PropertyChangedEventArgs(propertyName));&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="keyword"&gt;public&lt;/span&gt; Person()&lt;br /&gt; {&lt;br /&gt;    id = 0;&lt;br /&gt; }&lt;br /&gt; [&lt;span class="cSharpClass"&gt;ExcelColumn&lt;/span&gt;(Name="ID",Storage="id")]&lt;br /&gt; &lt;span class="keyword"&gt;public double&lt;/span&gt; Id&lt;br /&gt; {&lt;br /&gt;    &lt;span class="keyword"&gt;get&lt;/span&gt; { &lt;span class="keyword"&gt;return&lt;/span&gt; id; }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; [&lt;span class="cSharpClass"&gt;ExcelColumn&lt;/span&gt;(Name = "FirstName", Storage = "fName")]&lt;br /&gt; &lt;span class="keyword"&gt;public string&lt;/span&gt; FirstName&lt;br /&gt; {&lt;br /&gt;    &lt;span class="keyword"&gt;get&lt;/span&gt; { &lt;span class="keyword"&gt;return&lt;/span&gt; this.fName; }&lt;br /&gt;    &lt;span class="keyword"&gt;set&lt;/span&gt; { fName = &lt;span class="keyword"&gt;value&lt;/span&gt;;&lt;br /&gt;            SendPropertyChanged("FirstName"); &lt;/div&gt;&lt;div class="code"&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; [&lt;span class="cSharpClass"&gt;ExcelColumn&lt;/span&gt;(Name = "LastName", Storage = "lName")]&lt;br /&gt; &lt;span class="keyword"&gt;public string&lt;/span&gt; LastName&lt;br /&gt; {&lt;br /&gt;    &lt;span class="keyword"&gt;get&lt;/span&gt; { &lt;span class="keyword"&gt;return this&lt;/span&gt;.lName; }&lt;br /&gt;    &lt;span class="keyword"&gt;set&lt;/span&gt; { lName = &lt;span class="keyword"&gt;value&lt;/span&gt;;&lt;br /&gt;            SendPropertyChanged("LastName"); &lt;/div&gt;&lt;div class="code"&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; [&lt;span class="cSharpClass"&gt;ExcelColumn&lt;/span&gt;(Name = "BirthDate", Storage = "bDate")]&lt;br /&gt; &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="cSharpClass"&gt;DateTime&lt;/span&gt; BirthDate&lt;br /&gt; {&lt;br /&gt;     &lt;span class="keyword"&gt;get&lt;/span&gt; { &lt;span class="keyword"&gt;return this&lt;/span&gt;.bDate; }&lt;br /&gt;    &lt;span class="keyword"&gt;set&lt;/span&gt; { bDate= &lt;span class="keyword"&gt;value&lt;/span&gt;; }&lt;br /&gt;             SendPropertyChanged("BirthDate"); &lt;/div&gt;&lt;div class="code"&gt;    }&lt;br /&gt; }&lt;br /&gt;} &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8464318054952214783?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8464318054952214783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8464318054952214783' title='55 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8464318054952214783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8464318054952214783'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html' title='LINQ to Excel Provider 2.5'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>55</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3007111779282544777</id><published>2008-01-27T19:20:00.001-08:00</published><updated>2008-01-27T22:03:56.876-08:00</updated><title type='text'>LINQ to Excel: SQL Import</title><content type='html'>Here is a simple technique you can use to import data from  Microsoft Excel to Microsoft SQL Server by using a combination of &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-20.html"&gt;LINQ to Excel&lt;/a&gt; and LINQ to SQL. All that is really required is to adorn your class with the LINQ to SQL attributes and also with the LINQ to Excel attributes. With that simple addition, your class is now capable of handling both LINQ providers and you can now move data from Microsoft Excel to Microsoft SQL Server using LINQ.&lt;br /&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='cSharpClass'&gt;ExcelProvider&lt;/span&gt; provider = &lt;span class='cSharpClass'&gt;ExcelProvider&lt;/span&gt;.Create(@"c:\deploy\Book1.xls");&lt;br /&gt;&lt;span class'cSharpClass'&gt;DataContext&lt;/span&gt; dc = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span&gt;DataContext&lt;/span&gt;("yourSqlConnection");&lt;br /&gt;&lt;span class='keyword'&gt;foreach&lt;/span&gt; (&lt;span class='cSharpClass'&gt;Person&lt;/span&gt; per &lt;span class='keyword'&gt;in&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in&lt;/span&gt; provider.GetSheet&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class='keyword'&gt;where&lt;/span&gt; p.LastName == "Johnson" &lt;span class='keyword'&gt;select&lt;/span&gt; p))&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;dc.GetTable&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;().InsertOnSubmit(per);&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;    &lt;br /&gt;dc.SubmitChanges();&lt;br /&gt;&lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine("Done");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;[&lt;span class='cSharpClass'&gt;ExcelSheet&lt;/span&gt;(Name="Sheet1")]&lt;br /&gt;[&lt;span class='cSharpClass'&gt;Table&lt;/span&gt;(Name="Person")]&lt;br /&gt;&lt;span class='keyword'&gt;public class&lt;/span&gt; Person&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private double&lt;/span&gt; id;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private string&lt;/span&gt; fName;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private string&lt;/span&gt; lName;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private&lt;/span&gt; &lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt; bDate;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; Person()&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id = 0;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name="ID",Storage="id")]&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;Column&lt;/span&gt;(Name="ID",Storage="id", IsPrimaryKey=&lt;span class='keyword'&gt;true&lt;/span&gt;)]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public double&lt;/span&gt; Id&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return&lt;/span&gt; id; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name = "FirstName", Storage = "fName")]&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;Column&lt;/span&gt;(Name = "FirstName", Storage = "fName")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public string&lt;/span&gt; FirstName&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return&lt;/span&gt; this.fName; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;set&lt;/span&gt; { fName = &lt;span class='keyword'&gt;value&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name = "LastName", Storage = "lName")]&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;Column&lt;/span&gt;(Name = "LastName", Storage = "lName")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public string&lt;/span&gt; LastName&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return this&lt;/span&gt;.lName; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;set&lt;/span&gt; { lName = &lt;span class='keyword'&gt;value&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name = "BirthDate", Storage = "bDate")]&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;Column&lt;/span&gt;(Name = "BirthDate", Storage = "bDate")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt; BirthDate&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return this&lt;/span&gt;.bDate; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;set&lt;/span&gt; { bDate= &lt;span class='keyword'&gt;value&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3007111779282544777?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3007111779282544777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3007111779282544777' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3007111779282544777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3007111779282544777'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/01/linq-to-excel-sql-import.html' title='LINQ to Excel: SQL Import'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-6036337496236589577</id><published>2008-01-23T15:34:00.001-08:00</published><updated>2009-01-25T12:20:14.638-08:00</updated><title type='text'>Forth .Net Tax Example Program</title><content type='html'>I have been looking to develop a larger Forth .Net example program but had been struggling coming up with a good example. (You can refer to my Forth .Net implementation I have created &lt;a href="http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html"&gt;here&lt;/a&gt;.) Finally I got the idea, with income tax time coming around, of creating a Forth .Net application to automate the tax formula that people need to use if their income falls above the provided tax tables. What this example program will do is create one of the IRS tax formulas on page 75 in the &lt;a href="http://www.irs.gov/pub/irs-pdf/i1040.pdf"&gt; IRS 2007 Form 1040 instructions&lt;/a&gt; document. The formula this example program will build is the one for the people with a filing status of Single, Section A.&lt;br /&gt;&lt;br /&gt;The first thing this program will need to do is create conversions to cents and to dollars.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;: ToCents (dollar cents – cents) swap 100 * + ;&lt;br /&gt;: ToDollar (cents – dollar cents) dup 100 / swap 100 mod ;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The next thing we need to do is build a Forth word to handle calculating percentages. We will assume that this word is going to work with cents only. The if section is handling rounding fractions up if they are larger than .5&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;: Percent (cents percentRate – cents) * dup 100 / swap 100 mod 49 &gt; if 1 + then ;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Since we are dealing with tax brackets, we need a Forth word to test if a value falls in between two values. Note 0 = false and 1 = true&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;: InRange (value lowValue highValue – 0/1) rot dup rot &gt;= rot &lt;= = ;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now that the ‘helper’ words are in place, we need to create Forth words to handle the tax brackets for the single filer.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;: SingleTooLowBracket (cents -- ) 100000 00 ToCents &lt; if .”Use Tax Table” cr drop then ;&lt;br /&gt;&lt;br /&gt;: SingleLowBracket (cents --) 100000 00 ToCents 160850 00 ToCents&lt;br /&gt;InRange true = if&lt;br /&gt; 28 Percent 5889 25 ToCents – ToDollar swap .”$” . .&lt;br /&gt;Then ;&lt;br /&gt;&lt;br /&gt;: SingleMiddleBracket (cents --) 160850 01 ToCents 349700 00 ToCents&lt;br /&gt;InRange true = if&lt;br /&gt;33 Percent 13931 75 ToCents – ToDollar swap .”$” . .&lt;br /&gt;Then ;&lt;br /&gt;&lt;br /&gt;: SingleHighBracket (cents --) 349700 00 ToCents &gt; if&lt;br /&gt;35 Percent 20925 75 ToCents – ToDollar swap .”$” . .&lt;br /&gt;Then ;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;With the brackets all in place all that is left is to encapsulate all this work into one Forth word.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;: SingleTax (dollar cents --) ToCents dup dup SingleTooLowBracket dup SingleLowBracket dup SingleMiddleBracket dup SingleHighBracket drop ;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;To now use this program all you need to do is enter an income followed by the Forth word SingleTax&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;146000 00 SingleTax&lt;br /&gt;&lt;br /&gt;And you should get&lt;br /&gt;$34990 75 ok&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1419675494&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0976458705&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0966215613&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0911827005&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-6036337496236589577?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/6036337496236589577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=6036337496236589577' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6036337496236589577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6036337496236589577'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/01/forth-net-tax-example-program.html' title='Forth .Net Tax Example Program'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-6077680757396197412</id><published>2008-01-19T07:49:00.000-08:00</published><updated>2009-05-12T16:09:51.791-07:00</updated><title type='text'>LINQ to Excel Provider 2.0</title><content type='html'>&lt;b&gt;Note:&lt;/b&gt; View the newest version of the provider in this &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html"&gt;post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This LINQ to Excel provider is an improvement based on the provider discussed in my first &lt;a href="http://solidcoding.blogspot.com/2007/12/linq-to-excel-provider.html"&gt;LINQ to Excel Provider&lt;/a&gt; post.  This provider strives to mimic the LINQ to SQL model which provides the developer a strongly typed .Net class to represent the Microsoft Excel sheets. A developer will map an Excel sheet to a .Net class by adorning the class with the ExcelSheetAttribute, and the properties with the ExcelColumn attribute. &lt;br /&gt;&lt;br /&gt;This provider still uses an OleDB connection to load data from Excel into a queryable memory collection at which point normal LINQ queries can be performed. The generic GetSheet method is called on the provider with a mapped Excel sheet class in order to initiate this process. This is similar to calling the generic GetTable method on the DataContext in the LINQ to SQL model. &lt;br /&gt;&lt;br /&gt;The next steps I am working on is to track changes, and save or delete data.&lt;br /&gt;&lt;br /&gt;The source file is available &lt;a href='http://solidcodingarchive.appspot.com/resources/LINQExcelProvider2.cs'&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is example that is querying the following sample Excel data. Data is assumed to be in Sheet1.&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;FirstName&lt;/td&gt;&lt;td&gt;LastName&lt;td&gt;BirthDate&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;Anderson&lt;/td&gt;&lt;td&gt;12/12/1980&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;Frank&lt;/td&gt;&lt;td&gt;Johnson&lt;/td&gt;&lt;td&gt;11/10/1976&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;Olson&lt;/td&gt;&lt;td&gt;5/7/1973&lt;/td&gt;&lt;tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='cSharpClass'&gt;ExcelProvider&lt;/span&gt; provider = &lt;span class='cSharpClass'&gt;ExcelProvider&lt;/span&gt;.Create(@"c:\deploy\Book1.xls");&lt;br /&gt;&lt;span class='keyword'&gt;foreach&lt;/span&gt; (&lt;span class='cSharpClass'&gt;Person&lt;/span&gt; per &lt;span class='keyword'&gt;in&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in&lt;/span&gt; provider.GetSheet&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class='keyword'&gt;where&lt;/span&gt; p.LastName == "Johnson" &lt;span class='keyword'&gt;select&lt;/span&gt; p))&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine(per.FirstName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine(per.LastName);&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;    &lt;br /&gt;&lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine("Done");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;[&lt;span class='cSharpClass'&gt;ExcelSheet&lt;/span&gt;(Name="Sheet1")]&lt;br /&gt;&lt;span class='keyword'&gt;public class&lt;/span&gt; Person&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private double&lt;/span&gt; id;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private string&lt;/span&gt; fName;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private string&lt;/span&gt; lName;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;private&lt;/span&gt; &lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt; bDate;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; Person()&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id = 0;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name="ID",Storage="id")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public double&lt;/span&gt; Id&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return&lt;/span&gt; id; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name = "FirstName", Storage = "fName")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public string&lt;/span&gt; FirstName&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return&lt;/span&gt; this.fName; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;set&lt;/span&gt; { fName = &lt;span class='keyword'&gt;value&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name = "LastName", Storage = "lName")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public string&lt;/span&gt; LastName&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return this&lt;/span&gt;.lName; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;set&lt;/span&gt; { lName = &lt;span class='keyword'&gt;value&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;[&lt;span class='cSharpClass'&gt;ExcelColumn&lt;/span&gt;(Name = "BirthDate", Storage = "bDate")]&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt; BirthDate&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;get&lt;/span&gt; { &lt;span class='keyword'&gt;return this&lt;/span&gt;.bDate; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;set&lt;/span&gt; { bDate= &lt;span class='keyword'&gt;value&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-6077680757396197412?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/6077680757396197412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=6077680757396197412' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6077680757396197412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6077680757396197412'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-20.html' title='LINQ to Excel Provider 2.0'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-6463648204406514502</id><published>2008-01-10T20:15:00.001-08:00</published><updated>2008-01-10T20:21:45.005-08:00</updated><title type='text'>LINQ : Query Types With Reflection</title><content type='html'>I had the idea of doing a simple experiment with LINQ in conjunction with Reflection to provide a more efficient and flexible means to inspect and query types in my assemblies. The code below shows a simple example of using LINQ with Reflection in order to find all the public classes in my assembly that have a certain attribute.&lt;br /&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System.Reflection;&lt;br /&gt;&lt;br /&gt;&lt;span class='keyword'&gt;namespace&lt;/span&gt; ReflectLinq&lt;br /&gt;{&lt;br /&gt;&amp;nbsp&lt;span class='keyword'&gt;class&lt;/span&gt; &lt;span class='cSharpClass'&gt;Program&lt;/span&gt;&lt;br /&gt;&amp;nbsp{&lt;br /&gt;&amp;nbsp;&amp;nbsp&lt;span class='keyword'&gt;static void&lt;/span&gt; Main(&lt;span class='keyword'&gt;string&lt;/span&gt;[] args)&lt;br /&gt;&amp;nbsp;&amp;nbsp{&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp&lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Type&lt;/span&gt;&amp;gt; results = &lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp(&lt;span class='keyword'&gt;from&lt;/span&gt; t &lt;span class='keyword'&gt;in&lt;/span&gt; &lt;span class='cSharpClass'&gt;Assembly&lt;/span&gt;.GetExecutingAssembly().GetTypes() &lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&lt;span class='keyword'&gt;where&lt;/span&gt; t.HasAttribute(&lt;span class='keyword'&gt;typeof&lt;/span&gt;(&lt;span class='cSharpClass'&gt;TestAttribute&lt;/span&gt;)) == &lt;span class='keyword'&gt;true&lt;/span&gt; &amp;&amp;&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbspt.IsPublic ==&lt;span class='keyword'&gt;true select&lt;/span&gt; t).ToList();&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&lt;span class='keyword'&gt;foreach&lt;/span&gt; (&lt;span class='cSharpClass'&gt;Type&lt;/span&gt; t &lt;span class='keyword'&gt;in&lt;/span&gt; results)&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp{&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine(t.FullName);&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp}&lt;br /&gt;            &lt;br /&gt;&amp;nbsp;&amp;nbsp}&lt;br /&gt;&amp;nbsp}&lt;br /&gt;&lt;br /&gt;&amp;nbsp&lt;span class='keyword'&gt;public static class&lt;/span&gt; &lt;span class='cSharpClass'&gt;TypeExt&lt;/span&gt;&lt;br /&gt;&amp;nbsp{&lt;br /&gt;&amp;nbsp;&amp;nbsp&lt;span class='keyword'&gt;public static bool&lt;/span&gt; HasAttribute(&lt;span class='keyword'&gt;this&lt;/span&gt; Type t, Type attribute)&lt;br /&gt;&amp;nbsp;&amp;nbsp{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&lt;span class='keyword'&gt;object&lt;/span&gt;[] results = t.GetCustomAttributes(attribute, &lt;span class='keyword'&gt;true&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp&lt;span class='keyword'&gt;return&lt;/span&gt; results.Length &gt; 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp}&lt;br /&gt;&amp;nbsp}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-6463648204406514502?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/6463648204406514502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=6463648204406514502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6463648204406514502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/6463648204406514502'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2008/01/linq-query-types-with-reflection.html' title='LINQ : Query Types With Reflection'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7786497359571504081</id><published>2007-12-30T19:14:00.001-08:00</published><updated>2009-05-06T22:53:34.853-07:00</updated><title type='text'>Let Forth Speak</title><content type='html'>This is an example showing how an extension method can be created in a .Net class library to add new Forth words to the Forth environment I described in the 'Forth in .Net 3.5 Framework' &lt;a href='http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html'&gt;post&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This example creates a new Forth word, Say, which utilizes the System.Speech.Synthesis namespace to allow the computer to say the value that is on top of the Forth stack.&lt;br /&gt;&lt;br /&gt;Here’s the source for the Forth word Say:&lt;br /&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; System.Speech.Synthesis;&lt;br /&gt;&lt;span class='keyword'&gt;using&lt;/span&gt; ForthAPI;&lt;br /&gt;&lt;br /&gt;&lt;span class='keyword'&gt;namespace&lt;/span&gt; ForthSpeak&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;public static class&lt;/span&gt;  &lt;span class='cSharpClass='&gt;ExtendedForthWords&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;public static void&lt;/span&gt; Say(&lt;span class='keyword'&gt;this&lt;/span&gt; &lt;span class='cSharpClass='&gt;Forth&lt;/span&gt; f)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;int&lt;/span&gt; arg = f.DotGet();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;using&lt;/span&gt; (System.Speech.Synthesis.&lt;span class='cSharpClass='&gt;SpeechSynthesizer&lt;/span&gt; speak = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass='&gt;SpeechSynthesizer&lt;/span&gt;())&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;speak.Speak(arg.ToString());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To try this out I have created the assembly ForthSpeak.dll which has this word defined. It is available &lt;a href='http://solidcodingarchive.appspot.com/resources/ForthSpeak.zip'&gt;here&lt;/a&gt;. Copy this assembly to the same directory that the Forth.exe resides in. If you do not have Forth.exe, you can get it along with the ForthAPI.dll &lt;a href='http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html'&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now launch Forth.exe and type in this Forth program, also make sure your speakers are on.&lt;br /&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;10 0 do I dup . cr say loop .”done”&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Or if you prefer to count by twos&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;10 0 do I dup . cr say 2 +loop .”done”&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7786497359571504081?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7786497359571504081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7786497359571504081' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7786497359571504081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7786497359571504081'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/let-forth-speak.html' title='Let Forth Speak'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-2041670993435013397</id><published>2007-12-28T04:10:00.001-08:00</published><updated>2009-05-06T22:51:32.574-07:00</updated><title type='text'>Forth in the .Net 3.5 Framework</title><content type='html'>A project containing a Forth API in C# 3.0, extendable using extension methods, and a Forth to .Net compiler/interpreter&lt;br /&gt;&lt;br /&gt;This effort began as an experiment on how extension methods can be used to extend the functionality of a .Net class. What I wanted was an interesting test platform.  I had experimented with Forth in college, and was familiar with how you can create new Forth ‘words’ (subroutines) to add functionality to Forth. So I thought it would be interesting to try and mimic a Forth based language as a .Net class and then use extension methods as the mechanism to allow users to add their own Forth words to extend the class.&lt;br /&gt;&lt;br /&gt;Well, what I have now goes well beyond that original goal. Here is a high level list of features implemented thus far:&lt;br /&gt;&lt;br /&gt;1. A Forth API, exposed as a .Net class library, contains the base Forth keywords as methods on the class.&lt;br /&gt;&lt;br /&gt;2. A start to a Forth compiler/interpreter that will provide the familiar iterative Forth programming experience. &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a. The Forth words are converted into IL instructions to call the appropriate method on the Forth API or out to other class libraries containing Forth words. The compiler searches for Forth words in the Forth API class, and if it cannot find it there, will search other .Net dlls residing in the same location. Its searching for any extension method for the Forth API class and then is doing a simple method name comparison.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;b. This application is able to switch between compile mode and execution mode depending on if the source input is creating a new word definition, executing a word or being asked to do both.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;c. When the application is executing words, the compiled IL code is run in a dynamic assembly and then discarded after the program is finished&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;d. The states of the Forth stacks are saved after execution of a program and put back in place at the start of the execution of the next program. This provides the developer the ability to execute word by word and examine how those word(s) affect the stack. This is really useful, probably required, with the iterative Forth programming style.&lt;br /&gt;&lt;br /&gt;3. New Forth words built in the compiler/interpreter are built into a well known assembly named ForthWords.dll.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;a. The words built in this assembly are constructed as extension methods so they are available when using the Forth API directly.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;b. Because of the iterative Forth programming experience, this assembly stores the source code for its words so the entire ForthWords.dll can be rebuilt whenever a new Forth word is added.&lt;br /&gt;&lt;br /&gt;4. Forth words can also be added in C# or Visual Basic .Net by creating class libraries which have extension methods on the Forth API class. From there a developer can use the Forth API methods to write their own Forth words and also to expose Forth to the entire .Net Framework.&lt;br /&gt;&lt;br /&gt;At this point the base Forth stack manipulation, variables, constants, math operators, loops, and condition words have been implemented. Even with that, there might be some words I have missed.&lt;br /&gt;&lt;br /&gt;To try it out, download the components &lt;a href='http://solidcodingarchive.appspot.com/resources/ForthAPI.zip'&gt;here&lt;/a&gt;. Note: The components require the .Net 3.5 Framework to be installed.&lt;br /&gt;&lt;br /&gt;The source code is available &lt;a href='http://solidcodingarchive.appspot.com/resources/Forth.zip'&gt;here&lt;/a&gt;. The project was built using &lt;a href='http://www.microsoft.com/express/vcsharp/Default.aspx'&gt;Microsoft C# Visual Studio 2008 Express Edition&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;To begin a session, start the Forth.exe.&lt;br /&gt;&lt;br /&gt;A simple calculation example&lt;br /&gt;Enter&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;2 2 + . cr&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;You should see:&lt;br /&gt;&lt;div class ='code'&gt;&lt;br /&gt;4&lt;br /&gt; ok. &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;An example of the compiler/interpreter switching between new word compilation and then word execution&lt;br /&gt;&lt;div class ='code'&gt;&lt;br /&gt;: hello .”Hello World” cr ; hello&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;You should see:&lt;br /&gt;&lt;div class = 'code'&gt;&lt;br /&gt;Hello World&lt;br /&gt; ok.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;This should have added a new .Net assembly named ForthWords.dll in the same directory as Forth.exe&lt;br /&gt;&lt;br /&gt;To inspect the stack type .S&lt;br /&gt;&lt;br /&gt;To close a session type bye&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Check out:&lt;/b&gt;&lt;br /&gt;&lt;a href="http://solidcoding.blogspot.com/2008/12/wforth-javascript-forth-interpreter.html"&gt;JavaScript Forth Interpreter. Forth in the browser?&lt;/a&gt;&lt;br /&gt;&lt;a href="http://solidcoding.blogspot.com/2008/03/roomba-hacking-forth-style.html"&gt;Hacking Roomba with Forth&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; 4/22/08&lt;/b&gt; Compiling from source files now &lt;a href="http://solidcoding.blogspot.com/2008/04/forthnet-update-source-file-support.html"&gt;supported&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1419675494&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0976458705&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0966215613&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0911827005&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-2041670993435013397?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/2041670993435013397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=2041670993435013397' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2041670993435013397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/2041670993435013397'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/forth-in-net-35-framework.html' title='Forth in the .Net 3.5 Framework'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3957795782921963067</id><published>2007-12-20T18:08:00.000-08:00</published><updated>2009-05-12T16:10:45.801-07:00</updated><title type='text'>LINQ to Excel Provider</title><content type='html'>View the newest version of the provider in this &lt;a href="http://solidcoding.blogspot.com/2008/01/linq-to-excel-provider-25.html"&gt;post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is a very simple and generic provider to allow a developer to build LINQ queries to access Microsoft Excel data. The provider uses an OleDB connection to load data from Microsoft Excel into a queryable memory collection. From that point LINQ queries can filter and manipulate the data. &lt;br /&gt;&lt;br /&gt;You will build your LINQ queries against the ExcelProvider class which will return a generic ExcelRow data type. ExcelRow has an indexer, column counter, and conversion to string method to allow access to the columns in the row. This class can be extended to handle conversion for other data types.&lt;br /&gt;&lt;br /&gt;The source file is available &lt;a href='http://solidcodingarchive.appspot.com/resources/LINQExcelProvider.cs'&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All the example code I have written has been done using &lt;a href='http://www.microsoft.com/express/vcsharp/Default.aspx'&gt;Microsoft C# Visual Studio 2008 Express Edition&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is example that is querying the following sample Excel data. Data is assumed to be in Sheet1.&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;FirstName&lt;/td&gt;&lt;td&gt;LastName&lt;td&gt;BirthDate&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;John&lt;/td&gt;&lt;td&gt;Anderson&lt;/td&gt;&lt;td&gt;12/12/1980&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;Frank&lt;/td&gt;&lt;td&gt;Johnson&lt;/td&gt;&lt;td&gt;11/10/1976&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;Bob&lt;/td&gt;&lt;td&gt;Olson&lt;/td&gt;&lt;td&gt;5/7/1973&lt;/td&gt;&lt;tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;            &lt;span class='cSharpClass'&gt;ExcelProvider&lt;/span&gt; provider = &lt;span class='cSharpClass'&gt;ExcelProvider&lt;/span&gt;.Create(@"c:\test\Book1.xls", "Sheet1");&lt;br /&gt;&lt;span class='keyword'&gt;foreach&lt;/span&gt; (&lt;span class='cSharpClass'&gt;ExcelRow&lt;/span&gt; row &lt;span class='keyword'&gt;in&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; x &lt;span class='keyword'&gt;in&lt;/span&gt; provider &lt;span class='keyword'&gt;where&lt;/span&gt; x.GetString(2) == "Johnson" &lt;span class='keyword'&gt;select&lt;/span&gt; x))&lt;br /&gt;            {&lt;br /&gt;            &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine(row.GetString(1) + " " + row.GetString(2));&lt;br /&gt;            }&lt;br /&gt;            &lt;br /&gt;            &lt;span class='cSharpClass'&gt;Console&lt;/span&gt;.WriteLine("Done");&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3957795782921963067?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3957795782921963067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3957795782921963067' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3957795782921963067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3957795782921963067'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/linq-to-excel-provider.html' title='LINQ to Excel Provider'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-9111653183476967709</id><published>2007-12-15T06:36:00.000-08:00</published><updated>2007-12-15T12:38:56.283-08:00</updated><title type='text'>LINQ: Query Reuse Part 3</title><content type='html'>Another topic I would like to discuss on the LINQ query reuse implementation I have been describing is a strategy to limit the number of entity references on the DataContext. &lt;br /&gt;&lt;br /&gt;Using extension methods to ‘hook’ the DataContext in order to reference our entity's data access layer sets us up in great position to control which entities we want to see on the DataContext. This is done by organizing your entity implementations into sets of namespaces. In this way an entity’s data access layer can only show up on the DataContext instance if its namespace has been referenced.&lt;br /&gt;&lt;br /&gt;For example, let say our Person entity and data access layer was implemented in a namespace MyCompany.HumanResources. If that namespace is not referenced where you are using the DataContext; the Person data access layer is not found. However, once it is referenced, you have access to it. This seems to me to be a very slick approach to referencing entities on the DataContext. It is a much better implementation than inheriting from the DataContext and adding all your entity references to that, or creating multiple inherited DataContexts with entity references with a goal of them being used in different parts of an application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-9111653183476967709?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/9111653183476967709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=9111653183476967709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/9111653183476967709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/9111653183476967709'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/linq-query-reuse-part-3.html' title='LINQ: Query Reuse Part 3'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3802572024387283260</id><published>2007-12-12T17:07:00.000-08:00</published><updated>2007-12-12T17:11:33.180-08:00</updated><title type='text'>LINQ: Query Reuse Part 2</title><content type='html'>This is a continuation from yesterday’s &lt;a href='http://solidcoding.blogspot.com/2007/12/linq-query-reuse.html'&gt;blog&lt;/a&gt; and would like to show another example of reusing base queries. With the way I separated out the logic yesterday it sets us up well for building a set of queries on the entity’s derived collection, the data access layer, which can take a different set of parameters and can be exposed to the user as a simple overloaded method. &lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='keyword'&gt;public class&lt;/span&gt; &lt;span class='cSharpClass'&gt;Persons&lt;/span&gt; : &lt;span class='cSharpClass'&gt;TableView&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span class='keyword'&gt;public&lt;/span&gt; Persons(&lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt; dc)&lt;br /&gt;            : &lt;span class='keyword'&gt;base&lt;/span&gt;(dc)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class='cSharpClass'&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; FindByName(&lt;span class='keyword'&gt;string&lt;/span&gt; lastName)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class='keyword'&gt;return&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; names &lt;span class='keyword'&gt;in this where&lt;/span&gt; names.LastName == lastName  &lt;span class'keyword'&gt;select&lt;/span&gt; names);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class='cSharpClass'&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; FindByName(&lt;span class='keyword'&gt;string&lt;/span&gt; firstName, &lt;span class='keyword'&gt;string&lt;/span&gt; lastName)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class='keyword'&gt;return&lt;/span&gt; FindByName(lastName).Where(p =&gt; p.FirstName == firstName);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class='cSharpClass'&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; FindByName(&lt;span class='keyword'&gt;string&lt;/span&gt; firstName, &lt;span class='keyword'&gt;string&lt;/span&gt; middleName, &lt;span class='keyword'&gt;string&lt;/span&gt; lastName)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class='keyword'&gt;return&lt;/span&gt; FindByName(firstName, lastName).Where(p =&gt; p.MiddleName == middleName);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class'cSharpClass'&gt;Person&lt;/span&gt; FindById(&lt;span class='keyword'&gt;int&lt;/span&gt; id)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class='keyword'&gt;return&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in this where&lt;/span&gt; p.Id == id &lt;span class='keyword'&gt;select&lt;/span&gt; p).FirstOrDefault();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3802572024387283260?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3802572024387283260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3802572024387283260' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3802572024387283260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3802572024387283260'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/linq-query-reuse-part-2.html' title='LINQ: Query Reuse Part 2'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7432014169921104399</id><published>2007-12-11T19:38:00.000-08:00</published><updated>2009-05-06T22:31:15.708-07:00</updated><title type='text'>LINQ: A Query Reuse Mechanism</title><content type='html'>Another item I have been working on with LINQ is an effective means to expose LINQ queries I write throughout my application. I have seen Microsoft recommend inheriting from the DataContext and adding properties that encapsulate making calls to the DataContext’s GetTable generic method. That’s OK, but I wanted something more flexible. What I am planning on doing is three things.&lt;br /&gt; &lt;br /&gt;1) Create my own base collection that encapsulates the functionality of the GetTable method.&lt;br /&gt; &lt;br /&gt;2) Create derived classes from that collection for each of my entities and then add the LINQ queries as methods to that class. &lt;br /&gt;&lt;br /&gt;3) Create an extension method for each of the classes built in item 2 to expose them on the DataContext.&lt;br /&gt;&lt;br /&gt;What this gives you is access to the LINQ queries for your entities on any DataContext instance.&lt;br /&gt;&lt;br /&gt;Step 1. Build the Base Collection Class&lt;br /&gt;&lt;br /&gt;You can get the source file &lt;a href='http://solidcodingarchive.appspot.com/resources/TableView.cs'&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Step 2.&lt;br /&gt;Create the derived collection for the entity. I’ll use the Person entity for this example&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public class&lt;/span&gt; &lt;span class='cSharpClass'&gt;Persons&lt;/span&gt; : TableView&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; Persons(&lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt; dc)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;: base(dc)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; IQueryable&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; FindByLastName(&lt;span class='keyword'&gt;string&lt;/span&gt; name)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;return&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; names &lt;span class='keyword'&gt;in this where&lt;/span&gt; names.LastName == name  &lt;span class='keyword'&gt;select&lt;/span&gt; names);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public&lt;/span&gt; &lt;span class='cSharpClass'&gt;Person&lt;/span&gt; FindById(&lt;span class='keyword'&gt;int&lt;/span&gt; id)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;return&lt;/span&gt; (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in this where&lt;/span&gt; p.Id == id &lt;span class='keyword'&gt;select&lt;/span&gt; p).FirstOrDefault();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Step 3. Adding the Extension Method on the DataContext&lt;br /&gt;&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;public static class&lt;/span&gt; &lt;span class='cSharpClass'&gt;PersonsDataAccess&lt;/span&gt;&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;public static&lt;/span&gt; &lt;span class='cSharpClass'&gt;Persons&lt;/span&gt; Persons(&lt;span class='keyword'&gt;this&lt;/span&gt; &lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt; dc)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;return new&lt;/span&gt; &lt;span class='cSharpClass'&gt;Persons&lt;/span&gt;(dc);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The Result: Accessing the LINQ queries from the DataContext&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt; &amp;nbsp;&lt;span class='keyword'&gt;using&lt;/span&gt; (&lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt; dc = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt;(@"connestringstring"))&lt;br /&gt; &amp;nbsp;&amp;nbsp;{&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; pers = dc.Persons().FindByLastName("Anderson").ToList();&lt;br /&gt; &amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;My Favorite Part: Extending the Base Queries&lt;br /&gt;&lt;br /&gt;You might be wondering why I have a return type of IQueryable&amp;lt;Person&amp;gt; on the FindByLastName query. The reason is it allows us to add additional LINQ criteria to the query. Starting with the base query you can add additional conditions like an order by, more where conditions, or even narrow down the select. One word: crazy!  I will get into that more in future posts. Here’s an order by example teaser&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&amp;nbsp;&lt;span class='keyword'&gt;using&lt;/span&gt; (&lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt; dc = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;DataContext&lt;/span&gt;(@"connectionstring"))&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; pers = (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in&lt;/span&gt; dc.Persons().FindByLastName("Anderson") &lt;span class='keyword'&gt;orderby&lt;/span&gt; p.LastName &lt;span class='keyword'&gt;descending select&lt;/span&gt; p).ToList();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7432014169921104399?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7432014169921104399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7432014169921104399' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7432014169921104399'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7432014169921104399'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/linq-query-reuse.html' title='LINQ: A Query Reuse Mechanism'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7574812290455071057</id><published>2007-12-09T07:41:00.000-08:00</published><updated>2007-12-09T17:51:00.591-08:00</updated><title type='text'>LINQ: Handling No Result Queries</title><content type='html'>One of the things I struggled with at first with LINQ is finding a simple way to return null for a query that returns no results. I found some examples that used the First extension method. However, if the query returned no results, calling the First extension method would throw an exception.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt; per =  (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class='keyword'&gt;where&lt;/span&gt; p.Id == id &lt;span class='keyword'&gt;select&lt;/span&gt; p).First();&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The simple solution is to use the FirstOrDefault extension method instead.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt; per =  (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class='keyword'&gt;where&lt;/span&gt; p.Id == id &lt;span class='keyword'&gt;select&lt;/span&gt; p).FirstOrDefault();&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7574812290455071057?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7574812290455071057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7574812290455071057' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7574812290455071057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7574812290455071057'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/linq-handling-no-result-queries.html' title='LINQ: Handling No Result Queries'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7027567030994623755</id><published>2007-12-08T17:31:00.000-08:00</published><updated>2009-10-28T19:03:40.412-07:00</updated><title type='text'>Left Outer Join in LINQ</title><content type='html'>I found out how to perform a left outer join using LINQ from Bilal Haidar's&lt;a href="http://bhaidar.net/cs/archive/2007/08/01/left-outer-join-in-linq-to-sql.aspx"&gt; blog&lt;/a&gt;. My example shows how to perform a left join from Person to Person Address.&lt;br /&gt;&lt;br /&gt;LINQ Query&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;var&lt;/span&gt; query = (&lt;span class="keyword"&gt;from&lt;/span&gt; p &lt;span class="keyword"&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;Person&lt;/span&gt;&amp;gt;()&lt;br /&gt;&lt;span class="keyword"&gt;join&lt;/span&gt; pa &lt;span class="keyword"&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class="cSharpClass"&gt;PersonAddress&lt;/span&gt;&amp;gt;() &lt;span class="keyword"&gt;on&lt;/span&gt; p.Id &lt;span class="keyword"&gt;equals&lt;/span&gt; pa.PersonId &lt;span class="keyword"&gt;into&lt;/span&gt; tempAddresses&lt;br /&gt;&lt;span class="keyword"&gt;from&lt;/span&gt; addresses &lt;span class="keyword"&gt;in&lt;/span&gt; tempAddresses.DefaultIfEmpty()&lt;br /&gt;&lt;span class="keyword"&gt;select new&lt;/span&gt; { p.FirstName, p.LastName, addresses.State });&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;SQL Translation&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8&lt;br /&gt;SELECT [t0].[FirstName], [t0].[LastName], [t1].[State] AS [State]&lt;br /&gt;FROM [dbo].[Person] AS [t0]&lt;br /&gt;LEFT OUTER JOIN [dbo].[PersonAddress] AS [t1] ON [t0].[Id] = [t1].[PersonID]&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1590597893&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;b&gt;Need a break?&lt;/b&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Checkout my virtual Florida Keys vacation &lt;a href='http://solidcoding.blogspot.com/2009/01/virtual-florida-keys-vacation-with.html'&gt;slide show&lt;/a&gt; I built using a site I created that allows programmers to automate scripts for Google Street View using the programming language Forth.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7027567030994623755?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7027567030994623755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7027567030994623755' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7027567030994623755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7027567030994623755'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/left-outer-join-in-linq.html' title='Left Outer Join in LINQ'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-3382456361587273977</id><published>2007-12-06T13:19:00.000-08:00</published><updated>2010-02-12T06:51:37.058-08:00</updated><title type='text'>SQL In Clause in LINQ</title><content type='html'>I had been trying to figure how to perform an equivalent SQL ‘in’ clause using LINQ. What I discovered is you need to call the Contains method on the collection that is holding your argument list and pass that method the property of the object you want to search for.&lt;br /&gt;&lt;br /&gt;So this example uses a class named Person which has an Id, FirstName and LastName property and the property we want to perform an in clause on is LastName.  We want to see if it is equal to Anderson or Johnson&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;using&lt;/span&gt; (&lt;span  class='cSharpClass'&gt;DataContext&lt;/span&gt; dc = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span  class='cSharpClass'&gt;DataContext&lt;/span&gt;("connectionstring"))&lt;br /&gt;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;&amp;nbsp;&amp;nbsp&amp;nbsp;&amp;nbsp                &lt;span  class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='keyword'&gt;string&lt;/span&gt;&amp;gt; names = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span  class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='keyword'&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;names.Add("Anderson");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;names.Add("Johnson");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt; list = (&lt;span class='keyword'&gt;from&lt;/span&gt; p &lt;span class='keyword'&gt;in&lt;/span&gt; dc.GetTable&amp;lt;&lt;span class='cSharpClass'&gt;Person&lt;/span&gt;&amp;gt;() &lt;span class='keyword'&gt;where&lt;/span&gt; names.Contains(p.LastName) &lt;span class='keyword'&gt;select&lt;/span&gt; p).ToList();&lt;br /&gt;&amp;nbsp;&amp;nbsp}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This is the  SQL generated by LINQ. (I am performing some formatting on it from the Log property in order to setup the parameters so I can paste the SQL into query analyzer, but the select statement is untouched)&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;DECLARE @p1 NVarChar(8);&lt;br /&gt;DECLARE @p0 NVarChar(7);&lt;br /&gt;&lt;br /&gt;Select @p1 = 'Johnson';&lt;br /&gt;Select @p0 = 'Anderson';&lt;br /&gt;&lt;br /&gt;-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8&lt;br /&gt;SELECT [t0].[Id], [t0].[FirstName], [t0].[LastName]&lt;br /&gt;FROM [dbo].[Person] AS [t0]&lt;br /&gt;WHERE [t0].[LastName] IN (@p0, @p1)&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-3382456361587273977?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/3382456361587273977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=3382456361587273977' title='21 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3382456361587273977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/3382456361587273977'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/sql-in-clause-in-linq.html' title='SQL In Clause in LINQ'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>21</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5542160956703915714</id><published>2007-12-05T21:08:00.000-08:00</published><updated>2007-12-05T21:15:49.986-08:00</updated><title type='text'>Diff List LINQ Extension Method</title><content type='html'>An example extension method that will allow you to diff lists of the same type with a LINQ extension method.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;    &lt;span class='keyword'&gt;static class&lt;/span&gt; &lt;span class='cSharpClass'&gt;NotInExtension&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;public static&lt;/span&gt; &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;T&amp;gt; NotIn&amp;lt;T&amp;gt;(&lt;span class='keyword'&gt;this&lt;/span&gt; &lt;span class='cSharpClass'&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; source, &lt;span class='cSharpClass'&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt dest)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;T&amp;gt; notinList = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;T&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;foreach&lt;/span&gt; (T s &lt;span class='keyword'&gt;in&lt;/span&gt; source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;bool&lt;/span&gt; found = &lt;span class='keyword'&gt;false&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;foreach&lt;/span&gt; (T d &lt;span class='keyword'&gt;in&lt;/span&gt; dest)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;if&lt;/span&gt; (d != &lt;span class='keyword'&gt;null&lt;/span&gt; &amp;&amp; s != &lt;span class='keyword'&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;if&lt;/span&gt; (d.Equals(s))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;found = &lt;span class='keyword'&gt;true&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;if&lt;/span&gt; (found == &lt;span class='keyword'&gt;false&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;notinList.Add(s);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span class='keyword'&gt;return&lt;/span&gt; notinList;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;In action&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;            &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='keyword'&gt;int&lt;/span&gt;&amp;gt; a = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='keyword'&gt;int&lt;/span&gt;&amp;gt;();&lt;br /&gt;            a.AddRange(&lt;span class='keyword'&gt;new int&lt;/span&gt;[] {1,2,3});&lt;br /&gt;&lt;br /&gt;            &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='keyword'&gt;int&lt;/span&gt;&amp;gt; b = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='keyword'&gt;int&lt;/span&gt;&amp;gt;();&lt;br /&gt;            b.AddRange(&lt;span class='keyword'&gt;new int&lt;/span&gt;[] {2, 4,5 });&lt;br /&gt;&lt;br /&gt;            &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;Tint&amp;gt; result = a.NotIn(b);&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5542160956703915714?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5542160956703915714/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5542160956703915714' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5542160956703915714'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5542160956703915714'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/12/diff-list-linq-extension-method.html' title='Diff List LINQ Extension Method'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1951257559563323983</id><published>2007-11-30T17:37:00.001-08:00</published><updated>2007-12-03T06:06:05.406-08:00</updated><title type='text'>Using LINQ Extension Methods</title><content type='html'>One of the many cool things about LINQ is the extension methods you can use to manipulate results from a LINQ query. In a prior &lt;a href=’http://solidcoding.blogspot.com/2007/11/c30-extension-method-to-check-holidays.html’&gt;post&lt;/a&gt; I used LINQ to query a calendar month to find U.S. holidays. Many holidays fall on the day of the month. For example, Thanksgiving is on the 4th Thursday of the month. Using the LINQ extension methods it is easy to pick that date out of calendar.&lt;br /&gt;&lt;br /&gt;First we need to build a calendar for November; we’ll use 2007 for our year.&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;  &lt;span class='cSharpClass'&gt;List&lt;/span&gt; &amp;lt;&lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt;&amp;gt; november = &lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;List&lt;/span&gt;&amp;lt;&lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt;&amp;gt;();&lt;br /&gt;  &lt;span class='keyword'&gt;for&lt;/span&gt; (&lt;span class='keyword'&gt;int&lt;/span&gt; count = 1; count &lt; 31; count++)&lt;br /&gt;  {&lt;br /&gt;  november.Add(&lt;span class='keyword'&gt;new&lt;/span&gt; &lt;span class='cSharpClass'&gt;DateTime&lt;/span&gt;(2007, 11, count));&lt;br /&gt;  }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Next we will create a DayOfWeek class instance to apply as a filter to our LINQ query&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;  DayOfWeek thursdays = DayOfWeek.Thursday;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now to build our LINQ query we will start by finding all the Thursdays in November.&lt;br /&gt;&lt;div class = 'code'&gt;&lt;br /&gt;&lt;span class='keyword'&gt;var&lt;/span&gt; temp = (&lt;span class='keyword'&gt;from&lt;/span&gt; d &lt;span class='keyword'&gt;in&lt;/span&gt; november &lt;span class='keyword'&gt;where&lt;/span&gt; d.DayOfWeek == thursdays &lt;span class='keyword'&gt;orderby&lt;/span&gt; d.Day &lt;span class='keyword'&gt;ascending select&lt;/span&gt; d);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;We can trim this to just return the first 4 Thursday s buy using the Take extension method as such. It is same principle as SQL select top command.&lt;br /&gt;&lt;div = class='code'&gt;&lt;br /&gt;&lt;span class='keyword'&gt;var&lt;/span&gt; temp = (&lt;span class='keyword'&gt;from&lt;/span&gt; d &lt;span class='keyword'&gt;in&lt;/span&gt; november &lt;span class='keyword'&gt;where&lt;/span&gt; d.DayOfWeek == thursdays &lt;span class='keyword'&gt;orderby&lt;/span&gt; d.Day &lt;span class='keyword'&gt;ascending select&lt;/span&gt; d).Take(4);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To pull the last Thursday from that list, the fourth Thursday of the month, we will add another LINQ extension method Last to pull the last item from the query. Since this extension method returns one value, a DateTime, we can store the results in a DateTime variable&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span='cSharpClass'&gt;DateTime&lt;/span&gt; thanksgiving = (&lt;span class='keyword'&gt;from&lt;/span&gt; d &lt;span class='keyword'&gt;in&lt;/span&gt; november &lt;span class='keyword'&gt;where&lt;/span&gt; d.DayOfWeek == thursdays &lt;span class='keyword'&gt;orderby&lt;/span&gt; d.Day &lt;span class='keyword'&gt;ascending select&lt;/span&gt; d).Take(4).Last(); &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Another alternative to this is to simply use the ElementAt extension&lt;br /&gt;&lt;div class='code'&gt;&lt;br /&gt;&lt;span='cSharpClass'&gt;DateTime&lt;/span&gt; thanksgiving = (&lt;span class='keyword'&gt;from&lt;/span&gt; d &lt;span class='keyword'&gt;in&lt;/span&gt; november &lt;span class='keyword'&gt;where&lt;/span&gt; d.DayOfWeek == thursdays &lt;span class='keyword'&gt;orderby&lt;/span&gt; d.Day &lt;span class='keyword'&gt;ascending select&lt;/span&gt; d).ElementAt(4); &lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1951257559563323983?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1951257559563323983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1951257559563323983' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1951257559563323983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1951257559563323983'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/using-linq-extension-methods.html' title='Using LINQ Extension Methods'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5438315316461544654</id><published>2007-11-30T17:33:00.001-08:00</published><updated>2008-10-23T09:46:11.198-07:00</updated><title type='text'>Paging With LINQ</title><content type='html'>Here is a simple C#3.0 extension method to page LINQ queries. It will allow you to declare where in the results you would like to start, and then how many results to return from that point.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;&lt;span class="keyword"&gt;public static class&lt;/span&gt; &lt;span class="cSharpClass"&gt;PagingExtensions&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;  &lt;span class="codecomments"&gt;//used by LINQ to SQL&lt;/span&gt;&lt;br /&gt;  &lt;span class="keyword"&gt;public static&lt;/span&gt; &lt;span class="cSharpClass"&gt;IQueryable&lt;/span&gt;&amp;lt;TSource&amp;gt; Page&amp;lt;TSource&amp;gt;(&lt;span class="keyword"&gt;this&lt;/span&gt; &lt;span class="cSharpClass"&gt;IQueryable&lt;/span&gt;&amp;lt;TSource&amp;gt; source, &lt;span class="keyword"&gt;int&lt;/span&gt; page, &lt;span class="keyword"&gt;int&lt;/span&gt; pageSize)&lt;br /&gt;  {&lt;br /&gt;    &lt;span class="keyword"&gt;return&lt;/span&gt; source.Skip((page - 1)*pageSize).Take(pageSize);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="codecomments"&gt;//used by LINQ&lt;/span&gt;&lt;br /&gt;  &lt;span class="keyword"&gt;public static&lt;/span&gt; &lt;span class="cSharpClass"&gt;IEnumerable&lt;/span&gt;&amp;lt;TSource&amp;gt; Page&amp;lt;TSource&amp;gt;(&lt;span class="keyword"&gt;this&lt;/span&gt; &lt;span class="cSharpClass"&gt;IEnumerable&lt;/span&gt;&amp;lt;TSource&amp;gt; source, &lt;span class="keyword"&gt;int&lt;/span&gt; page, &lt;span class="keyword"&gt;int&lt;/span&gt; pageSize)&lt;br /&gt;  {&lt;br /&gt;    &lt;span class="keyword"&gt;return&lt;/span&gt; source.Skip((page - 1)*pageSize).Take(pageSize);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="cSharpClass"&gt;Program&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;  &lt;span class="keyword"&gt;static void&lt;/span&gt; Main(&lt;span class="keyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;  {&lt;br /&gt;  &lt;span class="cSharpClass"&gt;List&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;string&lt;/span&gt;&amp;gt; names = &lt;span class="keyword"&gt;new&lt;/span&gt; &lt;span class="cSharpClass"&gt;List&lt;/span&gt;&amp;lt;string&amp;gt;();&lt;br /&gt;  names.AddRange(&lt;span class="keyword"&gt;new string&lt;/span&gt;[]{"John","Frank","Jeff","George","Bob","Grant", "McLovin"});&lt;br /&gt;  &lt;span class="keyword"&gt;foreach&lt;/span&gt; (&lt;span class="keyword"&gt;string&lt;/span&gt; name &lt;span class="keyword"&gt;in&lt;/span&gt; names.Page(2, 2))&lt;br /&gt;  {&lt;br /&gt;    &lt;span class="cSharpClass"&gt;Console&lt;/span&gt;.WriteLine(name);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Since counting starts at 1, the above example will take Jeff and George&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5438315316461544654?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5438315316461544654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5438315316461544654' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5438315316461544654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5438315316461544654'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/paging-with-linq.html' title='Paging With LINQ'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-8469056311072334301</id><published>2007-11-29T06:32:00.001-08:00</published><updated>2008-02-26T17:30:15.211-08:00</updated><title type='text'>ODBC Destination Script for SSIS</title><content type='html'>I recently helped, and have seen some posts with the same question, on how to use ODBC destinations in Microsoft SQL Server Integration Services (SSIS). The solution I came up with was to develop a Visual Basic .Net class that can be used in a Script Component Destination to save data to a database using ODBC connections.&lt;br /&gt;&lt;br /&gt;Add this class to Script Destination component. If you are wondering where to locate it, paste it after the class that the Script Component creates for you. It is usually named ScriptMain.&lt;br /&gt;&lt;br /&gt;A couple good resources on SSIS: &lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1932577254&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;iframe src="http://rcm.amazon.com/e/cm?t=solcod-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0672327813&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;Source code for VB.Net class:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;Public Class ODBCDestination&lt;br /&gt;Private _columns As System.Collections.Generic.Dictionary(Of String, Object)&lt;br /&gt;Private _connection As String&lt;br /&gt;Private _table As String&lt;br /&gt;&lt;br /&gt;Public Sub New()&lt;br /&gt;_columns = New System.Collections.Generic.Dictionary(Of String, Object)()&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Public Property Connection() As String&lt;br /&gt;Get&lt;br /&gt;Return _connection&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal value As String)&lt;br /&gt;_connection = value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;&lt;br /&gt;Public Property Table() As String&lt;br /&gt;Get&lt;br /&gt;Return _table&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal value As String)&lt;br /&gt;_table = value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;&lt;br /&gt;Public Sub AddColumn(ByVal name As String, ByVal value As Object, ByVal isNull As Boolean)&lt;br /&gt;If _columns.ContainsKey(name) = False Then&lt;br /&gt;If isNull Then&lt;br /&gt;_columns.Add(name, Nothing)&lt;br /&gt;Else&lt;br /&gt;_columns.Add(name, value)&lt;br /&gt;End If&lt;br /&gt;Else&lt;br /&gt;If isNull Then&lt;br /&gt;_columns(name) = Nothing&lt;br /&gt;Else&lt;br /&gt;_columns(name) = value&lt;br /&gt;End If&lt;br /&gt;End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Public Sub Save()&lt;br /&gt;Using cn As System.Data.Odbc.OdbcConnection = New System.Data.Odbc.OdbcConnection(_connection)&lt;br /&gt;cn.Open()&lt;br /&gt;Using cmd As System.Data.Odbc.OdbcCommand = BuildInsert(cn)&lt;br /&gt;cmd.ExecuteNonQuery()&lt;br /&gt;End Using&lt;br /&gt;End Using&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Function BuildInsert(ByVal cn As System.Data.Odbc.OdbcConnection) As System.Data.Odbc.OdbcCommand&lt;br /&gt;&lt;br /&gt;Dim cmd As System.Data.Odbc.OdbcCommand = cn.CreateCommand()&lt;br /&gt;cmd.CommandType = CommandType.Text&lt;br /&gt;&lt;br /&gt;Dim buildCol As System.Text.StringBuilder = New System.Text.StringBuilder()&lt;br /&gt;Dim buildVal As System.Text.StringBuilder = New System.Text.StringBuilder()&lt;br /&gt;&lt;br /&gt;Dim firstTimeIn As Boolean = True&lt;br /&gt;Dim count As Integer = 0&lt;br /&gt;For Each key As String In _columns.Keys&lt;br /&gt;If firstTimeIn = False Then&lt;br /&gt;buildCol.Append(", ")&lt;br /&gt;buildVal.Append(", ")&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;buildCol.Append(key)&lt;br /&gt;buildVal.Append("?")&lt;br /&gt;&lt;br /&gt;Dim arg As Object = _columns(key)&lt;br /&gt;If arg Is Nothing Then&lt;br /&gt;cmd.Parameters.AddWithValue(key, DBNull.Value)&lt;br /&gt;Else&lt;br /&gt;cmd.Parameters.AddWithValue(key, arg)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;firstTimeIn = False&lt;br /&gt;count = count + 1&lt;br /&gt;Next&lt;br /&gt;Dim insertBuilder As System.Text.StringBuilder = New System.Text.StringBuilder()&lt;br /&gt;&lt;br /&gt;insertBuilder.Append("insert into ")&lt;br /&gt;insertBuilder.Append(_table)&lt;br /&gt;insertBuilder.Append(" (")&lt;br /&gt;insertBuilder.Append(buildCol.ToString())&lt;br /&gt;insertBuilder.Append(")")&lt;br /&gt;insertBuilder.Append(" values (")&lt;br /&gt;insertBuilder.Append(buildVal.ToString())&lt;br /&gt;insertBuilder.Append(")")&lt;br /&gt;cmd.CommandText = insertBuilder.ToString()&lt;br /&gt;Return cmd&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;End Class&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now add the following code to the main script component class&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;Public Class ScriptMain&lt;br /&gt;Inherits UserComponent&lt;br /&gt;&lt;br /&gt;Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)&lt;br /&gt;'&lt;br /&gt;'Add your code here&lt;br /&gt;'&lt;br /&gt;Dim cmd As ODBCDestination = New ODBCDestination ()&lt;br /&gt;cmd.Table = "TableName"&lt;br /&gt;cmd.Connection = "ODBC connection string"&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;&lt;br /&gt;Public Class ODBCDestination&lt;br /&gt;…&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The next step is to map the columns. This is done by calling the AddColumn method. The interesting point with this function is that you are required to pass three arguments. The first argument is the name of column in the destination table. The second argument is the value you want to save to that column. The third argument is a Boolean flag to state if the data is null.&lt;br /&gt;&lt;br /&gt;Why are you required to pass the value of the column, and a flag if it is null or not? It is required because of the way .Net handles certain data types. For example the integer type in .Net is not allowed to be null it always has a value. However databases allow integer columns to be null. Double, Float, DateTime, are some other data types that behave this way in .Net. SSIS worked around this by representing each column in the InputBuffer with two properties. One contains the value of the column, the other a flag if it is null or not. The null property is always the name of the column with ‘_IsNull’ appended to the end of the name&lt;br /&gt;&lt;br /&gt;Once you have mapped all the column call the Save method to persist the data to the destination database.&lt;br /&gt;&lt;br /&gt;Sample implementation&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;Public Class ScriptMain&lt;br /&gt;Inherits UserComponent&lt;br /&gt;&lt;br /&gt;Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)&lt;br /&gt;'&lt;br /&gt;'Add your code here&lt;br /&gt;'&lt;br /&gt;Dim cmd As ODBCDestination = New ODBCDestination()&lt;br /&gt;cmd.Table = "TableName"&lt;br /&gt;cmd.Connection = "ODBC connection string"&lt;br /&gt;cmd.AddColumn("id", Row.id, Row.id_IsNull)&lt;br /&gt;cmd.AddColumn("Column1", Row.Column1, Row.Column1_IsNull)&lt;br /&gt;cmd.AddColumn("Column2", Row.Column2, Row.Column2_IsNull)&lt;br /&gt;cmd.Save()&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;&lt;br /&gt;Public Class ODBCDestination&lt;br /&gt;...&lt;br /&gt;&lt;/div&gt;&lt;em&gt;&lt;/em&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-8469056311072334301?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/8469056311072334301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=8469056311072334301' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8469056311072334301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/8469056311072334301'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/odbc-destination-script-for-ssis.html' title='ODBC Destination Script for SSIS'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-1839271144508902143</id><published>2007-11-27T16:12:00.000-08:00</published><updated>2007-11-27T22:30:00.285-08:00</updated><title type='text'>C#3.0 Extension Method to Check Holidays</title><content type='html'>The following is an extension method to determine if a DateTime instance falls on a US holiday. The code contains an algorithm to calculate Easter, Thanksgiving, Presidents Day, Memorial Day, Martin Luther King Day and Labor Day. LINQ functionality is used to search the listed holidays along with being used in some date calculations such as with Thanksgiving, and Presidents Day. There are probably better algorithms to find some of these holiday dates, but LINQ was chosen here to show how it can be used to query collections.&lt;br /&gt;&lt;br /&gt;Here is the complete source code for the extension:&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;    public static class DateTimeExtensions&lt;br /&gt;    {&lt;br /&gt;        &amp;nbsp;public static bool IsHoliday(this DateTime currentDate)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;            &amp;nbsp;int year = currentDate.Year;&lt;br /&gt;            &amp;nbsp;List&amp;lt;DateTime&amp;gt; holidays = new List&amp;lt;DateTime&amp;gt;();&lt;br /&gt;            &amp;nbsp;//New Years&lt;br /&gt;            &amp;nbsp;holidays.Add(new DateTime(year, 1, 1));&lt;br /&gt;            &amp;nbsp;//Martin Luther King Day&lt;br /&gt;            &amp;nbsp;holidays.Add(MLKDay(year));&lt;br /&gt;            &amp;nbsp;holidays.Add(PresidentsDay(year));&lt;br /&gt;            &amp;nbsp;holidays.Add(Easter(year));&lt;br /&gt;            &amp;nbsp;holidays.Add(MemorialDay(year));&lt;br /&gt;            &amp;nbsp;//Independence Day&lt;br /&gt;            &amp;nbsp;holidays.Add(new DateTime(year,7,4));&lt;br /&gt;            &amp;nbsp;holidays.Add(LaborDay(year));&lt;br /&gt;            &amp;nbsp;holidays.Add(Thanksgiving(year));&lt;br /&gt;            &amp;nbsp;//X-mas&lt;br /&gt;            &amp;nbsp;holidays.Add(new DateTime(year, 12, 25));&lt;br /&gt;&lt;br /&gt;            &amp;nbsp;foreach (DateTime d in (from h in holidays where h.Month == &amp;nbsp;currentDate.Month &amp;&amp; h.Day == currentDate.Day select h))&lt;br /&gt;           &amp;nbsp; {&lt;br /&gt;            &amp;nbsp;&amp;nbsp;    return true;&lt;br /&gt;            &amp;nbsp;}&lt;br /&gt;            &amp;nbsp;return false;&lt;br /&gt;       &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;private static DateTime MLKDay(int year)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;            &lt;br /&gt;            &amp;nbsp;DateTime mlkDay = DateTime.MinValue;&lt;br /&gt;           &amp;nbsp; List&amp;lt;DateTime&amp;gt; jan = new List&amp;lt;DateTime&amp;gt;();&lt;br /&gt;            &amp;nbsp;for (int count = 1; count &amp;lt; 32; count++)&lt;br /&gt;            &amp;nbsp;{&lt;br /&gt;            &amp;nbsp;&amp;nbsp;    jan.Add(new DateTime(year, 1, count));&lt;br /&gt;           &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;            &amp;nbsp;DayOfWeek monday = DayOfWeek.Monday;&lt;br /&gt;            &amp;nbsp;//Martin Luther King Day is the 3rd Monday of the month&lt;br /&gt;            &amp;nbsp;//use LINQ query to find all Mondays and return in ascending order&lt;br /&gt;            &amp;nbsp;//Use a combination of Take and Last to get the 3rd Monday&lt;br /&gt;            &amp;nbsp;mlkDay = (from d in jan where d.DayOfWeek == monday orderby d.Day ascending select d).Take(3).Last();&lt;br /&gt;            &amp;nbsp;return mlkDay;&lt;br /&gt;       &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;private static DateTime PresidentsDay(int year)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;            &amp;nbsp;DateTime leapYear = new DateTime(year, 2, 1);&lt;br /&gt;           &lt;br /&gt;            &amp;nbsp;DateTime presidentsDay = DateTime.MinValue;&lt;br /&gt;           &amp;nbsp; List&amp;lt;DateTime&amp;gt; feb = new List&amp;lt;DateTime&amp;gt;();&lt;br /&gt;            &amp;nbsp;for (int count = 1; count &amp;lt; 28; count++)&lt;br /&gt;            &amp;nbsp;{&lt;br /&gt;            &amp;nbsp;&amp;nbsp;    feb.Add(new DateTime(year, 2, count));&lt;br /&gt;           &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;            &amp;nbsp;DayOfWeek monday = DayOfWeek.Monday;&lt;br /&gt;            &amp;nbsp;//use LINQ query to find all Mondays and return in ascending order&lt;br /&gt;            &amp;nbsp;//Presidents Day is the 3rd Monday of the month&lt;br /&gt;            &amp;nbsp;//Use a combination of Take and Last to get the 3rd Monday&lt;br /&gt;            &amp;nbsp;presidentsDay = (from d in feb where d.DayOfWeek == monday orderby d.Day ascending select d).Take(3).Last();&lt;br /&gt;            &amp;nbsp;return presidentsDay;&lt;br /&gt;       &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;private static DateTime MemorialDay(int year)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;        &amp;nbsp;    DateTime memorialDay = DateTime.MinValue;&lt;br /&gt;        &amp;nbsp;    List&amp;lt;DateTime&amp;gt; may = new List&amp;lt;DateTime&amp;gt;();&lt;br /&gt;        &amp;nbsp;    for (int count = 1; count &amp;lt; 32; count++)&lt;br /&gt;        &amp;nbsp;    {&lt;br /&gt;        &amp;nbsp;        may.Add(new DateTime(year, 5, count));&lt;br /&gt;        &amp;nbsp;    }&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;    DayOfWeek monday = DayOfWeek.Monday;&lt;br /&gt;        &amp;nbsp;    //use LINQ query to find all Mondays and return in descending order to get the last Monday of the month&lt;br /&gt;        &amp;nbsp;    //use First extension to get 1 Monday; the last one because of descending sort&lt;br /&gt;         &amp;nbsp;   memorialDay = (from d in may where d.DayOfWeek == monday orderby d.Day descending select d).First();&lt;br /&gt;         &amp;nbsp;   return memorialDay;&lt;br /&gt;        &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;private static DateTime LaborDay(int year)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;        &amp;nbsp;    DateTime laborDay = DateTime.MinValue;&lt;br /&gt;        &amp;nbsp;    List&amp;lt;DateTime&amp;gt; sept = new List&amp;lt;DateTime&amp;gt;();&lt;br /&gt;        &amp;nbsp;    for (int count = 1; count &amp;lt; 31; count++)&lt;br /&gt;        &amp;nbsp;    {&lt;br /&gt;        &amp;nbsp;&amp;nbsp;        sept.Add(new DateTime(year, 9, count));&lt;br /&gt;        &amp;nbsp;    }&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;    DayOfWeek monday = DayOfWeek.Monday;&lt;br /&gt;        &amp;nbsp;    //use LINQ query to find all Mondays and return in ascending order to get the first Monday of the month&lt;br /&gt;         &amp;nbsp;   //use First extension to get one Monday, the first one&lt;br /&gt;&lt;br /&gt;          &amp;nbsp;  laborDay = (from d in sept where d.DayOfWeek == monday orderby d.Day ascending select d).First();&lt;br /&gt;          &amp;nbsp;  return laborDay ;&lt;br /&gt;        &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;       &amp;nbsp; private static DateTime Thanksgiving(int year)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;        &amp;nbsp;    DateTime thanksgiving = DateTime.MinValue;&lt;br /&gt;        &amp;nbsp;    List&amp;lt;DateTime&amp;gt; november = new List&amp;lt;DateTime&amp;gt;();&lt;br /&gt;        &amp;nbsp;    for (int count = 1; count &amp;lt; 31; count++)&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;       november.Add(new DateTime(year, 11, count));&lt;br /&gt;         &amp;nbsp;   }&lt;br /&gt;         &amp;nbsp;   DayOfWeek thursdays = DayOfWeek.Thursday;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   //Use LINQ query to find all the thursdays of the month of November.&lt;br /&gt;         &amp;nbsp;   //Thanksgiving is on the 4th thursday&lt;br /&gt;         &amp;nbsp;   //Use the combination of Take and Last to get the 4th thursday of the month&lt;br /&gt;         &amp;nbsp;   thanksgiving = (from d in november where d.DayOfWeek == thursdays orderby d.Day ascending select d).Take(4).Last();&lt;br /&gt;         &amp;nbsp;   return thanksgiving;&lt;br /&gt;        &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;private static DateTime Easter(int year)&lt;br /&gt;        &amp;nbsp;{&lt;br /&gt;        &amp;nbsp;    //This algorithm is a C# conversion of the one described at&lt;br /&gt;        &amp;nbsp;    //http://www.assa.org.au/edm.html#Computer&lt;br /&gt;        &amp;nbsp;    int firstDigit;&lt;br /&gt;        &amp;nbsp;    int remain19;&lt;br /&gt;        &amp;nbsp;    int temp;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   int tableA;&lt;br /&gt;         &amp;nbsp;   int tableB;&lt;br /&gt;         &amp;nbsp;   int tableC;&lt;br /&gt;         &amp;nbsp;   int tableD;&lt;br /&gt;         &amp;nbsp;   int tableE;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   int d; //day of easter&lt;br /&gt;         &amp;nbsp;   int m; //month of easter&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   firstDigit = year / 100;&lt;br /&gt;        &amp;nbsp;    remain19 = year % 19;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   temp = (firstDigit - 15) / 2 + 202 - 11 * remain19;&lt;br /&gt;            &lt;br /&gt;         &amp;nbsp;   int[] substract1 = {21, 24, 25, 27,28,29,30,31, 32, 34, 35, 38};&lt;br /&gt;         &amp;nbsp;   List&amp;lt;int&amp;gt; subtract1List = new List&amp;lt;int&amp;gt;(substract1);&lt;br /&gt;         &amp;nbsp;   if (subtract1List.Contains(firstDigit))&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;       temp = temp - 1;&lt;br /&gt;          &amp;nbsp;  }&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   int[] substract2 = {33, 36, 37, 39, 40};&lt;br /&gt;         &amp;nbsp;   List&amp;lt;int&amp;gt; subtract2List = new List&amp;lt;int&amp;gt;(substract2);&lt;br /&gt;          &amp;nbsp;  if (subtract2List.Contains(firstDigit))&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;       temp = temp - 2;&lt;br /&gt;          &amp;nbsp;  }&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   temp = temp % 30;&lt;br /&gt;         &amp;nbsp;   tableA = temp + 21;&lt;br /&gt;         &amp;nbsp;   if (temp == 29) {&lt;br /&gt;          &amp;nbsp;      tableA = tableA -1;&lt;br /&gt;         &amp;nbsp;   }&lt;br /&gt;         &amp;nbsp;   if (temp == 28 &amp;&amp; remain19 &amp;gt; 10)&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;       tableA = tableA - 1;&lt;br /&gt;         &amp;nbsp;   }&lt;br /&gt;         &amp;nbsp;   //find the next Sunday&lt;br /&gt;         &amp;nbsp;   tableB = (tableA - 19) % 7;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   tableC = (40 - firstDigit) % 4;&lt;br /&gt;          &amp;nbsp;  if (tableC == 3)&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;        &amp;nbsp;&amp;nbsp;        tableC++;&lt;br /&gt;         &amp;nbsp;   }&lt;br /&gt;         &amp;nbsp;   if (tableC &amp;gt; 1)&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;&amp;nbsp;       tableC++;&lt;br /&gt;         &amp;nbsp;   }&lt;br /&gt;&lt;br /&gt;        &amp;nbsp;    temp = year % 100;&lt;br /&gt;         &amp;nbsp;   tableD = (temp + temp / 4) % 7;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   tableE = ((20 - tableB - tableC - tableD) % 7) + 1;&lt;br /&gt;         &amp;nbsp;   d = tableA + tableE;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;         &amp;nbsp;   if (d &amp;gt; 31)&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;&amp;nbsp;       d = d - 31;&lt;br /&gt;         &amp;nbsp;&amp;nbsp;       m = 4;&lt;br /&gt;         &amp;nbsp;   }&lt;br /&gt;         &amp;nbsp;   else&lt;br /&gt;         &amp;nbsp;   {&lt;br /&gt;         &amp;nbsp;&amp;nbsp;       m = 3;&lt;br /&gt;          &amp;nbsp;  }&lt;br /&gt;          &amp;nbsp;  return new DateTime(year,m,d);&lt;br /&gt;       &amp;nbsp; }&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-1839271144508902143?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/1839271144508902143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=1839271144508902143' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1839271144508902143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/1839271144508902143'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/c30-extension-method-to-check-holidays.html' title='C#3.0 Extension Method to Check Holidays'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-5487146667825572724</id><published>2007-11-22T17:20:00.000-08:00</published><updated>2008-04-02T18:14:03.066-07:00</updated><title type='text'>C#3.0 ToXml Extension Method</title><content type='html'>I know I stated in my last post I was going to work on extension methods for DateTime. However sometimes you do not know when an idea is going to spark your interest. I have this project where I am building business classes that inherited from a base class which has a method on it to allow the inherited classes to be converted to Xml via the .Net Xml Serialization functionality. As I was working with extensions I had the idea of creating that method as an extension method so it could be used by any data type. &lt;br /&gt;&lt;br /&gt;The code is really quite simple. I set the first argument as object, so all types can reference the method. After that it just calls into the XmlSerialization classes to perform the conversion. Code is written C#. The previous post explains how to write extension methods in VB&lt;br /&gt;&lt;br /&gt;You will need to add these namespaces. &lt;br /&gt;&lt;div class="Code"&gt;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Xml.Serialization;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Method Source Code&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;    public static class XmlConvertExtensions&lt;br /&gt;    {&lt;br /&gt;     &amp;nbsp;public static string ToXml(this object obj)&lt;br /&gt;     &amp;nbsp;   {&lt;br /&gt;     &amp;nbsp;    XmlSerializer s = new XmlSerializer(obj.GetType());&lt;br /&gt;     &amp;nbsp;    using (StringWriter writer = new StringWriter()) {&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       s.Serialize(writer, obj);&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       return writer.ToString();&lt;br /&gt;     &amp;nbsp;    }&lt;br /&gt;     &amp;nbsp;  }&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Example showing the extension in action:&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;            string input = "hello world";&lt;br /&gt;            string xmlData = input.ToXml();&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;That’s cool, but how can we get it back from Xml? Add this class. It has generic support to convert an Xml string back to a data type.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;    public class FromXml&amp;lt;T&amp;gt;&lt;br /&gt;    {&lt;br /&gt;     &amp;nbsp;   public T Convert(string data)&lt;br /&gt;     &amp;nbsp;   {&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       XmlSerializer s = new XmlSerializer(typeof(T));&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       using (StringReader reader = new StringReader(data))&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       {&lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;           object obj = s.Deserialize(reader);&lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;           return (T)obj;&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       }&lt;br /&gt;     &amp;nbsp;   }&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Example showing moving a string to and from Xml.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;            string input = "hello world";&lt;br /&gt;            string xmlData = input.ToXml();&lt;br /&gt;            string backFromXml = new FromXml&amp;lt;string&amp;gt;().Convert(xmlData);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update&lt;/b&gt;&lt;br /&gt;Thanks to the comment from Steve for the suggestion of moving the conversion from an Xml string onto the string class as an extension method. It is a much cleaner solution than what I first had.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;    public static class FromXmlExt&lt;br /&gt;    {&lt;br /&gt;     &amp;nbsp;   public T FromXml&amp;lt;T&amp;gt;(this string data)&lt;br /&gt;     &amp;nbsp;   {&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       XmlSerializer s = new XmlSerializer(typeof(T));&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       using (StringReader reader = new StringReader(data))&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       {&lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;           object obj = s.Deserialize(reader);&lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;           return (T)obj;&lt;br /&gt;     &amp;nbsp;&amp;nbsp;       }&lt;br /&gt;     &amp;nbsp;   }&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now you can simply do the following:&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;            string input = "hello world";&lt;br /&gt;            string xmlData = input.ToXml();&lt;br /&gt;            string backFromXml = xmlData.FromXml&amp;lt;string&amp;gt;();&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Thanks Steve!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-5487146667825572724?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/5487146667825572724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=5487146667825572724' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5487146667825572724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/5487146667825572724'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/c-toxml-extension-method.html' title='C#3.0 ToXml Extension Method'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-847148020471551530</id><published>2007-11-21T16:15:00.000-08:00</published><updated>2007-11-28T20:53:15.063-08:00</updated><title type='text'>C#3.0 and VB9 Extension Method How To</title><content type='html'>.Net Extension Method Code Example for Integer Type&lt;br /&gt;&lt;br /&gt;With the next release of Visual Studio, Microsoft is introducing the concept of extension methods. In a nutshell, what they do is allow you to add methods to data types you do not own. For example, let say in your code you are always testing that an integer is between a certain range before performing any work on it. Currently you need to write an If statement or a maybe even a helper method to do. With extension methods, you are creating a helper method, but the method will be visible as an instance method on the integer type. So now, for the most part, anywhere you use integers you will now have access to use that method.&lt;br /&gt;What this example shows is how to create an extension method in C# and Visual Basic that will allow a developer to test if an integer falls between two numbers.&lt;br /&gt;In Visual Basic extension methods need to be added to a Module file.  Add a Module file to your project and paste in this code.&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;    &lt;br /&gt;&amp;lt;System.Runtime.CompilerServices.Extension()&amp;gt; _&lt;br /&gt;Public Function IsBetween(ByVal value As Integer, ByVal minvalue As Integer, ByVal maxvalue As Integer) As Boolean        &lt;br /&gt;Return value &gt;= minvalue AndAlso value &lt;= maxvalue    &lt;br /&gt;End Function&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Overall it looks like a normal method. The two things that you need to be aware of is that the attribute Runtime.CompilerServices.Extension() is required to inform the compiler that this is an extension method. The second is that the first arguement always defines what type this extension method works on along with providing a reference to an instance of that type. Remember extension methods only work on instances of types, and this first argument provides access to that instance. Still confused? I think an example will clear it up.&lt;br /&gt;&lt;br /&gt;An example of the extention method in action using Visual Basic:&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;Dim x as Integer = 5&lt;br /&gt;If x.IsBetween(2,7) then&lt;br /&gt;…&lt;br /&gt;End if&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;You will notice that I only passed it two arguments. The reason is, the value of x is passed to IsBetween as the first arugment.&lt;br /&gt;&lt;br /&gt;In C# the syntax to declare an extension method is slightly different. You need to define them in a static class and as a static method. Here is our working example now in C#&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;    &lt;br /&gt;public static class IntExtensions    {        &lt;br /&gt;   public static bool IsBetween(this int value, int minValue, int maxValue)           {            &lt;br /&gt;return value &gt;= minValue &amp;amp;&amp;amp; value &lt;= maxValue; &lt;br /&gt;       }    &lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Here there is no need to declare the extension attribute like in Visual Basic. Also the syntax of the first argument is easier to follow in C# to mean that it refers to the instance of the type from which this method was called.&lt;br /&gt;An example of the extention method in action using C#&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;             &lt;br /&gt;int x = 5;&lt;br /&gt;x.IsBetween(2, 7);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;This is just the tip of the iceberg. What I am working on next is adding some extension methods to DateTime that will try and incorporate LINQ to answer some questions such as:&lt;br /&gt;&lt;br /&gt;Is the current date a holiday?&lt;br /&gt;Is today a weekend day?&lt;br /&gt;Given the current date, what will be the last Friday of that month?&lt;br /&gt;&lt;br /&gt;I would like to here any other suggestions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-847148020471551530?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/847148020471551530/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=847148020471551530' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/847148020471551530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/847148020471551530'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/c30-and-vb-extension-method-how-to.html' title='C#3.0 and VB9 Extension Method How To'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4398517536448454544.post-7307057138075915110</id><published>2007-11-20T19:16:00.000-08:00</published><updated>2007-11-28T09:05:10.875-08:00</updated><title type='text'>Internet Explorer Extension to Get Directions</title><content type='html'>An Internet Explorer Add In to Get Directions from Google Maps&lt;br /&gt;&lt;br /&gt;Many of you like me have found yourself highlighting an address to a place you have found on the web and then navigating to a site like Google Maps to paste in that address to get directions. This post will explain how to create an Internet Explorer extension to streamline that process. We will create an extension that will allow you to highlight and right click on an address which will open a new browser window containing Google Maps directions from a starting point you define to the address you just highlighted.&lt;br /&gt;&lt;br /&gt;The first step is to create the script file used by the extension to read the highlighted text, build the url to Google Maps, and open the new browser window. Using you favorite text editor copy the example code below and save the file as GetDirections.html&lt;br /&gt;&lt;br /&gt;&amp;lt;script &amp;gt;&lt;br /&gt;var dest = new String(external.menuArguments.document.selection.createRange().text);&lt;br /&gt;var rExp = "/ /g";&lt;br /&gt;//format for google maps&lt;br /&gt;dest = dest.replace(rExp, "+");&lt;br /&gt;dest = dest.replace(/\n/g, ",+");&lt;br /&gt;var start = "1234 Main St Anywhere, MN 55334";&lt;br /&gt;var formatStart = start;&lt;br /&gt;formatStart = formatStart.replace(rExp, "+");&lt;br /&gt;formatStart = formatStart.replace(/\n/g, ",+");&lt;br /&gt;// Google Maps&lt;br /&gt;var address = "http://maps.google.com/maps?f=d&amp;amp;hl=en&amp;amp;saddr=" + formatStart + "&amp;amp;daddr=" + dest&lt;br /&gt;window.open(address,"","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");&lt;br /&gt;&amp;lt;/script &amp;gt;&lt;br /&gt;&lt;br /&gt;The first line pulls the highlighted text from the current browser. The next 3 lines replace any spaces and carriage returns with a plus sign. This is to conform to how addresses are formatted in Google Maps. The next line is used to define your starting address. Enter what you would like to use as a starting address in this line. Type the address as you normally would, the next lines after it will format it correctly for use in Google Maps. After that, the url containing the formatted starting and ending addresses is assembled. The last line directs Internet Explorer to open the url in a new window.&lt;br /&gt;&lt;br /&gt;The next step is to register the new extension with Internet Explorer. This is performed by adding an entry in the Windows registry under Internet Explorer.&lt;br /&gt;&lt;br /&gt;1. Open the registry from the command line or from Start --&amp;gt; Run by typing regedit.&lt;br /&gt;Within the registry navigate to //HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt&lt;br /&gt;&lt;br /&gt;2. From MenuExt right click, select New --&amp;gt; Key. Now the name of this folder will be the name of the menu item that appears in the context menu of Internet Explorer. Name this folder Get Directions.&lt;br /&gt;&lt;br /&gt;3. With Get Directions selected, locate the key value on the right side named (default). Right click it, and select Modify. In the value data textbox write in or paste the path of the GetDirections.html file created in the first step.&lt;br /&gt;&lt;br /&gt;4. With Get Directions selected again, right click and select New --&amp;gt; DWord Value. Name this key ‘Contexts’. Set its value to 10 and make sure the base is set to hexadecimal. This setting tells Internet Explorer when the Get Directions menu item is available. Hex 10 tells it to make this menu item visible only for highlighted text.&lt;br /&gt;&lt;br /&gt;5. Close the registry.&lt;br /&gt;&lt;br /&gt;Open the browser and navigate to a website with an address. Highlight the address and right click. There should be a menu option named Get Directions. Select it. A new browser window should appear with Google Map directions to that highlighted address from the starting address you set in GetDirections.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4398517536448454544-7307057138075915110?l=solidcoding.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://solidcoding.blogspot.com/feeds/7307057138075915110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4398517536448454544&amp;postID=7307057138075915110' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7307057138075915110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4398517536448454544/posts/default/7307057138075915110'/><link rel='alternate' type='text/html' href='http://solidcoding.blogspot.com/2007/11/internet-explorer-extention-to-get.html' title='Internet Explorer Extension to Get Directions'/><author><name>K Jacobson</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
