<?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>Flyvergrillen &#187; Kode</title>
	<atom:link href="http://www.flyvergrillen.dk/category/kode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flyvergrillen.dk</link>
	<description>Et sted på Amager hvor nørder samles</description>
	<lastBuildDate>Thu, 20 May 2010 10:24:45 +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>TryUpdateModel and unknown model-types</title>
		<link>http://www.flyvergrillen.dk/2010/05/20/tryupdatemodel-and-unknown-model-types/</link>
		<comments>http://www.flyvergrillen.dk/2010/05/20/tryupdatemodel-and-unknown-model-types/#comments</comments>
		<pubDate>Thu, 20 May 2010 10:23:29 +0000</pubDate>
		<dc:creator>Anders Rasmussen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ExtensionMethod]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/?p=95</guid>
		<description><![CDATA[TryUpdateModel does not work on types not known at compile time. For example when creating an object through the Activator.CreateInstance()
To remedy this use this snippet of code:

public static class ControllerHelpers
&#123;
  public static bool TryUpdateGenericModel&#40;this Controller controller, object model&#41;
  &#123;
    var param = new Type&#91;&#93; &#123; model.GetType&#40;&#41; &#125;;
    [...]]]></description>
			<content:encoded><![CDATA[<p>TryUpdateModel does not work on types not known at compile time. For example when creating an object through the Activator.CreateInstance()</p>
<p>To remedy this use this snippet of code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> ControllerHelpers
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">bool</span> TryUpdateGenericModel<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Controller controller, <span style="color: #FF0000;">object</span> model<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    var param <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Type<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> model.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
    var controllerType <span style="color: #008000;">=</span> controller.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var controllerMethods <span style="color: #008000;">=</span> controllerType.<span style="color: #0000FF;">GetMethods</span><span style="color: #000000;">&#40;</span>BindingFlags.<span style="color: #0000FF;">NonPublic</span> <span style="color: #008000;">|</span> BindingFlags.<span style="color: #0000FF;">Instance</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var TUMmethod <span style="color: #008000;">=</span> controllerMethods.<span style="color: #0000FF;">First</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> x.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;TryUpdateModel&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> x.<span style="color: #0000FF;">GetParameters</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var TUMgeneric <span style="color: #008000;">=</span> TUMmethod.<span style="color: #0000FF;">MakeGenericMethod</span><span style="color: #000000;">&#40;</span>param<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var result <span style="color: #008000;">=</span> TUMgeneric.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span>controller, <span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> model <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span><span style="color: #000000;">&#41;</span>result<span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And in your controller when trying to update your model, use it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var emptyModelObject <span style="color: #008000;">=</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span>modelType<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// whichever way you get it doesn't really matter.</span>
var result <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TryUpdateGenericModel</span><span style="color: #000000;">&#40;</span>modelObject<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2010/05/20/tryupdatemodel-and-unknown-model-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit testing with Linq to SQL</title>
		<link>http://www.flyvergrillen.dk/2010/02/09/unit-testing-with-linq-to-sql/</link>
		<comments>http://www.flyvergrillen.dk/2010/02/09/unit-testing-with-linq-to-sql/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 12:57:17 +0000</pubDate>
		<dc:creator>Anders Hellerup Madsen</dc:creator>
				<category><![CDATA[Kode]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/?p=53</guid>
		<description><![CDATA[For some time we have been using Microsofts Linq-to-Sql as our ORM for several of our projects. It has some nice features, but it is also very different from just about every other ORM out there, and in a lot of ways it is troublesome and difficult to work with. One of the things that [...]]]></description>
			<content:encoded><![CDATA[<p>For some time we have been using Microsofts Linq-to-Sql as our ORM for several of our projects. It has some nice features, but it is also very different from just about every other ORM out there, and in a lot of ways it is troublesome and difficult to work with. One of the things that have been irritating me about Linq-to-Sql is that it&#8217;s central object, the datacontext, does not implement an interface and therefore it is difficult to unittest code that depends on it. Today I stumpled upon a solution to that problem in this post: <a href="http://www.iridescence.no/post/Linq-to-Sql-Programming-Against-an-Interface-and-the-Repository-Pattern.aspx">http://www.iridescence.no/post/Linq-to-Sql-Programming-Against-an-Interface-and-the-Repository-Pattern.aspx</a></p>
<p>Let&#8217;s start with an example of the problem. We use a repository pattern to encapsulate our Linq our Linq-queries into manageable and reusable componentes. Are repository can look kindof like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ClipRepository <span style="color: #008000;">:</span> IClipRepository
<span style="color: #000000;">&#123;</span>
    IDataContext _dc<span style="color: #008000;">;</span>
    IDataContext dc
    <span style="color: #000000;">&#123;</span>
        get
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_dc <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                _dc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PiratDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> _dc<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> IQueryable getClipsFromSite<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> siteid<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> from sc <span style="color: #0600FF;">in</span> dc.<span style="color: #0000FF;">SiteClips</span>
        where sc.<span style="color: #0000FF;">SiteID</span> <span style="color: #008000;">==</span> siteid
        select sc.<span style="color: #0000FF;">Clip</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The repository implements a IClipRepository interface an all code that depends on the repository is written against the interface instead of the specific implementation. This is great because we can then switch from a database backend-implementation to, say, a cachebackend without changing any of the dependant code. We use a servicelocator to provice simple inversion-of-control and break dependencies, and as a bonus, we can write unittest of code that uses the repository be reconfiguring the servicelocator to return a MockedClipRepository instead of the real one.</p>
<p>However, as mentioned above, the DataContext itself does not implement an interface, so we cannot use the servicelocator to provide the datacontext, and therefore we cannot really unittest our repositories without great difficulty.</p>
<h2>Wrapping the DataContext</h2>
<p>C# is flexible &#8211; with generics we can create a proxy class around a DataContext, and we can make that class implement a suitable interface.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IDataContext
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// Gets the repository for the given type of entities</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;/summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;typeparam name=&quot;T&quot;&amp;gt;The type of the entity&amp;lt;/typeparam&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;returns&amp;gt;The repository of the given type&amp;lt;/returns&amp;gt;</span>
    IQueryable<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> GetTable<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &amp;lt;summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// Adds a new entity to the repository</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;/summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;typeparam name=&quot;T&quot;&amp;gt;The type of the entity&amp;lt;/typeparam&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;param name=&quot;item&quot;&amp;gt;The entity to add&amp;lt;/param&amp;gt;</span>
    <span style="color: #0600FF;">void</span> Insert<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>T item<span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &amp;lt;summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// Deletes the specified entity from the repository</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;/summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;typeparam name=&quot;T&quot;&amp;gt;The type of the entity&amp;lt;/typeparam&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;param name=&quot;item&quot;&amp;gt;The entity to delete&amp;lt;/param&amp;gt;</span>
    <span style="color: #0600FF;">void</span> Delete<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>T item<span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &amp;lt;summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// Commits the changes to the repository</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;/summary&amp;gt;</span>
    <span style="color: #0600FF;">void</span> Save<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &amp;lt;summary&amp;gt;</span>
    <span style="color: #008080; font-style: italic;">/// Provides access to the modified objects tracked by the system</span>
    <span style="color: #008080; font-style: italic;">/// &amp;lt;/summary&amp;gt;</span>
    ChangeSet GetChangeSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And the wrapper class implementation for LinqToSql datacontexts:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LinqToSqlDataContext<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t_datacontexttype<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #008000;">:</span> IDataContext where T_DataContextType <span style="color: #008000;">:</span> DataContext
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> DataContext _dc<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> DataContext dc
    <span style="color: #000000;">&#123;</span>
        get
        <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_dc <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                _dc <span style="color: #008000;">=</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t_datacontexttype<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> _dc<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> IQueryable<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> GetTable<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> dc.<span style="color: #0000FF;">GetTable</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Cast</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Insert<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>T item<span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged
    <span style="color: #000000;">&#123;</span>
        dc.<span style="color: #0000FF;">GetTable</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InsertOnSubmit</span><span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Delete<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>T item<span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged
    <span style="color: #000000;">&#123;</span>
        dc.<span style="color: #0000FF;">GetTable</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">DeleteOnSubmit</span><span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Save<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        dc.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> ChangeSet GetChangeSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> dc.<span style="color: #0000FF;">GetChangeSet</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080;">#endregion</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h2>Using the wrapper</h2>
<p>With this wrapper in place, we then change the implementation of the repository above so that instead of creating it&#8217;s datacontext directly it uses the wrapper:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// creating the context</span>
<span style="color: #008080; font-style: italic;">// in the ServiceLocators config, IDataContext is setup to return LinqToSqlDataContext&amp;lt;piratdatacontext&amp;gt;</span>
_dc <span style="color: #008000;">=</span> ServiceLocator.<span style="color: #008000;">New</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>idatacontext<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// using it</span>
<span style="color: #0600FF;">return</span> from sc <span style="color: #0600FF;">in</span> dc.<span style="color: #0000FF;">GetTable</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>siteclip<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
         where sc.<span style="color: #0000FF;">SiteID</span> <span style="color: #008000;">==</span> siteid
         select sc.<span style="color: #0000FF;">Clip</span><span style="color: #008000;">;</span></pre></div></div>

<h2>Unit testing</h2>
<p>With the above setup we can now create a MemoryDataContext, that has the same interface as the LinqToSql context, but does not depend on a database:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MemoryDataContext <span style="color: #008000;">:</span> IDataContext
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> _inMemoryDataStore <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> IList<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> _Inserts <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> IList<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> _Deletes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> IList<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> _Updates <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> MemoryDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> MemoryDataContext<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">params</span> INotifyPropertyChanged<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> objects<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var obj <span style="color: #0600FF;">in</span> objects<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _insert<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> _insert<span style="color: #000000;">&#40;</span>INotifyPropertyChanged item<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        _inMemoryDataStore.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        item.<span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> PropertyChangedEventHandler<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>s,e<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> _Updates.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> IQueryable<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> GetTable<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged
    <span style="color: #000000;">&#123;</span>
        var list <span style="color: #008000;">=</span> from objects <span style="color: #0600FF;">in</span> _inMemoryDataStore
                    where <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">IsAssignableFrom</span><span style="color: #000000;">&#40;</span>objects.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    select objects <span style="color: #0600FF;">as</span> T<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> list.<span style="color: #0000FF;">AsQueryable</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Insert<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>T item<span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged
    <span style="color: #000000;">&#123;</span>
        _insert<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        _Inserts.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Delete<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>t<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>T item<span style="color: #000000;">&#41;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>, INotifyPropertyChanged
    <span style="color: #000000;">&#123;</span>
        _inMemoryDataStore.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        _Deletes.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Save<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>Completed <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Completed<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, EventArgs.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> ChangeSet GetChangeSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        var constructor <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ChangeSet<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetConstructors</span><span style="color: #000000;">&#40;</span>BindingFlags.<span style="color: #0000FF;">Instance</span> <span style="color: #008000;">|</span> BindingFlags.<span style="color: #0000FF;">NonPublic</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">First</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var changes <span style="color: #008000;">=</span> constructor.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008000;">new</span> ReadOnlyCollection<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>_Inserts<span style="color: #000000;">&#41;</span>,
            <span style="color: #008000;">new</span> ReadOnlyCollection<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>_Deletes<span style="color: #000000;">&#41;</span>,
            <span style="color: #008000;">new</span> ReadOnlyCollection<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>object<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span>_Updates<span style="color: #000000;">&#41;</span>,
        <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> ChangeSet<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">return</span> changes<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler Completed<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And there &#8211; we can now write unittests of our repository methods like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #000000;">&#91;</span>TestInitialize<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> init<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var memContext <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Clip <span style="color: #000000;">&#123;</span> ID <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, Title <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;hest&quot;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Clip <span style="color: #000000;">&#123;</span> ID <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>, Title <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;giraf&quot;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Clip <span style="color: #000000;">&#123;</span> ID <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>, Title <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;tobis&quot;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Clip <span style="color: #000000;">&#123;</span> ID <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>, Title <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;laks&quot;</span>, AllowExternalEmbedding <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> SiteClip <span style="color: #000000;">&#123;</span> ClipID <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, SiteID <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> SiteClip <span style="color: #000000;">&#123;</span> ClipID <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>, SiteID <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> SiteClip <span style="color: #000000;">&#123;</span> ClipID <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>, SiteID <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> SiteClip <span style="color: #000000;">&#123;</span> ClipID <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>, SiteID <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            memContext.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> SiteClip <span style="color: #000000;">&#123;</span> ClipID <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>, SiteID <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ServiceLocator.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>IDataContext<span style="color: #000000;">&#41;</span>, memContext<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>TestMethod<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> getClipsFromSiteTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ClipRepository target <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ClipRepository<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Assert.<span style="color: #0000FF;">AreEqual</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span>, target.<span style="color: #0000FF;">getClipsFromSite</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">50</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Assert.<span style="color: #0000FF;">AreEqual</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span>, target.<span style="color: #0000FF;">getClipsFromSite</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Assert.<span style="color: #0000FF;">AreEqual</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, target.<span style="color: #0000FF;">getClipsFromSite</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2010/02/09/unit-testing-with-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Error Handler in IIS7</title>
		<link>http://www.flyvergrillen.dk/2009/04/02/custom-error-handler-in-iis7/</link>
		<comments>http://www.flyvergrillen.dk/2009/04/02/custom-error-handler-in-iis7/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 07:48:15 +0000</pubDate>
		<dc:creator>Anders Rasmussen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[httpErrors]]></category>
		<category><![CDATA[httpHandler]]></category>
		<category><![CDATA[IHttpHandler]]></category>
		<category><![CDATA[iis 7.0]]></category>
		<category><![CDATA[iis7]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2009/04/02/custom-error-handler-in-iis7/</guid>
		<description><![CDATA[Introduction
During the development of SKUM3 some problems have not manifested themselves while developing for one simple reason: Visual Studio 2008 uses a version of IIS 6 as a development server, but our final setup will be an IIS 7 server. The differences between these two version are significant enough to cause headaches.
One such headache is [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>During the development of SKUM3 some problems have not manifested themselves while developing for one simple reason: Visual Studio 2008 uses a version of IIS 6 as a development server, but our final setup will be an IIS 7 server. The differences between these two version are significant enough to cause headaches.</p>
<p>One such headache is the inability to debug code running on the remote server. This combined with differences in how errors are handled, both in the setup in the web.config file, and in the way a custom error handler is called, produced a very difficult to solve problem. Also a lack in documentation is partly to blame.</p>
<h3>The problem</h3>
<p>web.config differences.</p>
<p><strong>IIS 7 version:</strong></p>
<pre><code>&lt;httpErrors&gt;
    &lt;remove statusCode="404" subStatusCode="-1" /&gt;
    &lt;error statusCode="404" prefixLanguageFilePath=""
        path="/path/to/handlerwebservice"
        responseMode="ExecuteURL" /&gt;
&lt;/httpErrors&gt;</code></pre>
<p><strong> IIS 6 version:</strong></p>
<pre>&lt;customErrors mode="On"&gt;
    &lt;error statusCode="404" redirect="webservices/media/image"/&gt;
&lt;/customErrors&gt;</pre>
<p>With the IIS 6 version all 404 errors are redirected to webservices/media/image?aspxerrorpath=original/path. In IIS 7 though this querystring parameter is missing so what to do?</p>
<h3>The Solution</h3>
<p>Well, microsoft is not very helpful and I tried <a href="http://stackoverflow.com/questions/705934/how-do-i-find-out-which-request-path-is-missing-in-a-404-error-handler-in-iis7" title="stackoverflow question">asking my question to the Internet</a> but as I didn&#8217;t receive any answers I just tried changing</p>
<pre><code>context.Request.Path</code></pre>
<p>to</p>
<pre><code>context.Request.RawUrl</code></pre>
<p>Resulting in this code to handle the differences:</p>
<pre><code>string requestpath;

if(context.Request.QueryString.AllKeys.Contains("aspxerrorpath"))
{
    requestpath = context.Request.QueryString["aspxerrorpath"];
}
else
{
    requestpath = context.Request.RawUrl;
}</code></pre>
<p>This seemed to have the desired effect. The difference between these two are that RawUrl contains the requested path unaltered by redirection or anything else and Path is the Url after any redirection. I had forgotten this minor detail even though I&#8217;ve used it in the breadcrumb method to split an original path up into individual pieces, after the request had been redirected by our UrlRewriter.</p>
<p>If you are getting weird errors about httpErrors being locked down use a cheat code</p>
<pre>%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/httpErrors</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2009/04/02/custom-error-handler-in-iis7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Typeface.js</title>
		<link>http://www.flyvergrillen.dk/2008/11/11/typefacejs/</link>
		<comments>http://www.flyvergrillen.dk/2008/11/11/typefacejs/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 21:45:26 +0000</pubDate>
		<dc:creator>Anders Rasmussen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Typeface.js]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2008/11/11/typefacejs/</guid>
		<description><![CDATA[Typeface.js er et rimeligt interessant stykke software. Interessant fordi det uden problemer tillader en at bruge fonte i websites selvom næsten ingen endnu har implementeret @font-face css-reglen.
Jeg skriver at det er uden problemer og det er en sandhed med modifikationer. Det er problemfrit når man bare bruger det som tekst rendering og ikke forventer at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://typeface.neocracy.org/">Typeface.js</a> er et rimeligt interessant stykke software. Interessant fordi det uden problemer tillader en at bruge fonte i websites selvom næsten ingen endnu har implementeret <a href="http://www.w3.org/TR/css3-webfonts/#font-descriptions">@font-face</a> css-reglen.</p>
<p>Jeg skriver at det er uden problemer og det er en sandhed med modifikationer. Det er problemfrit når man bare bruger det som tekst rendering og ikke forventer at det kan redde verden. Det virker i de fleste grade A browsere. Lige netop det at det ikke virker i alle grade A browsere er det som denne artikel handler om.</p>
<p>I Opera virker det nemlig overhovedet ikke. Det påstås heller ikke fra forfatterens side, men det virkede lidt underligt at det ikke skulle virke, for Opera plejer at opføre sig ordentligt det meste af tiden.</p>
<p>Efter en hurtig omgang debugging i typeface kilden med Operas indbyggede debugger værktøj, fandt jeg ud af at Opera opfattede at de elementer som skulle have specielle fonte, skulle renderes med Arial. Det er jo ikke rigtigt til at forstå, eftersom Arial ikke var i stylesheet&#8217;et. Jeg kom frem til at Opera måtte smide specialfonten væk, fordi den ikke kunne finde den, og så bruge det den troede man havde brug for i stedet.</p>
<p>Efter en del søgen på det store Internet fandt jeg et <a href="http://dev.opera.com/forums/topic/244486">indlæg</a> i Operas developer forum om emnet. Det som Operas udvikler svarer er at de har taget en design beslutning og implementeret det på den måde de har. <a href="http://www.w3.org">w3&#8217;s</a> <a href="http://www.w3.org/TR/1998/REC-CSS2-19980512/cascade.html#q1">specifikation</a> på området omkring computed styles (den værdi som der bliver hentet ud i dette tilfælde, og som indeholder beregnede værdier af de værdier som står i stylesheet&#8217;et) er yderst vag, og den beskriver kun at man skal lave pixel beregninger og sørge for at inherit værdier er ændret til de værdier som skal bruges. Mozilla skriver i deres <a href="https://developer.mozilla.org/en/DOM/window.getComputedStyle">developer central wiki</a> at de faktisk har snydt lidt og bruger used styles som resultat af computed styl, men det ændrer ikke ved at de returnerer det rigtige resultat, nemlig en streng som indeholder en kommasepereret liste af de fonte som er i stylesheet&#8217;et. Forhåbentligt går der ikke mange dage før Opera har rettet op på denne fejl. Indlægget blev besvaret i går af en af deres udviklere og han skriver:</p>
<blockquote><p>This was by design but will be &#8220;fixed&#8221; <img src="http://dev.opera.com/community/graphics/smilies/smile.gif" class="smilie" alt=":smile:" height="17" width="17" /></p></blockquote>
<p>Så man har to valg:</p>
<ul>
<li>Vente og se hvornår de får implementeret den nye funktionalitet</li>
<li>Implementere en traversering af tilknyttede stylesheets for at finde de regler som berører netop de elementer man har brug for</li>
</ul>
<p>I dette tilfælde vil det nok være lidt nyttesløst at vælge det sidste, eftersom der ikke er nok der bruger Opera til at det giver mening, derudover er Opera ikke en standardbrowser på nogen platform, så folk der bruger Opera kan se siden i mindst én anden browser.</p>
<p>Hvis man endelig skulle vælge vej nummer 2 og kigge stylesheet&#8217;ene igennem, så skulle man nok implementere et fuldt css bibliotek, som også vil kunne bruges til at udjævne forskelle mellem browsere i forhold til implementationer af nuværende standarder og også i forhold til at implementere kommende standarder, indtil browserne selv gør det. Javascript er jo netop nået et punkt hvor det er gjort så hurtigt at det ikke vil betyde store ventetider at have store scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2008/11/11/typefacejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>z-index og ie 6</title>
		<link>http://www.flyvergrillen.dk/2008/11/11/z-index-og-ie-6/</link>
		<comments>http://www.flyvergrillen.dk/2008/11/11/z-index-og-ie-6/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 15:16:47 +0000</pubDate>
		<dc:creator>Anders Rasmussen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[z-index]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2008/11/11/z-index-og-ie-6/</guid>
		<description><![CDATA[Dette er viden som skulle have været ubrugelig for længe siden, men folk er ignorante, og derfor skal vi stadig supportere forældede browsere.
Den browser som givers os flest problemer er jo selvfølgeligt Microsofts Internet Explorer version 6.
En af de utallige bugs vi har haft problemer med er at vi har nogle popup-elementer som sidder på [...]]]></description>
			<content:encoded><![CDATA[<p>Dette er viden som skulle have været ubrugelig for længe siden, men folk er ignorante, og derfor skal vi stadig supportere forældede browsere.</p>
<p>Den browser som givers os flest problemer er jo selvfølgeligt Microsofts Internet Explorer version 6.</p>
<p>En af de utallige bugs vi har haft problemer med er at vi har nogle popup-elementer som sidder på vores brugerprofiler. Det virker som det skal i alle andre browsere, men ie6 synes ikke at det z-index popup-elementet har fået er godt nok og derfor vil den måske kunne skjule det bag andre elementer.</p>
<p>Måden den skjuler elementet på var dog ikke lige til at finde ud af, for det var kun nogen elementer der gemte popup&#8217;en. Efter lidt undersøgelse fandt jeg at de elementer der skjuler popup-elementet var relativt positioneret. og det element som popupen var i også var relativt positioneret. Det viser sig nemlig at ie6 ikke er tilfreds med at hvert element har deres helt eget z-index. I stedet siger den at den boks som elementet er inden i ligger i et lag for sig selv, som ingen andre elementer udefra kan komme imellem.</p>
<p>Dette betyder at man kan komme et hvilket som helst z-index på popup-elementet, det er stadig relativt i forhold til det element det er indeni. Og elementer der kommer umiddelbart efter vil, i kraft af at de kommer senere i dokumentet, overlappe ved &#8220;by-design&#8221; at have et højere z-index (på en måde). For atfå ie6 til at tegne det ordentligt, så bliver man nødt til at sætte z-index&#8217;et på popup-elementets relative parent til et andet højt z-index.</p>
<p>For mere dybdegående information: <a href="http://aplus.rs/lab/z-pos/">http://aplus.rs/lab/z-pos/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2008/11/11/z-index-og-ie-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ViewState optimering</title>
		<link>http://www.flyvergrillen.dk/2008/06/16/viewstate-optimering/</link>
		<comments>http://www.flyvergrillen.dk/2008/06/16/viewstate-optimering/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 15:38:55 +0000</pubDate>
		<dc:creator>Anders Hellerup Madsen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[idioti]]></category>
		<category><![CDATA[ViewState]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2008/06/16/viewstate-optimering/</guid>
		<description><![CDATA[Da jeg for mange år siden var en lille dreng der gik ude på DTU og lærte hvordan man blev ingeniør, var en af de ting jeg synes var rigtigt sjovt at hukommelsesoptimere. Præcis hvorfor ved jeg ikke, men det tiltalte mig på en eller anden måde rigtigt meget at få vredet lige otte bytes [...]]]></description>
			<content:encoded><![CDATA[<p>Da jeg for mange år siden var en lille dreng der gik ude på DTU og lærte hvordan man blev ingeniør, var en af de ting jeg synes var rigtigt sjovt at hukommelsesoptimere. Præcis hvorfor ved jeg ikke, men det tiltalte mig på en eller anden måde rigtigt meget at få vredet lige otte bytes mere ud af et eller andet minimalt embedded system, eller at få en datastruktur til at fylde lige to bytes mindre pr. entry.</p>
<p>Det er mig en gåde hvorfor jeg dengang syntes at det var skægt, og efterhånden som jeg blev ældre lagde min fascination af den her helt særlige form for totur sig, og blev afløst af en langt mere naturlig foragt for den slags programmering. Ikke at jeg synes man skal svine unødigt med hukommelse, men inden for moderne udvikling så kan det simpelthen ikke være rigtigt at programmøren selv skal side og manuelt tilrette hver eneste datastruktur, og selv sidde og finde hver eneste lille ekstra byte ud af hukommelsen &#8211; og det ER selv følgelig heller ikke rigtigt. Med garbage collection, smartere compilere og nærmest uendelig performance og hukommelse så er det ikke noget programmører i dag nogensinde prøver at beskæftige sig med.</p>
<p>Derfor har det også overrasket mig pænt meget, når jeg tænker tilbage på hvad jeg har lavet den sidste uge. Jeg har siddet og kigget på lange, lange stackdumps, aflæst hvor meget hukkomelse hver enkelt object bruger, flyttet rundt på kode, tænkt datastrukturer om og klappet i mine små hænder hver gang jeg har sparet 15-20 bytes. Præcis som da jeg var en lille dreng på DTU &#8211; forskellen er bare at i dag hader jeg det som pesten.</p>
<p>Det jeg laver er at gå alle vores ASP.NET controls igennem og få styr på hvor meget de plads de bruger når de er serialiseret ud i ASP.NETs ViewState. 200 controls, hvoraf hveranden gemmer bare 100 bytes i viewstate giver 10kb i ViewState, og det bliver overført frem og tilbage mellem server og klient hvert eneste gang siden forsager et postback &#8211; og med moderne ting som AJAX og asynkrone postbacks, så kan det ske masser af gange i minuttet. I Skum 3 har vi nogen widgets (Skum fiduser) og hver gang de bliver flyttet melder de tilbage til serveren, at de bor et andet sted igennem et postback: Med et ViewState på 10kb skal man kun flytte en widget 50 gange, før man har overført en megabyte data. Ingen billeder, ingen ting, bare retursvar til serveren om hvor den her widget bor nu.</p>
<p>Med andre ord, hvis man ikke passer ekstremt meget på hvad man har i ViewState laver man meget, meget nemt den største og tungeste website nogensinde &#8211; uden at man får noget ekstra funktionalitet ud af det.</p>
<p>Så nu går jeg altså alle vore controls igennem en for en og sikrer mig at de ikke sviner i ViewState, ligesom programmørene i 1978 gik deres C eller Fortran kode igennem funktion for funtion, og datastruktur for datastruktur for at sikre sig de ikke svinede med hukommelsen. Jeg har lært mig følgende regler som alle folk burde følge når de udvikler ASP.NET controls:</p>
<ol>
<li>Det eneste der skal bo i ViewState er information som er direkte forsaget af en brugers handlinger, og ikke er gemt i databasen endnu.</li>
<li>Alt, hvis værdi på nogensomhelst måde kan sættes før eller under en controls init-event skal sættes der. Efter Init event&#8217;et tracker ViewState og så bliver alting serialiseret ud til klienten.</li>
<li>I UserControls skal alle værdier der overhovedet kan sættes i .ascx filen (som properties på et tag) sættes der. Den slags properties bliver sat før ViewState begynder og tracke, og derfor sviner de ikke i ViewState.</li>
<li>Hvis man endelig ikke kan undgå at noget skal være i ViewState, så vær ekstremt omhyggelig med hvad du kommer derind. Alt andet end strings, bytes, bools og andre simple typer bliver serialiseret med en byteserializer der er ekstremt ueffektiv. Controls i ViewState er især super forbudt &#8211; brug ID&#8217;er i stedet. Overload hellere SaveViewstate og LoadViewstate en gang for meget end en gang for lidt.</li>
</ol>
<p>ViewState kan være svært at forstå, og det er svært at læse sig frem til hvad det er og hvad det gør, hvis man kun bruger Microsofts dokumentation. Den her artikel er absolut den bedste jeg har set om ViewState og det bør være &#8220;required reading&#8221; for alle der har med ASP.NET at gøre:</p>
<p><a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx">Infinities Loop: Truly Understanding Viewstate</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2008/06/16/viewstate-optimering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Source Safe &#8211; Det er ikke et versionstyringssystem</title>
		<link>http://www.flyvergrillen.dk/2008/04/14/source-safe-det-er-ikke-et-versionstyringssystem/</link>
		<comments>http://www.flyvergrillen.dk/2008/04/14/source-safe-det-er-ikke-et-versionstyringssystem/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 13:48:33 +0000</pubDate>
		<dc:creator>Anders Rasmussen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[VCS]]></category>
		<category><![CDATA[Visual Studio Source Safe]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2008/04/14/source-safe-det-er-ikke-et-versionstyringssystem/</guid>
		<description><![CDATA[Dette indlæg er min galde som spildes. Og min afsky for det monstrum, der er Source Safe, kommer råt og usødet til udtryk.
Visual Studio Source Safe er IKKE et versionsstyringssoftware! Det er et filkontrolsystem designet til at kun én person kan arbejde på en fil samtidigt. Sletter man filer fra ens kodetræ, så skal man [...]]]></description>
			<content:encoded><![CDATA[<p>Dette indlæg er min galde som spildes. Og min afsky for det monstrum, der er Source Safe, kommer råt og usødet til udtryk.</p>
<p>Visual Studio Source Safe er IKKE et versionsstyringssoftware! Det er et filkontrolsystem designet til at kun én person kan arbejde på en fil samtidigt. Sletter man filer fra ens kodetræ, så skal man først ofre 7 jomfruer og derefter håbe på at ingen andre har problemer med at få opdateret deres træ. Jeg har endnu ikke oplevet noget tidspunkt, hvor en refaktorering af selv en mindre stump af koden ikke er gået galt og er endt i et projekt der ikke ville kompilere, for alle andre, som efterfølgende forsøger at bruge rettelserne.</p>
<p>Og fordi det er så meget forskelligt fra alle andre VCS&#8217;er så er der åbenbart ikke rigtigt nogen der kan finde ud af det heller, eftersom tingene selvfølgeligt ikke har navne som stemmer overens med alle andre former for vcs&#8217;er. Det resulterer i at nogle filer bliver checket ind mens andre ikke gør. Som eksempel kan jeg jo tage .csproj som er filer der styrer enkelte projekter i en visual studio solution. Åbenbart er der nogen der ikke checker rettelserne i den fil ind, hvis de f.eks. sletter en fil. Og hvorfor skal man have ting checket ud hele weeken den? Kan man ikke have lavet ens ændringer og lagt dem op? Det giver bare konflikter på så mange niveauer.</p>
<p>Der er ingen mulighed for at eksludere filer såsom binaries (.dll&#8217;er eller .pdb&#8217;er), som jo ikke behøver versionskontrol eftersom de genereres hver gang man bygger projektet. At man har disse filer i ens &#8220;pending check ins&#8221; gør at folk der arbejder med systemet bliver mistroiske over hvilke filer de skal checke ind.</p>
<p>Og dertil kommer at klient programmet fylder 212 mb (eller noget i den stil). sammenligner man det med Tortoisesvn (8,9 mb installer) så fylder det 23,5 gang så meget. </p>
<p>Hvis du ikke er blevet udsat for Source Safe, så vil jeg på det kraftigste fraråde dig at ønske det. Det giver ikke andet end problemer langt hen ad vejen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2008/04/14/source-safe-det-er-ikke-et-versionstyringssystem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Et lille skridt for menneskeheden, men et stort skridt for mig</title>
		<link>http://www.flyvergrillen.dk/2008/04/07/et-lille-skridt-for-menneskeheden-men-et-stort-skridt-for-mig/</link>
		<comments>http://www.flyvergrillen.dk/2008/04/07/et-lille-skridt-for-menneskeheden-men-et-stort-skridt-for-mig/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 19:44:38 +0000</pubDate>
		<dc:creator>Mikkel Munch Mortensen</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Kode]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[skum 3]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2008/04/07/et-lille-skridt-for-menneskeheden-men-et-stort-skridt-for-mig/</guid>
		<description><![CDATA[Jeg har netop fået strikket min første ASP.NET Control sammen næsten uden hjælp. Den kan ikke alt hvad den skal kunne endnu, og den ser heller ikke helt ud som den skal. Men begge dele skal nok komme.
Den er ikke så satans avanceret: Det er bare en lille menu til &#8211; fx. &#8211; brugersider. Så [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg har netop fået strikket min første ASP.NET Control sammen næsten uden hjælp. Den kan ikke alt hvad den skal kunne endnu, og den ser heller ikke helt ud som den skal. Men begge dele skal nok komme.</p>
<p>Den er ikke så satans avanceret: Det er bare en lille menu til &#8211; fx. &#8211; brugersider. Så som sådan er det ikke det vilde. Næh, det vilde ligger i at jeg endeligt, grundlæggende har forstået (og haft tid til at forstå) hvordan hele det her ASP.NET-cirkus fungerer.</p>
<p>Jeg er stadigt ikke vildt begejstret for det. Men det er heldigvis heller ikke det jeg får mine penge for at være.</p>
<p>Nå, men se den fine menu i aktion her:</p>
<p style="text-align: center"><img src="http://www.flyvergrillen.dk/wp-content/uploads/2008/04/skummenu.png" alt="Menu" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2008/04/07/et-lille-skridt-for-menneskeheden-men-et-stort-skridt-for-mig/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Svensk data</title>
		<link>http://www.flyvergrillen.dk/2008/02/28/svensk-data/</link>
		<comments>http://www.flyvergrillen.dk/2008/02/28/svensk-data/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 11:19:07 +0000</pubDate>
		<dc:creator>Mikkel Munch Mortensen</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[skum]]></category>
		<category><![CDATA[svensk]]></category>
		<category><![CDATA[WTF]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2008/02/28/svensk-data/</guid>
		<description><![CDATA[Vi sidder lige for tiden og kigger Skums database igennem for at se hvilke data vi gerne vil have med over i et kommende, nyt Skum. Det er svenske Netstar der i sin tid har lavet det nuværende system, baseret på ASP 3.0,  til os. I koden her de benyttet sig af Hungarian Notation, [...]]]></description>
			<content:encoded><![CDATA[<p>Vi sidder lige for tiden og kigger <a href="http://www.dr.dk/skum">Skum</a>s database igennem for at se hvilke data vi gerne vil have med over i et kommende, nyt Skum. Det er svenske Netstar der i sin tid har lavet det nuværende system, baseret på ASP 3.0,  til os. I koden her de benyttet sig af <a href="http://en.wikipedia.org/wiki/Hungarian_notation" title="Wikipedia om Hungarian Notation">Hungarian Notation</a>, og dette har de taget mig sig i databasen. Således er alle tabeller prefixet med &#8220;tbl&#8221; &#8211; fx. &#8220;tblUser&#8221; og &#8220;tblForumRooms&#8221; &#8211; og felterne hedder ting som &#8220;intID&#8221; og &#8220;strName&#8221;.</p>
<p>På Skum kan brugerne &#8211; som så mange andre steder &#8211; sende private beskeder til hinanden. Disse ligger i tabellen &#8220;tblMessage&#8221;. Vel at mærke kun de ulæste af slagsen, for læste beskeder flyttes &#8211; på snedigste vis &#8211; til tabellen &#8220;tblMessageRead&#8221;. Normalt ville man nok have et felt i tabellen der angav om beskeden var læst eller ej, men i Sverige giver det åbenbart mere mening at fordele det på 2 tabeller.</p>
<p>I &#8220;tblMessage&#8221; og dens søstertabel er vi faldet over et spøjst felt. Det hedder &#8220;blnDoNotShowAsNotInList&#8221;, og værdien af dette felt er altid False. Er der mon nogen der kan gætte hvad dette felt er til?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2008/02/28/svensk-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PNG This!</title>
		<link>http://www.flyvergrillen.dk/2007/12/11/png-this/</link>
		<comments>http://www.flyvergrillen.dk/2007/12/11/png-this/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 10:29:52 +0000</pubDate>
		<dc:creator>Jonas Swiatek</dc:creator>
				<category><![CDATA[Kode]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[PNG]]></category>

		<guid isPermaLink="false">http://www.flyvergrillen.dk/2007/12/11/png-this/</guid>
		<description><![CDATA[Nu har jeg endelig efter at have skubbet problemet i næsten 3 år, igennem 2 jobs, løst problemet med at jeg ikke har kunne streame en PNG ud på en HTTP Stream (GDI+ har givet en intern framework fejl).
Løsningen skal åbenbart findes i hvordan PNG formattet virker &#8211; hele PNGen skal være genereret før den [...]]]></description>
			<content:encoded><![CDATA[<p>Nu har jeg endelig efter at have skubbet problemet i næsten 3 år, igennem 2 jobs, løst problemet med at jeg ikke har kunne streame en PNG ud på en HTTP Stream (GDI+ har givet en intern framework fejl).</p>
<p>Løsningen skal åbenbart findes i hvordan PNG formattet virker &#8211; hele PNGen skal være genereret før den kan skrives til en stream.</p>
<p>Til at sikre dette kan man skrive PNG&#8217;en til en MemoryStream, og derefter skrive den MemoryStream til Response.OutputStream.</p>
<pre><font size="2" color="#008080">AsyncButtonResult</font><font size="2"> async = result </font><font size="2" color="#0000ff">as</font><font size="2"> </font><font size="2" color="#008080">AsyncButtonResult</font><font size="2">;
</font><font size="2" color="#0000ff">using</font><font size="2"> (</font><font size="2" color="#008080">MemoryStream</font><font size="2"> ms = </font><font size="2" color="#0000ff">new</font><font size="2"> </font><font size="2" color="#008080">MemoryStream</font><font size="2">())
</font><font size="2">{
     async.img.Save(ms, </font><font size="2" color="#008080">ImageFormat</font><font size="2">.Png);
</font><font size="2">     ms.WriteTo(async.context.Response.OutputStream);
}
</font></pre>
<p>Kode eksemplet ovenover er fra en IHttpAsyncHandler  der genererer knapper der skal bruges på SKUMs nye community.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flyvergrillen.dk/2007/12/11/png-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
