<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Path Notes of a Kodefu Master</title>
        <link>http://geekswithblogs.net/Shadowin/Default.aspx</link>
        <description>blog</description>
        <language>en-US</language>
        <copyright>Chris Eargle</copyright>
        <managingEditor>shadowin@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Path Notes of a Kodefu Master</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/Shadowin/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Inane Generic Usage</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/09/29/inane-generic-usage.aspx</link>
            <description>&lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;in·ane&lt;/b&gt; (ĭn-ān') adj. &lt;b&gt;in·an·er&lt;/b&gt;, &lt;strong&gt;in·an·est       &lt;br /&gt;&lt;/strong&gt;One that lacks sense or substance&lt;em&gt;.       &lt;br /&gt;&lt;/em&gt;      &lt;br /&gt;&lt;em&gt;The American Heritage® Dictionary of the English Language, Fourth Edition       &lt;br /&gt;Copyright © 2009 by Houghton Mifflin Company.        &lt;br /&gt;Published by Houghton Mifflin Company. All rights reserved.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;One of the first signs that code needs to be refactored is that it looks complex. Complex solutions are rather easy to come by, but are far less maintainable than their harder to write, easier to read brethren. Like any well-crafted sculpture, it didn’t like start that way, and it requires work to craft that beautiful piece of code. But sometimes you come across code for which there is no reason for the complexity. It appears that someone just wanted to type extra characters throughout their code. &lt;/p&gt;  &lt;p&gt;A while back, I analyzed another developer’s code that used a lot of generics. Since nothing was being returned from many of these methods, I decided to look at the signature to discover why the generics were necessary. Here’s one of them.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static void &lt;/span&gt;PrintReport&amp;lt;T&amp;gt;(T report)
{
    WriteEvent(report.ToString());
    &lt;span style="color: #2b91af"&gt;IReport &lt;/span&gt;r = report &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClientReport&lt;/span&gt;;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(r != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: green"&gt;//Do stuff
    &lt;/span&gt;}
    r = report &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EmployeeReport&lt;/span&gt;;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(r != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: green"&gt;//Do stuff
    &lt;/span&gt;}
}&lt;/pre&gt;

&lt;p&gt;Looking at this, you may notice there is absolutely no reason for the generic declaration. There are no constraints on it, so it is the same thing as declaring the parameter as an object. Everwhere this was used, it was calling PrintReport&amp;lt;ClientReport&amp;gt;(report) and so on. I pointed this out to the developer, and said it should be refactored because a) the generic adds no value, and b) there are object oriented solutions that are much better than static methods and casting. Of course, this is what I got back.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static void &lt;/span&gt;PrintReport&amp;lt;T&amp;gt;(T report) &lt;span style="color: blue"&gt;where &lt;/span&gt;T : &lt;span style="color: #2b91af"&gt;IReport
&lt;/span&gt;{
    WriteEvent(report.ToString());
    &lt;span style="color: #2b91af"&gt;IReport &lt;/span&gt;r = report &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClientReport&lt;/span&gt;;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(r != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: green"&gt;//Do stuff
    &lt;/span&gt;}
    r = report &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EmployeeReport&lt;/span&gt;;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(r != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: green"&gt;//Do stuff
    &lt;/span&gt;}
}&lt;/pre&gt;

&lt;p&gt;There’s now a constraint! A constraint that has no meaning other than preventing someone from printing an object that isn’t an IReport. Of course, the same thing could be accomplished by making the parameter be an IReport rather than a T. I then showed the developer how the generic adds absolutely no value (I think I saw a grimace as I cut all of those &amp;lt;xReport&amp;gt;s out of the myriad of classes making that call). I then explained how when I see things like casting in a method like that, it makes me consider that perhaps that behavior belongs on the class, perhaps called by a method defined on the interface.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static void &lt;/span&gt;PrintReport(&lt;span style="color: #2b91af"&gt;IReport &lt;/span&gt;report)
{
    WriteEvent(report.ToString());
    report.DoStuff();
}&lt;/pre&gt;

&lt;p&gt;For future reference, inane usage of generics involves using a generic on a method, not involving a parameterized class, where 1) the return type isn’t the generic type, and 2) the constraint isn’t new() or class.&lt;/p&gt;

&lt;p&gt;If someone can think of a situation where this is actually useful, post a comment.&lt;/p&gt;

&lt;p&gt;Also, another quick lesson. The developer did place PrintReport&amp;lt;ClientReport&amp;gt; in many places, but did you know that this wasn’t even necessary? With generic methods, you get generic inference. The compiler will determine the type for you. This  is very handy with LINQ. Without generic inference, you would have to write ugly methods like strings.Where&amp;lt;string&amp;gt;(s =&amp;gt; s.StartsWith(“s”)).&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/09/29/Inane-Generic-Usage.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/135167.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/09/29/inane-generic-usage.aspx</guid>
            <pubDate>Tue, 29 Sep 2009 23:05:21 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/135167.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/09/29/inane-generic-usage.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/135167.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/135167.aspx</trackback:ping>
        </item>
        <item>
            <title>Prototype Cobwebs</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/09/15/prototype-cobwebs.aspx</link>
            <description>&lt;p&gt;I was tasked with taking this small project stored in TFS and compiling it for delivery to a stakeholder. It’s really nothing more than a prototype, and I will be building the full-fledged product.&lt;/p&gt;  &lt;p&gt;Of course, it didn’t compile… when the task is that simple, something is bound to go wrong. In this case, the app.config was just missing. I checked source control, and it was like it was never added. I decided to add one myself and deal with and configuration issues as I came across them.&lt;/p&gt;  &lt;p&gt;I then came across this error: Unable to find manifest signing certificate in the certificate store.&lt;/p&gt;  &lt;p&gt;If you get this, open the project’s properties and go to the Signing tab. Uncheck the “Sign the ClickOnce manifests” unless you’re actually going to sign the application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/442326fa62b0/57E0A4A8/SignClickOnce.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SignClickOnce" border="0" alt="SignClickOnce" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/442326fa62b0/3A6E539C/SignClickOnce_thumb.png" width="244" height="217" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After that, the application compiled and ran without any problems. I’m rather curious as to how these issues manifested.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/09/15/Prototype-Cobwebs.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/134834.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/09/15/prototype-cobwebs.aspx</guid>
            <pubDate>Tue, 15 Sep 2009 22:44:23 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/134834.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/09/15/prototype-cobwebs.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/134834.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/134834.aspx</trackback:ping>
        </item>
        <item>
            <title>Microsoft XNA Game Studio 3.1 Zune Extensions</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/09/15/microsoft-xna-game-studio-3.1-zune-extensions.aspx</link>
            <description>&lt;p&gt;Microsoft has &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=48f7ba37-8ba7-4d16-8873-0b7f83ef77f9&amp;amp;displaylang=en"&gt;released&lt;/a&gt; extensions to the XNA Game Studio 3.1 for the Zune HD. The add-on will allow you to take advantage of the Touch APIs and the new Accelerometer. Included in the download are documentation and examples on how to leverage the new APIs.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/09/15/Microsoft-XNA-Game-Studio-31-Zune-Extensions.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/134833.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/09/15/microsoft-xna-game-studio-3.1-zune-extensions.aspx</guid>
            <pubDate>Tue, 15 Sep 2009 22:04:15 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/134833.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/09/15/microsoft-xna-game-studio-3.1-zune-extensions.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/134833.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/134833.aspx</trackback:ping>
        </item>
        <item>
            <title>SyndicationFeed and Beating FeedProxy</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/09/08/syndicationfeed-and-beating-feedproxy.aspx</link>
            <description>&lt;p&gt;Reading in a series of blog posts is made easy utilizing &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx"&gt;classes&lt;/a&gt; that came in the .NET Framework 3.5. As long as the feed is in the Atom 1.0 or RSS 2.0 formats, you easily build your own aggregator service.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;SyndicationFeed &lt;/span&gt;feed = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;XmlReader &lt;/span&gt;reader = &lt;span style="color: #2b91af"&gt;XmlReader&lt;/span&gt;.Create(feedUrl))
{
    feed = &lt;span style="color: #2b91af"&gt;SyndicationFeed&lt;/span&gt;.Load(reader);
}
&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SyndicationItem &lt;/span&gt;item &lt;span style="color: blue"&gt;in &lt;/span&gt;feed.Items)
{
}&lt;/pre&gt;

&lt;p&gt;Off of the item, you will probably want to grab the Title.Text and the Summary.Text. Be sure to &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx"&gt;HtmlDecode&lt;/a&gt; them! Another important thing is the Categories collection, which I’m using as tags. Here’s the line of code from my project: Tags = item.Categories.Select(c =&amp;gt; c.Name).Aggregate((a, b) =&amp;gt; a + "," + b).&lt;/p&gt;

&lt;p&gt;Lastly, an aggregator would be pointless unless you were grabbing the url (get it from Links[0].Uri.ToString()). However, many feeds are using &lt;a href="http://www.feedburner.com"&gt;Feedburner&lt;/a&gt;. If you pull from feedburner, the url will be a feedproxy.google.com url instead of one that goes directly to the blog article. The trick to get around this turned out to be quite simple. Make a WebRequest to the feedproxy url then read the WebResponse’s url.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private static string &lt;/span&gt;GetTrueUrl(&lt;span style="color: blue"&gt;string &lt;/span&gt;url)
{
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(url.StartsWith(&lt;span style="color: #a31515"&gt;"http://feedproxy.google.com"&lt;/span&gt;))
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: #2b91af"&gt;WebRequest&lt;/span&gt;.Create(url);
        &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;response = request.GetResponse())
        {
            url = response.ResponseUri.ToString();
            response.Close();
        }
    }
    &lt;span style="color: blue"&gt;return &lt;/span&gt;url;
}&lt;/pre&gt;
That’s all there is to reading in standard feeds. I’ll leave it up to you to decide on a specific implementation.&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/09/08/SyndicationFeed-and-Beating-FeedProxy.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/134559.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/09/08/syndicationfeed-and-beating-feedproxy.aspx</guid>
            <pubDate>Tue, 08 Sep 2009 20:06:21 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/134559.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/09/08/syndicationfeed-and-beating-feedproxy.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/134559.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/134559.aspx</trackback:ping>
        </item>
        <item>
            <title>Plea to Mozilla</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/08/18/plea-to-mozilla.aspx</link>
            <description>&lt;p&gt;I had one of those problems that I had trouble resolving with a search engine this past weekend. Once it was pointed out to me what I did wrong, it was really quite simple. Basically, I needed the enter key to fire a function from a certain input textbox. I wrote up a jquery script, and it worked for IE, Chrome, and Safari, but it did not work for Firefox. Here was the script.&lt;/p&gt;
&lt;pre class="code"&gt;$(&lt;span style="COLOR: #a31515"&gt;"#Location"&lt;/span&gt;).keydown(&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(evt) {
    &lt;span style="COLOR: blue"&gt;switch &lt;/span&gt;(event.keyCode) {
        &lt;span style="COLOR: blue"&gt;case &lt;/span&gt;13:
            findFresh();
            &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
    }
}); &lt;/pre&gt;
&lt;p&gt;Do you see the problem? The parameter for the function is named evt, but I switched on event instead. When this was pointed out, I was perplexed that three different browsers would automagically map this parameter to a variable for me.&lt;/p&gt;
&lt;p&gt;Then someone else told me the real reason this works in everything but Firefox: event refers to a nonstandard (if everything but Firefox is nonstandard) object known as window.event. This contains the information from the last event that was fired.&lt;/p&gt;
&lt;p&gt;I can deal with that because I would prefer my functions to be as pure as possible, and analyzing a parameter is more pure than analyzing a global object. I changed my code to use the evt parameter and would do so even if Firefox supported window.event. However, I really do feel that Firefox goes out of its way to make a developer’s life miserable. It’s like they’re standing on the principle that if Microsoft initiated it, they want nothing to do with it.&lt;/p&gt;
&lt;p&gt;Window.event is such a small item that one could let it slide, but what about when you need to do something with an element in JavaScript? In every other browser, you assign an ID to the element, then reference the ID directly as a variable. Not in Firefox. They force you to call document.getElementById, and this preserves no functional purity as you’re accessing the global variable document. There is no reasoning behind this other than asininity.&lt;/p&gt;
&lt;p&gt;Message to the Mozilla team: there are hundreds of thousands of search hits related to people trying to figure out how to make their code work in Firefox. Their code works in all other major browsers, but they are wasting hours of their precious evenings and weekends pleasing users of your browser. Please consider the millions of wasted man-hours and make your browser compatible with IE, Chrome, and Safari.&lt;/p&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;. &lt;br /&gt;
&lt;a href="http://www.kodefuguru.com/post/2009/08/18/Plea-to-Mozilla.aspx"&gt;Permalink&lt;/a&gt; &lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/134172.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/08/18/plea-to-mozilla.aspx</guid>
            <pubDate>Tue, 18 Aug 2009 21:21:57 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/134172.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/08/18/plea-to-mozilla.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/134172.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/134172.aspx</trackback:ping>
        </item>
        <item>
            <title>Fields in C#</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/08/05/fields-in-c.aspx</link>
            <description>&lt;p&gt;Fields… not the kind with green grass and butterflies. Rather, fields that contain the deep dark secrets of a class. You know: &lt;em&gt;member variables&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;There’s plenty of divergence in naming these pieces of class data. Some developers prefix the field name with an underscore. Some prefer m (meaning member) and an underscore.  I personally prefer straight camelCasing. Here are some variations I’ve seen.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;private string name; &lt;/li&gt;    &lt;li&gt;private string _name; &lt;/li&gt;    &lt;li&gt;private string m_name; &lt;/li&gt;    &lt;li&gt;private string _Name; &lt;/li&gt;    &lt;li&gt;private string m_Name; &lt;/li&gt;    &lt;li&gt;private string mName; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;There’s a lot of argument to be had concerning, and I was involved in a debate yesterday concerning this. A fellow developer in Greenville claimed that camelCasing was a bad practice because it confuses VB developers. He was advocating for PascalCased fields (and even regular variables / parameters… ::shudder::).&lt;/p&gt;  &lt;p&gt;Here’s the deal. PascalCasing private member fields and variables is confusing to me as a C# developer. When I see PascalCasing, I assume that it’s part of the interface of the class. When I see camelCasing, I assume it’s private. Besides, I will&lt;/p&gt;  &lt;p&gt;I find prefixing with an “m” rather bizarre. I believe this may be a holdover from some other language. I’ve heard the argument that it helps you differentiate between your members and local variables within a method. I would respond that underscore works just as well for that purpose, and your methods are too long if you couldn’t differentiate between the two.&lt;/p&gt;  &lt;p&gt;This leaves underscore. I just think underscores are ugly. They are practical when a parameter name is the same as a field name, but I scope my variables in that situation which is the recommended practice anyway (e.g. this.name = name).&lt;/p&gt;  &lt;p&gt;Number 1 (camelCasing with no underscore) is the rule I’ve always followed because it felt most natural. But I can also say definitively that it is the accepted best C# styling practice. &lt;a href="http://code.msdn.microsoft.com/sourceanalysis"&gt;StyleCop&lt;/a&gt; rules SA1306 and SA1309 dictate that field names must begin with a lower case letter and must not begin with an underscore. For those that think “aha, m_ it is,” SA1310 states that field names must not contain an underscore.&lt;/p&gt;  &lt;p&gt;The only time you should violate this rule when naming a field is when the field is not private. The only time your field should not be private is when it marked readonly. Be careful when doing this, as this will cause a change to your interface if you need to promote the field to a property. The only time I’ve seen a real use for this is with static readonly fields.&lt;/p&gt;  &lt;p&gt;I’ve seen some people expose fields as protected. When this happens, it is important to remember that protected means the fields are public to derived classes. In other words, you have broken encapsulation. Encapsulate your fields as properties when you need to expose them anywhere outside of the class (except for static readonly fields, shorthand for “I need a const but need an instance in this context”).&lt;/p&gt;  &lt;p&gt;That concludes my rant on fields. I’m sure some will disagree… feel free to voice your opinion in the comments. Keep in mind that unless your authority is greater than StyleCop (aka the styling authority of Microsoft), I will be hard to persuade. At the same time, I understand that different organizations adopt different styles for different reasons, and that’s find for your organization as long as you don’t start breaking &lt;a href="http://www.amazon.com/gp/product/0321545613?ie=UTF8&amp;amp;tag=kodef-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0321545613"&gt;framework guidelines&lt;/a&gt;&lt;img style="border-bottom-style: none !important; border-right-style: none !important; margin: 0px; border-top-style: none !important; border-left-style: none !important" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=kodef-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0321545613" width="1" height="1" /&gt; as those affect consumers of your product.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/08/05/Fields-in-CSharp.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133921.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/08/05/fields-in-c.aspx</guid>
            <pubDate>Wed, 05 Aug 2009 16:25:59 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133921.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/08/05/fields-in-c.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133921.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133921.aspx</trackback:ping>
        </item>
        <item>
            <title>PDC 2009 Registration Open</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/08/04/pdc-2009-registration-open.aspx</link>
            <description>&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="pdc09" border="0" alt="pdc09" align="left" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/PDC2009RegistrationOpen/7F1F7AE9/pdc09.png" width="157" height="39" /&gt; Registration for &lt;a href="http://microsoftpdc.com/"&gt;PDC 2009&lt;/a&gt; is now open. If you register by September 15th you can save a hundred bucks. Or you could get there my way: win a contest (hey, I’m a poor developer). As I mentioned in a previous &lt;a href="http://www.kodefuguru.com/post/2009/07/07/4-Cool-Summer-Coding-Competitions.aspx"&gt;article&lt;/a&gt;, INETA has a &lt;a href="http://www.ineta.org/codechallenge/"&gt;component contest&lt;/a&gt; that prizes a trip to PDC. But, it’s not the only one: Microsoft has announced the &lt;a href="https://www.code7contest.com/Default.aspx"&gt;Code7 Contest&lt;/a&gt; - Code the Power of 7. It pays out great prizes, but you have to take advantage of the technologies built into Windows 7 like Libraries, Touch, Shell Integration, DirectX 11, and Sensors.&lt;/p&gt;  &lt;p&gt;The PDC has also announced an initial list of &lt;a href="http://microsoftpdc.com/Sessions/RSS"&gt;sessions&lt;/a&gt; that will be available. Here are a few I’m interested in.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Zero to Awesome in Nothing Flat: The Microsoft Web Platform and You     &lt;br /&gt;&lt;/strong&gt;Heavy on code and demos and light on slides. Join Scott Hanselman and build a seriously nice Web site in less than an hour using the Microsoft Web App Gallery, Web Platform Installer and the guts and glory of the Microsoft Web Platform. Starting from an open source application from the Gallery, the app customization goes into hyper drive with Microsoft Web Platform dev tools, frameworks, and database. Finish it off by optimizing for SEO and a few clicks to deploy to a real live Windows Server.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Windows Workflow Foundation 4 from the Inside Out&lt;/strong&gt;    &lt;br /&gt;See why Windows Workflow Foundation 4 is a powerful platform for simplifying application coordination logic and state management. Learn about the core runtime abstractions and under-the-hood improvements related to areas such as performance, transactions, and persistence. Get insights and techniques that enhance your investments in Workflow.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The State of Parallel Programming&lt;/strong&gt;    &lt;br /&gt;Parallel programming has been more difficult than it needs to be, perhaps because its tools have been treated as an “add-on” to serial programming. The objectives of composability and productivity demand something better. Come hear a relatively recent consensus view about what is needed for productive parallel programming, and why.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Petabytes for Peanuts! Making Sense Out of “Ambient” Data&lt;/strong&gt;    &lt;br /&gt;Today, the key to success with data is no longer about who can afford to acquire, store and process data effectively. That’s the cheap and easy part. The challenge now is to develop ways to better use data than your competition so you can make sense of all the data you have. Learn how algorithmic processing, at modest and extreme scale, is completely changing how we build information systems. Hear how Microsoft is dealing with this shift and using these emerging concepts in their online services. Also see examples of how some of this technology is beginning to surface in Microsoft’s product stream.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Microsoft Unified Communications: Developer Platform Futures&lt;/strong&gt;    &lt;br /&gt;Learn how Microsoft Communications Server and Microsoft Exchange provide a comprehensive and flexible communications platform for developers. Get a first look at the next generation of this platform through a series of demos and code examples. See how to embed Communicator features in your application using new Microsoft Silverlight and Windows Presentation Foundation (WPF) controls, and learn about the new API to develop full custom clients for Communications Server. Also see how the UC Managed API 3.0 provides access to the new Voice-over-IP features of Communication Server.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Developing Quality Software using Visual Studio Team System 2010&lt;/strong&gt;    &lt;br /&gt;Poor software quality causes unnecessary losses for companies every year. Learn how Visual Studio Team System 2010's new code quality features can improve your teams ability to discover flaws early and to better understand the root cause of any issue. There are tools for everybody including architects, developers, managers, and testers.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;During this full-day workshop, we’ll start at the beginning with requirements and design, and then move into unit testing, debugging, testing, and collaboration. We will complement these with demonstrations of code quality best practices that have proven to work on a variety of projects. Come see how much easier it can be to improve code quality by using VSTS 2010!&lt;/p&gt;  &lt;p&gt;It looks exciting! If anyone wants to hook me up with a trip to PDC, please use the &lt;a href="http://www.kodefuguru.com/contact.aspx"&gt;contact form&lt;/a&gt; on my website.    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="bg_logowires" border="0" alt="bg_logowires" align="right" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/PDC2009RegistrationOpen/29F7DEFC/bg_logowires.gif" width="312" height="124" /&gt;&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/08/04/PDC-2009-Registration-Open.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133906.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/08/04/pdc-2009-registration-open.aspx</guid>
            <pubDate>Tue, 04 Aug 2009 18:04:12 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133906.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/08/04/pdc-2009-registration-open.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133906.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133906.aspx</trackback:ping>
        </item>
        <item>
            <title>Automating KiGG Submission</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/30/automating-kigg-submission.aspx</link>
            <description>&lt;p&gt;This is part 3 of a series on KiGG Automation. Code in this article may be dependent on previous entries.&lt;/p&gt;  &lt;p&gt;Part 1: &lt;a href="http://www.kodefuguru.com/post/2009/07/14/Automating-KiGG-Publishing.aspx"&gt;Automating KiGG Publishing&lt;/a&gt;     &lt;br /&gt;Part 2: &lt;a title="KiGG’s Story Summary" href="http://www.kodefuguru.com/post/2009/07/20/KiGGe28099s-Story-Summary.aspx"&gt;KiGG’s Story Summary&lt;/a&gt;  &lt;br /&gt;Part 3: &lt;a href="http://www.kodefuguru.com/post/2009/07/30/Automating-KiGG-Submission.aspx"&gt;Automating KiGG Submission&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When you’re first starting a KiGG site and your user base is low, creating a bot can ease the pain of obtaining content. However, in the default install of KiGG there is no way to automate this. You can search blogs and news sites, but submitting articles from those sites is a manual process; even for the sources you trust.&lt;/p&gt;  &lt;p&gt;My goal in this article is to build off of the first article so that submission can be automated. There are many sources of content out there, and I may cover some aspects of retrieving this in future articles. But for now, that it is up to you to &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx"&gt;explore&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Finding the submit route is pretty simple: it is Submit and it is handled by the StoryController.&lt;/p&gt;  &lt;pre class="code"&gt;_routes.MapRoute(&lt;span style="color: #a31515"&gt;"Submit"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Submit"&lt;/span&gt;, 
    &lt;span style="color: blue"&gt;new &lt;/span&gt;{ controller = &lt;span style="color: #a31515"&gt;"Story"&lt;/span&gt;, action = &lt;span style="color: #a31515"&gt;"Submit" &lt;/span&gt;});&lt;/pre&gt;

&lt;p&gt;The method on the controller makes it clear what http method we must use and the parameters required.&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;AcceptVerbs&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;HttpVerbs&lt;/span&gt;.Post), &lt;span style="color: #2b91af"&gt;ValidateInput&lt;/span&gt;(&lt;span style="color: blue"&gt;false&lt;/span&gt;), &lt;span style="color: #2b91af"&gt;Compress&lt;/span&gt;]
&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ActionResult &lt;/span&gt;Submit(&lt;span style="color: blue"&gt;string &lt;/span&gt;url, 
    &lt;span style="color: blue"&gt;string &lt;/span&gt;title, &lt;span style="color: blue"&gt;string &lt;/span&gt;category, &lt;span style="color: blue"&gt;string &lt;/span&gt;description, &lt;span style="color: blue"&gt;string &lt;/span&gt;tags)&lt;/pre&gt;

&lt;p&gt;Analyzing this method shows that another JSON class can be used: JsonCreateViewData. We will need to add this to our bot’s codebase. It uses two properties already found on KiggResult, so we will call this KiggCreateResult and derive from the former class.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggCreateResult &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;KiggResult
&lt;/span&gt;{        
    [&lt;span style="color: #2b91af"&gt;JsonProperty&lt;/span&gt;(PropertyName = &lt;span style="color: #a31515"&gt;"url"&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;Url { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggCreateResult &lt;/span&gt;Create(&lt;span style="color: blue"&gt;string &lt;/span&gt;json)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;JsonConvert&lt;/span&gt;.DeserializeObject&amp;lt;&lt;span style="color: #2b91af"&gt;KiggCreateResult&lt;/span&gt;&amp;gt;(json);
    }
}&lt;/pre&gt;

&lt;p&gt;Now, inside KiggBot.cs, we will need to add our submit method. I think it may be better to return the url to the story here, but I’ll worry about refactoring this later. Remember that HttpDictionary will handle the form encoding for us.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public bool &lt;/span&gt;Submit(&lt;span style="color: blue"&gt;string &lt;/span&gt;storyUrl, &lt;span style="color: blue"&gt;string &lt;/span&gt;title, 
    &lt;span style="color: blue"&gt;string &lt;/span&gt;category, &lt;span style="color: blue"&gt;string &lt;/span&gt;description, &lt;span style="color: blue"&gt;string &lt;/span&gt;tags)
{
    &lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;dictionary = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;{ 
        {&lt;span style="color: #a31515"&gt;"url"&lt;/span&gt;, storyUrl}, 
        {&lt;span style="color: #a31515"&gt;"title"&lt;/span&gt;, title},
        {&lt;span style="color: #a31515"&gt;"category"&lt;/span&gt;, category},
        {&lt;span style="color: #a31515"&gt;"description"&lt;/span&gt;, description},
        {&lt;span style="color: #a31515"&gt;"tags"&lt;/span&gt;, tags}
    };

    &lt;span style="color: blue"&gt;var &lt;/span&gt;result = &lt;span style="color: #2b91af"&gt;KiggCreateResult&lt;/span&gt;.Create(
        session.Post(url + &lt;span style="color: #a31515"&gt;"Submit"&lt;/span&gt;, dictionary));

    &lt;span style="color: blue"&gt;return &lt;/span&gt;result.IsSuccessful;
}&lt;/pre&gt;

&lt;p&gt;That seemed easy enough. Now, in the test program I will call this with a few parameters to see how it works.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;KiggBot &lt;/span&gt;bot = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggBot&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"http://localhost:1736"&lt;/span&gt;);
bot.Login(&lt;span style="color: #a31515"&gt;"bee"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"iambusy"&lt;/span&gt;);
bot.Submit(&lt;span style="color: #a31515"&gt;"http://example.com/"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Example"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Agile"&lt;/span&gt;, 
    &lt;span style="color: #a31515"&gt;"This is a test"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Example, News"&lt;/span&gt;);
bot.Logout();&lt;/pre&gt;

&lt;p&gt;No dice. I received an error that the user agent must be set. I think user agent should be configurable in our program, but for simplicity I will add a constant to WebSession for userAgent and set it on the request object in the Post method.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private const string &lt;/span&gt;userAgent = &lt;span style="color: #a31515"&gt;"Pigg"&lt;/span&gt;;
&lt;span style="color: blue"&gt;public string &lt;/span&gt;Post(&lt;span style="color: blue"&gt;string &lt;/span&gt;url, &lt;span style="color: blue"&gt;string &lt;/span&gt;formData)
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: #2b91af"&gt;WebRequest&lt;/span&gt;.Create(url) &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebRequest&lt;/span&gt;;
    request.UserAgent = userAgent;
    ...
}&lt;/pre&gt;

&lt;p&gt;I tried again, and it worked perfectly. The bot created an entry with two new tags: Example and News. Keep in mind that Category must match a valid category in your KiGG install.&lt;/p&gt;

&lt;p&gt;If you’re following along, you can now automate KiGG publishing and article submission. You can also define what part of the html from which the story summary is retrieved. Leave a comment on what part of KiGG automation you would like me to look at next.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/30/Automating-KiGG-Submission.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133823.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/30/automating-kigg-submission.aspx</guid>
            <pubDate>Thu, 30 Jul 2009 22:38:38 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133823.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/30/automating-kigg-submission.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133823.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133823.aspx</trackback:ping>
        </item>
        <item>
            <title>Free PowerShell EBook</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/24/free-powershell-ebook.aspx</link>
            <description>&lt;p&gt;Looking for something to do this weekend? Looking to master PowerShell? Windows PowerShell MVP Dr. Tobias Weltner has released a free book just for you, &lt;a href="http://powershell.com/cs/blogs/ebook/"&gt;Mastering Powershell&lt;/a&gt;! This isn’t a little cheatsheet; it’s 567 pages long. Here’s a linked chapter list if you want to jump directly into a topic.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2008/10/19/chapter-1-the-powershell-console.aspx"&gt;Chapter 1. The PowerShell Console&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2008/10/20/chapter-2-interactive-powershell.aspx"&gt;Chapter 2. Interactive PowerShell&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2008/10/22/chapter-3-variables.aspx"&gt;Chapter 3. Variables&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2008/10/22/chapter-4-arrays-and-hashtables.aspx"&gt;Chapter 4. Arrays and Hashtables&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2008/11/23/chapter-5-the-powershell-pipeline.aspx"&gt;Chapter 5. The PowerShell Pipeline&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/08/chapter-6-using-objects.aspx"&gt;Chapter 6. Using Objects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/08/chapter-7-conditions.aspx"&gt;Chapter 7. Conditions&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/08/chapter-8-loops.aspx"&gt;Chapter 8. Loops&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-9-functions.aspx"&gt;Chapter 9. Functions&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-10-scripts.aspx"&gt;Chapter 10. Scripts&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-11-finding-and-avoiding-errors.aspx"&gt;Chapter 11. Finding and Avoiding Errors&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-12-command-discovery-and-scriptblocks.aspx"&gt;Chapter 12. Command Discovery and Scriptblocks&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-13-text-and-regular-expressions.aspx"&gt;Chapter 13. Text and Regular Expressions&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-14-xml.aspx"&gt;Chapter 14. XML&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-15-the-file-system.aspx"&gt;Chapter 15. The File System&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-16-the-registry.aspx"&gt;Chapter 16. The Registry&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/04/10/chapter-17-processes-services-event-logs.aspx"&gt;Chapter 17. Processes, Services, Event Logs&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/04/10/chapter-18-wmi-windows-management-instrumentation.aspx"&gt;Chapter 18. WMI: Windows Management Instrumentation&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/04/10/chapter-19-user-management.aspx"&gt;Chapter 19. User Management&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://powershell.com/cs/blogs/ebook/archive/2009/04/10/chapter-20-your-own-cmdlets-and-extensions.aspx"&gt;Chapter 20. Your Own Cmdlets and Extensions&lt;/a&gt;&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/24/Free-PowerShell-EBook.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133696.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/24/free-powershell-ebook.aspx</guid>
            <pubDate>Fri, 24 Jul 2009 20:24:22 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133696.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/24/free-powershell-ebook.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133696.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133696.aspx</trackback:ping>
        </item>
        <item>
            <title>Basic Unit Testing Guidelines</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/23/basic-unit-testing-guidelines.aspx</link>
            <description>&lt;p&gt;When I recently started looking through a certain project’s tests, I was struck by how difficult it was for me to read and understand. The tests were laid out haphazardly, and the code contained enough logic to make me wonder if it would be easier to analyze the functional code. Tests don’t do anyone good if they require that much analysis. In contrast, one of my &lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=Kigg"&gt;favorite open source projects&lt;/a&gt; contains tests that allow me to learn the functionality of the system without looking at any functional code.&lt;/p&gt;  &lt;p&gt;The intent of this post isn’t to describe advanced unit testing techniques but to describe a few guidelines that I feel should be implemented regardless if you’re mocking objects, using test driven development, or just want to ensure your code works. I am using Microsoft’s unit testing framework, but these same guidelines apply in most other unit testing frameworks.&lt;/p&gt;  &lt;h2&gt;Name Code Files Sensibly&lt;/h2&gt;  &lt;p&gt;You should be able to find your test, which may be difficult to do if you name your file “MyTests.cs.” Naming the file after the class you’re testing is a guideline many people use. Alternatively, you can name it after a functional area if you have more than one fixture per file. Yes, generally speaking you should have &lt;a href="http://www.kodefuguru.com/post/2009/06/30/One-Public-Type-Per-File.aspx"&gt;one class per file&lt;/a&gt;, but I admit to relaxing this rule because you are going to experience class explosion if you’re striving for 100% coverage. I prefer to name my class files after the class just as I do in functional development.&lt;/p&gt;  &lt;h2&gt;Name Fixture After Scenario&lt;/h2&gt;  &lt;p&gt;Your test fixture should set up a scenario, and the name of the class should reflect that scenario. For example, if you’re testing what happens when a user activates an account, name the class “WhenUserActivatesAccount.”&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestClass&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WhenUserActivatesAccount
&lt;/span&gt;{
}&lt;/pre&gt;

&lt;h2&gt;Setup Code in Constructor&lt;/h2&gt;

&lt;p&gt;Usually, your constructor (or Setup method in some frameworks) should initialize the scenario that you’re testing. If external setup must be done, use the ClassInitializer attribute on a static method.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;User &lt;/span&gt;user;
&lt;span style="color: #2b91af"&gt;Account &lt;/span&gt;account;

&lt;span style="color: blue"&gt;public &lt;/span&gt;WhenUserActivatesAccount()
{
    user = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;User&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"kodefuguru"&lt;/span&gt;);
    account = user.Account;
    account.Activate();
}&lt;/pre&gt;

&lt;p&gt;If you expect exceptions with certain parameters in various, similar scenarios; it may be necessary to call the setup code from within the testing method. I prefer to refactor my tests so that the test for the expected exception is in a derived class that tweaks the modifications within its constructor before calling the base constructor… for example, “public class WhenInvalidUserActivatesAccount : WhenUserActivatesAccount.”&lt;/p&gt;

&lt;h2&gt;Name Test After Expected Result&lt;/h2&gt;

&lt;p&gt;Ideally, tests contain one Assert statement. You’re testing a specific condition that you expect to occur as a result of the scenario you’ve presented. When a user activates an account, you expect the account to activated. Therefore, your test should be named “AccountActivatedShouldBeTrue,” with the assertion “Assert.IsTrue(account.Activated).”&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;AccountActivatedShouldBeTrue()
{
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(account.Activated);
}&lt;/pre&gt;

&lt;h2&gt;No Conditionals Containing Assertions&lt;/h2&gt;

&lt;p&gt;If assertions are contained within a conditional statement, then you aren’t really ensuring that your code is running as expected. When you’re writing tests, you’re declaring the behavior of your system based upon certain conditions.&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;AccountActivatedShouldDependOnUserValid()
{
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(user.Valid)
    {
        &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(account.Activated);
    }
    &lt;span style="color: blue"&gt;else
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsFalse(account.Activated);
    }
}&lt;/pre&gt;

&lt;p&gt;If I have a test like this, I’m not really declaring a fact about the system. Instead, I’m declaring facts about two different situations, one of which will not occur. Whether user.Valid is true or not should depend on the setup of my test, and I should know what the value will be when this test runs.&lt;/p&gt;

&lt;h2&gt;Differentiate Between Unit Tests and Integration Tests&lt;/h2&gt;

&lt;p&gt;Unit tests are for testing an individual unit of code. Integration tests are for testing functionality between different systems. It is best to separate unit tests and integration tests by placing them in separate projects. If you’re not already doing so, at some point you may wish to automate your testing process. In a continuous integration environment, unit tests should be run with every build. Integration tests tend to be slower, and it is oftentimes not practical to automate them as frequently.&lt;/p&gt;

&lt;p&gt;If you have trouble differentiating between unit tests and integration tests (i.e. everything you do connects to a service or persists to the database), it would be a good idea to look into &lt;a href="http://code.google.com/p/moq/"&gt;mocking&lt;/a&gt; and &lt;a href="http://blog.benhartonline.com/post/2008/09/24/Dependency-Inversion-for-Dummies-Constructor-Injection.aspx"&gt;inversion of control&lt;/a&gt; so that you can create tests for units of functionality.&lt;/p&gt;

&lt;p&gt;---&lt;/p&gt;

&lt;p&gt;There are many more things you can do to create effective unit tests, but if you follow the few guidelines I have listed you will benefit immediately. It is important that it is easy for anyone looking at your tests to know how the system is supposed to behave. There is additional benefit in that you can harvest fixture and test names to create functional documentation for your software.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/23/Basic-Unit-Testing-Guidelines.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133675.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/23/basic-unit-testing-guidelines.aspx</guid>
            <pubDate>Thu, 23 Jul 2009 20:26:40 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133675.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/23/basic-unit-testing-guidelines.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133675.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133675.aspx</trackback:ping>
        </item>
        <item>
            <title>2009 Silverlight Control Builder Contest</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/15/2009-silverlight-control-builder-contest.aspx</link>
            <description>&lt;p&gt;A week ago, I posted a few summer contests to partake in during those lazy weekends we all experience (yea right). Since that time, another &lt;a href="http://www.gosilverlight.org"&gt;contest&lt;/a&gt; was announced by Silverlight MVP, &lt;a href="http://pagebrooks.com"&gt;Page Brooks&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.gosilverlight.org"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="2009SilverlightControlBuilderContest" border="0" alt="2009SilverlightControlBuilderContest" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/2009SilverlightControlBuilderContest/045287CA/2009SilverlightControlBuilderContest.png" width="244" height="78" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This contest is all about building a Silverlight control. The boundaries are rather loose. You can make it practical, you can make it cool, but most importantly have fun making it!&lt;/p&gt;  &lt;p&gt;The deadline for the contest is September 19, leaving just 66 days to get your entry in. If you win, you’ll receive tons of goodies from &lt;a href="http://www.devexpress.com/"&gt;Devexpress&lt;/a&gt;, &lt;a href="http://www.infragistics.com/"&gt;Infragistics&lt;/a&gt;, &lt;a href="http://www.telerik.com/"&gt;Telerik&lt;/a&gt;, and the &lt;a href="http://www.silverlightshow.com/"&gt;SilverlightShow&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Good luck… I will be competing in this one as well.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/15/2009-Silverlight-Control-Builder-Contest.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133518.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/15/2009-silverlight-control-builder-contest.aspx</guid>
            <pubDate>Wed, 15 Jul 2009 20:46:27 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133518.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/15/2009-silverlight-control-builder-contest.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133518.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133518.aspx</trackback:ping>
        </item>
        <item>
            <title>Response to CRUD is bad for REST</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/15/response-to-crud-is-bad-for-rest.aspx</link>
            <description>&lt;p&gt;Arnon Rotem-Gal-Oz wrote an article for Architect Zone where he makes the claim that &lt;a href="http://architects.dzone.com/news/crud-bad-rest"&gt;CRUD is bad for REST&lt;/a&gt;. I couldn’t disagree more, so I felt it important to respond to his criticism.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;CRUD which stands for Create, Read, Update and Delete, are the four basic database operations. Some of the  HTTP verbs, namely POST, GET, PUT and DELETE (there are others like OPTIONS or HEAD) seem to have a 1-1 mapping to CRUD. As I said earlier they don’t. The table below briefly contrast HTTP verbs and CRUD&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Actually, they do map perfectly as CRUD itself is pretty simple (it’s literally create, retrieve, update, delete without caveats). The examples that are laid out in Arnon’s article are comparing REST directly to SQL Server commands. The question shouldn’t be do http verbs fit perfectly with SQL operations, but rather do they map to the four basic functions of persistent storage? I can say without any doubt that POST, GET, PUT, and DELETE map quite well, making it possible for REST useful for persistence.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The way I see it,  the HTTP verbs are more document oriented than database oriented (which is why document databases like &lt;a href="http://www.rgoarchitects.com/nblog/ct.ashx?id=d6d71d3d-1370-477d-a8c6-2c95c7f41a4e&amp;amp;url=http%3a%2f%2fcouchdb.apache.org%2f"&gt;CouchDB&lt;/a&gt; are seamlessly RESTful). In any event, what I tried to show here is that while you can update, delete and create new resources the way you do that is not exactly CRUD in the database sense of the word – at least when it comes to using the HTTP verbs.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I see http verbs as resource oriented, and data is just one type of resource. Of course, if I’m creating an ADO.NET Data Service, I want to expose my data as more useful resources (e.g. a useful representation of a Customer rather than just the customer data).&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;However, the main reason CRUD is wrong for REST is an architectural one. One of the base characteristics [1] of REST is using hypermedia to externalize the statemachine of the protocol (a.k.a. HATEOS– Hypertext as the engine of state). The URI to URI transition is what makes the protocol tick. […] If you are busy with inserting and updating (CRUDing) resources you are not, in fact, thinking about protocols or externalizing a State machine and, in my opinion, miss the whole point about REST.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I could think about protocols, but a useful one already exists (HTTP). I could think about externalizing my state machine, but that’s already taken care of when using a product like ADO.NET Data Services. If you are busy with inserting and updating resources, you probably have a resource oriented architecture which doesn’t miss the whole point of REST as it *is* an implementation of a REST architecture.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;CRUD services leads and promoted to the database as a service kind of thinking (e.g. ADO.NET data services) which as &lt;a href="http://www.rgoarchitects.com/nblog/ct.ashx?id=d6d71d3d-1370-477d-a8c6-2c95c7f41a4e&amp;amp;url=http%3a%2f%2fwww.rgoarchitects.com%2fnblog%2f2008%2f08%2f17%2fWhyTheDatabaseAsAServiceIsABadIdea.aspx"&gt;I explained in another post last year&lt;/a&gt; is a bad idea since:&lt;/p&gt;    &lt;ol&gt;     &lt;li&gt;It circumvents the whole idea about "Services" - there's no business logic. &lt;/li&gt;      &lt;li&gt;It is exposing internal database structure or data rather than a thought-out contract. &lt;/li&gt;      &lt;li&gt;It encourages bypassing real services and going straight to their data. &lt;/li&gt;      &lt;li&gt;It creates a blob service (the data source). &lt;/li&gt;      &lt;li&gt;It encourages minuscule demi-serices (the multiple "interfaces" of said blob) that disregard few of the fallacies of distributed computing. &lt;/li&gt;      &lt;li&gt;It is just client-server in sheep's clothing. &lt;/li&gt;   &lt;/ol&gt; &lt;/blockquote&gt;  &lt;p&gt;1. ADO.NET Data Services provides a standard ORM that can be consumed by any application. That in itself is useful as a service (retrieve entities rather than data, mapping is hidden). However, one can provide business logic in that tier if one chooses, but I think that’s bad design.&lt;/p&gt;  &lt;p&gt;2. Even with the most direct ORM, you’re still providing mapped objects rather than an internal data structure. If you have a well-thought out map, then you will be providing that instead.&lt;/p&gt;  &lt;p&gt;3. You aren’t going straight to the data, you are utilizing entities. The service exists and can act as a gate keeper.&lt;/p&gt;  &lt;p&gt;4. I don’t understand this complaint… the data source is a binary large object service? If blob is meant in another sense, my answer is that you only expose what you want to expose with ADO.NET Data Services.&lt;/p&gt;  &lt;p&gt;5. I suppose I’ve never thought about setting up multiple demi-services?&lt;/p&gt;  &lt;p&gt;6. The problem with client-server is the disregard of object-relational mapping and business layers. Even in the worst case scenario with ADO.NET Data Services, you get object-relational mapping.&lt;/p&gt;  &lt;p&gt;I don’t believe CRUD is bad for REST at all. In fact, I believe they perfectly complement each other in the construction of a resource oriented architecture.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/15/Response-to-CRUD-is-bad-for-REST.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133514.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/15/response-to-crud-is-bad-for-rest.aspx</guid>
            <pubDate>Wed, 15 Jul 2009 16:31:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133514.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/15/response-to-crud-is-bad-for-rest.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133514.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133514.aspx</trackback:ping>
        </item>
        <item>
            <title>Automating KiGG Publishing</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/14/automating-kigg-publishing.aspx</link>
            <description>&lt;p&gt;When I set up my first &lt;a href="http://www.codeplex.com/Kigg"&gt;KiGG&lt;/a&gt; &lt;a href="http://mtgbattlefield.com"&gt;site&lt;/a&gt;, I was surprised to discover that I had to manually publish articles. I assumed it would be an automated process that would run once a day. Since there are times I may not be able to log into my website, I set about figuring out how to automate the process.&lt;/p&gt;  &lt;p&gt;I should note that during this process, I didn’t use best practices. I had one requirement: make a program that I can schedule to publish stories on KiGG. I wasn’t really sure what I would need to go about doing that. So, I did what I assume most developers do: create a console application prototype. I don’t claim this code is perfect, but if you want classes to automate publishing in KiGG (or control MVC applications), this will do the trick.&lt;/p&gt;  &lt;p&gt;KiGG is an ASP.NET MVC application. This made it easy to figure out where to begin. I wanted to Publish, so I needed to find the admin link and see what it called. I guessed it would be something like, /Publish, and I was correct.&lt;/p&gt;  &lt;pre class="code"&gt;scriptManager.RegisterOnReady(&lt;span style="color: #a31515"&gt;"Administration.set_publishUrl('{0}');"
    &lt;/span&gt;.FormatWith(Url.RouteUrl(&lt;span style="color: #a31515"&gt;"Publish"&lt;/span&gt;)));&lt;/pre&gt;

&lt;p&gt;set_publishUrl is simply a setter in the JavaScript to prevent a url from being hardcoded in script. Looking over the JavaScript I could tell there wasn’t much more needed than calling the proper url.&lt;/p&gt;

&lt;pre class="code"&gt;$.ajax(
    {
        url: Administration._publishUrl,
        type: &lt;span style="color: #a31515"&gt;'POST'&lt;/span&gt;,
        dataType: &lt;span style="color: #a31515"&gt;'json'&lt;/span&gt;,
        data : &lt;span style="color: #a31515"&gt;'__MVCASYNCPOST=true'&lt;/span&gt;, &lt;span style="color: green"&gt;// a fake param to fool iis for content-lenth,
        &lt;/span&gt;beforeSend: &lt;span style="color: blue"&gt;function&lt;/span&gt;()
        {
            $U.showProgress(&lt;span style="color: #a31515"&gt;'Publishing stories...'&lt;/span&gt;);
        },
        success: &lt;span style="color: blue"&gt;function&lt;/span&gt;(result)
        {
            $U.hideProgress();

            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.isSuccessful)
            {
                $U.messageBox(&lt;span style="color: #a31515"&gt;'Success'&lt;/span&gt;, &lt;span style="color: #a31515"&gt;'Story publishing process completed.'&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
            }
            &lt;span style="color: blue"&gt;else
            &lt;/span&gt;{
                $U.messageBox(&lt;span style="color: #a31515"&gt;'Error'&lt;/span&gt;, result.errorMessage, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            }
        }
    }
);&lt;/pre&gt;

&lt;p&gt;The script is doing a POST on the /Publish url with fake data (to fool IIS?).&lt;/p&gt;

&lt;p&gt;Next, it was time to check the routing for /Publish. Routing in KiGG is defined in Kigg.Web\BootstrapperTasks\RegisterRoutes.cs. It was &lt;a href="http://weblogs.asp.net/rashid/archive/2009/02/17/use-bootstrapper-in-your-asp-net-mvc-application-and-reduce-code-smell.aspx"&gt;done this way&lt;/a&gt; to be consistent with the &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc546578.aspx"&gt;Open Closed Principle&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code"&gt;_routes.MapRoute(&lt;span style="color: #a31515"&gt;"Publish"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Publish"&lt;/span&gt;, 
    &lt;span style="color: blue"&gt;new &lt;/span&gt;{ controller = &lt;span style="color: #a31515"&gt;"Story"&lt;/span&gt;, action = &lt;span style="color: #a31515"&gt;"Publish" &lt;/span&gt;});&lt;/pre&gt;

&lt;p&gt;Now we know the entry to this is in the story controller and that the method is Publish. The story controller being used is defined within the web.config file using &lt;a href="http://msdn.microsoft.com/en-us/library/dd140117.aspx"&gt;Unity&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;typeAlias &lt;/span&gt;&lt;span style="color: red"&gt;alias&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;StoryController&lt;/span&gt;" &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Kigg.Web.StoryController, Kigg.Web&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;I set up a break point and wrote a quick routine to post to the publish url.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: #2b91af"&gt;WebRequest&lt;/span&gt;.Create(&lt;span style="color: #a31515"&gt;&lt;a href="http://localhost:1736/Publish"&gt;http://localhost:1736/Publish&lt;/a&gt;&lt;/span&gt;);&lt;br /&gt;request.ContentType = &lt;span style="color: #a31515"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;;
request.Method = &lt;span style="color: #a31515"&gt;"POST"&lt;/span&gt;;

&lt;span style="color: blue"&gt;var &lt;/span&gt;form = &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.ASCII.GetBytes(&lt;span style="color: #a31515"&gt;"__MVCASYNCPOST=true"&lt;/span&gt;);
&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Stream &lt;/span&gt;requestStream = request.GetRequestStream())
{
    requestStream.Write(form, 0, form.Length);
    requestStream.Close();
}

&lt;span style="color: blue"&gt;var &lt;/span&gt;response = request.GetResponse();
&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;StreamReader &lt;/span&gt;reader = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StreamReader&lt;/span&gt;(response.GetResponseStream()))
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;responseText = reader.ReadToEnd();
    &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(responseText);
    reader.Close();
}&lt;/pre&gt;

&lt;p&gt;Everything executed fine, but the return message indicated something was wrong: “{"isSuccessful":false,"errorMessage":"You are currently not authenticated."}.” It’s pretty obvious that authentication would be necessary, otherwise I could publish &lt;a href="http://dotnetshoutout.com/"&gt;DotNetShoutOut&lt;/a&gt; whenever I wanted. Unfortunately, the obvious way to authenticate does not work.&lt;/p&gt;

&lt;pre class="code"&gt;request.Credentials = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NetworkCredential&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"admin"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"password"&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Since it is a NetworkCredential, I assume this code would work with Windows authentication turned on. However, we’re using forms authentication. I looked at the routes and found one for Login and Logout. At this point it was clear that I would be calling post multiple times, so I moved the code to a method that would accept a url and formdata as a string.&lt;/p&gt;

&lt;pre class="code"&gt;Post(&lt;span style="color: #a31515"&gt;"http://localhost:1736/Login"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"userName=admin&amp;amp;password=password"&lt;/span&gt;);
Post(&lt;span style="color: #a31515"&gt;"http://localhost:1736/Publish"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"__MVCASYNCPOST=true"&lt;/span&gt;);
Post(&lt;span style="color: #a31515"&gt;"http://localhost:1736/Logout"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"__MVCASYNCPOST=true"&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;This returned the following results:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{"isSuccessful":true,"errorMessage":null} 
    &lt;br /&gt;{"isSuccessful":false,"errorMessage":"You are currently not authenticated."} 

    &lt;br /&gt;{"isSuccessful":false,"errorMessage":"You are currently not logged in."}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I put a breakpoint in the Login method of the MembershipController, and from there was able to see what was happening. Although it was a few levels deep, it was clear that FormsAuthentication.SetAuthCookie was the important piece of code; I needed a way to retain cookies between requests.&lt;/p&gt;

&lt;p&gt;Cookies are only available by using HttpWebRequest and HttpWebReponse rather than their base classes. So, I cast my variables to the proper class. One odd thing I found was the cookies have to be retrieved from the request rather than the response after you have requested the response. I wrapped this functionality up in a WebSession class.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebSession
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;protected &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CookieCollection &lt;/span&gt;Cookies { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;WebSession()
    {
        Cookies = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CookieCollection&lt;/span&gt;();
    }

    &lt;span style="color: blue"&gt;public string &lt;/span&gt;Post(&lt;span style="color: blue"&gt;string &lt;/span&gt;url, &lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;formData)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;Post(url, formData.ToString());
    }

    &lt;span style="color: blue"&gt;public string &lt;/span&gt;Post(&lt;span style="color: blue"&gt;string &lt;/span&gt;url, &lt;span style="color: blue"&gt;string &lt;/span&gt;formData)
    {            
        &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: #2b91af"&gt;WebRequest&lt;/span&gt;.Create(url) &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebRequest&lt;/span&gt;;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(request == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
        {
            &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpException&lt;/span&gt;();
        }
        request.ContentType = &lt;span style="color: #a31515"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;;
        request.Method = &lt;span style="color: #a31515"&gt;"POST"&lt;/span&gt;;
        request.CookieContainer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CookieContainer&lt;/span&gt;();
        request.CookieContainer.Add(request.RequestUri, Cookies);

        &lt;span style="color: blue"&gt;var &lt;/span&gt;form = &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.ASCII.GetBytes(formData);
        WriteToRequest(request, form);

        &lt;span style="color: blue"&gt;var &lt;/span&gt;response = request.GetResponse() &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebResponse&lt;/span&gt;;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(response == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
        {
            &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpException&lt;/span&gt;();
        }

        &lt;span style="color: blue"&gt;var &lt;/span&gt;responseText = ReadResponse(response);
        Cookies = request.CookieContainer.GetCookies(request.RequestUri);

        &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(responseText);
        
        &lt;span style="color: blue"&gt;return &lt;/span&gt;responseText;
    }

    &lt;span style="color: blue"&gt;private static void &lt;/span&gt;WriteToRequest(&lt;span style="color: #2b91af"&gt;WebRequest &lt;/span&gt;request, &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] form)
    {
        &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Stream &lt;/span&gt;requestStream = request.GetRequestStream())
        {
            requestStream.Write(form, 0, form.Length);
            requestStream.Close();
        }
    }

    &lt;span style="color: blue"&gt;private string &lt;/span&gt;ReadResponse(&lt;span style="color: #2b91af"&gt;WebResponse &lt;/span&gt;response)
    {
        &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;StreamReader &lt;/span&gt;reader = 
            &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StreamReader&lt;/span&gt;(response.GetResponseStream()))
        {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;responseText = reader.ReadToEnd();
            reader.Close();
            &lt;span style="color: blue"&gt;return &lt;/span&gt;responseText;
        }
    }
}&lt;/pre&gt;

&lt;p&gt;If you look closely you’ll notice an HttpDictionary class. This is because I wanted to treat the form data as a dictionary rather than a string. I suppose this could be written as an extension method on Dictionary&amp;lt;string, string&amp;gt; instead.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;
{
    &lt;span style="color: blue"&gt;public override string &lt;/span&gt;ToString()
    {
        &lt;span style="color: blue"&gt;return this&lt;/span&gt;.Select(q =&amp;gt; EncodePair(q))
            .Aggregate((a, b) =&amp;gt; a + &lt;span style="color: #a31515"&gt;"&amp;amp;" &lt;/span&gt;+ b);
    }

    &lt;span style="color: blue"&gt;private string &lt;/span&gt;EncodePair(&lt;span style="color: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; pair)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpUtility&lt;/span&gt;.HtmlEncode(pair.Key) +
            &lt;span style="color: #a31515"&gt;"=" &lt;/span&gt;+ &lt;span style="color: #2b91af"&gt;HttpUtility&lt;/span&gt;.HtmlEncode(pair.Value);
    }
}&lt;/pre&gt;

&lt;p&gt;I also felt it necessary to wrap up the result received from KiGG in a class that can be used. Otherwise, it’s difficult to know whether or not the call was successful. To convert from Json, I used &lt;a href="http://www.codeplex.com/Json"&gt;Json.NET&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggResult
&lt;/span&gt;{        
    [&lt;span style="color: #2b91af"&gt;JsonProperty&lt;/span&gt;(PropertyName=&lt;span style="color: #a31515"&gt;"isSuccessful"&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;IsSuccessful{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

    [&lt;span style="color: #2b91af"&gt;JsonProperty&lt;/span&gt;(PropertyName = &lt;span style="color: #a31515"&gt;"errorMessage"&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;ErrorMessage { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggResult &lt;/span&gt;Create(&lt;span style="color: blue"&gt;string &lt;/span&gt;json)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;JsonConvert&lt;/span&gt;.DeserializeObject&amp;lt;&lt;span style="color: #2b91af"&gt;KiggResult&lt;/span&gt;&amp;gt;(json);
    }
}&lt;/pre&gt;

&lt;p&gt;Finally, I made a KiggBot class to provide us an interface that makes sense for accessing a KiGG site. This can be changed to throw an exception if the result indicates the call was not successful.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggBot 
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;private static readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;mvcAsyncPost = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpDictionary
    &lt;/span&gt;{
        {&lt;span style="color: #a31515"&gt;"__MVCASYNCPOST"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"true"&lt;/span&gt;}
    };

    &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebSession &lt;/span&gt;session;
    &lt;span style="color: blue"&gt;private string &lt;/span&gt;url;

    &lt;span style="color: blue"&gt;public &lt;/span&gt;KiggBot(&lt;span style="color: blue"&gt;string &lt;/span&gt;url)
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!url.EndsWith(&lt;span style="color: #a31515"&gt;"/"&lt;/span&gt;))
            url += &lt;span style="color: #a31515"&gt;"/"&lt;/span&gt;;

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.url = url;
        session = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebSession&lt;/span&gt;();
    }

    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;Login(&lt;span style="color: blue"&gt;string &lt;/span&gt;userName, &lt;span style="color: blue"&gt;string &lt;/span&gt;password)
    {
        &lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;dictionary = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpDictionary &lt;/span&gt;{ 
            {&lt;span style="color: #a31515"&gt;"userName"&lt;/span&gt;, userName}, {&lt;span style="color: #a31515"&gt;"password"&lt;/span&gt;, password}};

        &lt;span style="color: blue"&gt;var &lt;/span&gt;result = &lt;span style="color: #2b91af"&gt;KiggResult&lt;/span&gt;.Create(
            session.Post(url + &lt;span style="color: #a31515"&gt;"Login"&lt;/span&gt;, dictionary));
        
        &lt;span style="color: blue"&gt;return &lt;/span&gt;result.IsSuccessful;
    }

    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;Logout()
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;result = &lt;span style="color: #2b91af"&gt;KiggResult&lt;/span&gt;.Create(
            session.Post(url + &lt;span style="color: #a31515"&gt;"Logout"&lt;/span&gt;, mvcAsyncPost));

        &lt;span style="color: blue"&gt;return &lt;/span&gt;result.IsSuccessful;
    }

    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;Publish()
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;result = &lt;span style="color: #2b91af"&gt;KiggResult&lt;/span&gt;.Create(
            session.Post(url + &lt;span style="color: #a31515"&gt;"Publish"&lt;/span&gt;, mvcAsyncPost));

        &lt;span style="color: blue"&gt;return &lt;/span&gt;result.IsSuccessful;
    }
}&lt;/pre&gt;

&lt;p&gt;With these classes, it’s fairly easy to create an automated publishing program. At the very least, write a console app and use scheduler to fire it daily.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;KiggBot &lt;/span&gt;bot = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KiggBot&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"http://localhost:1736"&lt;/span&gt;);
bot.Login(&lt;span style="color: #a31515"&gt;"admin"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"password"&lt;/span&gt;);
bot.Publish();
bot.Logout();&lt;/pre&gt;
Hope that helps. If anyone makes a cool GUI for this and releases it, might I recommend PiGG?&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/14/Automating-KiGG-Publishing.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133495.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/14/automating-kigg-publishing.aspx</guid>
            <pubDate>Tue, 14 Jul 2009 23:18:33 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133495.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/14/automating-kigg-publishing.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133495.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133495.aspx</trackback:ping>
        </item>
        <item>
            <title>WCF from CLR Functions</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/13/wcf-from-clr-functions.aspx</link>
            <description>&lt;p&gt;I don’t approve of calling a WCF server from SQL Server, but there was a business requirement that had to be met. It concerned regulations regarding the safeguarding of certain data elements. Due to performance issues and the application’s infrastructure, calling the service from the application itself wasn’t an option.&lt;/p&gt;  &lt;p&gt;Coding the CLR functions were the easy part. To do this, reference the Microsoft.SqlServer.Server and System.Data.SqlTypes namespaces (contained in System.Data.dll) and set the appropriate attributes on static methods contained within a static class. Also, it is probably best if you use the SqlTypes (SqlString, SqlDateTime, etc) for parameters and return values rather than rely on Sql Server to convert the values for you. Be sure to &lt;a href="http://www.kodefuguru.com/post/2009/06/16/Enable-CLR-in-SQL-2008.aspx"&gt;enable CLR&lt;/a&gt; on your SQL Server.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Data.SqlTypes;
&lt;span style="color: blue"&gt;using &lt;/span&gt;Microsoft.SqlServer.Server;

&lt;span style="color: blue"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlFunctions
&lt;/span&gt;{
    [&lt;span style="color: #2b91af"&gt;SqlFunction&lt;/span&gt;(DataAccess = &lt;span style="color: #2b91af"&gt;DataAccessKind&lt;/span&gt;.Read, IsDeterministic = &lt;span style="color: blue"&gt;true&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlString &lt;/span&gt;HelloWorld()
    {
        &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlString&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Hello World!"&lt;/span&gt;);
    }

}&lt;/pre&gt;

&lt;p&gt;I wanted to avoid pulling too many assemblies into SQL Server, so I limited my references to the bare essentials for working with WCF and Sql Server: System, System.Data, System.Runtime.Serialization, System.ServiceModel, and System.XML.&lt;/p&gt;

&lt;p&gt;Here’s the script to drop the assemblies if they exist and add them back (double slashes are intentional to allow copy/paste with formatting to work). Because of dependencies, it is necessary to add more assemblies than directly referenced by the project. If you created this within a database project, you can deploy by right-clicking the project. I have previously posted instructions on how to &lt;a href="http://www.kodefuguru.com/post/2009/07/02/Convert-Class-Library-to-Database-Project.aspx"&gt;convert a class library to a database project&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;IF  EXISTS &lt;/span&gt;(&lt;span style="color: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;sys.assemblies asms 
&lt;span style="color: blue"&gt;WHERE &lt;/span&gt;asms.name = N&lt;span style="color: #a31515"&gt;'Microsoft.Transactions.Bridge'&lt;/span&gt;) 
    &lt;span style="color: blue"&gt;DROP &lt;/span&gt;ASSEMBLY [Microsoft.Transactions.Bridge]
GO

&lt;span style="color: blue"&gt;IF  EXISTS &lt;/span&gt;(&lt;span style="color: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;sys.assemblies asms 
&lt;span style="color: blue"&gt;WHERE &lt;/span&gt;asms.name = N&lt;span style="color: #a31515"&gt;'System.IdentityModel.Selectors'&lt;/span&gt;) 
    &lt;span style="color: blue"&gt;DROP &lt;/span&gt;ASSEMBLY [System.IdentityModel.Selectors]
GO

&lt;span style="color: blue"&gt;IF  EXISTS &lt;/span&gt;(&lt;span style="color: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;sys.assemblies asms 
&lt;span style="color: blue"&gt;WHERE &lt;/span&gt;asms.name = N&lt;span style="color: #a31515"&gt;'System.IdentityModel'&lt;/span&gt;) 
    &lt;span style="color: blue"&gt;DROP &lt;/span&gt;ASSEMBLY [System.IdentityModel]
GO

&lt;span style="color: blue"&gt;IF  EXISTS &lt;/span&gt;(&lt;span style="color: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;sys.assemblies asms 
&lt;span style="color: blue"&gt;WHERE &lt;/span&gt;asms.name = N&lt;span style="color: #a31515"&gt;'System.Messaging'&lt;/span&gt;) 
    &lt;span style="color: blue"&gt;DROP &lt;/span&gt;ASSEMBLY [System.Messaging]
GO

&lt;span style="color: blue"&gt;IF  EXISTS &lt;/span&gt;(&lt;span style="color: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;sys.assemblies asms 
&lt;span style="color: blue"&gt;WHERE &lt;/span&gt;asms.name = N&lt;span style="color: #a31515"&gt;'System.Web'&lt;/span&gt;) 
    &lt;span style="color: blue"&gt;DROP &lt;/span&gt;ASSEMBLY [System.Web]
GO

&lt;span style="color: blue"&gt;IF  EXISTS &lt;/span&gt;(&lt;span style="color: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="color: blue"&gt;FROM &lt;/span&gt;sys.assemblies asms 
&lt;span style="color: blue"&gt;WHERE &lt;/span&gt;asms.name = N&lt;span style="color: #a31515"&gt;'SMDiagnostics'&lt;/span&gt;)
    &lt;span style="color: blue"&gt;DROP &lt;/span&gt;ASSEMBLY [SMDiagnostics]
GO

&lt;span style="color: blue"&gt;CREATE &lt;/span&gt;ASSEMBLY 
SMDiagnostics &lt;span style="color: blue"&gt;from
&lt;/span&gt;&lt;span style="color: #a31515"&gt;'C:\Windows\Microsoft.NET\Framework\v3.0\
\Windows Communication Foundation\SMDiagnostics.dll'
&lt;/span&gt;&lt;span style="color: blue"&gt;with &lt;/span&gt;permission_set = UNSAFE
GO

&lt;span style="color: blue"&gt;CREATE &lt;/span&gt;ASSEMBLY 
[System.Web] &lt;span style="color: blue"&gt;from
&lt;/span&gt;&lt;span style="color: #a31515"&gt;'C:\Windows\Microsoft.NET\Framework\v2.0.50727\
\System.Web.dll'
&lt;/span&gt;&lt;span style="color: blue"&gt;with &lt;/span&gt;permission_set = UNSAFE
GO

&lt;span style="color: blue"&gt;CREATE &lt;/span&gt;ASSEMBLY 
[System.Messaging] &lt;span style="color: blue"&gt;from
&lt;/span&gt;&lt;span style="color: #a31515"&gt;'C:\Windows\Microsoft.NET\Framework\v2.0.50727\
\System.Messaging.dll'
&lt;/span&gt;&lt;span style="color: blue"&gt;with &lt;/span&gt;permission_set = UNSAFE
GO

&lt;span style="color: blue"&gt;CREATE &lt;/span&gt;ASSEMBLY  
[System.IdentityModel] &lt;span style="color: blue"&gt;from
&lt;/span&gt;&lt;span style="color: #a31515"&gt;'C:\Program Files\Reference Assemblies\Microsoft\
\Framework\v3.0\System.IdentityModel.dll'
&lt;/span&gt;&lt;span style="color: blue"&gt;with &lt;/span&gt;permission_set = UNSAFE
GO

&lt;span style="color: blue"&gt;CREATE &lt;/span&gt;ASSEMBLY  
[System.IdentityModel.Selectors] &lt;span style="color: blue"&gt;from
&lt;/span&gt;&lt;span style="color: #a31515"&gt;'C:\Program Files\Reference Assemblies\Microsoft\
\Framework\v3.0\System.IdentityModel.Selectors.dll'
&lt;/span&gt;&lt;span style="color: blue"&gt;with &lt;/span&gt;permission_set = UNSAFE
GO

&lt;span style="color: blue"&gt;CREATE &lt;/span&gt;ASSEMBLY &lt;span style="color: green"&gt; 
&lt;/span&gt;[Microsoft.Transactions.Bridge] &lt;span style="color: blue"&gt;from
&lt;/span&gt;&lt;span style="color: #a31515"&gt;'C:\Windows\Microsoft.NET\Framework\v3.0\
\Windows Communication Foundation\Microsoft.Transactions.Bridge.dll'
&lt;/span&gt;&lt;span style="color: blue"&gt;with &lt;/span&gt;permission_set = UNSAFE
GO&lt;/pre&gt;

&lt;p&gt;You will need to add your own assembly to the list in a similar manner as the .NET assemblies. Notice that they are marked &lt;a href="http://msdn.microsoft.com/en-us/library/ms189524.aspx"&gt;UNSAFE&lt;/a&gt;. This is a necessary evil if you wish to use WCF with SQL Server. Because of this, if you have not done so you will need to reconfigure your database to allow it.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;ALTER DATABASE &lt;/span&gt;&lt;span style="color: black"&gt;KodefuGuru &lt;/span&gt;&lt;span style="color: blue"&gt;SET &lt;/span&gt;&lt;span style="color: black"&gt;TRUSTWORTHY &lt;/span&gt;&lt;span style="color: blue"&gt;ON
reconfigure&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The interesting part about this is that more assemblies than those specified are pulled in. When you remove the ones you specifically added, these are removed as well. Here is the list of assemblies:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Accessibility 
    &lt;br /&gt;Microsoft.Transactions.Bridge 

    &lt;br /&gt;SMDiagnostics 

    &lt;br /&gt;System.Configuration.Install 

    &lt;br /&gt;System.Design 

    &lt;br /&gt;System.DirectoryServices 

    &lt;br /&gt;System.DirectoryServices.Protocols 

    &lt;br /&gt;System.Drawing 

    &lt;br /&gt;System.Drawing.Design 

    &lt;br /&gt;System.EnterpriseServices 

    &lt;br /&gt;System.IdentityModel 

    &lt;br /&gt;System.IdentityModel.Selectors 

    &lt;br /&gt;System.Messaging 

    &lt;br /&gt;System.Runtime.Remoting 

    &lt;br /&gt;System.Runtime.Serialization 

    &lt;br /&gt;System.Runtime.Serialization.Formatters.Soap 

    &lt;br /&gt;System.ServiceModel 

    &lt;br /&gt;System.ServiceProcess 

    &lt;br /&gt;System.Web 

    &lt;br /&gt;System.Web.RegularExpressions 

    &lt;br /&gt;System.Windows.Forms&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;System.Windows.Forms? What?! Some of the dependencies are truly mind boggling.&lt;/p&gt;

&lt;p&gt;This should be just enough to allow you to put your service calls inside of CLR functions. I attempted to be as lightweight as possible and avoided pulling in extra libraries, though you certainly could pull in a massive programmatic infrastructure with this.&lt;/p&gt;

&lt;p&gt;I only agreed to this because the service call was directly related to the integrity of the data and further restrictions prevented the use of a separate physical tier to handle it. If you’re in the same situation, I hope this helps.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/13/WCF-from-CLR-Functions.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133467.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/13/wcf-from-clr-functions.aspx</guid>
            <pubDate>Mon, 13 Jul 2009 22:16:44 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133467.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/13/wcf-from-clr-functions.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133467.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133467.aspx</trackback:ping>
        </item>
        <item>
            <title>4 Cool Summer Coding Competitions</title>
            <link>http://geekswithblogs.net/Shadowin/archive/2009/07/07/4-cool-summer-coding-competitions.aspx</link>
            <description>&lt;p&gt;I never seem to have the time to enter coding competitions. It’s a shame, because they look like a lot of fun! I do usually bookmark these contests just in case I find myself with a free weekend, and I want to share those with the community. It may mean more competition in case I do enter, but it also means more cool community applications that I get to play with. For example, &lt;a href="http://twtri.com/" target="_blank"&gt;Twtri&lt;/a&gt; is great for updating Twitter or Facebook with your flight status, and it won the grand prize in the &lt;a href="http://www.newcloudapp.com/index.html" target="_blank"&gt;new CloudApp()&lt;/a&gt; competition!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.componentart.com/community/competition2009/"&gt;&lt;img style="border-right-width: 0px; margin: 0px 5px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="silverlightcompetitonthumbnail" border="0" alt="silverlightcompetitonthumbnail" align="left" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/SummerCodingCompetitions/33C469B1/silverlightcompetitonthumbnail.jpg" width="154" height="112" /&gt;&lt;/a&gt;ComponentArt is hosting the &lt;a href="http://www.componentart.com/community/competition2009/" target="_blank"&gt;2009 Summer Silverlight Coding Competition&lt;/a&gt; from June 22nd to September 22nd. The grand prize is $10,000 USD, and the authors of the top two runner-up apps each get a Component Art license. You must have designed the Silverlight 1, 2, or 3 application yourself, and use of ComponentArt products is not required.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://willcodeforgreen.gnomedex.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 0px 0px 0px 5px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="willcodeforgreen" border="0" alt="willcodeforgreen" align="right" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/SummerCodingCompetitions/61458974/willcodeforgreen.jpg" width="154" height="112" /&gt; Will Code For Green&lt;/a&gt; is sponsored by Bing and Gnomedex, and two grand prize winners will each receive $10,000 USD. The point of the contest is to design a web application or mashup that uses Bing services to help people in this bad global economy or to improve the ecology of our planet. Submission is open through August 12th. The winners will be announced at &lt;a href="http://www.gnomedex.com/"&gt;Gnomedex 2009&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.ineta.org/codechallenge/"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="ineta" border="0" alt="ineta" align="left" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/SummerCodingCompetitions/75CAD8F2/ineta.jpg" width="110" height="108" /&gt;&lt;/a&gt; Win a trip to &lt;a href="http://www.microsoftpdc.com/"&gt;PDC 2009&lt;/a&gt; with &lt;a href="http://www.ineta.org/codechallenge/"&gt;INETA Component Code Challenge&lt;/a&gt;. The goal of the competition is to mash together at least 2 components from 2 different approved vendors to create a .NET application. Then, you must create a 3-5 minute Camtasia video showing off your application and the components you used. Submissions must be received by August 25th, and winners will be announced on September 14th. The top 10 entries will receive prizes, but only the top 2 go to PDC.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dreambuildplay.com/"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 5px; display: inline; border-top: 0px; border-right: 0px" title="dreambuildplay" border="0" alt="dreambuildplay" align="right" src="http://www.kodefuguru.com/image.axd?picture=WindowsLiveWriter/SummerCodingCompetitions/5C62D5B8/dreambuildplay.jpg" width="139" height="112" /&gt;&lt;/a&gt; The deadline has passed to register for the &lt;a href="http://www.dreambuildplay.com/"&gt;Dream-Build-Play 2009 Challenge&lt;/a&gt;, but you can still enjoy the entries as they come in by visiting the &lt;a href="http://www.dreambuildplay.com/main/Gallery.aspx"&gt;gallery&lt;/a&gt;. What is Dream-Build-Play? Well, it’s a competition to create an XNA game. It also has the largest payouts of all the contests I’ve come across: $40,000 grand prize, $20,000 first prize, $10,000 second prize, and $5,000 third prize. Not only that, but the winning teams have an opportunity to potentially receive an Xbox LIVE Arcade Publishing Contract. If you were lucky enough to register in time, you have until August 6th to submit your entry.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;I only support contests that I feel contribute back to the community, but I sometimes come across a contest that seems interesting, only to read the fine print and discover they claim sole rights to the application you enter. An example of this is the &lt;a href="http://www.mortgageloanplace.com/mortgage-calculator.php" rel="nofollow"&gt;“Super Sexy” Mortgage Calculator Contest&lt;/a&gt;. I’m not sure how a mortgage calculator can be thought of as “sexy,” but it nevertheless seemed interesting to me. I tried to read their terms and conditions only to discover they linked to the terms and conditions of a mortgage rather than a contest. However, next to the link was the text, “Mortgage Loan Place will retain sole right to ownership of all submissions.” Dirty stuff.&lt;/p&gt;  &lt;p&gt;I’m sure I missed a few contests out there. If you know of any, be sure to leave a comment.&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.kodefuguru.com"&gt;KodefuGuru&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.kodefuguru.com/post/2009/07/07/4-Cool-Summer-Coding-Competitions.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt; &lt;img src="http://geekswithblogs.net/Shadowin/aggbug/133311.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Chris Eargle</dc:creator>
            <guid>http://geekswithblogs.net/Shadowin/archive/2009/07/07/4-cool-summer-coding-competitions.aspx</guid>
            <pubDate>Tue, 07 Jul 2009 17:23:48 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Shadowin/comments/133311.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Shadowin/archive/2009/07/07/4-cool-summer-coding-competitions.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Shadowin/comments/commentRss/133311.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Shadowin/services/trackbacks/133311.aspx</trackback:ping>
        </item>
    </channel>
</rss>
