<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Tobi + C# = T#</title> <link>http://saftsack.fs.uni-bayreuth.de/~dun3</link> <description>This is a collection of interesting stuff that I found on the web or stuff I worked on at the time.</description> <lastBuildDate>Mon, 21 Dec 2009 16:44:50 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/dun3" /><feedburner:info uri="dun3" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Part 3: Adding a dynamic decorator to an object – the “Why not”</title><link>http://feedproxy.google.com/~r/dun3/~3/I8tQH4tBvtw/426.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/part-3-adding-dynamic-decorator-to-object-why-not/426.html#comments</comments> <pubDate>Mon, 21 Dec 2009 16:44:50 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Patterns]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=426</guid> <description><![CDATA[Krzysztof pointed me to his post Castle Dynamic Proxy FAQ: why there’s no &#8220;class proxy with target&#8221; why the dynamic decorator is not part of Castles&#8217;s DynamicProxy implementation yet.
Looking at the code one realizes that the real problem is, that IsAdult() is not virtual. That&#8217;s why the decorator is not able to intercept and redirect [...]]]></description> <content:encoded><![CDATA[<p>Krzysztof pointed me to his post <a
href="http://kozmic.pl/archive/2009/12/02/castle-dynamic-proxy-faq-why-therersquos-no-ldquoclass-proxy-with.aspx" rel="nofollow">Castle Dynamic Proxy FAQ: why there’s no &#8220;class proxy with target&#8221;</a> why the dynamic decorator is not part of Castles&#8217;s DynamicProxy implementation yet.</p><p>Looking at the code one realizes that the real problem is, that IsAdult() is not virtual. That&#8217;s why the decorator is not able to intercept and redirect that call to the target. There is no way around it &#8211; that is a real bug and it does show why a class proxy with a target is indeed dangerous. Thanks for pointing it out to me, Krzysztof!</p><p>The question we have to ask now is: If we refuse to generate the proxy, if any member more visible than protected is non-virtual, would that get rid of the bug? I would argue that it will, since the proxy will now be able to redirect the call to the target and everything works out fine. Or am I again missing something?</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Part+3%3A+Adding+a+dynamic+decorator+to+an+object+%E2%80%22+the+%22Why+not%27%27+-+http://bit.ly/6MXJrp" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Part+3%3A+Adding+a+dynamic+decorator+to+an+object+%E2%80%22+the+%22Why+not%27%27+-+http://bit.ly/6MXJrp" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=I8tQH4tBvtw:PcwhYM-zxno:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=I8tQH4tBvtw:PcwhYM-zxno:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/I8tQH4tBvtw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/part-3-adding-dynamic-decorator-to-object-why-not/426.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/part-3-adding-dynamic-decorator-to-object-why-not/426.html</feedburner:origLink></item> <item><title>Part 2: Adding a dynamic decorator to an object – the “Why”</title><link>http://feedproxy.google.com/~r/dun3/~3/CNIHB8ovfkI/422.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/part-2-adding-dynamic-decorator-proxy-to-object-why/422.html#comments</comments> <pubDate>Sun, 20 Dec 2009 16:03:31 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=422</guid> <description><![CDATA[I got the question "Why would we do that, we can't guarantee that nobody would use the original reference to manipulate stuff."
Well, this question is answered best by an example.
Imagine an object with a complicated creation and/hydration path. We are in a multithreaded environment and the object is passed between theads often, etc. There are [...]]]></description> <content:encoded><![CDATA[<p>I got the question "Why would we do that, we can't guarantee that nobody would use the original reference to manipulate stuff."</p><p>Well, this question is answered best by an example.</p><p>Imagine an object with a complicated creation and/hydration path. We are in a multithreaded environment and the object is passed between theads often, etc. There are to approaches to ensure that on has no data corruption because of multi threading. Either locking or immutability. Immutability is a strong feature but usually it is quite clumsy to use. Especially since with purely immutable objects there can be a lot of memory pressure with all the copying and creating of objects. Think "creating a complex immutable tree".</p><p>A solution to circumvent the memory pressure is to have a mutable object during creation and marking it as immutable after it is fully hydrated. This usually leads in C# to code similar to this:</p><div
class="igBar"><span
id="lcsharp-3"><a
href="#" onclick="javascript:showCodeTxt('csharp-3'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-3"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">class</span> MyImmutable</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">private</span> <span
class="kw4">string</span> m_property;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw4">string</span> Property</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; get <span
class="br0">&#123;</span> <span
class="kw1">return</span> m_property; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; set</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">if</span> <span
class="br0">&#40;</span>m_immutable<span
class="br0">&#41;</span> <span
class="br0">&#123;</span> <span
class="kw1">throw</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MemberAccessException<span
class="br0">&#40;</span><span
class="st0">"Type is marked as immutable"</span><span
class="br0">&#41;</span>; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_property = value;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">private</span> <span
class="kw4">bool</span> m_immutable = <span
class="kw1">false</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> MarkAsImmutable<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; m_immutable = <span
class="kw1">true</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">class</span> MyImmutableFactory</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> MyImmutable CreateMyImmutable<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MyImmutable myImmutable = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyImmutable<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; myImmutable.<span
class="me1">Property</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; myImmutable.<span
class="me1">MarkAsImmutable</span><span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">return</span> myImmutable;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2"><span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw4">class</span> ImmutableOldStyleTest</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw1">void</span> Test<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; MyImmutableFactory myImmutableFactory = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyImmutableFactory<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MyImmutable myImmutable = myImmutableFactory.<span
class="me1">CreateMyImmutable</span><span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw4">bool</span> caughtException = <span
class="kw1">false</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">try</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myImmutable.<span
class="me1">Property</span> = <span
class="st0">"Test2"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">catch</span> <span
class="br0">&#40;</span>MemberAccessException<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; caughtException = <span
class="kw1">true</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>caughtException<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>myImmutable.<span
class="me1">Property</span> == <span
class="st0">"Test"</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>For each set it is the programmer's resposibility to check within the setter, if it may or may not proceed with the setting of the value. Which can be quite tiring for multiple properties (DRY for the check!) and multiple immutable types (DRY for the MarkAsImmutable() method).</p><p>An alterative approach would be to use a decorator:</p><div
class="igBar"><span
id="lcsharp-4"><a
href="#" onclick="javascript:showCodeTxt('csharp-4'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-4"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">class</span> ImmutableInterceptor : IInterceptor&lt;MyType&gt;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> InterceptGetter<span
class="br0">&#40;</span>IProxy proxy, MyType @<span
class="kw4">object</span>, <span
class="kw4">string</span> propertyName, <span
class="kw1">out</span> <span
class="kw4">object</span> value<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; proxy.<span
class="me1">ProceedGetter</span><span
class="br0">&#40;</span>propertyName, <span
class="kw1">out</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> InterceptSetter<span
class="br0">&#40;</span>IProxy proxy, MyType @<span
class="kw4">object</span>, <span
class="kw4">string</span> propertyName, <span
class="kw4">object</span> value<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">throw</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MemberAccessException<span
class="br0">&#40;</span><span
class="st0">"Type is marked as immutable"</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2"><span
class="kw1">public</span> <span
class="kw4">class</span> MyTypeFactory</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> MyType CreateMyType<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; MyType myType = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyType<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; myType.<span
class="me1">Property</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">return</span> MarkAsImmutable<span
class="br0">&#40;</span>myType<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">private</span> MyType MarkAsImmutable<span
class="br0">&#40;</span>MyType myType<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; ImmutableInterceptor immutableInterceptor = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> ImmutableInterceptor<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">return</span> GenerateProxy<span
class="br0">&#40;</span>myType, immutableInterceptor<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="co1">// This method belongs in a proxy generator</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">private</span> <span
class="kw1">static</span> MyType GenerateProxy<span
class="br0">&#40;</span>MyType myType, IInterceptor&lt;MyType&gt; interceptor<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">return</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyTypeProxy<span
class="br0">&#40;</span>myType, interceptor<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2"><span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw4">class</span> ImmutableTest</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw1">void</span> Test<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; MyTypeFactory myTypeFactory = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyTypeFactory<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MyType myType = myTypeFactory.<span
class="me1">CreateMyType</span><span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw4">bool</span> caughtException = <span
class="kw1">false</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">try</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myType.<span
class="me1">Property</span> = <span
class="st0">"Test2"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">catch</span> <span
class="br0">&#40;</span>MemberAccessException<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; caughtException = <span
class="kw1">true</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>caughtException<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>myType.<span
class="me1">Property</span> == <span
class="st0">"Test"</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>Way more straight forward, isn't it?</p><p>Another application could be the old INotifyPropertyChanged problem, read-only collections, ...</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Part+2%3A+Adding+a+dynamic+decorator+to+an+object+--+the+%22Why%27%27+-+http://bit.ly/4CvDOp" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Part+2%3A+Adding+a+dynamic+decorator+to+an+object+--+the+%22Why%27%27+-+http://bit.ly/4CvDOp" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=CNIHB8ovfkI:O-VLrJfLQ8E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=CNIHB8ovfkI:O-VLrJfLQ8E:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/CNIHB8ovfkI" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/part-2-adding-dynamic-decorator-proxy-to-object-why/422.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/part-2-adding-dynamic-decorator-proxy-to-object-why/422.html</feedburner:origLink></item> <item><title>Adding a dynamic decorator to an object</title><link>http://feedproxy.google.com/~r/dun3/~3/XApL3FRHuww/416.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/adding-dynamic-decorator-proxy-to-object/416.html#comments</comments> <pubDate>Sat, 19 Dec 2009 16:01:29 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Patterns]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=416</guid> <description><![CDATA[I am really confused that non of the dynamic proxy frameworks out there allow me to add dynamic behavior after the fact - I have an instantiated object and need to add behavior when a property is accessed. Like this:
PLAIN TEXT
C#:var myType = new MyType&#40;&#41;;myType.Property = "Test";&#160;var interceptor = new MyInterceptor&#40;&#41;;MyType wrappedMyType = proxyGenerator.GenerateProxy&#40;myType, interceptor&#41;;wrappedMyType.Property [...]]]></description> <content:encoded><![CDATA[<p>I am really confused that non of the dynamic proxy frameworks out there allow me to add dynamic behavior after the fact - I have an instantiated object and need to add behavior when a property is accessed. Like this:</p><div
class="igBar"><span
id="lcsharp-7"><a
href="#" onclick="javascript:showCodeTxt('csharp-7'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-7"><div
class="csharp"><ol><li
class="li1"><div
class="de1">var myType = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyType<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">myType.<span
class="me1">Property</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">var interceptor = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyInterceptor<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">MyType wrappedMyType = proxyGenerator.<span
class="me1">GenerateProxy</span><span
class="br0">&#40;</span>myType, interceptor<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">wrappedMyType.<span
class="me1">Property</span> = <span
class="st0">"Test2"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>myType.<span
class="me1">Property</span> == <span
class="st0">"Test2"</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>interceptor.<span
class="me1">SetterWasCalled</span><span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>All current frameworks need me to instantiate the object using the proxy generator. Which is unfortunate, because, unlike in the example, I plan to introduce the decorator in a part of my application that is conceptionally in a completely different region of the application's source code. It would just not make sense to introduce the knowledge about the additional behavior at the point of object creation.</p><p>It should be fairly easy to pull off, since I am already able to do it by hand:</p><div
class="igBar"><span
id="lcsharp-8"><a
href="#" onclick="javascript:showCodeTxt('csharp-8'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-8"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">class</span> MyInterceptor : IInterceptor&lt;MyType&gt;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> InterceptGetter<span
class="br0">&#40;</span>IProxy proxy, MyType @<span
class="kw4">object</span>, <span
class="kw4">string</span> propertyName, <span
class="kw1">out</span> <span
class="kw4">object</span> value<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="co1">// do something before get</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; proxy.<span
class="me1">ProceedGetter</span><span
class="br0">&#40;</span>propertyName, <span
class="kw1">out</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="co1">// do something after get</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> InterceptSetter<span
class="br0">&#40;</span>IProxy proxy, MyType @<span
class="kw4">object</span>, <span
class="kw4">string</span> propertyName, <span
class="kw4">object</span> value<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="co1">// do something before set</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; proxy.<span
class="me1">ProceedSetter</span><span
class="br0">&#40;</span>propertyName, value<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="co1">// do something after set</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; m_setterCalled = <span
class="kw1">true</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">private</span> <span
class="kw4">bool</span> m_setterCalled = <span
class="kw1">false</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw4">bool</span> SetterWasCalled</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; get <span
class="br0">&#123;</span> <span
class="kw1">return</span> m_setterCalled; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">class</span> MyType</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">virtual</span> <span
class="kw4">string</span> Property <span
class="br0">&#123;</span> get; set; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2"><span
class="co1">/////// AUTOGENERATED PROXY ///////</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2"><span
class="kw1">public</span> <span
class="kw4">class</span> MyTypeProxy : MyType, IProxy</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">private</span> MyType m_object;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">private</span> IInterceptor&lt;MyType&gt; m_interceptor;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> MyTypeProxy<span
class="br0">&#40;</span>MyType @<span
class="kw4">object</span>, IInterceptor&lt;MyType&gt; interceptor<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; m_object = @<span
class="kw4">object</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; m_interceptor = interceptor;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">override</span> <span
class="kw4">string</span> Property</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; get</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw4">object</span> value;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_interceptor.<span
class="me1">InterceptGetter</span><span
class="br0">&#40;</span><span
class="kw1">this</span>, m_object, <span
class="st0">"Property"</span>, <span
class="kw1">out</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">return</span> <span
class="br0">&#40;</span><span
class="kw4">string</span><span
class="br0">&#41;</span>value;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; set <span
class="br0">&#123;</span> m_interceptor.<span
class="me1">InterceptSetter</span><span
class="br0">&#40;</span><span
class="kw1">this</span>, m_object, <span
class="st0">"Property"</span>, value<span
class="br0">&#41;</span>; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> ProceedGetter<span
class="br0">&#40;</span><span
class="kw4">string</span> propertyName, <span
class="kw1">out</span> <span
class="kw4">object</span> value<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">if</span> <span
class="br0">&#40;</span>propertyName == <span
class="st0">"Property"</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = m_object.<span
class="me1">Property</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">else</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">throw</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MissingMemberException<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">void</span> ProceedSetter<span
class="br0">&#40;</span><span
class="kw4">string</span> propertyName, <span
class="kw4">object</span> value<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">if</span> <span
class="br0">&#40;</span>propertyName == <span
class="st0">"Property"</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_object.<span
class="me1">Property</span> = <span
class="br0">&#40;</span><span
class="kw4">string</span><span
class="br0">&#41;</span>value;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">else</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">throw</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MissingMemberException<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="co1">/////// SUPPORTING CODE ///////</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">interface</span> IProxy</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">void</span> ProceedGetter<span
class="br0">&#40;</span><span
class="kw4">string</span> propertyName, <span
class="kw1">out</span> <span
class="kw4">object</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">void</span> ProceedSetter<span
class="br0">&#40;</span><span
class="kw4">string</span> propertyName, <span
class="kw4">object</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">interface</span> IInterceptor&lt;T&gt;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">void</span> InterceptGetter<span
class="br0">&#40;</span>IProxy proxy, T @<span
class="kw4">object</span>, <span
class="kw4">string</span> propertyName, <span
class="kw1">out</span> <span
class="kw4">object</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">void</span> InterceptSetter<span
class="br0">&#40;</span>IProxy proxy, T @<span
class="kw4">object</span>, <span
class="kw4">string</span> propertyName, <span
class="kw4">object</span> value<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="co1">/////// TEST ///////</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw4">class</span> Test</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw1">void</span> ProxyTest<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var myType = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyType<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; myType.<span
class="me1">Property</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; var interceptor = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyInterceptor<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MyType wrappedMyType = GenerateProxy<span
class="br0">&#40;</span>myType, interceptor<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; wrappedMyType.<span
class="me1">Property</span> = <span
class="st0">"Test2"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>myType.<span
class="me1">Property</span> == <span
class="st0">"Test2"</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span
class="me1">Assert</span><span
class="br0">&#40;</span>interceptor.<span
class="me1">SetterWasCalled</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="co1">// This method belongs in a proxy generator</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">private</span> <span
class="kw1">static</span> MyType GenerateProxy<span
class="br0">&#40;</span>MyType myType, IInterceptor&lt;MyType&gt; interceptor<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="kw1">return</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> MyTypeProxy<span
class="br0">&#40;</span>myType, interceptor<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>Who will help me to adapt the API to the Castle DynamicProxy API and to write the actual proxy/decorator generation? <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Adding+a+dynamic+decorator+to+an+object+-+http://bit.ly/5JaUGS" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Adding+a+dynamic+decorator+to+an+object+-+http://bit.ly/5JaUGS" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=XApL3FRHuww:S5rZ5CbHr1g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=XApL3FRHuww:S5rZ5CbHr1g:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/XApL3FRHuww" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/adding-dynamic-decorator-proxy-to-object/416.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/adding-dynamic-decorator-proxy-to-object/416.html</feedburner:origLink></item> <item><title>Silverlight 4 Beta released</title><link>http://feedproxy.google.com/~r/dun3/~3/wldj127565w/412.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/silverlight-4-beta-released/412.html#comments</comments> <pubDate>Wed, 18 Nov 2009 19:35:06 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Silverlight]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=412</guid> <description><![CDATA[AWESOME. This just made my day:
Silverlight 4 beta
This sounds like a great release that smoothes the edges around ADO, out of browser and code reuse between WPF and Silverlight. That's HUGE!
Plus PRINTING! Finally. And the mic and webcam features are nothing to sneeze at either. The list goes on and on. Seriously, they really packed [...]]]></description> <content:encoded><![CDATA[<p>AWESOME. This just made my day:</p><p><a
href="http://silverlight.net/getstarted/silverlight-4-beta/" rel="nofollow">Silverlight 4 beta</a></p><p>This sounds like a great release that smoothes the edges around ADO, out of browser and code reuse between WPF and Silverlight. That's HUGE!</p><p>Plus PRINTING! Finally. And the mic and webcam features are nothing to sneeze at either. The list goes on and on. Seriously, they really packed a lot of stuff in. And it seems to be all community feedback driven. They really listened to us over at <a
href="http://silverlight.uservoice.com/" rel="nofollow">uservoice</a>. 8 out of the top 10 features actually made it into that release. Great work!</p><p>Enjoy!</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Silverlight+4+Beta+released+-+http://bit.ly/abzo2" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Silverlight+4+Beta+released+-+http://bit.ly/abzo2" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=wldj127565w:dgnpbmciWNw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=wldj127565w:dgnpbmciWNw:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/wldj127565w" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/silverlight-4-beta-released/412.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/silverlight-4-beta-released/412.html</feedburner:origLink></item> <item><title>Bootstrapping easy_install for python 2.6 on Windows</title><link>http://feedproxy.google.com/~r/dun3/~3/5WmXko0ZMwk/410.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/bootstrapping-easy_install-python-2-6-windows-install/410.html#comments</comments> <pubDate>Fri, 04 Sep 2009 12:49:06 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[IT]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=410</guid> <description><![CDATA[I had to setup Python 2.6 on Windows. And of course I wanted to use the magnificent Setuptools, specifically easy_install. Unfortunatelly there is only an msi for 2.5 on the website. But actually bootstrapping the 2.6 egg is not that hard:
Download the 2.6 egg from the setuptools download site. Put it in a temporary directory [...]]]></description> <content:encoded><![CDATA[<p>I had to setup Python 2.6 on Windows. And of course I wanted to use the magnificent Setuptools, specifically easy_install. Unfortunatelly there is only an msi for 2.5 on the website. But actually bootstrapping the 2.6 egg is not that hard:</p><p>Download the 2.6 egg from the <a
href="http://pypi.python.org/pypi/setuptools#downloads">setuptools download site</a>. Put it in a temporary directory like c:\downloads\setuptools. Then unzip the egg to the same folder.</p><p>Open a command line, go to c:\downloads\setuptools and use the following command:</p><p><code><br
/> python -c "import sys; sys.path.insert(0, 'C:/Downloads/setuptools/setuptools-0.6c9-py2.6.egg'); from setuptools.command.easy_install import bootstrap; sys.exit(bootstrap())"<br
/> </code></p><p>That should be it.</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Bootstrapping+easy_install+for+python+2.6+on+Windows+-+http://bit.ly/mxbRW" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Bootstrapping+easy_install+for+python+2.6+on+Windows+-+http://bit.ly/mxbRW" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=5WmXko0ZMwk:oNSAB8LgjcE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=5WmXko0ZMwk:oNSAB8LgjcE:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/5WmXko0ZMwk" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/bootstrapping-easy_install-python-2-6-windows-install/410.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/bootstrapping-easy_install-python-2-6-windows-install/410.html</feedburner:origLink></item> <item><title>C# is not (yet) a high perf language</title><link>http://feedproxy.google.com/~r/dun3/~3/HQHZ6a8ubms/402.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/c-is-not-yet-a-high-perf-language/402.html#comments</comments> <pubDate>Sun, 02 Aug 2009 16:57:12 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[HPC]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Optimizations]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=402</guid> <description><![CDATA[Disclamer: The lcg used in this article has drawbacks but it was sufficiently random for my purposes. Please be sure to check if that assumption holds for you as well before using!
Well, this won't come to you as a shocker - but C# is not a high performance language... No, wrong, the C# compiler is [...]]]></description> <content:encoded><![CDATA[<p>Disclamer: The lcg used in this article has drawbacks but it was sufficiently random for my purposes. Please be sure to check if that assumption holds for you as well before using!</p><p>Well, this won't come to you as a shocker - but C# is not a high performance language... No, wrong, the C# compiler is not primarily optimized for performance. I noticed it while playing around with a <a
href="http://en.wikipedia.org/wiki/Linear_congruential_generator">linear congruential generator</a>, a fast and lightweight pseudo random generator.</p><p>The lcg is in essence this code fragment:</p><div
class="igBar"><span
id="lcsharp-13"><a
href="#" onclick="javascript:showCodeTxt('csharp-13'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-13"><div
class="csharp"><ol><li
class="li1"><div
class="de1">PRN = <span
class="br0">&#40;</span>A * PRN + C<span
class="br0">&#41;</span> % M; <span
class="co1">// [0;M[ </span></div></li></ol></div></div></div><p> which generates the next pseudo random number (PRN) which is a number between 0 and M (0 inclusive, M exclusive), using carefully chosen constants A, C and M.</p><p>In order to generate a double between 0 and max the naive way to do so is like this:</p><div
class="igBar"><span
id="lcsharp-14"><a
href="#" onclick="javascript:showCodeTxt('csharp-14'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-14"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">private</span> <span
class="kw1">static</span> <span
class="kw4">double</span> RandomLcg<span
class="br0">&#40;</span><span
class="kw4">double</span> max<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp;PRN = <span
class="br0">&#40;</span>A * PRN + C<span
class="br0">&#41;</span> % M; <span
class="co1">// [0;M[</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp;<span
class="kw1">return</span> max * PRN / M;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>Now what would you say, if I told you that this optimization, no not optimization - reordering,</p><div
class="igBar"><span
id="lcsharp-15"><a
href="#" onclick="javascript:showCodeTxt('csharp-15'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-15"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">private</span> <span
class="kw1">static</span> <span
class="kw4">double</span> RandomLcg<span
class="br0">&#40;</span><span
class="kw4">double</span> max<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp;PRN = <span
class="br0">&#40;</span>PRN * A + C<span
class="br0">&#41;</span> % M; <span
class="co1">// [0;M[</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp;<span
class="kw1">return</span> max * <span
class="br0">&#40;</span>PRN * <span
class="br0">&#40;</span><span
class="nu0">1</span>.<span
class="nu0">0</span> / M<span
class="br0">&#41;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p> is almost TWICE at fast as the original? Curious, isn't it?!</p><p>The fun part is - manually inlining the PRN write and access gives another 10% improvement. So the final version</p><div
class="igBar"><span
id="lcsharp-16"><a
href="#" onclick="javascript:showCodeTxt('csharp-16'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-16"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">private</span> <span
class="kw1">static</span> <span
class="kw4">double</span> RandomLcg<span
class="br0">&#40;</span><span
class="kw4">double</span> max<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp;<span
class="kw1">return</span> max * <span
class="br0">&#40;</span><span
class="br0">&#40;</span>PRN = <span
class="br0">&#40;</span>PRN * A + C<span
class="br0">&#41;</span> % M<span
class="br0">&#41;</span> * <span
class="br0">&#40;</span><span
class="nu0">1</span>.<span
class="nu0">0</span> / M<span
class="br0">&#41;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p> generates 1,000,000,000 pseudo numbers in 11,4 seconds on my machine - the original version needs 20,7 seconds.</p><p>This kind of performance improvement is not uncommon in any language, but especially the manual inlining surprised me. I guess it is a sign that the compiler team is - understandibly - focusing on other things than extracting the last bit of performance from C#. After all, who needs to regularly generate a billion PRNs using C#?</p><p><a
href='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/08/weirdperf.zip'>Download source for crude test program</a>.</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+C%23+is+not+%28yet%29+a+high+perf+language+-+http://bit.ly/ETCsu" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+C%23+is+not+%28yet%29+a+high+perf+language+-+http://bit.ly/ETCsu" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=HQHZ6a8ubms:axSXh1wt_Nc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=HQHZ6a8ubms:axSXh1wt_Nc:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/HQHZ6a8ubms" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/c-is-not-yet-a-high-perf-language/402.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/c-is-not-yet-a-high-perf-language/402.html</feedburner:origLink></item> <item><title>Optimizing heavy arithmetics in Mono</title><link>http://feedproxy.google.com/~r/dun3/~3/wxUuyKNy31A/394.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/optimizing-heavy-arithmetics-in-mono/394.html#comments</comments> <pubDate>Mon, 29 Jun 2009 18:38:33 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Operating System]]></category> <category><![CDATA[Optimizations]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=394</guid> <description><![CDATA[Sowhat as a tribute to this rather foolish letter.
---
This will be an article about how I optimized the md5 algorithm in Mono and the Microsoft .NET Framework. I haven't completed it yet, but there is quite a bit about optimization in my blog. Check out all the mentions of md5 in my blog for [...]]]></description> <content:encoded><![CDATA[<p>Sowhat as a tribute to this rather foolish <a
href="http://www.fsf.org/news/dont-depend-on-mono" rel="nofollow">letter</a>.</p><p>---</p><p>This will be an article about how I optimized the md5 algorithm in Mono and the Microsoft .NET Framework. I haven't completed it yet, but there is quite a bit about optimization in my blog. Check out all the mentions of <a
href="http://saftsack.fs.uni-bayreuth.de/~dun3/search/md5"><strong>md5 in my blog</strong></a> for some pointers.</p><p>If you need my work on this right now, raw and unpolished - please feel free to email me at tobias at hertkorn dot com. Or to get some hand-on example, go to my post about the <a
href="http://saftsack.fs.uni-bayreuth.de/~dun3/archives/optimized-md5cryptoserviceprovider-mono/41.html" target="_blank">optimized Md5CryptoServiceProvider in mono</a>.</p><h3>Optimizing the md5 algo on little endian machines</h3><p>This decoding step is a major part within the md5 algo. It translates a 64 byte array into a 16 uint array. The general endian-safe step looks like this:</p><div
class="igBar"><span
id="lcsharp-25"><a
href="#" onclick="javascript:showCodeTxt('csharp-25'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-25"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">for</span> <span
class="br0">&#40;</span>i = <span
class="nu0">0</span>; i &lt;<span
class="nu0">16</span>; i++<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; buff<span
class="br0">&#91;</span>i<span
class="br0">&#93;</span> = <span
class="br0">&#40;</span><span
class="kw4">uint</span><span
class="br0">&#41;</span><span
class="br0">&#40;</span>inputBuffer<span
class="br0">&#91;</span>inputOffset + <span
class="nu0">4</span> * i<span
class="br0">&#93;</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; | <span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="kw4">uint</span><span
class="br0">&#41;</span><span
class="br0">&#40;</span>inputBuffer<span
class="br0">&#91;</span>inputOffset + <span
class="nu0">4</span> * i + <span
class="nu0">1</span><span
class="br0">&#93;</span><span
class="br0">&#41;</span><span
class="br0">&#41;</span> &lt;&lt;<span
class="nu0">8</span> <span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; | <span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="kw4">uint</span><span
class="br0">&#41;</span><span
class="br0">&#40;</span>inputBuffer<span
class="br0">&#91;</span>inputOffset + <span
class="nu0">4</span> * i + <span
class="nu0">2</span><span
class="br0">&#93;</span><span
class="br0">&#41;</span><span
class="br0">&#41;</span> &lt;&lt;<span
class="nu0">16</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; | <span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="kw4">uint</span><span
class="br0">&#41;</span><span
class="br0">&#40;</span>inputBuffer<span
class="br0">&#91;</span>inputOffset + <span
class="nu0">4</span> * i + <span
class="nu0">3</span><span
class="br0">&#93;</span><span
class="br0">&#41;</span><span
class="br0">&#41;</span> &lt;&lt;<span
class="nu0">24</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>If this step is performed on a little endian machine, the bytes are already safed in memory in the right order and there is no need for all the bitlogic. Therefore optimizing it using unsafe code and direct copying 4 consecutive bytes as one uint gives a huge speed increase:</p><div
class="igBar"><span
id="lcsharp-26"><a
href="#" onclick="javascript:showCodeTxt('csharp-26'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-26"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">unsafe</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="kw1">fixed</span> <span
class="br0">&#40;</span><span
class="kw4">byte</span>* bFixed = inputBuffer<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw4">byte</span>* inputPointer = bFixed + inputOffset;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">for</span> <span
class="br0">&#40;</span>i = <span
class="nu0">0</span>; i &lt;<span
class="nu0">16</span>; i++<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; buff<span
class="br0">&#91;</span>i<span
class="br0">&#93;</span> = *<span
class="br0">&#40;</span><span
class="kw4">uint</span>*<span
class="br0">&#41;</span><span
class="br0">&#40;</span>inputPointer<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; inputPointer += <span
class="nu0">4</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>As we are already in unsafe context using an additional pointer for buff gives an additional speed increase:</p><div
class="igBar"><span
id="lcsharp-27"><a
href="#" onclick="javascript:showCodeTxt('csharp-27'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-27"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">unsafe</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="kw1">fixed</span> <span
class="br0">&#40;</span><span
class="kw4">byte</span>* bFixed = inputBuffer<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="kw1">fixed</span> <span
class="br0">&#40;</span><span
class="kw4">uint</span>* aFixed = buff<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="kw4">byte</span>* inputPointer = bFixed + inputOffset;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="kw4">uint</span>* bufferPointer = aFixed;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="kw1">for</span> <span
class="br0">&#40;</span>i = <span
class="nu0">0</span>; i &lt;<span
class="nu0">16</span>; i++<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; *bufferPointer = *<span
class="br0">&#40;</span><span
class="kw4">uint</span>*<span
class="br0">&#41;</span><span
class="br0">&#40;</span>inputPointer<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; inputPointer += <span
class="nu0">4</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; bufferPointer++;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>Be sure to still make this Md5 implementation endian safe by introducing a if:</p><div
class="igBar"><span
id="lcsharp-28"><a
href="#" onclick="javascript:showCodeTxt('csharp-28'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-28"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">if</span> <span
class="br0">&#40;</span>BitConverter.<span
class="me1">IsLittleEndian</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="co1">// unsafe decode</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1"><span
class="kw1">else</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="co1">// bitshifting decode</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><h3>Avoiding unnecessary stloc and ldloc ops</h3><p>If possible do as much arithmetic as possible in one go. For example:</p><div
class="igBar"><span
id="lcsharp-29"><a
href="#" onclick="javascript:showCodeTxt('csharp-29'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-29"><div
class="csharp"><ol><li
class="li1"><div
class="de1">b += <span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="br0">&#40;</span>d ^ a<span
class="br0">&#41;</span> &amp; c<span
class="br0">&#41;</span> ^ a<span
class="br0">&#41;</span> + <span
class="br0">&#40;</span><span
class="kw4">uint</span><span
class="br0">&#41;</span>K<span
class="br0">&#91;</span><span
class="nu0">7</span><span
class="br0">&#93;</span> + buff<span
class="br0">&#91;</span><span
class="nu0">7</span><span
class="br0">&#93;</span>;</div></li><li
class="li2"><div
class="de2">b = <span
class="br0">&#40;</span>b &lt;&lt;<span
class="nu0">22</span><span
class="br0">&#41;</span> | <span
class="br0">&#40;</span>b&gt;&gt; <span
class="nu0">10</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">b += c;</div></li></ol></div></div></div><p></p><p>This b += c is not smart to use in this situation and actually produces a performance hit. Better would be:</p><div
class="igBar"><span
id="lcsharp-30"><a
href="#" onclick="javascript:showCodeTxt('csharp-30'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-30"><div
class="csharp"><ol><li
class="li1"><div
class="de1">b += <span
class="br0">&#40;</span><span
class="br0">&#40;</span><span
class="br0">&#40;</span>d ^ a<span
class="br0">&#41;</span> &amp; c<span
class="br0">&#41;</span> ^ a<span
class="br0">&#41;</span> + <span
class="br0">&#40;</span><span
class="kw4">uint</span><span
class="br0">&#41;</span>K<span
class="br0">&#91;</span><span
class="nu0">7</span><span
class="br0">&#93;</span> + buff<span
class="br0">&#91;</span><span
class="nu0">7</span><span
class="br0">&#93;</span>;</div></li><li
class="li2"><div
class="de2">b = <span
class="br0">&#40;</span><span
class="br0">&#40;</span>b &lt;&lt;<span
class="nu0">22</span><span
class="br0">&#41;</span> | <span
class="br0">&#40;</span>b&gt;&gt; <span
class="nu0">10</span><span
class="br0">&#41;</span><span
class="br0">&#41;</span> + c;</div></li></ol></div></div></div><p></p><p>Altering the whole segment like this in the md5 algorithm adds up to a 10-15% performance increase!</p><p>Let's look at the IL:</p><div
class="igBar"><span
id="lil-31"><a
href="#" onclick="javascript:showCodeTxt('il-31'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">IL:</span><div
id="il-31"><div
class="il"><ol><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">1</span></div></li><li
class="li2"><div
class="de2">ldloc.<span
class="nu0">3</span></div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">0</span></div></li><li
class="li2"><div
class="de2">xor</div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">2</span></div></li><li
class="li2"><div
class="de2">and</div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">0</span></div></li><li
class="li2"><div
class="de2">xor</div></li><li
class="li1"><div
class="de1">ldsfld unsigned int32<span
class="br0">&#91;</span><span
class="br0">&#93;</span> MD5CryptoServiceProviderMonoOrig::<span
class="me2">K</span></div></li><li
class="li2"><div
class="de2">ldc.<span
class="me1">i4</span>.<span
class="nu0">7</span></div></li><li
class="li1"><div
class="de1">ldelem.<span
class="me1">u4</span></div></li><li
class="li2"><div
class="de2">add</div></li><li
class="li1"><div
class="de1">ldarg.<span
class="nu0">0</span></div></li><li
class="li2"><div
class="de2">ldfld unsigned int32<span
class="br0">&#91;</span><span
class="br0">&#93;</span> MD5CryptoServiceProviderMonoOrig::<span
class="me2">buff</span></div></li><li
class="li1"><div
class="de1">ldc.<span
class="me1">i4</span>.<span
class="nu0">7</span></div></li><li
class="li2"><div
class="de2">ldelem.<span
class="me1">u4</span></div></li><li
class="li1"><div
class="de1">add</div></li><li
class="li2"><div
class="de2">add</div></li><li
class="li1"><div
class="de1">stloc.<span
class="nu0">1</span></div></li><li
class="li2"><div
class="de2">ldloc.<span
class="nu0">1</span></div></li><li
class="li1"><div
class="de1">ldc.<span
class="me1">i4</span>.<span
class="me1">s</span> <span
class="nu0">22</span></div></li><li
class="li2"><div
class="de2">shl</div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">1</span></div></li><li
class="li2"><div
class="de2">ldc.<span
class="me1">i4</span>.<span
class="me1">s</span> <span
class="nu0">10</span></div></li><li
class="li1"><div
class="de1">shr.<span
class="me1">un</span></div></li><li
class="li2"><div
class="de2">or</div></li><li
class="li1"><div
class="de1">stloc.<span
class="nu0">1</span>&nbsp; <span
class="co1">// stores b</span></div></li><li
class="li2"><div
class="de2">ldloc.<span
class="nu0">1</span>&nbsp; <span
class="co1">// loads b</span></div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">2</span></div></li><li
class="li2"><div
class="de2">add</div></li><li
class="li1"><div
class="de1">stloc.<span
class="nu0">1</span></div></li></ol></div></div></div><p></p><p>the second version's:</p><div
class="igBar"><span
id="lil-32"><a
href="#" onclick="javascript:showCodeTxt('il-32'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">IL:</span><div
id="il-32"><div
class="il"><ol><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">1</span></div></li><li
class="li2"><div
class="de2">ldloc.<span
class="nu0">3</span></div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">0</span></div></li><li
class="li2"><div
class="de2">xor</div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">2</span></div></li><li
class="li2"><div
class="de2">and</div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">0</span></div></li><li
class="li2"><div
class="de2">xor</div></li><li
class="li1"><div
class="de1">ldsfld unsigned int32<span
class="br0">&#91;</span><span
class="br0">&#93;</span> MD5AddOptimization3::<span
class="me2">K</span></div></li><li
class="li2"><div
class="de2">ldc.<span
class="me1">i4</span>.<span
class="nu0">7</span></div></li><li
class="li1"><div
class="de1">ldelem.<span
class="me1">u4</span></div></li><li
class="li2"><div
class="de2">add</div></li><li
class="li1"><div
class="de1">ldarg.<span
class="nu0">0</span></div></li><li
class="li2"><div
class="de2">ldfld unsigned int32<span
class="br0">&#91;</span><span
class="br0">&#93;</span> MD5AddOptimization3::<span
class="me2">buff</span></div></li><li
class="li1"><div
class="de1">ldc.<span
class="me1">i4</span>.<span
class="nu0">7</span></div></li><li
class="li2"><div
class="de2">ldelem.<span
class="me1">u4</span></div></li><li
class="li1"><div
class="de1">add</div></li><li
class="li2"><div
class="de2">add</div></li><li
class="li1"><div
class="de1">stloc.<span
class="nu0">1</span></div></li><li
class="li2"><div
class="de2">ldloc.<span
class="nu0">1</span></div></li><li
class="li1"><div
class="de1">ldc.<span
class="me1">i4</span>.<span
class="me1">s</span> <span
class="nu0">22</span></div></li><li
class="li2"><div
class="de2">shl</div></li><li
class="li1"><div
class="de1">ldloc.<span
class="nu0">1</span></div></li><li
class="li2"><div
class="de2">ldc.<span
class="me1">i4</span>.<span
class="me1">s</span> <span
class="nu0">10</span></div></li><li
class="li1"><div
class="de1">shr.<span
class="me1">un</span></div></li><li
class="li2"><div
class="de2">or</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
class="co1">// store, load eliminated</span></div></li><li
class="li2"><div
class="de2">ldloc.<span
class="nu0">2</span></div></li><li
class="li1"><div
class="de1">add</div></li><li
class="li2"><div
class="de2">stloc.<span
class="nu0">1</span></div></li></ol></div></div></div><p></p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Optimizing+heavy+arithmetics+in+Mono+-+http://bit.ly/P6AYV" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Optimizing+heavy+arithmetics+in+Mono+-+http://bit.ly/P6AYV" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=wxUuyKNy31A:475QdgzPK3M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=wxUuyKNy31A:475QdgzPK3M:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/wxUuyKNy31A" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/optimizing-heavy-arithmetics-in-mono/394.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/optimizing-heavy-arithmetics-in-mono/394.html</feedburner:origLink></item> <item><title>Version 1.2.1 of Hg Commit Monitor released</title><link>http://feedproxy.google.com/~r/dun3/~3/Zxl5fzSPV5U/387.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/version-121-of-hg-commit-monitor-released/387.html#comments</comments> <pubDate>Sun, 28 Jun 2009 23:32:32 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=387</guid> <description><![CDATA[Just finished a new version of Hg Commit Monitor. This version now includes ssh support, additional error handling and prevents a bug in the atom exporter of hgweb from influencing the updates. Enjoy.
Please leave a comment if I should follow Richard Stallman's plea to drop C# for Hg Commit Monitor - and rewrite the whole [...]]]></description> <content:encoded><![CDATA[<p>Just finished a new version of <a
href="http://saftsack.fs.uni-bayreuth.de/~dun3/hg-commit-monitor">Hg Commit Monitor</a>. This version now includes ssh support, additional error handling and prevents a bug in the atom exporter of hgweb from influencing the updates. Enjoy.</p><p>Please leave a comment if I should follow <a
href="http://www.fsf.org/news/dont-depend-on-mono" rel="nofollow">Richard Stallman's plea</a> to drop C# for Hg Commit Monitor - and rewrite the whole thing in say ... vb?</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Version+1.2.1+of+Hg+Commit+Monitor+released+-+http://bit.ly/LEuQU" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Version+1.2.1+of+Hg+Commit+Monitor+released+-+http://bit.ly/LEuQU" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=Zxl5fzSPV5U:xb6TqJa1Gyo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=Zxl5fzSPV5U:xb6TqJa1Gyo:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/Zxl5fzSPV5U" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/version-121-of-hg-commit-monitor-released/387.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/version-121-of-hg-commit-monitor-released/387.html</feedburner:origLink></item> <item><title>Stylishly improving Silverlight Toolkit Chart’s Performance</title><link>http://feedproxy.google.com/~r/dun3/~3/k-oC5uila-k/367.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/improving-silverlight-toolkit-chart-performance-style-template/367.html#comments</comments> <pubDate>Fri, 26 Jun 2009 22:13:16 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Optimizations]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Silverlight]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=367</guid> <description><![CDATA[TL;TR: Skip all the way down and download the complete style without "Show" storyboard for the Silverlight Toolkit March 2009 release.
I am currently looking at a couple of Silverlight features and extensions. And what's about the first thing one wants to see - GRAPHS. Well, that's me at least - maybe my background in Physics [...]]]></description> <content:encoded><![CDATA[<p><em>TL;TR: Skip all the way down and download the complete style without "Show" storyboard for the Silverlight Toolkit March 2009 release.</em></p><p>I am currently looking at a couple of Silverlight features and extensions. And what's about the first thing one wants to see - GRAPHS. Well, that's me at least - maybe my background in Physics does push me in weird ways <del
datetime="2009-06-26T21:29:43+00:00">most of the times</del> sometimes...</p><p>What I found was that the performance of the charts is not that great - when going to more than a couple datapoints ... to say like 1000?! <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> Oh, and of course those datapoints should change all the time, right? Turns out that does kinda have some impact on performance - since every single datapoint has an animation attached to it when it gets shown or hidden.</p><p>I am a total noob when it comes to XAML in general and Silverlight in particular - so it was a huge break-through for me to find out that one can change the style of existing controls. Yeah I know. Knocked me out though. So I got the trial of Expressoin Blend 2, did all the steps that were necessary to get to the templates. And found out that now all my datapoints where bright orange. Umm, that's not fun.</p><p>So after a bit more of fumbling around I found out that it's all very easy - when one knows how to do it... I know this is one of the "aha, actually he is not that bright" kinda revelation blog posts. <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> Aaaanyway.</p><p>The new template for a datapoint (in this particular case a LineDataPoint for LineSeries) that has no fade in translation looks like this:</p><div
class="igBar"><span
id="lxml-36"><a
href="#" onclick="javascript:showCodeTxt('xml-36'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">XML:</span><div
id="xml-36"><div
class="xml"><ol><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;ControlTemplate</span> <span
class="re0">TargetType</span>=<span
class="st0">'charting:LineDataPoint'</span> x:<span
class="re0">Key</span>=<span
class="st0">'LineNoTransition'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="sc3"><span
class="re1">&lt;Grid</span> <span
class="re0">Opacity</span>=<span
class="st0">'1'</span> x:<span
class="re0">Name</span>=<span
class="st0">'Root'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualStateManager.VisualStateGroups<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualStateGroup x:<span
class="re0">Name</span>=<span
class="st0">'CommonStates'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualStateGroup.Transitions<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualTransition <span
class="re0">GeneratedDuration</span>=<span
class="st0">'0:0:0.1'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualStateGroup.Transitions<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualState x:<span
class="re0">Name</span>=<span
class="st0">'Normal'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualState x:<span
class="re0">Name</span>=<span
class="st0">'MouseOver'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Storyboard<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;ColorAnimationUsingKeyFrames</span> <span
class="re0">BeginTime</span>=<span
class="st0">'00:00:00'</span> <span
class="re0">Duration</span>=<span
class="st0">'00:00:00.0010000'</span> Storyboard.<span
class="re0">TargetName</span>=<span
class="st0">'MouseOverHighlight'</span> Storyboard.<span
class="re0">TargetProperty</span>=<span
class="st0">'(Shape.Fill).(SolidColorBrush.Color)'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;SplineColorKeyFrame</span> <span
class="re0">KeyTime</span>=<span
class="st0">'00:00:00'</span> <span
class="re0">Value</span>=<span
class="st0">'#FFFFDF00'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/ColorAnimationUsingKeyFrames<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;DoubleAnimationUsingKeyFrames</span> <span
class="re0">BeginTime</span>=<span
class="st0">'00:00:00'</span> <span
class="re0">Duration</span>=<span
class="st0">'00:00:00.0010000'</span> Storyboard.<span
class="re0">TargetName</span>=<span
class="st0">'MouseOverHighlight'</span> Storyboard.<span
class="re0">TargetProperty</span>=<span
class="st0">'(UIElement.Opacity)'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;SplineDoubleKeyFrame</span> <span
class="re0">KeyTime</span>=<span
class="st0">'00:00:00'</span> <span
class="re0">Value</span>=<span
class="st0">'0.24'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/DoubleAnimationUsingKeyFrames<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/Storyboard<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualState<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualStateGroup<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualStateGroup x:<span
class="re0">Name</span>=<span
class="st0">'SelectionStates'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualStateGroup.Transitions<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualTransition <span
class="re0">GeneratedDuration</span>=<span
class="st0">'0:0:0.1'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualStateGroup.Transitions<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualState x:<span
class="re0">Name</span>=<span
class="st0">'Unselected'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualState x:<span
class="re0">Name</span>=<span
class="st0">'Selected'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Storyboard<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;DoubleAnimationUsingKeyFrames</span> <span
class="re0">BeginTime</span>=<span
class="st0">'00:00:00'</span> <span
class="re0">Duration</span>=<span
class="st0">'00:00:00.0010000'</span> Storyboard.<span
class="re0">TargetName</span>=<span
class="st0">'SelectionHighlight'</span> Storyboard.<span
class="re0">TargetProperty</span>=<span
class="st0">'(UIElement.Opacity)'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;SplineDoubleKeyFrame</span> <span
class="re0">KeyTime</span>=<span
class="st0">'00:00:00'</span> <span
class="re0">Value</span>=<span
class="st0">'0.18'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/DoubleAnimationUsingKeyFrames<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/Storyboard<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualState<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualStateGroup<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualStateGroup x:<span
class="re0">Name</span>=<span
class="st0">'RevealStates'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualState x:<span
class="re0">Name</span>=<span
class="st0">'Shown'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;vsm</span>:VisualState x:<span
class="re0">Name</span>=<span
class="st0">'Hidden'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualStateGroup<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/vsm</span>:VisualStateManager.VisualStateGroups<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;ToolTipService</span>.ToolTip<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;ContentControl</span> <span
class="re0">Content</span>=<span
class="st0">'{TemplateBinding FormattedDependentValue}'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/ToolTipService</span>.ToolTip<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Ellipse</span> <span
class="re0">Fill</span>=<span
class="st0">'{TemplateBinding Background}'</span> <span
class="re0">Stroke</span>=<span
class="st0">'{TemplateBinding BorderBrush}'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Ellipse</span> <span
class="re0">RenderTransformOrigin</span>=<span
class="st0">'0.661,0.321'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Ellipse</span>.Fill<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;RadialGradientBrush</span> <span
class="re0">GradientOrigin</span>=<span
class="st0">'0.681,0.308'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;GradientStop</span> <span
class="re0">Color</span>=<span
class="st0">'#00FFFFFF'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;GradientStop</span> <span
class="re0">Color</span>=<span
class="st0">'#FF3D3A3A'</span> <span
class="re0">Offset</span>=<span
class="st0">'1'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/RadialGradientBrush<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/Ellipse</span>.Fill<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/Ellipse<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Ellipse</span> <span
class="re0">Fill</span>=<span
class="st0">'Red'</span> <span
class="re0">Opacity</span>=<span
class="st0">'0'</span> x:<span
class="re0">Name</span>=<span
class="st0">'SelectionHighlight'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Ellipse</span> <span
class="re0">Fill</span>=<span
class="st0">'White'</span> <span
class="re0">Opacity</span>=<span
class="st0">'0'</span> x:<span
class="re0">Name</span>=<span
class="st0">'MouseOverHighlight'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="sc3"><span
class="re1">&lt;/Grid<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;/ControlTemplate<span
class="re2">&gt;</span></span></span></div></li></ol></div></div></div><p></p><p>Notice that I set the opacity of the "Root" grid to 1 (it is 0 in the original style) and removed all storyboards from the "Shown" and "Hidden" VisualStates. So now we have a ControlTemplate that shows the datapoint right away (opaycity to 1) and does not need any additional CPU cycles for animations (no storyboards).</p><p>In order to be able to attach these animation-less templates to the respective data series we need an additional template:</p><div
class="igBar"><span
id="lxml-37"><a
href="#" onclick="javascript:showCodeTxt('xml-37'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">XML:</span><div
id="xml-37"><div
class="xml"><ol><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;Style</span> <span
class="re0">TargetType</span>=<span
class="st0">'charting:LineDataPoint'</span> x:<span
class="re0">Key</span>=<span
class="st0">'LineDataPointStyleBlue'</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'Background'</span><span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span>.Value<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;RadialGradientBrush<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;RadialGradientBrush</span>.RelativeTransform<span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;TransformGroup<span
class="re2">&gt;</span></span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;ScaleTransform</span> <span
class="re0">CenterX</span>=<span
class="st0">'0.5'</span> <span
class="re0">CenterY</span>=<span
class="st0">'0.5'</span> <span
class="re0">ScaleX</span>=<span
class="st0">'2.09'</span> <span
class="re0">ScaleY</span>=<span
class="st0">'1.819'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;TranslateTransform</span> <span
class="re0">X</span>=<span
class="st0">'-0.425'</span> <span
class="re0">Y</span>=<span
class="st0">'-0.486'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/TransformGroup<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/RadialGradientBrush</span>.RelativeTransform<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;GradientStop</span> <span
class="re0">Color</span>=<span
class="st0">'#FFB9D6F7'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;GradientStop</span> <span
class="re0">Color</span>=<span
class="st0">'#FF284B70'</span> <span
class="re0">Offset</span>=<span
class="st0">'1'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/RadialGradientBrush<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="sc3"><span
class="re1">&lt;/Setter</span>.Value<span
class="re2">&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="sc3"><span
class="re1">&lt;/Setter<span
class="re2">&gt;</span></span></span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'BorderBrush'</span> <span
class="re0">Value</span>=<span
class="st0">'Gray'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'BorderThickness'</span> <span
class="re0">Value</span>=<span
class="st0">'1'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'IsTabStop'</span> <span
class="re0">Value</span>=<span
class="st0">'False'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'Width'</span> <span
class="re0">Value</span>=<span
class="st0">'8'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'Height'</span> <span
class="re0">Value</span>=<span
class="st0">'8'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="sc3"><span
class="re1">&lt;Setter</span> <span
class="re0">Property</span>=<span
class="st0">'Template'</span> <span
class="re0">Value</span>=<span
class="st0">'{StaticResource LineNoTransition}'</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2"><span
class="sc3"><span
class="re1">&lt;/Style<span
class="re2">&gt;</span></span></span></div></li></ol></div></div></div><p></p><p>Notice that I went to the source of the chart library and copied the original style for "Background" getting rid of the hideous "orange". Plus notice the Value for the Template that points to our new animation-less template.</p><p>Last but not least attach the new dataline template to the chart:</p><div
class="igBar"><span
id="lxml-38"><a
href="#" onclick="javascript:showCodeTxt('xml-38'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">XML:</span><div
id="xml-38"><div
class="xml"><ol><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;charting</span>:Chart x:<span
class="re0">Name</span>=<span
class="st0">"Performance"</span><span
class="re2">&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp;<span
class="sc3"><span
class="re1">&lt;charting</span>:LineSeries</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; x:<span
class="re0">Name</span>=<span
class="st0">"SleepTimez"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">ItemsSource</span>=<span
class="st0">"{Binding Path=Performance.SleepTimez}"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">Title</span>=<span
class="st0">"T"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">DependentValuePath</span>=<span
class="st0">"Count"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">IndependentValuePath</span>=<span
class="st0">"Time"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">DataPointStyle</span>=<span
class="st0">"{StaticResource LineDataPointStyleBlue}"</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp;<span
class="sc3"><span
class="re1">&lt;charting</span>:LineSeries</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; x:<span
class="re0">Name</span>=<span
class="st0">"ListSleepTimez"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">ItemsSource</span>=<span
class="st0">"{Binding Path=Performance.ListSleepTimez}"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">Title</span>=<span
class="st0">"LT"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">DependentValuePath</span>=<span
class="st0">"Count"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">IndependentValuePath</span>=<span
class="st0">"Time"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">DataPointStyle</span>=<span
class="st0">"{StaticResource LineDataPointStyleRed}"</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp;<span
class="sc3"><span
class="re1">&lt;charting</span>:LineSeries</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; x:<span
class="re0">Name</span>=<span
class="st0">"ChartSleepTimez"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">ItemsSource</span>=<span
class="st0">"{Binding Path=Performance.ChartSleepTimez}"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">Title</span>=<span
class="st0">"CT"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">DependentValuePath</span>=<span
class="st0">"Count"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="re0">IndependentValuePath</span>=<span
class="st0">"Time"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; <span
class="re0">DataPointStyle</span>=<span
class="st0">"{StaticResource LineDataPointStyleLightGreen}"</span> <span
class="re2">/&gt;</span></span></div></li><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;/charting</span>:Chart<span
class="re2">&gt;</span></span></div></li></ol></div></div></div><p></p><p>And that's pretty much it. Unfortunatelly I was not able to make the style palette work again - so right now I have to manually choose and attach colors to the various data series. But that's good enough for me right now.</p><p>I have not figured out yet how to remove the "hide" transition. It seems as if the removal of datapoints from a graph still trigger an animation, but I don't know why. Any hints?</p><p>Download: <a
href='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/06/linedatapointstyle.txt'>Complete LineDataPoint style</a></p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Stylishly+improving+Silverlight+Toolkit+Chart%27s+Performance+-+http://bit.ly/Az9CQ" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Stylishly+improving+Silverlight+Toolkit+Chart%27s+Performance+-+http://bit.ly/Az9CQ" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=k-oC5uila-k:NH_1P7G-BbM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=k-oC5uila-k:NH_1P7G-BbM:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/k-oC5uila-k" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/improving-silverlight-toolkit-chart-performance-style-template/367.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/improving-silverlight-toolkit-chart-performance-style-template/367.html</feedburner:origLink></item> <item><title>Falling into the deep hole of Constructor Autodiscovery</title><link>http://feedproxy.google.com/~r/dun3/~3/uQHjRk7IFC0/364.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/unity-constructor-autodiscovery-default-registertype/364.html#comments</comments> <pubDate>Wed, 24 Jun 2009 16:14:46 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=364</guid> <description><![CDATA[I am using Unity right now do some IoC. All I wanted to do is get an instance of the WCF Client that was auto-generated for me. So naively I thought this would be enough:
PLAIN TEXT
C#:m_container.RegisterType&#60;IService, ServiceClient&#62;&#40;&#41;;But that greeted me with a kinda weird error message:
Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Test.ServiceReference.ServiceClient, [...]]]></description> <content:encoded><![CDATA[<p>I am using Unity right now do some IoC. All I wanted to do is get an instance of the WCF Client that was auto-generated for me. So naively I thought this would be enough:</p><div
class="igBar"><span
id="lcsharp-41"><a
href="#" onclick="javascript:showCodeTxt('csharp-41'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-41"><div
class="csharp"><ol><li
class="li1"><div
class="de1">m_container.<span
class="me1">RegisterType</span>&lt;IService, ServiceClient&gt;<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>But that greeted me with a kinda weird error message:</p><p><code>Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Test.ServiceReference.ServiceClient, null]) failed: The current build operation (build key Build Key[Test.ServiceReference.ServiceClient, null]) failed: The type ServiceClient has multiple constructors of length 2. Unable to disambiguate. (Strategy type DynamicMethodConstructorStrategy, index 0) (Strategy type BuildPlanStrategy, index 3) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Test.ServiceReference.ServiceClient, null]) failed: The type ServiceClient has multiple constructors of length 2. Unable to disambiguate. (Strategy type DynamicMethodConstructorStrategy, index 0) ---> System.InvalidOperationException: The type ServiceClient has multiple constructors of length 2. Unable to disambiguate.<br
/> bei Microsoft.Practices.ObjectBuilder2.ConstructorSelectorPolicyBase`1.FindLongestConstructor(Type typeToConstruct)<br
/> bei Microsoft.Practices.ObjectBuilder2.ConstructorSelectorPolicyBase`1.SelectConstructor(IBuilderContext context)<br
/> bei Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)<br
/> bei Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)<br
/> --- Ende der internen Ausnahmestapelüberwachung ---<br
/> bei Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)<br
/> bei Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, Object buildKey)<br
/> bei Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)<br
/> bei Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)<br
/> --- Ende der internen Ausnahmestapelüberwachung ---<br
/> bei Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)<br
/> bei Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)<br
/> bei BuildUp_Test.ServiceReference.ServiceClient(IBuilderContext )</code></p><p>Turns out: I am used to Windsor Castle... Apparently Unity thinks of itself high enough to decide what it can and can't construct. Meaning - instead of using the constructor it could satisfy with all the types I registered (in other words the default constructor since I did not register anything else) it went straight for the longest constructor it could find - and got rightfully confused since there are multiple in any service client of length two.</p><p>Well, after a bit of soul searching I came up with this solution: "Specify the type of constructor I want Unity to use"</p><div
class="igBar"><span
id="lcsharp-42"><a
href="#" onclick="javascript:showCodeTxt('csharp-42'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-42"><div
class="csharp"><ol><li
class="li1"><div
class="de1">m_container.<span
class="me1">RegisterType</span>&lt;IService, ServiceClient&gt;<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span
class="me1">Configure</span>&lt;InjectedMembers&gt;<span
class="br0">&#40;</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span
class="me1">ConfigureInjectionFor</span>&lt;ServiceClient&gt;<span
class="br0">&#40;</span><a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> InjectionConstructor<span
class="br0">&#40;</span><span
class="br0">&#41;</span><span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>Now the default constructor is used when resolving IService to ServiceClient. (Note that the constructor of InjectionConstructor has no parameters...)</p><p>Still think that the Constructor discovery process of Unity is straight brain-dead. But now it works...</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Falling+into+the+deep+hole+of+Constructor+Autodiscovery+-+http://bit.ly/3FO8Go" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Falling+into+the+deep+hole+of+Constructor+Autodiscovery+-+http://bit.ly/3FO8Go" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=uQHjRk7IFC0:xAmr9DKHcaA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=uQHjRk7IFC0:xAmr9DKHcaA:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/uQHjRk7IFC0" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/unity-constructor-autodiscovery-default-registertype/364.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/unity-constructor-autodiscovery-default-registertype/364.html</feedburner:origLink></item> <item><title>Silverlight, TextBox, TwoWay Binding and the TextChanged event</title><link>http://feedproxy.google.com/~r/dun3/~3/m2ypKB7iCVs/359.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/silverlight-textbox-twoway-binding-textchanged-lostfocus-event-updatesourcetrigger/359.html#comments</comments> <pubDate>Mon, 22 Jun 2009 16:37:47 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Silverlight]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=359</guid> <description><![CDATA[Unfortunatelly Silverlight does not allow to set a UpdateSourceTrigger on the Binding. Therefore when using a TextBox the value of a twoway bound property only changes after the textbox looses the focus.
PLAIN TEXT
XML:&#60;TextBox x:Name="Description"&#160; &#160; Text="{Binding Path=Description, Mode=TwoWay}" /&#62;This is not the kind of behavior I was looking for when I designed [...]]]></description> <content:encoded><![CDATA[<p>Unfortunatelly Silverlight does not allow to set a UpdateSourceTrigger on the Binding. Therefore when using a TextBox the value of a twoway bound property only changes after the textbox looses the focus.</p><div
class="igBar"><span
id="lxml-46"><a
href="#" onclick="javascript:showCodeTxt('xml-46'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">XML:</span><div
id="xml-46"><div
class="xml"><ol><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;TextBox</span> x:<span
class="re0">Name</span>=<span
class="st0">"Description"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="re0">Text</span>=<span
class="st0">"{Binding Path=Description, Mode=TwoWay}"</span> <span
class="re2">/&gt;</span></span></div></li></ol></div></div></div><p></p><p>This is not the kind of behavior I was looking for when I designed a small tool that should filter a list on the fly. Of course it should update the list on every key-stroke I make to get an immediate GUI response for our filtering.</p><p>On the web one only finds the "workaround" to manually make the control loose and gain focus on ever textchanged event. I think that is rather silly. Instead of using that workaround I used the following method:</p><ul><li>Switch to OneWay Binding</li><li>Manually set the property of my object in the TextChanged event</li></ul><p>The resulting XAML looks like this:</p><div
class="igBar"><span
id="lxml-47"><a
href="#" onclick="javascript:showCodeTxt('xml-47'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">XML:</span><div
id="xml-47"><div
class="xml"><ol><li
class="li1"><div
class="de1"><span
class="sc3"><span
class="re1">&lt;TextBox</span> x:<span
class="re0">Name</span>=<span
class="st0">"Description"</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="re0">Text</span>=<span
class="st0">"{Binding Path=Description, Mode=OneWay}"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="re0">TextChanged</span>=<span
class="st0">"Description_TextChanged"</span> <span
class="re2">/&gt;</span></span></div></li></ol></div></div></div><p></p><p>And the code-behind like this:</p><div
class="igBar"><span
id="lcsharp-48"><a
href="#" onclick="javascript:showCodeTxt('csharp-48'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-48"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">private</span> <span
class="kw1">void</span> Description_TextChanged<span
class="br0">&#40;</span><span
class="kw4">object</span> sender, TextChangedEventArgs e<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; Filter.<span
class="me1">Description</span> = <span
class="br0">&#40;</span><span
class="br0">&#40;</span>TextBox<span
class="br0">&#41;</span>sender<span
class="br0">&#41;</span>.<span
class="me1">Text</span>;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>It's that simple. <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Silverlight%2C+TextBox%2C+TwoWay+Binding+and+the+TextChanged+event+-+http://bit.ly/OPS1G" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Silverlight%2C+TextBox%2C+TwoWay+Binding+and+the+TextChanged+event+-+http://bit.ly/OPS1G" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=m2ypKB7iCVs:BSQbCOo27fk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=m2ypKB7iCVs:BSQbCOo27fk:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/m2ypKB7iCVs" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/silverlight-textbox-twoway-binding-textchanged-lostfocus-event-updatesourcetrigger/359.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/silverlight-textbox-twoway-binding-textchanged-lostfocus-event-updatesourcetrigger/359.html</feedburner:origLink></item> <item><title>The one and only reason Wolfram Alpha will fail: …</title><link>http://feedproxy.google.com/~r/dun3/~3/xbXU2qtgZZw/356.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/reason-wolfram-alpha-will-fail-ego-surfing-googling/356.html#comments</comments> <pubDate>Tue, 16 Jun 2009 18:49:00 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[Personal]]></category> <category><![CDATA[Random Thoughts]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=356</guid> <description><![CDATA[... Ego Surfing does not work!
That's all. No need to add anything further - I predict it to fail, because it does not return any meaningful results when I enter my name.
What about your name?
Tweet this]]></description> <content:encoded><![CDATA[<p>... Ego Surfing does not work!</p><p>That's all. No need to add anything further - I predict it to fail, because it does not return any meaningful results when I enter my name. <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>What about your name?</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+The+one+and+only+reason+Wolfram+Alpha+will+fail%3A+...+-+http://bit.ly/RPQ4I" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+The+one+and+only+reason+Wolfram+Alpha+will+fail%3A+...+-+http://bit.ly/RPQ4I" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=xbXU2qtgZZw:CLdtqkJo4mE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=xbXU2qtgZZw:CLdtqkJo4mE:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/xbXU2qtgZZw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/reason-wolfram-alpha-will-fail-ego-surfing-googling/356.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/reason-wolfram-alpha-will-fail-ego-surfing-googling/356.html</feedburner:origLink></item> <item><title>Hg Commit Monitor – Get notified of new pushs to Mercurial repositories</title><link>http://feedproxy.google.com/~r/dun3/~3/gP1HWElNiSk/336.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/hg-commit-monitor-notify-new-push-mercurial-repository/336.html#comments</comments> <pubDate>Wed, 03 Jun 2009 20:05:45 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[IT]]></category> <category><![CDATA[Mercurial]]></category> <category><![CDATA[Source Control]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=336</guid> <description><![CDATA[I didn't find any commit monitor for Mercurial repositories. I am currently working on a project with multiple people pushing to one repository - and of course I want to know as soon as possible when one of the others did commit new source code. That way we can resolve merge conflicts soon and get [...]]]></description> <content:encoded><![CDATA[<p>I didn't find any commit monitor for Mercurial repositories. I am currently working on a project with multiple people pushing to one repository - and of course I want to know as soon as possible when one of the others did commit new source code. That way we can resolve merge conflicts soon and get a nice code review loop going.</p><p>Hg Commit Monitor uses the atom feeds of repositories to detect new commits. It was quite important for me that it does get out of my way and sight - unless I need to be notified. So it will just sit in the tray and only communicate via balloons.</p><p>If you are interested in such a tool, you can download it from <a
href="http://saftsack.fs.uni-bayreuth.de/~dun3/hg-commit-monitor">here</a>. I did publish both a compiled version and a snapshot of the mercurial repository.</p><p>Currently Hg Commit Monitor needs .NET 3.5. But if you want to run it on mono, please contact me and I will replace the reference to System.ServiceModel.Syndication with a third party Atom parser.</p><div
id="attachment_316" class="wp-caption alignleft" style="width: 310px"><a
href="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/06/hg-cm-v101.png"><img
src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/06/hg-cm-v101-300x182.png" alt="Screenshot Main Window V. 1.0.1" title="Screenshot Main Window V. 1.0.1" width="300" height="182" class="size-medium wp-image-316" /></a><p
class="wp-caption-text">Screenshot Main Window V. 1.0.1</p></div><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Hg+Commit+Monitor+--+Get+notified+of+new+pushs+to+Mercurial+repositories+-+http://bit.ly/QV1rl" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Hg+Commit+Monitor+--+Get+notified+of+new+pushs+to+Mercurial+repositories+-+http://bit.ly/QV1rl" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=gP1HWElNiSk:lSMXmOBQZAs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=gP1HWElNiSk:lSMXmOBQZAs:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/gP1HWElNiSk" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/hg-commit-monitor-notify-new-push-mercurial-repository/336.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/hg-commit-monitor-notify-new-push-mercurial-repository/336.html</feedburner:origLink></item> <item><title>Ignoring https related AuthenticationException when using a WebClient</title><link>http://feedproxy.google.com/~r/dun3/~3/iTt6BtagVtE/307.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/ignoring-https-related-authenticationexception-when-using-a-webclient/307.html#comments</comments> <pubDate>Sun, 31 May 2009 14:43:43 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=307</guid> <description><![CDATA[I am currently working on a little pet project that scrapes and parses html pages for information. Nothing fancy, just a little tool that sits in my taskbar and informs me on changes on that URL.
In order to do that I issue an http request using the System.Net.WebClient class.
PLAIN TEXT
C#:public string GetPage&#40;Uri uri, string username, [...]]]></description> <content:encoded><![CDATA[<p>I am currently working on a little pet project that scrapes and parses html pages for information. Nothing fancy, just a little tool that sits in my taskbar and informs me on changes on that URL.</p><p>In order to do that I issue an http request using the System.Net.WebClient class.</p><div
class="igBar"><span
id="lcsharp-51"><a
href="#" onclick="javascript:showCodeTxt('csharp-51'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-51"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">string</span> GetPage<span
class="br0">&#40;</span>Uri uri, <span
class="kw4">string</span> username, <span
class="kw4">string</span> password<span
class="br0">&#41;</span> <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; WebClient wc = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> WebClient<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; wc.<span
class="me1">Credentials</span> = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> NetworkCredential<span
class="br0">&#40;</span>username, password<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="kw1">return</span> wc.<span
class="me1">DownloadString</span><span
class="br0">&#40;</span>uri<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>The page I want to crawl is secured by basic authentication. That's why I have to set the appropriate Credentials.</p><p>Recently I have switched from hosting the page under http to hosting it under https. As this is my private server I did not bother to request a signed ssl certificate. I just used a self signed one. Unfortunatelly this rendered my little tool unusable, since the WebClient started to throw:<br
/> <code><br
/> failed: System.Net.WebException : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.<br
/> ----> System.Security.Authentication.AuthenticationException : The remote certificate is invalid according to the validation procedure.<br
/> </code></p><p>That's of course due to my self signed certificate not being trusted. And it's a good thing that the .NET Framework does not ignore these kinds of errors. After all there could be a man in the middle attack going on. Fortunatelly the framework also allows us to specify that this check should be overridden. All we need to do is specify a custom certificate verification method by attaching a custom ServerCertificateValidationCallbackHandler to the ServicePointManager.</p><div
class="igBar"><span
id="lcsharp-52"><a
href="#" onclick="javascript:showCodeTxt('csharp-52'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-52"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw4">string</span> GetPage<span
class="br0">&#40;</span>Uri uri, <span
class="kw4">string</span> username, <span
class="kw4">string</span> password<span
class="br0">&#41;</span> <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; WebClient wc = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> WebClient<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp; wc.<span
class="me1">Credentials</span> = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> NetworkCredential<span
class="br0">&#40;</span>username, password<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="kw1">return</span> wc.<span
class="me1">DownloadString</span><span
class="br0">&#40;</span>uri<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1"><span
class="kw1">public</span> <span
class="kw1">static</span> <span
class="kw1">void</span> SetBypassSslCertificateValidation<span
class="br0">&#40;</span><span
class="br0">&#41;</span> <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; ServicePointManager.<span
class="me1">ServerCertificateValidationCallback</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; += <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> RemoteCertificateValidationCallback<span
class="br0">&#40;</span>BypassSslCertificateValidation<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2"><span
class="kw1">private</span> <span
class="kw1">static</span> <span
class="kw4">bool</span> BypassSslCertificateValidation<span
class="br0">&#40;</span><span
class="kw4">object</span> sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error<span
class="br0">&#41;</span> <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="kw1">return</span> <span
class="kw1">true</span>;</div></li><li
class="li2"><div
class="de2"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>Well, just don't do this stunt, when there actually is a security risk. <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Ignoring+https+related+AuthenticationException+when+using+a+WebClient+-+http://bit.ly/16Ryj0" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Ignoring+https+related+AuthenticationException+when+using+a+WebClient+-+http://bit.ly/16Ryj0" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=iTt6BtagVtE:Du_iwrd7BQI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=iTt6BtagVtE:Du_iwrd7BQI:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/iTt6BtagVtE" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/ignoring-https-related-authenticationexception-when-using-a-webclient/307.html/feed</wfw:commentRss> <slash:comments>5</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/ignoring-https-related-authenticationexception-when-using-a-webclient/307.html</feedburner:origLink></item> <item><title>x86-only software is … unfortunate</title><link>http://feedproxy.google.com/~r/dun3/~3/3baL86KkTtk/305.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/x86-only-software-is-unfortunate/305.html#comments</comments> <pubDate>Sun, 17 May 2009 09:55:23 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[IT]]></category> <category><![CDATA[Operating System]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=305</guid> <description><![CDATA[I guess one can get away with regular software only being x86 compatible. It is not too big a problem that e.g. firefox runs as 32 bit. Seriously, if any given website needs more than 2GB to render its content - there's something wrong with the website anyway. Unfortunately it's a totally different story for [...]]]></description> <content:encoded><![CDATA[<p>I guess one can get away with regular software only being x86 compatible. It is not too big a problem that e.g. firefox runs as 32 bit. Seriously, if any given website needs more than 2GB to render its content - there's something wrong with the website anyway. Unfortunately it's a totally different story for software that touches the hardware or explorer shell extensions.</p><p>One of the examples for a deeply embedded software would be the Cisco VPN Client. Right now I have to use a virtual winxp 32bit in order to connect to my office's VPN. WTF?</p><p>Unfortunately I ran across another program: The shell extension tortoiseHg only comes in 32bit. Hmm, what? It's a software that specifically targets programmers and development started in 2007. How could that possibly come in 32bit only?</p><p>It's 2009 for crying out loud. Not only is 4GB common amongst developer, 4GB is fast becoming "annoyingly little RAM".</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+x86-only+software+is+...+unfortunate+-+http://bit.ly/H5q8W" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+x86-only+software+is+...+unfortunate+-+http://bit.ly/H5q8W" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=3baL86KkTtk:1hGkKY9Yd88:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=3baL86KkTtk:1hGkKY9Yd88:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/3baL86KkTtk" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/x86-only-software-is-unfortunate/305.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/x86-only-software-is-unfortunate/305.html</feedburner:origLink></item> <item><title>Dabbling in Mercurial</title><link>http://feedproxy.google.com/~r/dun3/~3/LFbsclXkBiU/300.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/dabbling-in-mercurial/300.html#comments</comments> <pubDate>Sun, 17 May 2009 01:58:48 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[IT]]></category> <category><![CDATA[Mercurial]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Source Control]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=300</guid> <description><![CDATA[What can I tell you - I have been using git for a bit a while ago, and I really liked it ... in a pure linux environment. It was a bit awkward when using windows. So I went back to subversion when doing my .NET development.
But I really did miss the offline functionality that [...]]]></description> <content:encoded><![CDATA[<p>What can I tell you - I have been using git for a bit a while ago, and I really liked it ... in a pure linux environment. It was a bit awkward when using windows. So I went back to subversion when doing my .NET development.</p><p>But I really did miss the offline functionality that is one of the biggest advantages (in my eyes) of DSCMs. Listening to a stackoverflow podcast lately I heard Joel rave on about <a
href="http://www.selenic.com/mercurial/wiki/Mercurial" rel="nofollow">Mercurial</a>. So I thought I have to check it out myself - and I have to say, I am more than a bit impressed. I was able to set up a windows machine and a linux machine with hg within minutes. Creating a hg push repository using apache was a breeze as well. All with authentication.</p><p>When it comes to using hg: Even using the command line interface is a not too annoying. I went through update, pull, push, merge, ... I even simulated merge conflicts. Easy! And using the graphlog extension it is quite simple to view the logs and all the paths that lead to the current version. All in all, it seriously was not a bit of trouble. And I haven't even installed tortoiseHg yet... But that's for tomorrow.</p><p>Conclusion: I guess I do have to switch from svn to hg. There simply is no need to put it off anymore. Should I dare to ask my boss, if we could switch at work as well?!</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Dabbling+in+Mercurial+-+http://bit.ly/wALOj" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Dabbling+in+Mercurial+-+http://bit.ly/wALOj" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=LFbsclXkBiU:Dn6RXTuTdOI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=LFbsclXkBiU:Dn6RXTuTdOI:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/LFbsclXkBiU" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/dabbling-in-mercurial/300.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/dabbling-in-mercurial/300.html</feedburner:origLink></item> <item><title>Does Microsoft claim exclusiveness – what would YOU need TrueCrypt for anyways?</title><link>http://feedproxy.google.com/~r/dun3/~3/K1xx1oqbrG0/289.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/does-microsoft-claim-exclusiveness-what-would-you-need-truecrypt-for-anyways/289.html#comments</comments> <pubDate>Wed, 06 May 2009 07:55:21 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[IT]]></category> <category><![CDATA[Operating System]]></category> <category><![CDATA[Personal]]></category> <category><![CDATA[Windows]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=289</guid> <description><![CDATA[I heard only the best things about the Windows 7 beta - so, with the RC being released I did set aside a bit of time to do my backups (which is breeze when using TrueImage), get the necessary drivers for my system, ...
Now a little more infos about my system: I have one main [...]]]></description> <content:encoded><![CDATA[<p>I heard only the best things about the Windows 7 beta - so, with the RC being released I did set aside a bit of time to do my backups (which is breeze when using TrueImage), get the necessary drivers for my system, ...</p><p>Now a little more infos about my system: I have one main drive for the operating system and two additional drives that are 100% TrueCrypt volumes, one for my personal data and one for my backups.</p><p>Well, alright, we are already kinda used to Windows overwriting the MBR on a disk that was booting to linux before, we all know that - but did you know that the installer now initializes ALL drives in the system? Imagine my surprise when both my TrueCrypt partitions were SHOT! Apparently the Windows Installer found it appropriate to write a boot sector and a boot manager on <strong>all</strong> disks in my system. And a encrypted disk without its headers is ... just a blob of random data.</p><p><del
datetime="2009-05-06T07:34:36+00:00">To be fair, of course I used an unsupported software on a beta operating system. Who's to blame but me?</del></p><p><strong>BUT ANYWAY: W.T.F.!</strong></p><p>Conclusion: USB Disk FTW. Remove ALL TrueCrypt Disks. Not Developers, Developers, Developers - but Backups, Backups, Backups.</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Does+Microsoft+claim+exclusiveness+--+what+would+YOU+need+TrueCrypt+for+anyways%3F+-+http://bit.ly/Bg68N" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Does+Microsoft+claim+exclusiveness+--+what+would+YOU+need+TrueCrypt+for+anyways%3F+-+http://bit.ly/Bg68N" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=K1xx1oqbrG0:MV8kc6foNFU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=K1xx1oqbrG0:MV8kc6foNFU:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/K1xx1oqbrG0" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/does-microsoft-claim-exclusiveness-what-would-you-need-truecrypt-for-anyways/289.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/does-microsoft-claim-exclusiveness-what-would-you-need-truecrypt-for-anyways/289.html</feedburner:origLink></item> <item><title>Mapping the uncharted waters of LINQ</title><link>http://feedproxy.google.com/~r/dun3/~3/ABvwCDrAdAc/253.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/mapping-the-unchartered-waters-of-linq/253.html#comments</comments> <pubDate>Wed, 11 Mar 2009 01:48:28 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[LINQ]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=253</guid> <description><![CDATA[Preamble
Today I had a really interesting discussion with Jon Skeet on stackoverflow.
It got started by a question by me: When does a library deserve the be called “Linq-something” or “something-Linq”?
In it I kinda rant about libraries that have "Linq" in their name even though they do not provide extension methods for IQueryable and IEnumerable but [...]]]></description> <content:encoded><![CDATA[<h4>Preamble</h4><p>Today I had a <a
href="http://stackoverflow.com/questions/629411/when-does-a-library-deserve-the-be-called-linq-something-or-something-linq/629428#629428" rel="nofollow">really interesting discussion</a> with <a
href="http://stackoverflow.com/users/22656/jon-skeet" rel="nofollow">Jon Skeet</a> on <a
href="http://stackoverflow.com" rel="nofollow">stackoverflow</a>.</p><p>It got started by a question by me: <a
href="http://stackoverflow.com/questions/629411/when-does-a-library-deserve-the-be-called-linq-something-or-something-linq" rel="nofollow">When does a library deserve the be called “Linq-something” or “something-Linq”?</a></p><p>In it I kinda rant about libraries that have "Linq" in their name even though they do not provide extension methods for IQueryable and IEnumerable but instead just for IEnumberable. And I asked the community if it is OK for libraries that just extend IEnumberable to have Linq in their name.</p><p>Jon Skeet's (who is kind of a <a
href="http://stackoverflow.com/questions/305223" rel="nofollow">stackoverflow celebrity</a>) answer made me wonder though. What are the classifications for Linq related libraries? Especially since he seemed to mix and match Linq-to-... libraries with his MoreLinq library. <a
href="http://stackoverflow.com/questions/629411/when-does-a-library-deserve-the-be-called-linq-something-or-something-linq/629428#629428" rel="nofollow">In the comments</a> (Click "Comments" to see them) I tried to clarify why I thought there was a difference but unfortunately I was not clear enough to get my point across in 300 characters. That's why I chose to write this blog post. Hope it will clarify my view on what parts LINQ is made of.</p><h4>Classifying the moving parts of LINQ</h4><p>First I want to clarify what I think that comparing a Linq-to-... library with MoreLinq is kinda flawed. Linq-to-... are what I (<a
href="http://en.wikipedia.org/wiki/Linq" rel="nofollow">and others</a>) call a Linq Provider library and something like MoreLinq is a Query Operators library.</p><h5>Linq Provider libraries</h5><p>To quote from the .NET Framework Glossary:</p><blockquote><p> LINQ provider<br
/> A library that implements the functionality of the standard query operators for a specific kind of data source. A LINQ provider translates queries expressed in Visual Basic or C# into the native language of the data source. For example, LINQ to SQL is a LINQ provider for SQL Server databases that translates queries into dynamic SQL and marshals the results into objects defined on the client computer.</p></blockquote><p>LINQ Provider are the base of LINQ. They connect the logical description of a data transformation to the actual data storage (which does not have to be a relational database but may be). Loosely speaking they can transform a "persisted" form of data or an in-memory representation of data into an alternative in-memory representation of data. We can give those providers abstract transformation rules and the provider will convert them into concrete transformation rules specific for the kind of data store it "owns". Abstract transformation they individually do not understand will get deferred until a rudimentary memory representation is formed and will be applied in memory to form the final in-memory representation of data.</p><p>A typical Linq Provider library will contain:</p><ul><li>An implementation of IQueryProvider</li><li>At least one implementation of IQueryable</li><li>Usually one or multiple ExpressionVisitor</li><li>Usually one or multiple ExpressionConverter</li></ul><p>Examples of Linq Provider libraries and their concrete IQueryProvider implementation:</p><ul><li>Linq to Sql (System.Data.Linq.Table&lt;TEntity&gt;)</li><li>Linq to Nhibernate (NHibernate.Linq.NHibernateQueryProvider)</li><li>Linq to Objects (System.Linq.EnumerableQuery&lt;T&gt;)</li></ul><h5>Linq Operator libraries</h5><p>Linq Operator libraries provide a rich set of abstract operations that can be used to construct the abstract transformation rules we can pass to any LINQ Provider. Most notably are the Standard Linq Operations actually baked into the C# 3.5 compiler as syntactical sugar.</p><p>Some examples for these operations:</p><ul><li>Where</li><li>GroupBy</li><li>Sum</li><li>Max</li><li>...</li></ul><p>To be able to be used across multiple Linq Provider and let the provider benefit from deep inspection of the abstract transformations the Linq Operators must extend IQueryable. Unfortunately the parsing and compiling of these abstract transformation expressions is CPU intensive and can severely impact the performance of in-memory transformations.<br
/> That's where <a
href="http://msdn.microsoft.com/en-us/library/bb397919.aspx" rel="nofollow">LINQ to Objects</a> comes (unfortunately) into play a second time. In this context Linq to Objects means using abstract Linq queries directly on IEnumerable&lt;T&gt; without the intermediate use of a Linq Provider.</p><p>Because of these two forms of abstract transformations, one with Linq Provider, one without, good Linq Operation libraries will provide both an implementation of the operation for IQueryable and for IEnumerable. Remember though - IEnumerable&lt;T&gt; could still be queried using the Linq to Objects Provider EnumerableQuery&lt;T&gt;. Fortunately writing Linq Operations for IEnumerable is by far easier than implementing the same operation for IQueryable.</p><h4>The Linq Operator library FilterByExample</h4><p>To clarify what the difference is we will implement the Linq Operation "FilterByExample" both for IEnumerable and IQueryable. FilterByExample will enable us to filter a given data set via a provided instance of the class within the data set. FilterByExample will allow us to specify certain properties of the given class. This is useful for quickly creating advanced filtering forms in GUI development.</p><p><a
href='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/03/comhertkornframeworkfilterbyexample.zip'>Download source for Com.Hertkorn.Framework.FilterByExample</a></p><p>Most of the magic happens in the method FilterByExample in Queryable (and Enumerable almost in the same way). Please notice that in this private version of FilterByExample <em>relevant</em> properties are listed. The public version gets properties that should be excluded (look at the unit tests for examples).</p><div
class="igBar"><span
id="lcsharp-58"><a
href="#" onclick="javascript:showCodeTxt('csharp-58'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-58"><div
class="csharp"><ol><li
class="li1"><div
class="de1"><span
class="kw1">private</span> <span
class="kw1">static</span> IQueryable&lt;T&gt; FilterByExample&lt;T&gt;<span
class="br0">&#40;</span><span
class="kw1">this</span> IQueryable&lt;T&gt; source, T example, <span
class="kw1">params</span> PropertyInfo<span
class="br0">&#91;</span><span
class="br0">&#93;</span> relevantPropertyz<span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2"><span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="co1">// since this method is private no additional precondition check.</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="kw1">if</span> <span
class="br0">&#40;</span>relevantPropertyz.<span
class="me1">Length</span> == <span
class="nu0">0</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="br0">&#123;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; <span
class="co1">// no filtering</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="kw1">return</span> source;</div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="br0">&#125;</span></div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; var exampleExpression = Expression.<span
class="me1">Constant</span><span
class="br0">&#40;</span>example, <a
href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span
class="kw3">typeof</span></a><span
class="br0">&#40;</span>T<span
class="br0">&#41;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; var otherParameterExpression = Expression.<span
class="me1">Parameter</span><span
class="br0">&#40;</span><a
href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span
class="kw3">typeof</span></a><span
class="br0">&#40;</span>T<span
class="br0">&#41;</span>, <span
class="st0">"other"</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; var filterExpression = Expression.<span
class="me1">Equal</span><span
class="br0">&#40;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; Expression.<span
class="me1">MakeMemberAccess</span><span
class="br0">&#40;</span>otherParameterExpression, relevantPropertyz<span
class="br0">&#91;</span><span
class="nu0">0</span><span
class="br0">&#93;</span><span
class="br0">&#41;</span>,</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; Expression.<span
class="me1">MakeMemberAccess</span><span
class="br0">&#40;</span>exampleExpression, relevantPropertyz<span
class="br0">&#91;</span><span
class="nu0">0</span><span
class="br0">&#93;</span><span
class="br0">&#41;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; <span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="kw1">for</span> <span
class="br0">&#40;</span><span
class="kw4">int</span> i = <span
class="nu0">1</span>; i &lt;relevantPropertyz.<span
class="me1">Length</span>; i++<span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; <span
class="br0">&#123;</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; var next = Expression.<span
class="me1">Equal</span><span
class="br0">&#40;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; Expression.<span
class="me1">MakeMemberAccess</span><span
class="br0">&#40;</span>otherParameterExpression, relevantPropertyz<span
class="br0">&#91;</span>i<span
class="br0">&#93;</span><span
class="br0">&#41;</span>,</div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; Expression.<span
class="me1">MakeMemberAccess</span><span
class="br0">&#40;</span>exampleExpression, relevantPropertyz<span
class="br0">&#91;</span>i<span
class="br0">&#93;</span><span
class="br0">&#41;</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; <span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; filterExpression = Expression.<span
class="me1">AndAlso</span><span
class="br0">&#40;</span>filterExpression, next<span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="br0">&#125;</span></div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; Expression&lt;Func&lt;T, bool&gt;&gt; filter = Expression.<span
class="me1">Lambda</span>&lt;Func&lt;T, bool&gt;&gt;<span
class="br0">&#40;</span>filterExpression, otherParameterExpression<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">&nbsp; <span
class="kw1">return</span> source.<span
class="me1">Where</span><span
class="br0">&#40;</span>filter<span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1"><span
class="br0">&#125;</span></div></li></ol></div></div></div><p></p><p>The summary explanation of this code snippet is: In line 15 through 28 all relevant properties are tested to be of equal value between two instances of an object of type T. These tests are linked via a logical AND in line 27 so that the resulting expression returns true if the value all relevant properties match in the two instances. This expression is passed to a where clause in line 32. So the returned IQueryable is a representation of the data where only object will be contained in the result where the relevant properties have matching values.</p><h4>Comparing FilterByExample's extension for IQueryable and IEnumerable</h4><p>The question is now. Why go through the stress of implementing FilterByExample twice. We can't really see any advantages in the library and its tests. On the contrary. The performance tests show that the IQueryable implementation is about three times slower than the IEnumerable implementation. Part of the reason why we don't see any advantage of the IQueryable implementation is that EnumerableQuery does not use an expression optimizer. So for any effect to appear we must switch to a different Linq Provider.</p><p><a
href='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/03/linqtosql.zip'>Download LinqToSql Example</a> - If you want to run it make sure to adjust the connection string in the app.config</p><h5>Using FilterByExample operator with Linq-to-Sql</h5><p>When using Linq to Sql we can actually see the SQL Query that gets sent to the DB Server based on the abstract transformation we specify using Linq. That way we can verify that the abstract transformation the operator creates is in fact what we were looking for.</p><p>A simple query using standard linq operators would look like this:</p><div
class="igBar"><span
id="lcsharp-59"><a
href="#" onclick="javascript:showCodeTxt('csharp-59'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-59"><div
class="csharp"><ol><li
class="li1"><div
class="de1">IQueryable&lt;TestClass&gt; filter = from t <span
class="kw1">in</span> c.<span
class="me1">TestClasses</span></div></li><li
class="li2"><div
class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where t.<span
class="me1">TestString</span> == <span
class="st0">"Test"</span></div></li><li
class="li1"><div
class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;select t;</div></li><li
class="li2"><div
class="de2">&nbsp;</div></li><li
class="li1"><div
class="de1">PerformQuery<span
class="br0">&#40;</span><span
class="st0">"standard version"</span>, c, filter<span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>and would result in this output:<br
/> <code><br
/> Performing standard version:<br
/> '1' 'Test' 'Test'<br
/> '4' 'Test' 'Me'<br
/> '5' 'Test' 'TestMe'<br
/> SELECT [t0].[TestInt], [t0].[TestString], [t0].[TestString2]<br
/> FROM [TestClass] AS [t0]<br
/> WHERE [t0].[TestString] = @p0<br
/> -- @p0: Input NVarChar (Size = 4; Prec = 0; Scale = 0) [Test]<br
/> -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1<br
/> </code></p><p>As expected we see a where clause in the select method which shows that the Linq Provider understood our abstract transformation and was able to translate it into SQL. That way not the whole data table "TestClass" gets pulled across the wire. Just the part we need.</p><p>Now we use the FilterByExample operator:</p><div
class="igBar"><span
id="lcsharp-60"><a
href="#" onclick="javascript:showCodeTxt('csharp-60'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-60"><div
class="csharp"><ol><li
class="li1"><div
class="de1">TestClass tc = <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
class="kw3">new</span></a> TestClass<span
class="br0">&#40;</span><span
class="br0">&#41;</span>;</div></li><li
class="li2"><div
class="de2">tc.<span
class="me1">TestString</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">IQueryable&lt;TestClass&gt; filter2 = c.<span
class="me1">TestClasses</span>.<span
class="me1">FilterByExample</span><span
class="br0">&#40;</span>tc, x =&gt; x.<span
class="me1">TestInt</span>, x =&gt; x.<span
class="me1">TestString2</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">PerformQuery<span
class="br0">&#40;</span><span
class="st0">"one relevant prop"</span>, c, filter2<span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>This means "filter the TestClass table by tc and ignore the values in TestInt and TestString2.<br
/> And it results in:</p><p><code><br
/> Performing one relevant prop:<br
/> '1' 'Test' 'Test'<br
/> '4' 'Test' 'Me'<br
/> '5' 'Test' 'TestMe'<br
/> SELECT [t0].[TestInt], [t0].[TestString], [t0].[TestString2]<br
/> FROM [TestClass] AS [t0]<br
/> WHERE [t0].[TestString] = @p0<br
/> -- @p0: Input NVarChar (Size = 4; Prec = 0; Scale = 0) [Test]<br
/> -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1<br
/> </code></p><p>Again lo and behold the actual SQL that gets produced looks exactly as if we would have used the standard where query.</p><p>Finally a more complex query - filter the list by two relevant properties:</p><div
class="igBar"><span
id="lcsharp-61"><a
href="#" onclick="javascript:showCodeTxt('csharp-61'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-61"><div
class="csharp"><ol><li
class="li1"><div
class="de1">tc.<span
class="me1">TestString</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li2"><div
class="de2">tc.<span
class="me1">TestInt</span> = <span
class="nu0">1</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">IQueryable&lt;TestClass&gt; filter3 = c.<span
class="me1">TestClasses</span>.<span
class="me1">FilterByExample</span><span
class="br0">&#40;</span>tc, x =&gt; x.<span
class="me1">TestString2</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">PerformQuery<span
class="br0">&#40;</span><span
class="st0">"two relevant props"</span>, c, filter3<span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>which results in:</p><p><code><br
/> Performing two relevant props:<br
/> '1' 'Test' 'Test'<br
/> SELECT [t0].[TestInt], [t0].[TestString], [t0].[TestString2]<br
/> FROM [TestClass] AS [t0]<br
/> WHERE ([t0].[TestInt] = @p0) AND ([t0].[TestString] = @p1)<br
/> -- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [1]<br
/> -- @p1: Input NVarChar (Size = 4; Prec = 0; Scale = 0) [Test]<br
/> -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1<br
/> </code></p><p>As expected a second parameter further specifies the where clause plus both are linked by an AND. Now just one object got sent across the wire.</p><p>Seems like our custom Linq Operator gets interpreted correctly by the SQL Linq Provider and the filter and transformation happens right where it belongs. Within the SQL Server itself. And even though I did not test it, I strongly believe that it would be the same with e.g. the Linq to NHibernate provider.</p><h5>In contrast the IEnumerable version</h5><p>Now to show the difference between the IQueryable and the IEnumerable operator we have to force the Linq to Sql to use the IEnumerable operator:</p><div
class="igBar"><span
id="lcsharp-62"><a
href="#" onclick="javascript:showCodeTxt('csharp-62'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">C#:</span><div
id="csharp-62"><div
class="csharp"><ol><li
class="li1"><div
class="de1">tc.<span
class="me1">TestString</span> = <span
class="st0">"Test"</span>;</div></li><li
class="li2"><div
class="de2">tc.<span
class="me1">TestInt</span> = <span
class="nu0">1</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">IEnumerable&lt;TestClass&gt; filter4 = FBE.<span
class="me1">Enumerable</span>.<span
class="me1">FilterByExample</span><span
class="br0">&#40;</span>c.<span
class="me1">TestClasses</span>, tc, x =&gt; x.<span
class="me1">TestString2</span><span
class="br0">&#41;</span>;</div></li><li
class="li1"><div
class="de1">&nbsp;</div></li><li
class="li2"><div
class="de2">PerformQuery<span
class="br0">&#40;</span><span
class="st0">"IEnumerable"</span>, c, filter4<span
class="br0">&#41;</span>;</div></li></ol></div></div></div><p></p><p>Notice how we don't get an IQueryable but an IEnumerable as result of the operation. Now the SQL reads:</p><p><code><br
/> Performing IEnumerable:<br
/> '1' 'Test' 'Test'<br
/> SELECT [t0].[TestInt], [t0].[TestString], [t0].[TestString2]<br
/> FROM [TestClass] AS [t0]<br
/> -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1<br
/> </code></p><p>It is not surprising that the Linq Provider was not able to analyse the abstract transformation we specified. There simply is no expression that could be analysed. So there is no where clause specified in the SQL query. Which results in the Linq Provider sending the <em>whole</em> table across the wire and the filtering being done in-memory. This is of course no biggie in our test scenario. But imagine the table having millions of rows. That certainly would be a big performance problem. Especially if we throw in some joins, etc.</p><h4>Conclusion</h4><h5>There is a difference between MoreLinq and Linq-to-...</h5><p>I hopefully did clarify that part.</p><h5>Real Linq Operators libraries extend IQueryable and IEnumerable</h5><p>If there is a Linq Operator that is worth putting into a library there have to be two versions of the operator. One for IQueryable to enable smart LINQ Provider to do the data transformation where it fits best. And one for IEnumerable to have the performance benefits when dealing with data that is already in-memory.</p><h5>No library is going to be able to extend what every provider can do...</h5><p>... because they would have to know all about all providers.</p><p>This is simply wrong. Providers are separate parts in Linq. And Operators certainly do not have to know anything about the provider that will use them. On the contrary, the abstract representation using Expressions is universal. There are just providers that can interpret and optimize those expressions better than other providers. By using Operations that manipulate IQueryable to impose the desired transformation the Linq Provider is given the chance to incorporate the abstract transformation when compiling the concrete transformation. When just using IEnumerable this chance is denied from the very beginning.</p><p>Downloads:<br
/> <a
href='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/03/comhertkornframeworkfilterbyexample.zip'>Source for Com.Hertkorn.Framework.FilterByExample</a> - the Operator example<br
/> <a
href='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/uploads/2009/03/linqtosql.zip'>LinqToSql Example</a> - using the Operator on Linq to SQL - If you want to run it make sure to adjust the connection string in the app.config</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Mapping+the+uncharted+waters+of+LINQ+-+http://bit.ly/239qMQ" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Mapping+the+uncharted+waters+of+LINQ+-+http://bit.ly/239qMQ" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=ABvwCDrAdAc:0kf_nwSOILc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=ABvwCDrAdAc:0kf_nwSOILc:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/ABvwCDrAdAc" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/mapping-the-unchartered-waters-of-linq/253.html/feed</wfw:commentRss> <slash:comments>7</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/mapping-the-unchartered-waters-of-linq/253.html</feedburner:origLink></item> <item><title>When a great experience suddenly turns into … horror</title><link>http://feedproxy.google.com/~r/dun3/~3/ZhtveNsEK0c/251.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/when-a-great-experience-suddenly-turns-into-horror/251.html#comments</comments> <pubDate>Tue, 24 Feb 2009 06:38:37 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[Debian]]></category> <category><![CDATA[IT]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Operating System]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=251</guid> <description><![CDATA[I was upgrading my server which is hosted by large provider from Debian etch to the current stable version lenny. And I was again amazed how simple upgrading a whole box can be with Debian. It seriously was a blast. A couple of questions about touched configurations, a bit of waiting and all was happily [...]]]></description> <content:encoded><![CDATA[<p>I was upgrading my server which is hosted by large provider from Debian etch to the current stable version lenny. And I was again amazed how simple upgrading a whole box can be with Debian. It seriously was a blast. A couple of questions about touched configurations, a bit of waiting and all was happily done.</p><p>At least I thought it was.</p><p>As usual I started doing the upgrade - even though I should have known better - at about 11 p.m. which I though would give ample time to finish up and go to bed. Well, it just was a good time to upgrade, traffic on the site was low, all services where not in use, so I was happy to not disturb too many people. And the best part was: I seriously was done at about half past twelve, spending most of the time doing some readjusting of the exim configuration after the upgrade. I seriously doubt that any other non-debian based system would have given me such a fast a smooth upgrade path. After verifying everything worked, I was eager to test - as a last thing before hopping into bed - if the server was still coming up without a glitch after a reboot/power-loss.</p><p>After giving ample time for the server to come up again, I tried to remote ssh to it. And got nothing but timeouts. Which was the point where I slightly started to panic. I immediately started thinking about kernel failures, data loss, mbr corruption, ... Oh the horror.</p><p>Lucky me, my hoster does provide terminal access even from remote, so I could check if it was disaster or if it was "just" connectivity - missing module in the new kernel or something similar. To make a long story short - somehow the dhcp client got deinstalled during the upgrade! D'oh! And of course I did not have the installation package locally. Chicken and egg problem, right? How should I fix the network connection without getting the dhcpclient package via the network connection. But trying the usual gateways like .1 or .254 via static routes did not seem to work out so well...</p><p>Fortunately I did find the correct settings for 1&#038;1 (which are a bit exotic) eventually - so for anybody having the same problem here they are:</p><p><code><br
/> iface eth0 inet static<br
/> address 212.227.xxx.xxx<br
/> netmask 255.255.255.255<br
/> network 212.227.xxx.xxx<br
/> broadcast 212.227.xxx.xxx<br
/> up        /sbin/route add -net 10.255.255.1 netmask 255.255.255.255 dev eth0<br
/> up        /sbin/route add default gw 10.255.255.1<br
/> </code></p><p>Substitute <strong>all</strong> the 212.227.xxx.xxx with your server address.</p><p>After setting the static interface information, reinstalling the dhcp client was not a bit of a problem. But how in hell could I have missed that the upgrade uninstalled such a vital package?<br
/> In the end I thought "All's well that ends well" and went to bed around 3 in the morning. Though one question remains: Will I be wiser in choosing the time to start an upgrade next time? Why do I seriously doubt that? <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+When+a+great+experience+suddenly+turns+into+...+horror+-+http://bit.ly/18cZWs" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+When+a+great+experience+suddenly+turns+into+...+horror+-+http://bit.ly/18cZWs" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=ZhtveNsEK0c:zRVMfGzWru8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=ZhtveNsEK0c:zRVMfGzWru8:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/ZhtveNsEK0c" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/when-a-great-experience-suddenly-turns-into-horror/251.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/when-a-great-experience-suddenly-turns-into-horror/251.html</feedburner:origLink></item> <item><title>Tweeting</title><link>http://feedproxy.google.com/~r/dun3/~3/GqLovfzrAkA/249.html</link> <comments>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/tweeting/249.html#comments</comments> <pubDate>Sat, 14 Feb 2009 19:24:54 +0000</pubDate> <dc:creator>Tobias Hertkorn</dc:creator> <category><![CDATA[Personal]]></category><guid isPermaLink="false">http://saftsack.fs.uni-bayreuth.de/~dun3/?p=249</guid> <description><![CDATA[Boring update: I finally got to twitter. Almost a week ago. I did not post this earlier here on the blog, because I wanted to see if it sticks. And I have to say it is a nice way of passing the time while code is compiling.   But I hope to keep it [...]]]></description> <content:encoded><![CDATA[<p>Boring update: I finally got to twitter. Almost a week ago. I did not post this earlier here on the blog, because I wanted to see if it sticks. And I have to say it is a nice way of passing the time while code is compiling. <img
src='http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> But I hope to keep it purely "professional" in the sense that I don't want to start talking about anything else than programming problems or at least programming related topics.</p><p>So, if you want to join me - and maybe yell at me for not posting anything of value to my blog in way too long - go to http://twitter.com/dun3 and look me up. Looking forward to your tweets.</p><p
align="left"><a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Tweeting+-+http://bit.ly/fByfc" title="Post to Twitter"><img
class="nothumb" src="http://saftsack.fs.uni-bayreuth.de/~dun3/tsharp/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" border="0" /></a> <a
rel="nofollow" class="tt" href="http://twitter.com/home/?status=Just+read:+Tweeting+-+http://bit.ly/fByfc" title="Post to Twitter">Tweet this</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/dun3?a=GqLovfzrAkA:9v4Ik0Y_W3U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/dun3?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/dun3?a=GqLovfzrAkA:9v4Ik0Y_W3U:lwXqHt5wHsE"><img src="http://feeds.feedburner.com/~ff/dun3?d=lwXqHt5wHsE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/dun3/~4/GqLovfzrAkA" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/tweeting/249.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://saftsack.fs.uni-bayreuth.de/~dun3/archives/tweeting/249.html</feedburner:origLink></item> </channel> </rss><!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk
Database Caching 5/9 queries in 0.036 seconds using disk

Served from: saftsack.fs.uni-bayreuth.de @ 2010-03-22 09:17:30 -->
