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

<channel>
	<title>Jochen Toppe&#039;s Blog &#187; .NET</title>
	<atom:link href="http://jtoee.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jtoee.com</link>
	<description>Putting the &#62;O&#60; in technology</description>
	<lastBuildDate>Mon, 22 Feb 2010 21:48:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Leveraging Model Driven Development</title>
		<link>http://jtoee.com/2008/10/leveraging-model-driven-development/</link>
		<comments>http://jtoee.com/2008/10/leveraging-model-driven-development/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 20:44:11 +0000</pubDate>
		<dc:creator>Jochen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[J2EE]]></category>

		<guid isPermaLink="false">http://jtoee.com/?p=289</guid>
		<description><![CDATA[Achieving efficiency in the software development process is one of the key motivators every team should strive for. Efficiency can be measured in a variety of ways. The most obvious measurements are cost, project timeline, and the feature set that can be implemented given the first two. In a sense, it boils down to the [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_306" class="wp-caption alignright" style="width: 222px"><a href="http://jtoee.com/wp-content/uploads/2008/10/triangle1.jpg"><img class="size-full wp-image-306" title="Project Triangle" src="http://jtoee.com/wp-content/uploads/2008/10/triangle1.jpg" alt="Project Triangle" width="212" height="101" /></a><p class="wp-caption-text">Project Triangle</p></div>
<p>Achieving efficiency in the software development process is one of the key motivators every team should strive for. Efficiency can be measured in a variety of ways. The most obvious measurements are cost, project timeline, and the feature set that can be implemented given the first two. In a sense, it boils down to the old project triangle (remember: pick any two of the criteria).</p>
<p>In essence, there is a trade-off between quality, timeline, and cost. For example, reducing the timeline at equal costs reduces quality just as implementing at a faster pace reduces quality. Yet I argue that the triangle approach is not necessarily valid anymore. Traditional development processes have clearly shown that just enhancing the timeline on a project to put special care into the design does not actually lead to higher quality software – quite the contrary.</p>
<p>Yet more dimensions are at play. The number of defects (“bugs”) found in a particular software directly translate into cost and time, especially when found late in development cycle, creating a dependency between testing quality, time, and cost. Inefficient software design increases the cost of introducing new functionality as requirements change and a lack of refactoring capabilities sooner or later lead to the need for a full re-development. The problems are amplified when the software spans multiple independent subsystems, which is often the case in modern web architectures which span across content management systems, web services, search engines, commerce engines, custom web applications, etc.</p>
<p>Agile development methodologies have tackled many of these problems in great detail through test-driven development (TDD) and time-boxed iterative release cycles. This article discusses a number of tactics you can deploy in addition to what you find in your agile toolkit: To speed up development and tackle complex problems with smaller teams in less time leveraging the key ideas of Model-Driven-Development (MDD).<br />
<span id="more-289"></span></p>
<h3>Leaning on MDD</h3>
<p>Model-Driven-Development (MDD) is a rather interesting software development paradigm which puts the modeling aspect of software engineering at the center of the development process.</p>
<div id="attachment_313" class="wp-caption alignright" style="width: 264px"><a href="http://jtoee.com/wp-content/uploads/2008/10/mddoverview2.jpg"><img class="size-full wp-image-313" title="MDD Overview" src="http://jtoee.com/wp-content/uploads/2008/10/mddoverview2.jpg" alt="MDD Overview" width="254" height="190" /></a><p class="wp-caption-text">MDD Overview</p></div>
<p>The most popular notion of MDD is the <a href="http://www.omg.org/mda/" target="_blank">Model-Driven-Architecture standard</a> by the Object Management Group (<a href="http://www.omg.org/" target="_blank">OMG</a>). MDA is based on a variety of modeling artifacts. At top is a platform-independent model (PIM) which only captures the business requirements using appropriate domain-specific language. This model is then translated into any number of platform-specific models (PSM) using a platform definition model (PDM) for each platform. In essence, this is equivalent to modeling your software in a very high-level (business specific way) and then using a translator such as a code generator (the PDM) to convert the model into code (the platform specific model). Given the same business model, the software can automatically be built using C#, Java, and PHP given the correct translation routines.</p>
<p>MDA in theory has a number of advantages to traditional coding:</p>
<ul>
<li>It obviously appeals to the business owner who can finally re-use the conceptual business model across technology trends, i.e. re-implementing the solution using new technologies does not require a complete overhaul but is simply a matter of switching technologies. Numerous companies specialize in MDA and even rapid-prototyping tools exist which integrate agile development methodologies with MDA. Instead of developing software in iterations, the model is developed iteratively and can then be generated into executable code.</li>
<li>When using code generation frameworks, such as the open source tool AndroMDA, one can quickly build applications using existing code generators. A simple UML domain diagram can immediately be translated into Spring MVC controllers, domain objects, Hibernate mappings, and much more.</li>
<li>When the software spans multiple sub-systems, MDA nicely enforces the correct translation of the model across different technologies used in each one of these systems. While I prefer writing generic code to duplicating code via code generation, this isn’t always feasible (e.g. for XML configuration files or TeamSite CMS data capture templates). In MDD changes to the model can instantly be translated into multiple code artifacts using different technologies by the push of a button.</li>
</ul>
<p>Yet I also see a number of serious issues with the OMG&#8217;s vision:</p>
<ul>
<li>As an &#8220;agilist&#8221; at heart I strongly oppose the idea of spending excessive time modeling software in great detail such as highly granular UML diagrams. Software is meant to be code, not a myriad of UML diagrams which are modeled without an in-depth understanding of the features and limitations of the underlying frameworks. I value the use of UML as a pictorial language, especially when illustrating concepts either on a white board or in documentation. But not when used in a strong forward-engineering paradigm.</li>
<li>MDA reduces the application of a particular technology or framework to a simply technicality, i.e. the creation of a platform definition model. Yet building applications efficiently heavily relies on the capabilities and limitation of the underlying frameworks.</li>
<li>Code generation is equivalent to duplicating a code template using the model as an input. However, I generally prefer writing generic, re-usable code to unnecessary duplication. The benefits of generic code are obvious, not only is the application smaller, but debugging and maintaining the code is by far easier. Generated code would force you to debug the same piece of logic in many places of the application and fixing it requires changing the code generator templates and ultimately re-generating the entire application.</li>
<li>Building a platform dependent model, i.e. the code generator, for an entire application can be a huge undertaking. On the upside, many vendors and open source technologies, such as AndroMDA, ship with a variety of pre-built cartridges. However, by using existing code-generators one reduces implementation flexibility as well as maintainability of the application. Debugging and fixing issues in these pre-built code generators can be tedious and easily be overwritten by the next release of the generator. Further, generic code generators tend to be quite complex due to the fact that they have to be very generic.</li>
<li>When building web applications, I usually like to encourage my teams to push the boundaries and leverage the latest technologies available. Using existing code generation frameworks obviously won’t leverage the bleeding edge of technology, forcing you to write your own.</li>
</ul>
<h3>Leveraging the Key Tenets of MDD</h3>
<p>While I argue that in its pure form, that being the notion of building an entire application using this paradigm, MDD is not my first choice, I would also argue that it has an obvious allure to it. Writing generic code is not always an option as all modern frameworks require configuration, plumbing code, mapping directives, etc. This is exactly where the code generation aspect comes to fruition. Given a central domain model, many artifacts surrounding a domain object can be automatically generated.</p>
<p>A major objection I am confronted with often is whether this approach lacks flexibility as the code is generated according to the same pattern every time. My argument is that this is actually an advantage for the majority of every application. Of course the code generation framework needs to be able to handle special situations where the generic functionality needs to be extended.</p>
<p>Let’s consider this by an example. A software team is integrating an XML-based content management system with a web application. The CMS team is responsible for defining the content input forms in the CMS which are used by the end user to create the XML. The application team writes a parsing layer which parses the XML into domain objects and a web application on top of it. After the teams agree on a content model, i.e. the structure of the XML files, both teams can start implementing all necessary coding artifacts.</p>
<div id="attachment_309" class="wp-caption aligncenter" style="width: 269px"><a href="http://jtoee.com/wp-content/uploads/2008/10/cms_web_app1.jpg"><img class="size-full wp-image-309" title="Sample Application" src="http://jtoee.com/wp-content/uploads/2008/10/cms_web_app1.jpg" alt="Sample Application" width="259" height="108" /></a><p class="wp-caption-text">Sample Application</p></div>
<p>However, since all artifacts are developed manually, when integrating the pieces, the teams will encounter a number of bugs which are a result of the two separate systems relying on the same underlying domain model. Further, different bugs are most likely to be found each one of the content forms and the associated parsing layer because different developers make different mistakes.</p>
<p>Consistency may be another issue. Especially when multiple developers are working on the individual functionality, each usually adds their own spin to the code. Some of date fields in the CMS forms may have calendar buttons next to date fields, some may not. Some developers might use camel case, another one may not.</p>
<p>Of course both of these issues can be addressed by establishing sound coding conventions as well as doing impeccable up-front design of all the sub-systems. But reality shows this is rarely the case. Especially when reacting to changes during the development cycle, such as the web application noticing that they need additional fields in the CMS, the original design efforts are often neglected.</p>
<div id="attachment_311" class="wp-caption aligncenter" style="width: 335px"><a href="http://jtoee.com/wp-content/uploads/2008/10/cms_web_app_22.jpg"><img class="size-full wp-image-311" title="MDD with Code Generator" src="http://jtoee.com/wp-content/uploads/2008/10/cms_web_app_22.jpg" alt="MDD with Code Generator" width="325" height="261" /></a><p class="wp-caption-text">MDD with Code Generator</p></div>
<p>Consider the alternative which is more aligned with the MDD paradigm. The teams agree on a domain model and then build a vertical slice, i.e. a functional prototype of the system through all defined layers. Then, using this prototype, the teams build a code generator which takes the domain model as an input and automatically generates the CMS forms and application-level parsing layer for the resulting XML files. The domain model is then fed into the code generator and the application is automatically generated. The code generator automatically enforces consistency. If any bugs where to be encountered which are a result of the coupling of the two systems, the code generator would have to be changed and the application re-generated.</p>
<p>In addition to the maintenance and consistency advantages, the teams also saved time. In the traditional approach, each time had to manually build the application logic for each entity in the domain model in each of the participating subsystems. In the MDD scenario, the teams built a vertical slice prototype and then translated that into a code generator – which automatically generated the application.<br />
<!-- inpost DISABLED--></p>
<h3>Alternatives</h3>
<p>Especially when building web applications a strong alternative to MDD is the use of Rails-like frameworks, such as Ruby on Rails, Grails, Monorail, and many others. The underlying core ideas are aligned with what I consider the key advantages of MDD:</p>
<ul>
<li><strong>Don’t repeat yourself (DRY)</strong>: Instead of repeating yourself, write code once and then have the framework take care of creating the plumbing code. This is typically done under the hood by the framework.</li>
<li><strong>Conventions over Configuration (CoC)</strong>: Rather than having every aspect of the application be built differently, establish sound conventions and use these throughout the software to ensure consistency and eliminate unnecessary (and unmaintainable) bloated configuration files.</li>
</ul>
<p>In essence, these frameworks try to solve the same underlying problem. Yet Rails frameworks focus on building web applications within the same technology stack. For simple (web) projects which are easily contained into one logical application, not spreading across multiple software systems, any Rails framework is an excellent way of building an application quickly and iteratively. Once an architecture spans multiple technologies, frameworks, or requires custom coding using proprietary products (such as a CMS), MDD proves to be the big brother of Rails-like frameworks.</p>
<h3>Conclusion</h3>
<p>I have used both the Rails and the MDD approach throughout my career. I have introduced the light-weight MDD approach in a number of recent projects at <a href="http://www.razorfish.com" target="_blank">Razorfish</a>, which led to us building a jumpstart kit that in its first iteration lets us quickly bootstrap projects with <a href="http://www.interwoven.com" target="_blank">Interwoven TeamSite</a> and <a href="http://www.microsoft.com/NET/" target="_blank">.NET</a> as an application platform. This has not only saved us a lot of time, but also a lot of headaches and long nights of debugging code. We are able to quickly react to changes during the development cycle. Changes to the domain model can be made within the matter of the short time it takes to open a UML editor and re-run the code generator.</p>
<p>I consequently see MDD as a vital part of agile enterprise development and a complementing technology which picks up where a Rails framework hits its limits.</p>
<h3>Links</h3>
<ul>
<li><a href="http://www.omg.org/mda/" target="_blank">Object Management Group&#8217;s MDA Page</a></li>
<li><a href="http://en.wikipedia.org/wiki/Model-driven_architecture" target="_blank">Wikipedia on Model-Driven-Architecture</a></li>
<li><a href="http://www.andromda.org" target="_blank">AndroMDA code generator tool<br />
</a></li>
<li><a href="http://www.eclipse.org/modeling/emf/" target="_blank">Eclipse Modeling Framework (EMF)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jtoee.com/2008/10/leveraging-model-driven-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Browser Screenshots on the Server Side</title>
		<link>http://jtoee.com/2008/10/creating-browser-screenshots-on-the-server-side/</link>
		<comments>http://jtoee.com/2008/10/creating-browser-screenshots-on-the-server-side/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 15:02:14 +0000</pubDate>
		<dc:creator>Jochen</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://jtoee.com/?p=257</guid>
		<description><![CDATA[In the light of the plethora of gloomy headlines in the past few weeks I have started taking screenshots of some of the major web sites online, maybe just to have an archive of how the world ended one day :-)
I started thinking there&#8217;s got to be a way to automate this. Indeed, there are [...]]]></description>
			<content:encoded><![CDATA[<p>In the light of the plethora of gloomy headlines in the past few weeks I have started taking screenshots of some of the major web sites online, maybe just to have an archive of how the world ended one day :-)</p>
<p>I started thinking there&#8217;s got to be a way to automate this. Indeed, there are a number of downloadable utilities out there to create JPEG images of web sites, but I really wanted to build this myself. After some initial online research I decided to give it a spin in C#. I came across the <code>System.Windows.Forms.WebBrowser</code> class which, as it turns out, can do all these magic things for me directly on the server-side without requiring a desktop application.</p>
<p>The caveat is that the <code>WebBrowser</code> does need to execute in a standalone STA thread. As a side-note, the code is a total memory-hog the way it is written now, mostly due to IE.<br />
<span id="more-257"></span></p>
<p>Check out a single-threaded version of the code right here (full download at bottom of page):</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.ComponentModel;
<span class="kwrd">using</span> System.Drawing;
<span class="kwrd">using</span> System.Drawing.Imaging;
<span class="kwrd">using</span> System.Threading;
<span class="kwrd">using</span> System.Windows.Forms;

<span class="kwrd">namespace</span> JToEE
{
    <span class="kwrd">public</span> <span class="kwrd">class</span> Shoot
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Set URL for the screenshot</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">string</span> Url { get; set; }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Output filename</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">string</span> Filename { get; set; }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Width of the browser window</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">int</span>? Width { set; get; }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Initial height of the browser (get re-sized </span>
        <span class="rem">/// automatically if the page is longer)</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">int</span> DefaultHeight = 768;

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Default width of the browser if not specified. This</span>
        <span class="rem">/// class doesn't re-size the width.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">int</span> DefaultWidth = 1024;

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// </span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="url"&gt;&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="filename"&gt;&lt;/param&gt;</span>
        <span class="kwrd">public</span> Shoot(<span class="kwrd">string</span> url, <span class="kwrd">string</span> filename) : <span class="kwrd">this</span>()
        {
            Url = url;
            Filename = filename;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// </span>
        <span class="rem">/// &lt;/summary&gt;        </span>
        <span class="kwrd">public</span> Shoot()
        {
            Width = 1024;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Main entry method which created the screenshot</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> CreateScreenshot()

        {
            ThreadStart ts = Run;
            Thread t = <span class="kwrd">new</span> Thread(ts);
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Does the work in the thread</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">void</span> Run()
        {
            <span class="kwrd">using</span>(Bitmap bitmap = CreateBitmap())
            {
                ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
                var myEncoder = System.Drawing.Imaging.Encoder.Quality;
                var myEncoderParameters = <span class="kwrd">new</span> EncoderParameters(1);
                <span class="rem">// encode jpeg at 75%</span>
                var myEncoderParameter = <span class="kwrd">new</span> EncoderParameter(myEncoder, 75L);
                myEncoderParameters.Param[0] = myEncoderParameter;
                <span class="rem">// save to file</span>
                bitmap.Save(Filename, jgpEncoder, myEncoderParameters);
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Get a hold of a jpeg encoder</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="format"&gt;&lt;/param&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">static</span> ImageCodecInfo GetEncoder(ImageFormat format)
        {
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
            <span class="kwrd">foreach</span> (ImageCodecInfo codec <span class="kwrd">in</span> codecs)
            {
                <span class="kwrd">if</span> (codec.FormatID == format.Guid)
                {
                    <span class="kwrd">return</span> codec;
                }
            }
            <span class="kwrd">return</span> <span class="kwrd">null</span>;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create a bitmap of the browser window. The bitmap's height is</span>
        <span class="rem">/// automatically adapted to the length of the page while the width</span>
        <span class="rem">/// is kept at the specified value.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">private</span> Bitmap CreateBitmap()
        {
            <span class="kwrd">using</span> (var browser = <span class="kwrd">new</span> WebBrowser())
            {
                browser.ScrollBarsEnabled = <span class="kwrd">false</span>;
                <span class="rem">// set the initial height and width</span>
                browser.Size = <span class="kwrd">new</span> Size(Width ?? 1024, DefaultHeight);
                browser.ScriptErrorsSuppressed = <span class="kwrd">true</span>;
                <span class="rem">// supress creation of new windows</span>
                browser.NewWindow += OnNewWindow;
                <span class="rem">// navigate the browser to the URL</span>
                browser.Navigate(Url);
                <span class="rem">// wait for it to load</span>
                WaitForBrowserReady(browser);
                <span class="rem">// re-size the browser windows to the full height of the web page</span>
                var finalHeight = browser.Document == <span class="kwrd">null</span> ? DefaultHeight :
                                      browser.Document.Body.ScrollRectangle.Height;
                <span class="rem">// width of the bitmap</span>
                var width = Width ?? DefaultWidth;
                <span class="rem">// re-size the browser</span>
                browser.Size = <span class="kwrd">new</span> Size(width, finalHeight);
                WaitForBrowserReady(browser);
                <span class="rem">// create a bitmap                </span>
                Console.WriteLine(<span class="kwrd">string</span>.Format(<span class="str">"Creating bitmap of size {0}x{1}"</span>, width, finalHeight));
                var bitmap = <span class="kwrd">new</span> Bitmap(width, finalHeight);
                var rect = <span class="kwrd">new</span> Rectangle(0, 0, width, finalHeight);
                browser.DrawToBitmap(bitmap, rect);
                <span class="kwrd">return</span> bitmap;
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Waits for the browser to be ready loading the page</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="browser"&gt;&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> WaitForBrowserReady(WebBrowser browser)
        {
            Console.WriteLine(<span class="str">"Waiting for browser.."</span>);
            <span class="kwrd">while</span> (browser.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            Console.WriteLine(<span class="str">"Waiting ready"</span>);
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// New window delegate -- basically a popup blocker.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="sender"&gt;&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="e"&gt;&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> OnNewWindow(<span class="kwrd">object</span> sender, CancelEventArgs e)
        {
            e.Cancel = <span class="kwrd">true</span>;
        }
    }
}</pre>
<p>Download the full source code <a href="http://jtoee.com/software/" target="_self">here</a>.</p>
<pre class="csharpcode"></pre>
]]></content:encoded>
			<wfw:commentRss>http://jtoee.com/2008/10/creating-browser-screenshots-on-the-server-side/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 2008 Server Musings</title>
		<link>http://jtoee.com/2008/05/windows-2008-server-musings/</link>
		<comments>http://jtoee.com/2008/05/windows-2008-server-musings/#comments</comments>
		<pubDate>Wed, 28 May 2008 16:29:25 +0000</pubDate>
		<dc:creator>Jochen</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://jtoee.com/?p=61</guid>
		<description><![CDATA[I am currently coordinating an effort building a reference architecture with Microsoft Sharepoint 2007, diving into a rich content model and service-enabling the front-end with the overall goal to use it as a &#8220;real&#8221; web content management. Our goal was to stick with the Microsoft toolstack (simply because we have free access to all products [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently coordinating an effort building a reference architecture with Microsoft Sharepoint 2007, diving into a rich content model and service-enabling the front-end with the overall goal to use it as a &#8220;real&#8221; web content management. Our goal was to stick with the Microsoft toolstack (simply because we have free access to all products at work with Razorfish now being a Microsoft-owned company)</p>
<p>Our first idea was to start prototyping on the new Windows 2008 Server.</p>
<h2>32 vs 64 Bit</h2>
<p>Our initial gut instinct was to stick with what&#8217;s working, plus we where only installing on PCs with 4 Gigs of RAM. After the installation I tried to get Hyper-V (built-in virtualization) to work, however, Hyper-V is only supported on the 64 bit version of Windows. I then tried to install Virtual PC 2007 &#8212; it complained that the version of Windows I was using wasn&#8217;t compatible and that I at least needed to install IIS 6 compatibility modules.</p>
<p>We decided to re-install with the 64 bit version of Windows Server.</p>
<h2>Hyper-V</h2>
<p>As mentioned, Hyper-V requires 64 bit Windows. After installing all the optional patches and rebooting twice from Windows Update Hyper-V suddenly appeared. I proceeded to install a 64 bit Windows 2008 guest. Once it was installed and booted up I noticed it had no network access. Strange &#8212; Hyper-V was configured with a virtual adapter. As it turns out, the drivers for the virtual network adapter are part of the Windows Update patches for Server 2008 &#8212; so the guest couldn&#8217;t see the network without the updates and of course couldn&#8217;t download the updates without the network adapter &#8212; if Hyper-V wasn&#8217;t technically a CTP I&#8217;d be really pissed now. Luckily one can configure a &#8220;legacy network adapter&#8221; that a freshly installed guest can see at least long enough to fetch the updated drivers.</p>
<p>Hyper-V now runs along just fine with the small caveat that it randomly crashes with a nice message box &#8220;Worker process died&#8221;.</p>
<p>Verdict: This is not a stable development or even production environment yet.</p>
<h2>MOSS 2007</h2>
<p>At this point I decided to install MOSS 2007. After a download of the MOSS 2007 ISO the first installation attempt failed &#8212; Windows complained there were known compatibility issues with the software and the operating system. Now we downloaded the SP1 files for the WSS foundation and MOSS 2007. Unfortunately there is no consolidates ISO &#8212; you have copy the MOSS 2007 ISO to a temporary folder and manually extract the SP1 executables via the command line and copy the contents into the temporary folder with the ISO. The installation then fails with an error that the sample database cannot be set up.</p>
<p>Just trying to install WSS 3.0 SP1 by itself at least works fine.</p>
<h2>Really?</h2>
<p>At this point we decided to go back to Windows 2003 Server R2. Stay tuned for updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://jtoee.com/2008/05/windows-2008-server-musings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET 3.5 and LINQ</title>
		<link>http://jtoee.com/2008/02/net-35-and-linq/</link>
		<comments>http://jtoee.com/2008/02/net-35-and-linq/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 15:52:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://jtoee.com/wordpress/?p=40</guid>
		<description><![CDATA[I had a little spare time last week and finally dug into .NET 3.5, mostly extension methods, lamda expressions, and LINQ.  Pronounced LINK, it is the embedded query language in .NET 3.5.  I am not going to outline what it does or how it works, there&#8217;s plenty of that on the internet, but [...]]]></description>
			<content:encoded><![CDATA[<p>I had a little spare time last week and finally dug into .NET 3.5, mostly extension methods, lamda expressions, and LINQ.  Pronounced LINK, it is the embedded query language in .NET 3.5.  I am not going to outline what it does or how it works, there&#8217;s plenty of that on the internet, but I will continue my tradition to outline some funny annoyances :)</p>
<p>The nicest think IMHO about LINQ is the SQL bridge, which essentially implements a full OR-mapping framework like Hibernate in the .NET framework. Let&#8217;s dive into an example and map the following class to a database table:</p>
<p><span style="font-size: 10pt; font-family: 'Courier New'; color: blue">[<span style="color: #2b91af">Table</span>(Name = <span style="color: #a31515">"c_schema"</span>)]<o:p></o:p><br />
public</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'"> <span style="color: blue">class</span> <span style="color: #2b91af">LinqSchema<o:p></o:p></span><br />
{<span>        </span><o:p></o:p><br />
<span>        </span><span style="color: blue">private</span> <span style="color: blue">long</span> id;<span>        </span><o:p></o:p><br />
<span>        </span><span style="color: blue">private</span> <span style="color: blue">string</span> uuid;<span>        </span><o:p></o:p><br />
<span>        </span><span style="color: blue">private</span> <span style="color: blue">string</span> name;<o:p></o:p><br />
<span></span>    [<span style="color: #2b91af">Column</span>]<o:p></o:p><br />
<span>        </span><span style="color: blue">private</span> <span style="color: blue">long</span> id_creator = 1;<o:p></o:p><br />
<span>        </span>[<span style="color: #2b91af">Column</span>]<o:p></o:p><br />
<span>        </span><span style="color: blue">private</span> <span style="color: blue">long</span> id_owner = 1;<o:p></o:p><br />
<span>        </span>[<span style="color: #2b91af">Column</span>]<o:p></o:p><span><br />
</span><span style="color: blue">private</span> <span style="color: blue">int</span> version = 1;<o:p></o:p><br />
<span>        </span>[<span style="color: #2b91af">Column</span>]<o:p></o:p><span><br />
</span><span style="color: blue">private</span> <span style="color: blue">bool</span> is_public = <span style="color: blue">true</span>;<o:p> </o:p><br />
<span>        </span>[<span style="color: #2b91af">Column</span>(Name = <span style="color: #a31515">"id"</span>, IsPrimaryKey = <span style="color: blue">true</span>)]<o:p></o:p><br />
<span>        </span><span style="color: blue">public</span> <span style="color: blue">long</span> Id<o:p></o:p><br />
<span>        </span>{<o:p></o:p><br />
<span>            </span><span style="color: blue">get</span> { <span style="color: blue">return</span> id; }<o:p></o:p><br />
<span>            </span><span style="color: blue">set</span> { id = <span style="color: blue">value</span>; }<o:p></o:p><br />
<span>        </span>}<o:p> </o:p><br />
<span>        </span>[<span style="color: #2b91af">Column</span>(Name = <span style="color: #a31515">"uuid"</span>)]<o:p></o:p><br />
<span>        </span><span style="color: blue">public</span> <span style="color: blue">string</span> Uuid<o:p></o:p><br />
<span>        </span>{<o:p></o:p><br />
<span>            </span><span style="color: blue">get</span> { <span style="color: blue">return</span> uuid; }<o:p></o:p><br />
<span>            </span><span style="color: blue">set</span> { uuid = <span style="color: blue">value</span>; }<o:p></o:p><br />
<span>        </span>}<o:p> </o:p><br />
<span>        </span>[<span style="color: #2b91af">Column</span>(Name = <span style="color: #a31515">"name"</span>)]<o:p></o:p><br />
<span>        </span><span style="color: blue">public</span> <span style="color: blue">string</span> Name<o:p></o:p><br />
<span>        </span>{<o:p></o:p><br />
<span>            </span><span style="color: blue">get</span> { <span style="color: blue">return</span> name; }<o:p></o:p><br />
<span>            </span><span style="color: blue">set</span> { name = <span style="color: blue">value</span>; }<o:p></o:p><br />
<span>        </span>}<o:p></o:p><br />
}</span></p>
<p>So far so good, that looks almost like an annotated Hibernate mapping in Java. Now let&#8217;s read some existing data out of the database:<br />
<span style="font-size: 10pt; font-family: 'Courier New'; color: blue"><br />
string</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'; color: #2b91af"> connectionString = <span style="color: #a31515">@&#8221;&#8230;&#8221;</span>;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'; color: #2b91af">DataContext</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'; color: #2b91af"> db = <span style="color: blue">new</span> <span style="color: #2b91af">DataContext</span>(connectionString);<o:p></o:p><br />
Table</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'">&lt;<span style="color: #2b91af">LinqSchema</span>&gt; schemata = db.GetTable&lt;<span style="color: #2b91af">LinqSchema</span>&gt;();<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 10pt; font-family: 'Courier New'; color: blue">// nice little LINQ expression<o:p></o:p><br />
var</span><span style="font-size: 10pt; font-family: 'Courier New'"> query1 = <span style="color: blue">from</span> ss <span style="color: blue">in</span> schemata <span style="color: blue">where</span> ss.Name == <span style="color: #a31515">&#8220;minimal&#8221;</span> <span style="color: blue">select</span> ss;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 10pt; font-family: 'Courier New'; color: blue"><o:p></o:p>// iterate of the query result<o:p></o:p><br />
foreach</span><span style="font-size: 10pt; font-family: 'Courier New'"> (<span style="color: blue">var</span> qq <span style="color: blue">in</span> query1)<br />
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 0.5in"><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'; color: #2b91af">Console</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'">.WriteLine(<span style="color: blue">string</span>.Format(<span style="color: #a31515">&#8220;Schema {0}&#8221;</span>, qq.Uuid));</span><span lang="DE"><o:p></o:p></span></p>
<p> That&#8217;s pretty self-explanatory. Now the funny caveats. Initially, one of the columns was an <em>integer</em> type, and in .NET I put in a <em>long</em>. One would think integers can get casted into longs, yet the error I got was this:</p>
<p><img src="http://jtoee.com/wordpress/wp-content/uploads/2008/02/shotshot.jpg" alt="Error Snaphot" /></p>
<p>I was quite stunned that the SqlDependency extensions for query caching which were introduced in SQL Server 2005 and .NET 2.0 didn&#8217;t work with LINQ at all. There are a <a href="http://www.thedatafarm.com/blog/CommentView,guid,d6592445-2ee8-46ee-a812-a743ab228dc5.aspx">few hacks</a> out on the internet, but I couldn&#8217;t get them to work reliably.</p>
<p>I found association mappings to be somewhat inelegant, especially compared to Hibernate which doesn&#8217;t require you to redundantly map the IDs and the referenced objects (1-1 mapping shown in this example):</p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 10pt; font-family: 'Courier New'; color: blue">// column maps the id<o:p></o:p><br />
[<span style="color: #2b91af">Column</span>(Name=<span style="color: #a31515">"id_schema"</span>)]<o:p></o:p><br />
public</span><span style="font-size: 10pt; font-family: 'Courier New'"> <span style="color: blue">long</span> id_schema;<o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 10pt; font-family: 'Courier New'; color: blue">// entity reference holds the reference object<o:p></o:p><br />
private</span><span style="font-size: 10pt; font-family: 'Courier New'"> <span style="color: #2b91af">EntityRef</span>&lt;<span style="color: #2b91af">LinqSchema</span>&gt; _Schema;<span>        </span><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; color: blue">// the actual association. Storage refers to the entity reference,<br />
// ThisKey to the variable containing the id.<o:p></o:p><br />
[<span style="color: #2b91af">Association</span>(Storage = <span style="color: #a31515">"_Schema"</span>, ThisKey = <span style="color: #a31515">"id_schema"</span>, OtherKey = <span style="color: #a31515">"Id"</span>)]<o:p></o:p><br />
public</span><span style="font-size: 10pt; font-family: 'Courier New'; color: blue"> <span style="color: #2b91af">LinqSchema</span> Schema<o:p></o:p><br />
{<br />
get</span><span style="font-size: 10pt; font-family: 'Courier New'; color: blue">{ <span style="color: blue">return</span> _Schema.Entity;}<o:p></o:p><br />
set</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Courier New'"> { _Schema.Entity = <span style="color: blue">value</span>; }<o:p></o:p><br />
}</span></p>
<p class="MsoNormal">All in all, however, a big step in the right direction. On the downside, .NET now has multiple competing options for remoting and persistence, and interoperability between all these options is not necessarily given.</p>
<p class="MsoNormal">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://jtoee.com/2008/02/net-35-and-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encrypting web.config</title>
		<link>http://jtoee.com/2008/02/encrypting-webconfig/</link>
		<comments>http://jtoee.com/2008/02/encrypting-webconfig/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 18:01:59 +0000</pubDate>
		<dc:creator>Jochen</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://jtoee.com/wordpress/?p=41</guid>
		<description><![CDATA[It&#8217;s usually a good practice to encrypt database connection strings and other sensitive configuration entries for  a web application. .NET 2.0+ gives you a built-in mechanism to do this.
The instructions out there on MSDN are nice, but there doesn&#8217;t seem to be a page that outlines all the things you actually have to do [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s usually a good practice to encrypt database connection strings and other sensitive configuration entries for  a web application. .NET 2.0+ gives you a built-in mechanism to do this.</p>
<p>The instructions out there on MSDN are nice, but there doesn&#8217;t seem to be a page that outlines all the things you actually have to do to use a custom key container. I&#8217;m also faced with a deployment scenario on ancient Windows 2000 servers, and the commands are slightly different here. It&#8217;s pretty straight forward, so for posterity I&#8217;ll outline the steps here.</p>
<p>The core tool is delivered with the .NET framework and called <em>aspnet_regiis.exe</em>.</p>
<h3>Key Generation</h3>
<p>First of all, let&#8217;s create a new custom container to hold the application keys. Another option would be to use the system default container <em>NetFrameworkConfigurationKey</em>, but let&#8217;s create a container specific our application:<br />
<code><br />
C:\app&gt; aspnet_regiis -pc MyCustomContainer<br />
Creating RSA Key container...<br />
Succeeded!<br />
</code></p>
<p>This now created the container and a new key inside it. The next step is to export the key into an XML file:</p>
<p><code>C:\app&gt; aspnet_regiis -px MyCustomContainer mykeys.xml<br />
Exporting RSA Keys to file...<br />
Succeeded!</code></p>
<p>The file mykeys.xml now contains the keys. Keep this file safe, we will need to distribute it on the web farm later. The contents of the file looks like this:</p>
<p><code>&lt;RSAKeyValue&gt;&lt;Modulus&gt;5C31Pc/ppGZjWuoUdQ9HjiAIxp8UaVYvgYXz3K4i3qzpW9al6s+2kG8ktHpSfZ/y6H4qDpaqI2TU5ltYdxr4Iv6sPhnTEKMv1N7AWq/FNwVTCM8XiWXqs6K+UW7mDfCI<br />
ArF1Fqo+kFV1LJtuPUahy2TOmnji+ZUzzuwFqzqFop0=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;</code></p>
<h3>Encrypt your application configuration</h3>
<p>First of all, a new encryption provider needs to be registered in the web.config which specified the custom key store to use. You can skip this when using the default key store. Pay special attention to the <em>keyContainerName </em>attribute, it must match the name of the container created.<br />
<code><br />
&lt;!-- sets up the encrypted configuration to use a special container --&gt;<br />
&lt;configProtectedData&gt;<br />
&lt;providers&gt;<br />
&lt;add name="MyCustomProvider"<br />
type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"<br />
keyContainerName="</code><code>MyCustomContainer</code><code>"<br />
useMachineContainer="true" /&gt;<br />
&lt;/providers&gt;<br />
&lt;/configProtectedData&gt;</code></p>
<p>To now encrypt the configuration file from the command line (you can easily embedd this into an msbuild/nant script), call the following command. Make sure the provider name passed in matches the provider name from the above configuration snippet. The following script will encrypt the connection string section:</p>
<p><code>aspnet_regiis -pef "connectionStrings" MyWebFilesDirectory -prov "MyCustomProvider"</code></p>
<p>The connection string section in the web.config file should now look like this:<br />
<code><br />
&lt;connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider"&gt;<br />
&lt;EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"<br />
xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;<br />
&lt;EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /&gt;<br />
&lt;KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;<br />
&lt;EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;<br />
&lt;EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /&gt;<br />
&lt;KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;<br />
&lt;KeyName&gt;Rsa Key&lt;/KeyName&gt;<br />
&lt;/KeyInfo&gt;<br />
&lt;CipherData&gt;<br />
&lt;CipherValue&gt;qDaaLdZtxtv1pbrXplfiHvUCKLq0ZpwJQorowmlm74QIH3ogcZyhNpYTgLCSNxaB4KaTLtcryRaivqPr+v/Lr6iv18d/VaIV1Ht0sCagA3sZCUQu/GuSTcTgfpQGdveU4Qsx5g4ERC/B8mQEwXtHs7a6VNVsYD4f6GFlO9g4iUI=&lt;/CipherValue&gt;<br />
&lt;/CipherData&gt;<br />
&lt;/EncryptedKey&gt;<br />
&lt;/KeyInfo&gt;<br />
&lt;CipherData&gt;<br />
&lt;CipherValue&gt;lw9Y03jHQ6foqIAdN7UN0nOxc4y2zJ4ajb5dUjtxKyFa87vCmmMbBnTkatcoZ/6ZzibdEBg7Xmhf4SBqC4iCfQIgV5XIEb0j+P3gmDLSt+kC+enTLZGVlHt3ngND6dXJTF28C2jsVB2DIxI/u0p6cJ2UHRGfqvvetG24HnDPpZonlHuMGEyvKy/PhLf3OUv2Vc/v0aVi8srRwydjA1Ueqs9sGo+wGGqT1Leui3R/TCNiEwZrp1eO3Rt6W1NMEaRNkG3nz9tctHwOsNo9xiC+lM0IfGI/DFR04uwSzjuQX61Ph18nB+Q0zgcpauOsqRrNtorBSPqu+mfW8EL0bztU90T5F5i0TJ50BoXXo6F8kdTnJ1i90REFxsFBv/8jOXh++bUZMWRxnu3GUf+tJ5f7Kzr52GlApfkoMunTCLbd5zkPG8yga2iMJ+MGdqu9K2b+Qakpu8VNu6Ioo80l30Dbxw==&lt;/CipherValue&gt;<br />
&lt;/CipherData&gt;<br />
&lt;/EncryptedData&gt;<br />
&lt;/connectionStrings&gt;<br />
</code></p>
<h3>Register Keys on Web Farm</h3>
<p>Register the key on all web servers running the application. First of all, create the container with the keys from the XML file created earlier:</p>
<p><code> C:\app&gt; aspnet_regiis -pi MyCustomContainer </code><code>mykeys.xml</code><br />
<code> Creating RSA Key container...<br />
Succeeded!</code></p>
<p>Now the IIS application requires access to this container.</p>
<p>On Windows 2000, do this (assuming you&#8217;re not running IIS as a different user):</p>
<p><code>C:\&gt; aspnet_regiis.exe -pa "MyCustomContainer" "ASPNET"<br />
Adding ACL for access to the RSA Key container...<br />
Succeeded!</code></p>
<p>On Windows 2003 and up, the following command shall work:</p>
<p><code>C:\&gt; aspnet_regiis.exe -pa "MyCustomContainer" "NT AUTHORITY\NETWORK SERVICE"<br />
Adding ACL for access to the RSA Key container...<br />
Succeeded!</code></p>
<pre class="code" id="ctl00_rs1_mainContentContainer_ctl04other" space="preserve"></pre>
<p>And that&#8217;s really it. Once the application with the encrypted web.config sections is deployed, IIS will automatically decrypt it.</p>
]]></content:encoded>
			<wfw:commentRss>http://jtoee.com/2008/02/encrypting-webconfig/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
