<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Erata.NET</title>
 <link href="http://www.erata.net/atom.xml" rel="self"/>
 <link href="http://www.erata.net/"/>
 <updated>2014-10-18T18:58:34+00:00</updated>
 <id>http://www.erata.net</id>
 <author>
   <name></name>
   <email></email>
 </author>

 
 <entry>
   <title>Metrics.NET Update</title>
   <link href="http://www.erata.net/net/Metrics.NET-Update"/>
   <updated>2014-10-18T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/Metrics.NET-Update</id>
   <content type="html">&lt;p&gt;Since March, i&amp;#39;ve been working on this &lt;a href=&quot;https://github.com/etishor/Metrics.NET&quot;&gt;Metrics.NET&lt;/a&gt; library.&lt;/p&gt;

&lt;p&gt;I&amp;#39;m using it in a few production projects and i&amp;#39;ve become addicted to having everything measured and having the metrics information available when making decisions. Especialy when writing systems that are asyncronous where it&amp;#39;s difficult to rely
only on logging for understanding what is going one. &lt;/p&gt;

&lt;h4&gt;What it is&lt;/h4&gt;

&lt;p&gt;Metrics.NET library is a .NET Port, with lots of additional functionality, of the awesome Java &lt;a href=&quot;https://github.com/dropwizard/metrics&quot;&gt;metrics library&lt;/a&gt; by Coda Hale.&lt;/p&gt;

&lt;p&gt;To paraphrase the Java library description - Metrics is a library which gives you unparalleled insight into what your code does in production. Metrics provides a powerful toolkit of ways to measure the behavior of critical components in your production environment.&lt;/p&gt;

&lt;p&gt;The full description and documentation is available on the &lt;a href=&quot;https://github.com/etishor/Metrics.NET/wiki&quot;&gt;GitHub Wiki&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Plans for the future&lt;/h4&gt;

&lt;p&gt;For the near future, my focus will be on a solution for remote, persistent metrics. This includes the integration with Graphite/Ganglia/InfluxDb and maybe others. But for some odd reason none of this existing solutions runs on windows. Which is strange since they are all written in cross platform languages. We now run C# on unix, but we can&amp;#39;t run go or python on windows.&lt;/p&gt;

&lt;p&gt;And since I have to deal mostly with production running on windows I&amp;#39;m also considering storing metrics in the EventStore or even maybe in something like LMDB or Ayende&amp;#39;s Voron. Or even postgres if it comes to that.&lt;/p&gt;

&lt;p&gt;Any feedback, especialy on the public API of the library would be appreciated. &lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Metrics.NET</title>
   <link href="http://www.erata.net/net/Metrics.NET-Library"/>
   <updated>2014-04-13T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/Metrics.NET-Library</id>
   <content type="html">&lt;p&gt;For the past couple of weeks I&amp;#39;ve been working on a new pet project, a .NET port of &lt;a href=&quot;http://metrics.codahale.com/&quot;&gt;Coda Hale&amp;#39;s Metrics library&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/etishor/Metrics.NET&quot;&gt;Metrics.NET&lt;/a&gt; library provides a way of instrumenting applications with custom metrics (timers, historams, counters etc) that can be reported in various ways and can provide insights on what is happening inside a running application. &lt;/p&gt;

&lt;p&gt;The library is published on NuGet can be installed with the following command:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;Install-Package Metrics.NET
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Supported runtimes: .NET 4.5.1, .NET 4.5, .NET 4.0, Mono 3.4.0 ( tested on OsX ).&lt;/p&gt;

&lt;p&gt;The API of the library might change until a 1.X version will be made available.&lt;/p&gt;

&lt;p&gt;Documentation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/etishor/Metrics.NET/wiki/Available-Metrics&quot;&gt;Available Metrics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/etishor/Metrics.NET/wiki/Metrics-Visualization&quot;&gt;Metric Visualization&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/etishor/Metrics.NET/wiki/&quot;&gt;Documentation Wiki&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Quick Usage Sample&lt;/h3&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SampleMetrics&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Timer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; 
      &lt;span class=&quot;n&quot;&gt;Metric&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Timer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Requests&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SamplingType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FavourRecent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Unit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// measure until disposed&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NewContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; 
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// do some work&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For more information on the library see the &lt;a href=&quot;https://github.com/etishor/Metrics.NET&quot;&gt;GitHub repository&lt;/a&gt; and the &lt;a href=&quot;https://github.com/etishor/Metrics.NET/wiki/&quot;&gt;GitHub Wiki&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The Expert</title>
   <link href="http://www.erata.net/general/The-Expert"/>
   <updated>2014-03-30T00:00:00+00:00</updated>
   <id>http://www.erata.net/general/The-Expert</id>
   <content type="html">&lt;p&gt;I&amp;#39;m sure everybody felt like this expert at least some times. It makes me laugh and cry an laugh and cry...&lt;/p&gt;

&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;//www.youtube.com/embed/BKorP55Aqvg&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;

&lt;p&gt;Please share with everybody.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>NodaTime - Coherent date time types for .NET</title>
   <link href="http://www.erata.net/net/NodaTime-Coherent-date-time-types-for-.NET"/>
   <updated>2014-02-19T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/NodaTime-Coherent-date-time-types-for-.NET</id>
   <content type="html">&lt;p&gt;For the last two weeks I&amp;#39;ve been working on an internal project. Being a low risk project, I had the option of introducing new technology that was harder to introduce in other projects. I&amp;#39;m hoping to write a few posts about my experiences with &lt;a href=&quot;http://nancyfx.org&quot;&gt;NancyFx&lt;/a&gt;, &lt;a href=&quot;http://geteventstore.com&quot;&gt;EventStore&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://nodatime.org&quot;&gt;NodaTime&lt;/a&gt;, to name a few of the things I&amp;#39;m using. &lt;/p&gt;

&lt;p&gt;One library I&amp;#39;ve been looking for a chance to try is the &lt;a href=&quot;http://nodatime.org&quot;&gt;NodaTime&lt;/a&gt; library, written by the famous &lt;a href=&quot;http://stackoverflow.com/users/22656/jon-skeet&quot;&gt;Jon Skeet&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The experience of using NodaTime in a few words: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;extremely low learning curve&lt;/li&gt;
&lt;li&gt;perfect API&lt;/li&gt;
&lt;li&gt;everything is where you expected it to be and named as you expect it to be named &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I can&amp;#39;t say that I&amp;#39;ve experienced major issues with the native DateTime form .NET. But I have often felt that it is not a perfect match for representing a concept or not being clear enough in a public APIs. When trying to represent a particular day, or a time in a timezone or UTC the DateTime abstraction did not capture the full intent.&lt;/p&gt;

&lt;p&gt;So far the most useful types for me from NodaTime have been: &lt;strong&gt;Instant&lt;/strong&gt; &amp;amp; &lt;strong&gt;Duration&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instant&lt;/strong&gt; represents a specific point on a clear and unambiguous time axis. This is a common representation also found in other languages - like the time_t type in C - representing the number of ticks from the Unix epoch (January 1st 1970 00:00 UTC). &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &amp;quot;zero point&amp;quot; used everywhere in NodaTime is the Unix epoch: midnight at the start of January 1st 1970, UTC. (UTC itself did not exist in 1970, but that&amp;#39;s another matter.) &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Duration&lt;/strong&gt; represents an exact number of ticks on the same time axis. This is similar to the &lt;strong&gt;TimeSpan&lt;/strong&gt; type from .net.&lt;/p&gt;

&lt;p&gt;I have also used a &lt;strong&gt;LocalDate&lt;/strong&gt; type to represent a birth date.&lt;/p&gt;

&lt;p&gt;As I&amp;#39;ve said I&amp;#39;m using Nancy to expose an HTTP API and EventStore for persistence. For moving data across this boundaries I&amp;#39;m using the awesome and now almost standard &lt;a href=&quot;http://james.newtonking.com/json&quot;&gt;Json.NET&lt;/a&gt; library. My first worry was that I&amp;#39;m going to have to convert the types from NodaTime to and from a format supported by API and events consumers. &lt;/p&gt;

&lt;p&gt;Almost as expected, I&amp;#39;ve found that NodaTime already provides a NuGet package for this. Flawless Json.NET serialisation is available by installing the NodaTime.Serialization.JsonNet package. &lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;If you value the expressiveness and correctness of your code, I encourage you to give NodaTime a try. It risks becoming an addiction, but it is definitely worth it.&lt;/p&gt;

&lt;p&gt;As a starting point continue reading the excellent &lt;a href=&quot;http://nodatime.org/unstable/userguide/index.html&quot;&gt;User Guide for NodaTime&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the end I&amp;#39;d like to thank Jon Skeet and the rest of the &lt;a href=&quot;http://noda-time.googlecode.com/hg/AUTHORS.txt&quot;&gt;authors&lt;/a&gt; that made this awesome library available for the rest of us.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Moving to Jekyll</title>
   <link href="http://www.erata.net/general/moving-to-jekyll"/>
   <updated>2014-02-08T00:00:00+00:00</updated>
   <id>http://www.erata.net/general/moving-to-jekyll</id>
   <content type="html">&lt;p&gt;With hope that this will also mean writing more often, I&amp;#39;ve finally decided to move to a modern blogging platform.&lt;/p&gt;

&lt;h3&gt;Moving away from Wordpress&lt;/h3&gt;

&lt;p&gt;Wordpress is a mature blogging platform, full of extraordinary features. You get automatic updates, easy updates for 
plugins, nice interface to manage the whole thing and a lot of available plugins &amp;amp; themes.&lt;/p&gt;

&lt;p&gt;Why move away from this?&lt;/p&gt;

&lt;p&gt;It requires hosting, it is kinda slow and it is not exactly low ceremony.&lt;/p&gt;

&lt;h3&gt;Why &lt;a href=&quot;https://github.com/jekyll/jekyll&quot;&gt;Jekyll&lt;/a&gt;&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You get to host it for free on &lt;a href=&quot;https://help.github.com/articles/using-jekyll-with-pages&quot;&gt;Github pages&lt;/a&gt;. &lt;/li&gt;
&lt;li&gt;You get to write markdown.&lt;/li&gt;
&lt;li&gt;You get full control over the theme.&lt;/li&gt;
&lt;li&gt;You are free to use modern web technologies.&lt;/li&gt;
&lt;li&gt;You get to manage content with GIT.&lt;/li&gt;
&lt;li&gt;It&amp;#39;s low ceremony - write, commit &amp;amp; push to publish.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Update&lt;/h3&gt;

&lt;p&gt;I&amp;#39;ve finished migrating posts, and content to Jekyll. Even if some of the content required manual fiddling, it has not been a difficult experience. Now waiting for Google Webmaster&amp;#39;s Tools to tell me what I&amp;#39;ve screwed up.&lt;/p&gt;

&lt;p&gt;One thing I&amp;#39;ve noticed is that my blog now is blazing fast - which is normal, considering it&amp;#39;s just a bunch of static web pages hosted on Github.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Great slides from Rob Ashton</title>
   <link href="http://www.erata.net/programming/great-slides-rob-ashton"/>
   <updated>2013-07-02T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/great-slides-rob-ashton</id>
   <content type="html">&lt;p&gt;Verry good advice by Rob Ashton about TDD and testing in general. My favorite line from the slides: &amp;quot;Listen to the pain&amp;quot;&lt;/p&gt;

&lt;h2&gt;Listen to the pain&lt;/h2&gt;

&lt;iframe src=&quot;http://www.slideshare.net/slideshow/embed_code/23731623&quot; width=&quot;597&quot; height=&quot;486&quot; frameborder=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; style=&quot;border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px; max-width: 100%;&quot; allowfullscreen&gt; &lt;/iframe&gt; 

&lt;p&gt;&lt;a href=&quot;https://www.slideshare.net/RobAshton/testing-23731623&quot; title=&quot;Focus on the outside, testing in ASP.NET MVC&quot;&gt;Focus on the outside, testing in ASP.NET MVC&lt;/a&gt; from &lt;a href=&quot;http://www.slideshare.net/RobAshton&quot; title=&quot;Rob Ashton&quot;&gt;Rob Ashton&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The Repository Pattern</title>
   <link href="http://www.erata.net/programming/repository-pattern"/>
   <updated>2013-06-19T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/repository-pattern</id>
   <content type="html">&lt;p&gt;In the context of a question asked on the &lt;a href=&quot;https://groups.google.com/forum/#!topic/ravendb/Gfb6XTOWF0Q&quot;&gt;RavenDb mailing list&lt;/a&gt; I&amp;#39;ve decided to share my thoughts on the &lt;strong&gt;Repository Pattern&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It is a common mistake to consider the Repository pattern a generic &amp;quot;good practice&amp;quot;, without actually considering what it is good about it.&lt;/p&gt;

&lt;p&gt;According to &lt;a href=&quot;http://martinfowler.com/eaaCatalog/repository.html&quot;&gt;Martin Fowler&amp;#39;s P of EAA&lt;/a&gt; a Repository&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&amp;quot;Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This makes a lot of sense, and even if you are dealing with an &lt;a href=&quot;http://www.martinfowler.com/bliki/AnemicDomainModel.html&quot;&gt;anemic domain model&lt;/a&gt;, you don&amp;#39;t want to have data mapping code mixed in with your domain object code. The key here is &lt;strong&gt;&amp;quot;data mapping code&amp;quot;&lt;/strong&gt;. You don&amp;#39;t want code that deals with the internal representation of your data storage (whatever your actual storage is) mixed with code that performs business operations on your objects.&lt;/p&gt;

&lt;p&gt;Back in the day, when we used to write SQL code in our apps, it was essential that you implemented a layer that encapsulated the SQL queries and SQL mapping code from the rest of the application. With the technology choices available today, we rarely need to write SQL code or SQL mapping code. Today we have &lt;a href=&quot;http://nhforge.org/&quot; title=&quot;NHibernate&quot;&gt;NHibernate&lt;/a&gt;, &lt;a href=&quot;http://msdn.microsoft.com/en-us/data/ef.aspx&quot; title=&quot;Entity Framework&quot;&gt;Entity Framework&lt;/a&gt;, &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb425822.aspx&quot; title=&quot;Linq 2 SQL&quot;&gt;Linq2SQL&lt;/a&gt;, &lt;a href=&quot;http://ravendb.net/&quot; title=&quot;RavenDb&quot;&gt;RavenDb&lt;/a&gt; etc.&lt;/p&gt;

&lt;h3&gt;Nhibernate&lt;/h3&gt;

&lt;p&gt;Consider NHibernate - the session you open acts like an in-memory collection of domain objects, where you can query, fetch and add domain objects without needing to do any SQL specific stuff. The data-mapping and SQL stuff is encapsulated in your NHibernate mappings code. &lt;strong&gt;The NHibernate session IS your repository&lt;/strong&gt;. It also acts as a Unit of Work, but that is a different pattern.&lt;/p&gt;

&lt;h3&gt;RavenDb&lt;/h3&gt;

&lt;p&gt;The same thing happens with RavenDb&amp;#39;s client. It provides a &amp;quot;session&amp;quot; which encapsulates all the persistence details like http calls, (de)serialization, caching, concurrency, a lot of safety checks, while acting like an in-memory collection of domain objects. When you do session.Load() or session.Query(), you do this in a very similar way to what you would do when dealing with an in-memory collection of domain objects. &lt;strong&gt;The RavenDB&amp;#39;s session IS your repository&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;Complete Abstractions?&lt;/h3&gt;

&lt;p&gt;Do HNibernate or RavenDb sessions hide ALL the details of the persistence engine? No, but you don&amp;#39;t want them to be hidden from you. Except for the most trivial applications, you can&amp;#39;t ignore the way your data is persisted. You are going to need to handle relationships between the objects in your persistent store, you are going to need to handle concurrency problems and you are going to have to write efficient queries. All these concerns are application specific and no abstraction is going to be good enough to handle all your application&amp;#39;s use cases. But the concept of session from NHibernate or Raven does provide an abstraction over the persistence details, while exposing to the developer ways in which efficient operations can be performed.&lt;/p&gt;

&lt;p&gt;There is also a very strong resemblance between the session from RavenDb and the session from NHibernate, but that is probably because &lt;a href=&quot;http://ayende.com/blog&quot; title=&quot;Ayende&amp;#39;s blog&quot;&gt;Ayende&lt;/a&gt; is (was?) one of the most active and knowledgeable developers and &amp;quot;evangelist&amp;quot; for NHibernate, and also because the session is a good model for a unit of work. Ayende also has some good posts about the &lt;a href=&quot;http://ayende.com/blog/search?q=repository&quot; title=&quot;Ayende&amp;#39;s Repository posts&quot;&gt;Repository pattern&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Testing&lt;/h3&gt;

&lt;p&gt;One question that always pops up in the context of the Repository pattern is Unit Testing. How do you mock the ISession from RavenDb or NHibernate. Well ... you don&amp;#39;t. It&amp;#39;s very hard to mock a non-trivial repository. Instead you &amp;quot;use the real thing&amp;quot;, just in an in-memory form. RavenDb&amp;#39;s ecosystem provides an embedded, in-memory store that is perfect for running unit tests against the real store. NHibernate provides a SQLite back-end which, while not perfect, can be used for fast tests against a real sql implementation.&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;In conclusion, before you start defining the IRepository which i know sounds like a cool &amp;quot;good practice&amp;quot;, stop for a minute and check if you are not already using an abstraction over your persistence.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Clean Coders .COM</title>
   <link href="http://www.erata.net/programming/clean-coders-com"/>
   <updated>2012-08-31T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/clean-coders-com</id>
   <content type="html">&lt;p&gt;Lately I&amp;#39;ve started watching episodes from &lt;a href=&quot;http://www.cleancoders.com&quot; title=&quot;Clean Coders&quot;&gt;CleanCoders.com&lt;/a&gt;, a podcast created by Uncle Bob ( Robert C. Martin ) and i must say they are excellent.&lt;/p&gt;

&lt;p&gt;I must confess that when I&amp;#39;ve purchased the &amp;quot;Names&amp;quot; episode I was a bit skeptical about how much can be said about how to name the things you use in your code. I have already been paying much attention to names and overall &amp;quot;cleanness&amp;quot; of my code so I was not expecting to learn a lot of new things, but as usual, Mr. Martin as blown my mind with his way of explaining the &amp;quot;hows&amp;quot; and &amp;quot;whys&amp;quot; of doing things.&lt;/p&gt;

&lt;p&gt;I can say almost the same about the &amp;quot;Functions&amp;quot; episode. Very important small details that even if I was applying previously in my code, I can now actively think about them when writing code.&lt;/p&gt;

&lt;p&gt;Also for me one important gain from watching the videos was that now I can better explain to others the importance and details of clean code using the arguments and reasoning of Uncle Bob.&lt;/p&gt;

&lt;p&gt;I highly recommend following all the videos on cleancoders.com. No matter if you are a junior dev or have lots of years of experience I&amp;#39;m sure you will gain a lot of knowledge from them. The videos are created in a non-conventional and funny way which makes them pretty entertaining to watch.&lt;/p&gt;

&lt;p&gt;Thank you Uncle Bob for the great videos.&lt;/p&gt;

&lt;p&gt;Continue to &lt;a href=&quot;http://www.cleancoders.com&quot; title=&quot;Clean Coders&quot;&gt;Clean Coders&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>I'm becoming a fan boy</title>
   <link href="http://www.erata.net/mac/im-becoming-a-fan-boy"/>
   <updated>2012-02-29T00:00:00+00:00</updated>
   <id>http://www.erata.net/mac/im-becoming-a-fan-boy</id>
   <content type="html">&lt;p&gt;I could not resist anymore and i&amp;#39;ve bought a mac. I&amp;#39;ve been contemplating with the idea of getting a laptop lately and the &lt;a href=&quot;http://www.apple.com/macbookair/&quot;&gt;mac book air&lt;/a&gt; was always coming at the top of the search results.&lt;/p&gt;

&lt;p&gt;Finally i could not delay it anymore and one morning i wake up, went to the apple store, paid 2000$ and got the all new shiny 13 inch Mac Book Air.&lt;/p&gt;

&lt;p&gt;My expectations were to get some good and reliable hardware, with a toy OS where i can use bootcamp to run windows 7 for everything. Boy was i in for a surprise.&lt;/p&gt;

&lt;p&gt;The hardware is not good - its 10 levels above good, it extraordinary, everything just works great, from wake up time which is practically zero to install mono develop and create my first asp.net app with mono in less than 1 minute. I don&amp;#39;t care what anybody says apple is light years ahead the competition when is comes to hardware quality and especially design. Everything just fits together and leaves you the feeling that somebody has invested a good amount of thought in every little aspect of the product.&lt;/p&gt;

&lt;p&gt;Now comes the true surprise: Mac OS X 10.7.3 Lion - my first OS X system.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/Mac-OS-XMaxOsX.png&quot; alt=&quot;Mac OS X Lion&quot; title=&quot;Mac OS X Lion&quot;&gt;&lt;/p&gt;

&lt;p&gt;I don&amp;#39;t even know where to begin - it took me less than a minute to make a screen shot of the above window ( command-shift-4, space, click window ) and drag it in the MarsEdit that i&amp;#39;m using to write this. I was writing an email in italian and i&amp;#39;m terrible at writing italian and i notice that iMail starts correcting my words in proper italian - without ever configuring anything related to italian. I was able to setup email accounts without any frustration, setup all IM accounts, twitter, vpn, RSS reader and everything i use daily without having to spend a lot of time google for it or trying to guess what it is that i&amp;#39;m supposed to do.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve completely renounced at the idea of using bootcamp to run windows. Sure i&amp;#39;ll install parallels or vmware to run a VM with windows mostly for Visual Studio, but for now i&amp;#39;m in no hurry to do that.&lt;/p&gt;

&lt;p&gt;Final word: If you tried it already you have most probably switched to OS X, if you have not tried it and you have the $$ go for it and you will enjoy a new way of using a computer.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ll just enjoy the honeymoon with my new powerful &amp;quot;toy&amp;quot;.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;UPDATE: *&lt;/em&gt;and then i found parallels with coherence ... and i still don&amp;#39;t believe this it true ... i run visual studio like any other mac app. Somehow i&amp;#39;ve been in this field for more than 15 years and i just discover this now... and i don&amp;#39;t think there is any going back. There is absolutely no reason for to use anything else. And this comes from someone who has used FreeBSD as a main OS for years. Again - if you have the money, it will blow your mind, don&amp;#39;t hesitate another minute.&lt;/p&gt;

&lt;p&gt;Hopefully i&amp;#39;ll keep the posts coming.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Test Data Generator</title>
   <link href="http://www.erata.net/projects/test-data-generator"/>
   <updated>2011-11-17T00:00:00+00:00</updated>
   <id>http://www.erata.net/projects/test-data-generator</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve pushed to github a new project, &lt;a href=&quot;https://github.com/etishor/TestDataGenerator&quot; title=&quot;Test Data Generator&quot;&gt;TestDataGenerator&lt;/a&gt; that should help with filling random objects with data. I felt the need for a tool like this when testing various serialization techniques and persistence strategies.&lt;/p&gt;

&lt;p&gt;Basically this utility should construct the instance of an object using a public constructor, and fill all it&amp;#39;s public, writable properties with random data.&lt;/p&gt;

&lt;p&gt;Sample usage:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Sample&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stringValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;intValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stringValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringProp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DateProp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MinValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stringVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;      &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;intValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stringValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stringVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PrivateInt&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PrivateString&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stringValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StringProp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;25&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateTime&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateProp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;26&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;27&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;28&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;[Test]&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;29&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Catalog_Can_Create_Using_Consutrctor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;30&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;31&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Catalog&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;catalog&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Catalog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;32&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;catalog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CreateInstance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;33&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;34&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IsInstanceOfType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;35&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Sample&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sample&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;36&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;37&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AreNotEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(-&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PrivateInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;38&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IsNotNull&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PrivateString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;39&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IsNotNull&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringProp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;40&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AreNotEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MinValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DateProp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;41&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For more samples see &lt;a href=&quot;https://github.com/etishor/TestDataGenerator/tree/master/TestDataGenerator.Tests&quot; title=&quot;Unit Tests&quot;&gt;unit tests&lt;/a&gt;.&lt;br&gt;
I&amp;#39;ll try to add more cases ( abstract class, interface implementation discovery ) in the future. You are welcome to submit sample classes, preferably as unit tests.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>RavenDb EnsureDatabaseExists extension method</title>
   <link href="http://www.erata.net/net/ravendb-ensuredatabaseexists-extension-method"/>
   <updated>2011-11-03T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/ravendb-ensuredatabaseexists-extension-method</id>
   <content type="html">&lt;p&gt;Just a quick hint for others like me, who spent some minutes searching for the EnsureDatabaseExists method when trying to use &lt;a href=&quot;http://ravendb.net&quot; title=&quot;RavenDb&quot;&gt;RavenDb&lt;/a&gt; with  Multi-Databases. &lt;/p&gt;

&lt;p&gt;EnsureDatabaseExists is an extension method on IDatabaseCommands defined in the Raven.Client.Extensions namespace. &lt;/p&gt;

&lt;p&gt;To make it work you need to add a using statement for this namespace.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Raven.Client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Raven.Client.Extensions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DocumentStore&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;store&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DocumentStore&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;Url&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;http://localhost:8080/&amp;quot;&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;store&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;store&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DatabaseCommands&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EnsureDatabaseExists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;SomeDatabase&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Cassette - Asset management for .NET web apps</title>
   <link href="http://www.erata.net/net/cassette-asset-management-net-web-apps"/>
   <updated>2011-08-31T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/cassette-asset-management-net-web-apps</id>
   <content type="html">&lt;p&gt;A few weeks ago i&amp;#39;ve started using &lt;a href=&quot;http://getcassette.net/&quot; title=&quot;Get Cassette&quot;&gt;Cassette&lt;/a&gt;, a very nice asset management tool for .net web applications. It will basically take your assets ( javascript, coffescript, css, images ) and do the right thing with them ( combine, minify etc).&lt;/p&gt;

&lt;p&gt;While working with it i had a few issues which I&amp;#39;ve  managed to solve and i would like to share them.&lt;/p&gt;

&lt;h3&gt;File not found in module.txt&lt;/h3&gt;

&lt;p&gt;The first problem was related to a .css file for the jquery-ui theme that was present in the ~Content/themes/redmond/jquery-ui.medsentry.css folders. My module.txt looked like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;themes/redmond/jquery-ui-1.8.16.custom.css
Site.css
# other css files&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After compiling cassette locally and using the debug symbols to step trough the code I&amp;#39;ve noticed that cassette was storing a list of files ( assets ) it found in the Content folder but the path separator was &amp;quot;\&amp;quot; instead of &amp;quot;/&amp;quot;. After changing the slashes in the included paths in my module.txt everything works as expected. Now the module.txt looks like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;themes\redmond\jquery-ui-1.8.16.custom.css
Site.css
# other css files&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Using Cassette modules with IIS6&lt;/h3&gt;

&lt;p&gt;Due to some external constaints i had use IIS6 on a test instance of the application. After the deployment I&amp;#39;ve noticed that the images in the .css files are not working when using cassette modules to combine the files. This was due to cassette rewriting the paths and using Routes to manage them. In IIS6 you have to do one additional step for this to work. Open IIS Manager, locate your application and open the properties window.  On the Virtual Directory tab open the Configuration dialog, located in the Application settings section of the tab. In the Wildcard application maps section click Insert and add &amp;quot;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll&amp;quot; or whatever the path to aspnet_isapi.dll is on your system. Click Ok and Apply and enjoy.&lt;/p&gt;

&lt;p&gt;Another way to manage the images in the css files is to embed them as data links. Cassette &lt;a href=&quot;https://github.com/andrewdavey/cassette/blob/master/src/Example/CassetteConfiguration.cs&quot; title=&quot;Data uri conversion&quot;&gt;supports this&lt;/a&gt;, BUT Internet Explorer &amp;lt;= 7 does not. Also IE 8 has some size limitations.&lt;/p&gt;

&lt;h3&gt;Image Optimizer for Visual Studio&lt;/h3&gt;

&lt;p&gt;Not related to cassette but i&amp;#39;d also like to recommend the &lt;a href=&quot;http://blogs.microsoft.co.il/blogs/gilf/archive/2011/05/14/visual-studio-2010-image-optimizer-extension.aspx&quot; title=&quot;Image optimizer for visual studio&quot;&gt;Image Optimizer for Visual Studio Extension&lt;/a&gt;. Exactly what you would expect from an extension with this name :).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>NHibernate Cache Provider for Membase</title>
   <link href="http://www.erata.net/net/nhibernate-cache-provider-membase"/>
   <updated>2011-05-25T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/nhibernate-cache-provider-membase</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve written a cache provider for &lt;a href=&quot;http://nhforge.org&quot; title=&quot;NHibernate&quot;&gt;NHibernate&lt;/a&gt; which uses &lt;a href=&quot;http://membase.org&quot; title=&quot;Membase&quot;&gt;Membase&lt;/a&gt; as a cache engine.&lt;/p&gt;

&lt;p&gt;You can find the souce code on &lt;a href=&quot;https://github.com/etishor/NHibernate.Caches.Membase&quot; title=&quot;NHibernate.Caches.Membase&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Example configuration can be found in the &lt;a href=&quot;https://github.com/etishor/NHibernate.Caches.Membase/blob/master/NHibernate.Caches.Membase.Tests/App.config&quot; title=&quot;App.config&quot;&gt;test project&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;To use the cache provider add the following lines to the hnibernate configuration:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;cache.provider_class&amp;#39;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Nhibernate.Caches.Membase.MembaseCacheProvider, Nhibernate.Caches.Membase&lt;span class=&quot;nt&quot;&gt;&amp;lt;/property&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;cache.use_second_level_cache&amp;#39;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;true&lt;span class=&quot;nt&quot;&gt;&amp;lt;/property&amp;gt;&amp;lt;/pre&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you encounter any problems with it drop me a line.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>.NET Serialization Choices - Raven.Json</title>
   <link href="http://www.erata.net/net/net-serialization-choices-raven-json"/>
   <updated>2011-05-03T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/net-serialization-choices-raven-json</id>
   <content type="html">&lt;p&gt;This post is an addition to &lt;a href=&quot;http://www.erata.net/net/net-serialization-choices/&quot; title=&quot;.NET Serialization Choices&quot;&gt;.NET Serialization Choices&lt;/a&gt; post.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve added to the &lt;a href=&quot;https://github.com/etishor/SerializationTests&quot; title=&quot;Serialization Tests&quot;&gt;SerializationTests &lt;/a&gt; Project the new serialization implementation in Raven.Json.&lt;/p&gt;

&lt;p&gt;The Raven.Json Serializer is an extension to Newtonsoft Json.NET serializer and as expected the results are similar. Also the Pros &amp;amp; Cons are similar:&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;https://github.com/ravendb/Raven.Json&quot; title=&quot;Raven.Json&quot;&gt;Raven.Json&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Optimized DOM for Newtonsoft Json.NET&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; JSON Based, human readable, platform independent , fast, passes almost all the tests except the ones where the message has public readonly fields that have dirrerent names from the constructor parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Without automatic testing, naming a constructor parameter different from the field can cause hard to notice bugs where certain fields are not deserialized. It should however be possible to write a deserializer based on the existing one which throws an exception if there are doubts when deserializing.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>.NET Serialization Choices</title>
   <link href="http://www.erata.net/net/net-serialization-choices"/>
   <updated>2011-04-08T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/net-serialization-choices</id>
   <content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;

&lt;p&gt;Serialization is not a trivial problem in any language. In .NET there are quite some choices available for serializing/deserializing objects. Each available option has it&amp;#39;s strengths and weaknesses.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve started a project on git hub &lt;a href=&quot;https://github.com/etishor/SerializationTests&quot; title=&quot;Serialization Tests&quot;&gt;SerializationTests&lt;/a&gt; where i&amp;#39;m trying to determine what is supported by which library and draw a few conclusions that should be helpful when designing serializable objects and in general when dealing with serialization.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve started this project because I&amp;#39;ve been bitten too many times by issues related to serialization, either trying to send a message with an System.Uri property in NServiceBus, or trying to deserialize an object from Json which had an ID public readonly field named different from the corresponding parameter in the constructor.  In the end i&amp;#39;m trying to put together a few tips that i hope will be useful in the to myself and others.&lt;/p&gt;

&lt;h3&gt;Tested Implementations&lt;/h3&gt;

&lt;p&gt;The following serialization choices have been included in the SerializationTests project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx&quot;&gt;BinaryFormatter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx&quot;&gt;DataContractSerializer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.netdatacontractserializer.aspx&quot;&gt;NetDataContractSerializer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://json.codeplex.com/&quot;&gt;Newtonsoft Json.Net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;https://github.com/NServiceBus/NServiceBus&quot;&gt;NServiceBus BinarySerializer (Uses BinaryFormatter)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;https://github.com/NServiceBus/NServiceBus&quot;&gt;NServiceBus XMLSerialize&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://code.google.com/p/protobuf-net/&quot;&gt;ProtocolBufers.NET Serializer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack.Text&quot;&gt;ServiceStack JsonSerializer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter.aspx&quot;&gt;SoapFormatter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx&quot;&gt;XmlSerializer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Added &lt;a href=&quot;http://www.erata.net/net/net-serialization-choices-raven-json/&quot; title=&quot;Raven Json&quot;&gt;Raven.Json Serializer - see post&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Tested Messages&lt;/h3&gt;

&lt;p&gt;When designing an object that is meant to be used as a message, event or command there are a few approaches you can take:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;public readonly fields&lt;/strong&gt; and a constructor with appropriate parameters ( my favorite )&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;public properties with private setters&lt;/strong&gt; and a constructor with appropriate parameters ( if you don&amp;#39;t like public fields )&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;public fields&lt;/strong&gt;, no constructor ( only generated default )&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;public properties&lt;/strong&gt;, no constructor ( only generated default )&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;interfaces with getters&lt;/strong&gt; and separate internal implementation (ex for events )&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;interfaces with getters and setters&lt;/strong&gt; ( to help serialization )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I say i prefer the first choice since i find it the one that expresses my intentions the best. I want immutable data transfer objects. Also i have to mention that the first time i&amp;#39;ve seen this approach was in a &lt;a href=&quot;http://www.viddler.com/explore/GregYoung/videos/8/&quot; title=&quot;CQRS Class&quot;&gt;video by Greg Young&lt;/a&gt; about event sourcing and CQRS architecture. To get the idea an event it&amp;#39;s defined like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PersonCreated&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Guid&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;AggregateId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Street&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StreetNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;PersonCreated&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Guid&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;street&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;streetNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AggregateId&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Street&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;street&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StreetNumber&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;streetNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Serializers Conclusions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: I have not used all this serializers in real projects and i&amp;#39;m by no means an expert in any of them. Before adopting one of them do you research and try to see if they have any other drawbacks that might not be acceptable in your projects. If i don&amp;#39;t mention Cons for one, it only means that i have not been interested in it so much to research it deeper.&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx&quot;&gt;BinaryFormatter&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; The BinaryFormatter included in the .NET Framework passes all tests except the DataContractOnly test which is expected since it relies on the presence of the [Serializable] Attribute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;: Very Platform dependent. Assembly version dependent. It&amp;#39;s complicated to handle different versions of the same class. Requires the [Serializable] attribute which you might not always be able to add.&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx&quot;&gt;DataContractSerializer&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.netdatacontractserializer.aspx&quot;&gt;NetDataContractSerializer&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; Passes all the tests, XML Based, used in WCF&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Requires attributes on the class ( [DataContract] ) and all members ([DataMember])&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;http://json.codeplex.com/&quot;&gt;Newtonsoft Json.Net&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;One of the most common choices when doing serialization in an AJAX Call where the result is deserialized in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt;JSON Based, human readable, platform independent , fast, passes almost all the tests except the ones where the message has public readonly fields that have dirrerent names from the constructor parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Without automatic testing, naming a constructor parameter different from the field can cause hard to notice bugs where certain fields are not deserialized. It should however be possible to write a deserializer based on the existing one which throws an exception if there are doubts when deserializing.&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;https://github.com/NServiceBus/NServiceBus&quot;&gt;NServiceBus XMLSerialize&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Integrated in NServiceBus. Has caused me a lot of problems when it was silently ignoring some properties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; XML Based, integrated with NSB, leaving aside the problems i&amp;#39;ve had with it has performed quite well in a few projects. Even if i don&amp;#39;t personally love it, it&amp;#39;s actively maintained  by the NSB group and can be reliably used if you know it&amp;#39;s limitations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; You might end up with properties being silently not serialized/deserialized&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;http://code.google.com/p/protobuf-net/&quot;&gt;ProtocolBufers.NET Serializer&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;To quote the authors:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; Fast, platform independent, compact, throws exceptions when unable to serialize/deserialive, supports versioning&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Needs custom attributes on the class and members that need to be serialized.&lt;/p&gt;

&lt;p&gt;Overall a good choice when size and performance really matter.&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;https://github.com/ServiceStack/ServiceStack.Text&quot;&gt;ServiceStack JsonSerializer&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; it&amp;#39;s said to be the fastest json serializer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Fails a lot of tests - you have to make sure you write your objects in ways supported by the serializer&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter.aspx&quot;&gt;SoapFormatter&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; Xml Based, Passes all the tests except the one without the Serializable attribute&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; The outputed xml is big&lt;/p&gt;

&lt;h3&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx&quot;&gt;XmlSerializer&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt; widely known?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; I must be doing something wrong since it fails a lot of tests.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;My first conclusion is that when approaching an architecture that relies on serialization like EventSourcing and CQRS you should carefully plan the way you write and persist the events in your system.&lt;/p&gt;

&lt;p&gt;At the moment my choice is Json.NET with a Gzip filter. The main reason is that it has a minimal impact on how i must write events and is efficient in therms of speed and size yet is still human readable.&lt;/p&gt;

&lt;p&gt;I&amp;#39;m hoping after i let this sink in a little i&amp;#39;ll come back an update the conclusions.&lt;/p&gt;

&lt;p&gt;Also i would be glad if others share their opinions &amp;amp; experiences related to serialization.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config</title>
   <link href="http://www.erata.net/windows/verify-that-the-current-user-is-granted-access-in-the-appropriate-allowaccounts-section-of-smsvchost-exe-config"/>
   <updated>2011-03-07T00:00:00+00:00</updated>
   <id>http://www.erata.net/windows/verify-that-the-current-user-is-granted-access-in-the-appropriate-allowaccounts-section-of-smsvchost-exe-config</id>
   <content type="html">&lt;p&gt;Quick tip that maybe will save others time:&lt;/p&gt;

&lt;p&gt;In Windows 7 ( and maybe Vista) when hosting a WCF Service in a console application AS A USER and not as administrator, you might get an exception telling you that you don&amp;#39;t have access to register with the net.tcp port sharing service.&lt;/p&gt;

&lt;p&gt;To resolve this problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download &lt;a href=&quot;http://technet.microsoft.com/en-us/sysinternals/bb897417&quot; title=&quot;PsGetSid&quot;&gt;PsGetSid&lt;/a&gt; ( this will give you the &lt;a href=&quot;http://en.wikipedia.org/wiki/Security_Identifier&quot; title=&quot;Security Identifier&quot;&gt;Security Identifier - SID&lt;/a&gt; for your user or user group )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find and open SMSvcHost.exe.config ( usualy in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\SMSvcHost.exe.config or c:\Windows\Microsoft.NET\Framework\v4.0.30319\SMSvcHost.exe.config )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run psgetsid.exe &lt;youraccount&gt; to get the SID ( should look something like this S-1-5-21-1754548885-2506776180-2303324228-4659 )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By default the SMSvcHost.exe.config contains a section &lt;system.serviceModel.activation&gt; which has a &lt;net.tcp&gt; child which has a &lt;allowAccounts&gt; child. The IMPORTANT part if you are using an editor that does not do syntax highlight for XML - THE ABOVE SECTION IS COMMENTED by DEFAULT so adding child &lt;allowAccounts&gt; has not effect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;YOU NEED TO ADD A NEW &lt;system.serviceModel.activation&gt; SECTION with it&amp;#39;s children sections to make it work ( or uncomment the existing one and removing the // comments which are not valid xml ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restart the net.tcp portsharing service and you are good to go.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the end you should have something like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&amp;lt;&lt;/span&gt; ?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- The configuration file for SMSvcHost.exe --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;     &lt;span class=&quot;nt&quot;&gt;&amp;lt;runtime&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;         &lt;span class=&quot;nt&quot;&gt;&amp;lt;gcconcurrent&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;enabled=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/runtime&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;     &lt;span class=&quot;nt&quot;&gt;&amp;lt;system.serviceModel&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;         &lt;span class=&quot;nt&quot;&gt;&amp;lt;diagnostics&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;performanceCounters=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Off&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;etwProviderId=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;{f18839f5-27ff-4e66-bd2d-639b768cf18b}&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/system.serviceModel&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;system.serviceModel.activation&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;         &lt;span class=&quot;nt&quot;&gt;&amp;lt;net.tcp&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;listenBacklog=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;maxPendingConnections=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;maxPendingAccepts=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;receiveTimeout=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;00:00:10&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;teredoEnabled=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;             &lt;span class=&quot;nt&quot;&gt;&amp;lt;allowaccounts&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;                 &lt;span class=&quot;nt&quot;&gt;&amp;lt;add&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;securityIdentifier=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;S-1-5-21-1754548885-2506776180-2303324228-4659&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;             &lt;span class=&quot;nt&quot;&gt;&amp;lt;/allowaccounts&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;         &lt;span class=&quot;nt&quot;&gt;&amp;lt;/net.tcp&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/system.serviceModel.activation&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Also you might need to &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms733768.aspx&quot; title=&quot;Configuring HTTP and HTTPS&quot;&gt;grant access&lt;/a&gt; to the user to register as a listener for an url:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;netsh http add urlacl url=http://+: &amp;lt;port&amp;gt;/MyUri user=DOMAIN\user&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I have to admin the most of the time i&amp;#39;ve spent on this issue was because i was modifying the commented section in the the config xml.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>New Github account</title>
   <link href="http://www.erata.net/net/new-github-account"/>
   <updated>2011-02-25T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/new-github-account</id>
   <content type="html">&lt;p&gt;I’ve opened a &lt;a href=&quot;https://github.com/etishor&quot;&gt;Github account&lt;/a&gt; where i keep some stuff I&amp;#39;ve been playing with recently. At the moment is mostly related to doing DDD with CQRS and Event Sourcing. &lt;/p&gt;

&lt;p&gt;I’ve created a &lt;a href=&quot;https://github.com/etishor/CQRSEventSourcingSample&quot;&gt;sample project&lt;/a&gt; to demonstrate the concepts. Here is a short description of the sample:&lt;/p&gt;

&lt;h3&gt;Sample project demonstrating CQRS &amp;amp; Event Sourcing&lt;/h3&gt;

&lt;p&gt;The sample uses the following projects from &lt;a href=&quot;https://github.com/joliver&quot;&gt;Jonathan Oliver&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EventStore&lt;br&gt;&lt;/li&gt;
&lt;li&gt;NanoServiceBus&lt;br&gt;&lt;/li&gt;
&lt;li&gt;CommonDomain&lt;br&gt;&lt;/li&gt;
&lt;li&gt;StorageAccess &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information on CQRS and Event Sourcing &lt;a href=&quot;http://cqrsinfo.com/&quot;&gt;http://cqrsinfo.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A short description of the projects in the sample: &lt;/p&gt;

&lt;p&gt;a. Write Side &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;1. Sample.DomainModel   
    - the domain model for the sample   
    - this model is persisted using event sourcing and does not need to handle reads ( queries )   
    since they are done on the read side.   
    - the resulting event stream is the &amp;quot;source of truth&amp;quot; data. 

2. Sample.AppService   
    - the handlers for the commands our domain knows to execute 

3. Sample.AppServiceHost   
    - infrastructure for wiring up the command handlers to NanoServiceBus   
    - this is the actual instance of the service that needs to be running for the write side to process   
    commands. 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;b. Read Side &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;1. Sample.ReadModel   
    - the read model on witch queries are executed   
    - this model should be mapped as close as possible to the views   
    - this model can be regenerated from the event stream 

2. Sample.Denormalizer   
    - the event handlers for the domain events that are published by the DomainModel on the Write Side   
    - this handlers keep the read model in sync with the event stream   
    - a better name for it is welcome 

3. Sample.DenormalizerHost   
    - infrastructure for wiring up the event handlers to NanoServiceBus   
    - this process needs to run for the read side to be updated. 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;c. Infrastructure&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;1. Sample.Messages   
    - definitions for commands and events that are handled or published by the Domain Model   
2. Sample.Client.Web   
    - ASP.NET MVC3 application that demonstrates how to integrate the Write Side &amp;amp; the Read Side in an application. 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;TODO&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add more complex objects to the domain&lt;br&gt;&lt;/li&gt;
&lt;li&gt;Review transaction management on integration points&lt;br&gt;&lt;/li&gt;
&lt;li&gt;use ConfOrm for mapping the read model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’d be glad if other shared their comments on the code there.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Hardware-based brute force attacks</title>
   <link href="http://www.erata.net/jokes/hardware-based-brute-force-attacks"/>
   <updated>2011-02-09T00:00:00+00:00</updated>
   <id>http://www.erata.net/jokes/hardware-based-brute-force-attacks</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve found this image in a &lt;a href=&quot;http://www.tarsnap.com/scrypt/scrypt-slides.pdf&quot; title=&quot;scrypt: A new key derivation function&quot;&gt;PDF presentation document&lt;/a&gt; and i feel like sharing:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/hardware-crypto.png&quot; alt=&quot;Hardware-based brute force attacks&quot;&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href=&quot;http://www.tarsnap.com/scrypt/scrypt-slides.pdf&quot; title=&quot;scrypt: A new key derivation function&quot;&gt;scrypt-slides&lt;/a&gt; by Colin Percival&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Log4Net not logging errors to db</title>
   <link href="http://www.erata.net/net/log4net-not-logging-errors-to-db"/>
   <updated>2010-11-04T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/log4net-not-logging-errors-to-db</id>
   <content type="html">&lt;p&gt;This is a short post about logging errors to db with log4net.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve recently been bitten by a bug or better said miss configuration of log4net. I&amp;#39;m using log4net with database logging and file logging in a project and i was wandering why there are no error messages logged in the db when they are logged in the log files configured.&lt;/p&gt;

&lt;p&gt;At one point it hit me: Transactions. Good ol` transactions. Distributed ones.&lt;/p&gt;

&lt;p&gt;In this project i use a mix of &lt;a href=&quot;http://www.nservicebus.com&quot; title=&quot;NServiceBus&quot;&gt;NServiceBus&lt;/a&gt; based windows services and WCF services. They all use a variation of the &lt;a href=&quot;http://martinfowler.com/eaaCatalog/unitOfWork.html&quot; title=&quot;Unit Of Work&quot;&gt;Unit Of Work&lt;/a&gt; pattern to manage the atomicity of the operations. Since we use MSMQ messaging and NHibernate sessions they all fall under a distributed transaction. By default log4net AdoNet appender also uses a transaction to insert the log message in the db. And this transaction was enlisting in the ambient distributed transaction. Now in case of an error the unit of work get&amp;#39;s aborted and the transactions get rolled back. This also includes log4net&amp;#39;s transaction.&lt;/p&gt;

&lt;p&gt;The solution is simple after you figure out the problem. Just add &lt;useTransactions value=&quot;false&quot;/&gt; in the configuration section for the ADONetAppender. Ex:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;lt;appender&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;MySQLAppender&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;log4net.Appender.ADONetAppender&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt;     &lt;span class=&quot;nt&quot;&gt;&amp;lt;usetransactions&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;     &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- rest of the configuration --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;lt;/appender&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Context Matters</title>
   <link href="http://www.erata.net/programming/context-matters"/>
   <updated>2010-06-19T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/context-matters</id>
   <content type="html">&lt;p&gt;The next paragraph made me remember of a lot of hours of discussions with various developers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you’re arguing with me that NHibernate is the wrong tool because you’re writing reporting applications, just say “I write reporting applications.”  And when I say “I think NHibernate is the best tool for persisting domain models,” I should probably talk about that specific context.  And definitely, when you say “Linq to Sql rocks!” you better follow that up with “for applications with simplistic domain models.” (source: &lt;a href=&quot;http://codebetter.com/blogs/jeremy.miller/archive/2010/01/24/a-train-of-thought-january-2010-edition.aspx&quot; title=&quot;Context Matters&quot;&gt;Context Matters&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If more developers would think like this we would probably have better tools with better acceptance in a lot less time.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>NServiceBus with NHibernate and MySQL</title>
   <link href="http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql"/>
   <updated>2010-03-07T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql</id>
   <content type="html">&lt;p&gt;In the last project I have been working i finally got a chance to design and implement a solution based on &lt;a href=&quot;http://nservicebus.com/&quot; title=&quot;NServiceBus&quot;&gt;NServiceBus&lt;/a&gt; and &lt;a href=&quot;http://nhforge.org/&quot; title=&quot;NHibernate&quot;&gt;NHibernate&lt;/a&gt;, two tools I’ve been watching for a while but never got a chance to play with in more than sample applications. For some external reasons I&amp;#39;ve been forced to use &lt;a href=&quot;http://www.mysql.com/&quot;&gt;MySQL&lt;/a&gt; as a database server in this project.&lt;/p&gt;

&lt;p&gt;So basically I’m using &lt;a href=&quot;http://nservicebus.com/&quot; title=&quot;NServiceBus&quot;&gt;NServiceBus&lt;/a&gt; to provide reliable communication between the involved components and NHibernate to do the persistence of the domain objects used by the components. Up to this point the whole design of the solution looks good, with minimal effort i have reliable, fault tolerant services that are ready to do their job.&lt;/p&gt;

&lt;p&gt;Now i start implementing the details and get to the point where MySQL comes into play. I must say, it has surprised me... both ways.&lt;/p&gt;

&lt;p&gt;The good thing is that after careful tuning, where my previous UNIX experience had a very important role, the database is able to handle the amounts of data that i plan to throw at it. Also it surprised me that some pretty complex queries run a lot faster than expected.&lt;/p&gt;

&lt;p&gt;Then the bad things started to show up. The hardest to debug was that updating an indexed column from multiple parallel transactions causes deadlocks witch cause transactions to be aborted. Of course this only happens at high loads. It was not hard to avoid this after i found out what the problem was ... but still after this i had a feeling of working with something that might not be as reliable as expected.&lt;/p&gt;

&lt;p&gt;After that the &lt;a href=&quot;http://dev.mysql.com/downloads/connector/net/&quot; title=&quot;MySQL .NET connector&quot;&gt;MySQL .NET connector&lt;/a&gt; dropped the bomb on me: &lt;a href=&quot;http://bugs.mysql.com/bug.php?id=37283&quot; title=&quot;Distributed Transactions bug&quot;&gt;Distributed Transactions are not supported&lt;/a&gt;. Ok, they are not supported but why the hell does the connector throws an exception when used in a distributed transaction? I can understand that i can’t rely on the MySQL transaction being enlisted in the Distributed Transaction (DT) and that i have to handle that myself but not being able to use the connector AT ALL under a DT was unexpected. At this point i see only one solution: &lt;a href=&quot;http://bazaar.launchpad.net/%7Emysql-clr-team/connectornet/6.2/files&quot;&gt;grab the source&lt;/a&gt; for the connector and modify the part that checks if a DT is present and just ignore it. Turns out this was very easy to do. If anyone is interested in this change in the connector i can provide more details.&lt;/p&gt;

&lt;p&gt;Now i need to find a way of having a &lt;a href=&quot;http://nhforge.org&quot;&gt;NHibernate&lt;/a&gt; ISession and a ITransaction per &lt;a href=&quot;http://nservicebus.com/&quot; title=&quot;NServiceBus&quot;&gt;NServiceBus&lt;/a&gt; message handler.&lt;/p&gt;

&lt;p&gt;The first approach was something similar to what &lt;a href=&quot;http://andreasohlund.blogspot.com/2010/02/nhibernate-session-management-in.html&quot; title=&quot;Andreas Öhlund - Nhibernate Session Management&quot;&gt;Andreas Öhlund describes in this blog post&lt;/a&gt;. The only problem is that IMessageModule implementations in NServiceBus 2.0 are singletons and that was a problem because i need to store the ITransaction to commit or rollback at the end of the message handler. If in the next version of the NServiceBus there will be a way to have some message handler “wrapper” that it could work.&lt;/p&gt;

&lt;p&gt;My solution was to use a base abstract class for the massage handlers. So instead of just implementing IMessageHandler&lt;T&gt; now i derive from this base class. The code below should speak for itself:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// Base class for message handlers.&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// Manages the unit of work required for handling the message.&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MessageHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IMessageHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;           &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IMessage&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;/// The injected unit of work implementation.&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnitOfWork&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MessageHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IUnitOfWork&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;/// Concrete handlers must implement this method.&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HandleMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;25&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;26&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;27&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;HandleMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;28&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Complete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;29&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;30&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;31&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;32&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;33&lt;/span&gt;             &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;34&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;35&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;36&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;37&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;unitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Dispose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;38&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;39&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;40&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The implementation for the IUnitOfWork is in this case very simple, providing only the creation of the session and the transaction and the required operations. Since the unit of work is created per handler and the handlers don’t use other threads to do the work I don’t need to worry about making it thread safe.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MessageUnitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnitOfWork&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ISessionFactory&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ITransaction&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ISession&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MessageUnitOfWork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ISessionFactory&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpenSession&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;CurrentSessionContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BeginTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Complete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Commit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Rollback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;25&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Dispose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;26&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;27&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Dispose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;28&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;CurrentSessionContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Unbind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;29&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Dispose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;30&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;GC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SuppressFinalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;31&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;32&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;There is still one small problem. If the handler finishes it’s work without and exception and the mysql transaction is committed BUT an exception is thrown by the bus when committing the distributed transaction the MySQL transaction is not rolled back. But i realized that this only means that the same message might be sent again to the handler and that the handlers in general should handle this logical case since whoever sent the message is free to send it multiple times.&lt;/p&gt;

&lt;p&gt;Since I’ve got this solution working it has handled a few millions of messages and there have been crashes and transaction that got rolled back occasionally but after all the system is designed to be fault tolerant and it has proven it is. Also in all the cases the database remained in a consistent state, witch in the beginning i was not sure it will.&lt;/p&gt;

&lt;p&gt;In the end i would like to thank the &lt;a href=&quot;http://nservicebus.com/Community.aspx&quot; title=&quot;NServiceBus Community&quot;&gt;NServiceBus&lt;/a&gt; team ( mainly &lt;a href=&quot;http://www.udidahan.com/&quot; title=&quot;Udi Dahan&quot;&gt;Udi Dahan&lt;/a&gt; and &lt;a href=&quot;http://andreasohlund.blogspot.com&quot; title=&quot;Andreas Öhlund blog&quot;&gt;Andreas Öhlund&lt;/a&gt; ) witch was very responsive and helpful on the support mailing list. I can only hope to find the time to contribute a few ideas to the next release of NSB. Also i would like to thank the &lt;a href=&quot;http://nhforge.org&quot;&gt;NHibernate&lt;/a&gt; team for the great product they created ( can’t wait for the 3.0 ).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>C# HTTP Request</title>
   <link href="http://www.erata.net/net/csharp-http-request"/>
   <updated>2009-11-21T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/csharp-http-request</id>
   <content type="html">&lt;p&gt;A few years ago I&amp;#39;ve written an article on &lt;a href=&quot;http://www.erata.net/qt-boost/synchronous-http-request/&quot;&gt;how to perform a synchronous HTTP&lt;/a&gt; request using Qt 4.2. I I&amp;#39;ve seen this article today and since now I&amp;#39;m mostly working with C# i was wandering how fast can i do the same thing in c#. After very few minutes I&amp;#39;ve managed to came up with this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.IO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Program&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;WebRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpWebRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;WebResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StreamReader&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StreamReader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetResponseStream&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReadToEnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReadKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And of course the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.net.webrequest_members.aspx&quot;&gt;WebReqest &lt;/a&gt; class allows you to specify all the properties you would ever need for any request, and also allows you to perform request in an asynchronous maner. Now i don&amp;#39;t think you can be more expressive than this. I like qt a lot... but i love c# now.&lt;/p&gt;

&lt;h3&gt;Update...&lt;/h3&gt;

&lt;p&gt;Or you can do this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.IO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Program&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;         &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WebClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DownloadString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>A few things from C++ that i miss in C#</title>
   <link href="http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c"/>
   <updated>2009-07-11T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c</id>
   <content type="html">&lt;p&gt;The last 6-7 months i&amp;#39;ve been working mostly with C# and to be honest I&amp;#39;ve grown found to it. It has really nice features like lambda expressions,   auto properties, extension methods, LINQ witch can really speed up things in terms development time.&lt;/p&gt;

&lt;p&gt;Still ... there are some things from C++ that i now miss: Templates ( as in true generics ) , const correctness, deterministic destruction, static initialization and most of all the control over what is a value and what is a reference.&lt;/p&gt;

&lt;h3&gt;Generics ( Templates )&lt;/h3&gt;

&lt;p&gt;Yes, C# has generics witch give you a level of freedom and ability to write generic code but they are nothing compared to the power of c++ templates. In C++ templates are compiled when instantiated and you don&amp;#39;t need to specify any constraints on the  generic type and as long as the instantiated type is syntactically correct your code will compile. There are ways to define concepts witch can impose requirements on the types but the concepts are also verified when the template is instantiated. Also C# does not allow specialization or partial specialization of generic types.&lt;/p&gt;

&lt;h3&gt;Const Correctness&lt;/h3&gt;

&lt;p&gt;There are a lot of articles on the web about why C# does not implement const correctness. In the end you learn to leave without it but its a nice thing to have and as long as you use it consistently it can help prevent a lot of bugs mostly design bugs. I guess that there are ways in C# to prevent the bugs that const correctness prevents  ( immutable objects, ReadOnly interfaces ) but they are harder to impose on a team of developers.&lt;/p&gt;

&lt;h3&gt;Deterministic Destruction&lt;/h3&gt;

&lt;p&gt;I&amp;#39;m quite sure that I only miss this feature because i come with a C++ background. You can easily have deterministic destruction in C# by using IDisposable and using(...) features, still after years of C++ i kinda like to know when an object gets destructed.&lt;/p&gt;

&lt;h3&gt;Static Initialization&lt;/h3&gt;

&lt;p&gt;To be honest I don&amp;#39;t miss this feature too much. The only thing i find it useful for is implementing the factory pattern where objects register themselves in the factory using static initialization. The downside of this is that it can relay get messy ( hint Static Initialization Fiasco )&lt;/p&gt;

&lt;h3&gt;Control over what is a value and what is a reference&lt;/h3&gt;

&lt;p&gt;Now this i miss the most. I have to admit it I like pointers. Well i actually like smart pointers and i like being in control of what and how i pass as arguments to methods. In C# it&amp;#39;s written in stone: structs are values and classes are references (ok, with boxing you can have references to structs but that&amp;#39;s not the point ). One of the problems is that there is no way of declaring a method that accepts a CONST reference to an instance. When you pass an instance of a class to a method (you actually pass the reference to that instance) , the method has full control over the instance.  This might not be a problem when you write all the code, but in a team with developers of different skill bad things can happen. Add some multi-threading to this and things can get relay messy. Another problem is when you have a value object implemented as a struct that is holding a lot of data and you need to pass this object to a Method that only needs to read something from this object. If you pass it as a value object it will probably get copied ( i&amp;#39;m not sure if the compiler does not implement some copy-on-write here but i would not relay on that ) and if you pass it as a ref than the method might change the data.&lt;/p&gt;

&lt;p&gt;In conclusion I like working with C# but there are some things that i hope will get better in time. Other important &amp;quot;bonuses&amp;quot; you get with C# are the .NET Framework and Visual Studio IDE that speed up substantially the development. The major downsite witch in some cases is a showstopper: Platform Dependent. I don&amp;#39;t know where MONO is right now but if you develop with C# and .NET you better make sure your main target platform is Windows.&lt;/p&gt;

&lt;p&gt;I would be glad to hear what others think about this.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The power of SUDO</title>
   <link href="http://www.erata.net/jokes/the-power-of-sudo"/>
   <updated>2009-06-26T00:00:00+00:00</updated>
   <id>http://www.erata.net/jokes/the-power-of-sudo</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;/images/sandwich.png&quot; alt=&quot;The power of sudo&quot; title=&quot;The power of sudo&quot;&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>C# Extension Methods</title>
   <link href="http://www.erata.net/net/c-extension-methods"/>
   <updated>2009-06-24T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/c-extension-methods</id>
   <content type="html">&lt;p&gt;After a few months I&amp;#39;ve enjoyed the newly ( or not ) added extension methods in 3.0 yesterday i discovered that one of the assumptions I&amp;#39;ve made about them was false. My assumption was that if the instance on witch you call an extension method is NULL you would get a NullReferenceException. Turns out it&amp;#39;s not the case and you can call the extension method on a null reference.&lt;/p&gt;

&lt;p&gt;Thinking about it later, it makes sense. In reality extension methods are nothing more than syntax sugar for calling static methods. And since too much sugar can hurt extension methods might do the same thing if not properly used. The code speaks pretty much for itself.&lt;/p&gt;

&lt;p&gt;The class used as example:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestClass&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;//existing method defined on the class&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Hello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;6&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;7&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Static class defining extension method&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ExtensionContainer&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;//the extension method defined as static&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;NewHello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TestClass&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;6&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;World&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;7&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Test code:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Program&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;// declare and create a test instance&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;TestClass&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TestClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Hello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//outputs: &amp;quot;Hello&amp;quot;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;//call the extension method as a normal method&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NewHello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// outputs: &amp;quot;World&amp;quot;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;// declare a null reference&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;TestClass&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;second&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt;             &lt;span class=&quot;c1&quot;&gt;//calling a method on a null reference throws&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Hello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//will throw Null Reference exception&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NullReferenceException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;NullReference calling Hello&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;25&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;26&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;27&lt;/span&gt;             &lt;span class=&quot;c1&quot;&gt;//calling an extension method does not throw&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;28&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NewHello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//will not throw&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;29&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;30&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NullReferenceException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;31&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;32&lt;/span&gt;             &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;NullReference calling NewHello&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;33&lt;/span&gt;         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;34&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;35&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;//the next two calls are exactly the same&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;36&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NewHello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;37&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ExtensionContainer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NewHello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;38&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;39&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReadKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;40&lt;/span&gt;     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;41&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Even now is still consider extension methods as a very valuable addition to the language, but you just need to understand exactly what they are. The wrong assumption about calling them on a null reference can affect some design choices you may take where in case of a null reference you want an exception to be thrown and no other method called.&lt;/p&gt;

&lt;p&gt;Also using them when appropriate the ability to call extension methods on null references might help you write more readable code by moving the null check in the extension method. This can be particularly useful on writing extension methods that are supposed to be used in Views in ASP.NET MVC where moving the null check in the method leaves the the view&amp;#39;s html code easier to read an understand.&lt;/p&gt;

&lt;p&gt;One conclusion that I&amp;#39;ve drown from this is that in an extension method you should either check for null and throw NullReferenceException if null is not a valid value or handle null appropriately.&lt;/p&gt;

&lt;p&gt;PS: Is it visible that the last 6+ months I&amp;#39;ve been working with C# and not C++ ? :)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>ASP.NET MVC or ASP.NET just got plesent</title>
   <link href="http://www.erata.net/net/asp-net-mvc-or-asp-net-just-got-plesent"/>
   <updated>2009-06-15T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/asp-net-mvc-or-asp-net-just-got-plesent</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve been really busy the last months with the new job where we use c#. I&amp;#39;ve grown found to it ... it has a lot of nice features ... lambda expressions, anonymous types, generic types. Sure there are a lot of thing that can be improved like real generic types ( aka C++ templates ) but it&amp;#39;s a really reliable tool.&lt;/p&gt;

&lt;p&gt;In the past I&amp;#39;ve worked on a few ASP.NET applications and I&amp;#39;ve not enjoyed it very much ( actually every time I&amp;#39;ve used it i promised myself not to use it again ) ... until now. I&amp;#39;ve heard of  ASP.NET MVC witch is supposed to be a different way of developing web applications in .NET and after a few months of using it I can only say ... ya baby ... finally a nice way to use c# and .NET to do web apps.&lt;/p&gt;

&lt;p&gt;If you get the chance give it a go... it&amp;#39;s worthed.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>WordPress Exploit Scanner Plugin</title>
   <link href="http://www.erata.net/security/wordpress-exploit-scanner-plugin"/>
   <updated>2009-03-03T00:00:00+00:00</updated>
   <id>http://www.erata.net/security/wordpress-exploit-scanner-plugin</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve found a few days ago &lt;a href=&quot;http://ocaoimh.ie/exploit-scanner/&quot; title=&quot;Exploit Scanner&quot;&gt;this plugin&lt;/a&gt; and i would like to share with everybody since it may help secure the web. This plugin scans the wordpress installation folder for paterns usualy found in exploits/throjans/malware web scripts. The plugin produces quite a few false positive alerts but also it&amp;#39;s very easy to spot suspicious code in suspicious files.&lt;/p&gt;

&lt;p&gt;It would be nice if &lt;a href=&quot;http://wordpress.org&quot; title=&quot;Wordpress&quot;&gt;wordpress.org&lt;/a&gt; published an api to get the md5 of the core files in a specific version since the plugin right now is hardcoded with wordpress 6.3 md5s and will warn you about core files modifications if you use different versions. Also it would be nice if the plugins on &lt;a href=&quot;http://wordpress.org&quot; title=&quot;Wordpress&quot;&gt;wordpress.org&lt;/a&gt; would provide a way to get their md5 and use that to look for modifications and file additions.&lt;/p&gt;

&lt;p&gt;In conclusion there are ways to improve this plugin but as it is it&amp;#39;s a very useful security tool. Also, if you have wordpress installed in the root of your domain, it will scan every file under it. This plugin is actually what made me write the &lt;a href=&quot;http://www.erata.net/security/i-gave-up-on-coppermine-gallery/&quot; title=&quot;I Gave up on Coppermine&quot;&gt;Coppermine article&lt;/a&gt; since it found a few uploaded scripts.&lt;/p&gt;

&lt;p&gt;Stay safe&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://wordpress.org/extend/plugins/exploit-scanner/&quot; title=&quot;Exploit Scanner&quot;&gt;WordPress Exploit Scanner&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>I gave up on Coppermine Gallery</title>
   <link href="http://www.erata.net/security/i-gave-up-on-coppermine-gallery"/>
   <updated>2009-02-27T00:00:00+00:00</updated>
   <id>http://www.erata.net/security/i-gave-up-on-coppermine-gallery</id>
   <content type="html">&lt;p&gt;I used to use &lt;a href=&quot;http://coppermine-gallery.net/&quot; title=&quot;Coppermine Gallery&quot;&gt;Coppermine Photo Gallery&lt;/a&gt; for &lt;a href=&quot;http://gallery.erata.net&quot; title=&quot;Erata.NET Photo Gallery &quot;&gt;http://gallery.erata.net&lt;/a&gt; but today i&amp;#39;ve decided to close it down. The number of vulnerabilities ( most of them critical ) discovered over the years got me thinking. You can see what i mean here &lt;a href=&quot;http://www.milw0rm.com/search.php?dong=coppermine&quot; title=&quot;Exploits List&quot;&gt;http://www.milw0rm.com/search.php?dong=coppermine&lt;/a&gt;. 3 vulnerabilities found in the first two months of 2009.  4 in 2008. This remembers me of sendmail and bind ( witch I&amp;#39;ve heard got better but who cares about them anymore ).&lt;/p&gt;

&lt;p&gt;I know it&amp;#39;s not written in stone but from the number of vulnerabilities i deduce the quality of a pice of software. I also understand open-source ... and open-source brings a lot more peer reviews ... and i don&amp;#39;t mind (that much) vulnerabilities in pre 1.0 versions. But after a few years of development and after a few critical vulnerabilities i&amp;#39;d expect a product to get better and safer.&lt;/p&gt;

&lt;p&gt;Oh well... good luck to the developers of coppermine keeping their users safe.&lt;/p&gt;

&lt;p&gt;Alternatives i consider using for web gallery needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://picasaweb.google.com/&quot; title=&quot;Picassa&quot;&gt;Picassa&lt;/a&gt; - if it&amp;#39;s enough for the job works very well, provides desktop application for management and until proven wrong i belive it&amp;#39;s safe ( and if it&amp;#39;s not i don&amp;#39;t worry to much since it does not run on my server )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://wordpress.org&quot; title=&quot;Wordpress&quot;&gt;WordPress&lt;/a&gt; with &lt;a href=&quot;http://alexrabe.boelinger.com/wordpress-plugins/nextgen-gallery/&quot; title=&quot;NextGen Gallery &quot;&gt;NextGen Gallery&lt;/a&gt; plugin - can be greatly customized and works well and also allows other content posting.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Nokia to Add LGPL to Qt Licensing Model</title>
   <link href="http://www.erata.net/news/nokia-to-add-lgpl-to-qt-licensing-model"/>
   <updated>2009-02-11T00:00:00+00:00</updated>
   <id>http://www.erata.net/news/nokia-to-add-lgpl-to-qt-licensing-model</id>
   <content type="html">&lt;p&gt;This is incredible news. No point in making this post longer ... who knows what this means understands why it&amp;#39;s incredible. Who does not know what this means ... won&amp;#39;t care anyhow :)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt&quot; title=&quot;LGPL License Option Added to Qt &quot;&gt;http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And when i first heard about nokia buying trolltech i thought i&amp;#39;ll have to forget about Qt.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Life with g++</title>
   <link href="http://www.erata.net/programming/life-with-g"/>
   <updated>2008-05-28T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/life-with-g</id>
   <content type="html">&lt;p&gt;The intention of this article is to show a few useful ( i hope ) tips about using g++ in the every day development cycle. Also this article describes three build configurations that should help the developer catch bugs in the early stages of development.&lt;/p&gt;

&lt;h2&gt;Debug Build&lt;/h2&gt;

&lt;p&gt;Most often you will use this configuration. With this you will have a bigger and slower application but it will be easier to debug. The application will contain no optimizations made by the compiler and will also contain debug symbols witch are needed to run you application inside gdb ( or other debugger ) or if you want to analyze a core dump. For the debug build i suggest you use the following flags to g++:&lt;/p&gt;

&lt;p&gt;g++ -W -Wall -Werror -g -fno-inline&lt;/p&gt;

&lt;p&gt;The -W and -Wall parameters will enable all the warnings in g++ and the -Werror will make g++ treat the warnings as errors. If g++ is warning you about something it&amp;#39;s either a compiler bug ( witch is not very probable if you are using a recent version of g++ ) either something you need to fix. You might thing that the compiler is wrong but in 99.99% of the cases the bastard is right and the warning needs to be fixed. And by fixed i don&amp;#39;t mean adding something to quiet down the compiler but really fixed as in correcting the code. The -g option will make g++ add debugging symbols to the binary and the -fno-inline will prevent g++ from inlining any method or function. In some rare cases no-inline will make it easy to debug functions that otherwise would be inline.&lt;/p&gt;

&lt;h2&gt;Developer Release Build&lt;/h2&gt;

&lt;p&gt;The purpose of this build is to catch more warnings and errors that might not occur in the debug build. You should run all the test cases ( if you don&amp;#39;t have test cases stop reading and go write them ) against this version. Your application will be compiled with optimizations and also with debug code disabled but with debug symbols witch will only make the binary bigger. My recommendation for the flags is:&lt;/p&gt;

&lt;p&gt;g++ -W -Wall -Werror -g -O4 -DNDEBUG&lt;/p&gt;

&lt;p&gt;As with the debug build the -W -Wall and -Werror will add warnings and the -g will add the debug symbols. The -O4 will enable the optimizer inside g++. The use of the optimizer in this build is very important because it will enable g++ to find even more warnings than the debug build. Because of this you should do this build at least once a few hours of development or at least before an important commit to the repository. The -DNEBUG will disable all the debug code ( like asserts and debug messages ). You may need to add other defines if your code does not relay on NDEBUG for debug only code.&lt;/p&gt;

&lt;h2&gt;Customer Release Build&lt;/h2&gt;

&lt;p&gt;This is the build that will produce what is given to the customer. This should be an optimized build without debug symbols. This build should contain a build number ( a static string or something similar ) and in the repository you should add a tag or create a branch for the build. If the product is in an alfa/beta stage you might let the debug symbols in. The flags for the build are:&lt;/p&gt;

&lt;p&gt;g++ -W -Wall -Werror -O2 -DNDEBUG&lt;/p&gt;

&lt;p&gt;The only difference from above is the absence of -g because we don&amp;#39;t need debug symbols and the use of -O2 instead of -O4. In the developer build we use O4 to try to catch as many warnings high optimization might reveal but in practice the speed difference between -O4 and O2 is negligible. You should have a good reason for using more than -O2 in this kind of build. Usually computation intensive software ( science , math ) might benefit from using -O3 but for a desktop application -O2 should be more than enough.&lt;/p&gt;

&lt;h2&gt;Other Tips&lt;/h2&gt;

&lt;p&gt;After changing something that affects ABI ( application binary interface ), like adding a function/member, if you receive strange errors you should always make clean and rebuild your application. To speed up the step of make clean and make you may use &lt;a href=&quot;http://ccache.samba.org/&quot; title=&quot;ccache&quot;&gt;ccache&lt;/a&gt; witch caches preprocessed c++ files and saves a lot of time parsing included files. Also the build typed described above can be used with other compilers ( C or C++ compilers ), by using the equivalent options.&lt;/p&gt;

&lt;p&gt;In conclusion you should listen to your compiler and remember that most of the time you are wrong and he is right.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Wt, C++ Web Toolkit</title>
   <link href="http://www.erata.net/programming/wt-c-web-toolkit"/>
   <updated>2008-05-27T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/wt-c-web-toolkit</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://www.webtoolkit.eu/wt/&quot; title=&quot;Wt&quot;&gt;Wt&lt;/a&gt; (pronounced &amp;#39;witty&amp;#39;) is a C++ library and application server for developing and deploying web applications. It is not a &amp;#39;framework&amp;#39;, which enforces a way of programming, but a library.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve found myself a new toy :). No more php or C# or ASP or other things i don&amp;#39;t like to use but i have to use. I haven&amp;#39;t yet started to use Wt, but looks nice. Like it or not the web-app is competing really well with the native-app, at least from the desktop user&amp;#39;s point of view. It would be nice to have a way of writing web apps with things like type safety, generic code and most important reusing libraries like boost.&lt;/p&gt;

&lt;p&gt;From the first look at the Wt code i looks somehow familiar, maybe because I&amp;#39;ve used Qt a lot and the Wt&amp;#39;s slot/signal mechanism seems similar.&lt;/p&gt;

&lt;p&gt;A C++ library that allows creation of a web graphical interface by using widgets rather than hand written html. Sounds wonderful. I can only hope it will raise up to the expectations.&lt;/p&gt;

&lt;p&gt;More after a play with it.&lt;/p&gt;

&lt;p&gt;details at: &lt;a href=&quot;http://www.webtoolkit.eu/wt/&quot; title=&quot;Wt website&quot;&gt;http://www.webtoolkit.eu/wt/&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Flash on FreeBSD - Gnash</title>
   <link href="http://www.erata.net/freebsd/flash-on-freebsd-gnash"/>
   <updated>2008-05-27T00:00:00+00:00</updated>
   <id>http://www.erata.net/freebsd/flash-on-freebsd-gnash</id>
   <content type="html">&lt;p&gt;Watching flash content on FreeBSD was and still is a problem. It&amp;#39;s sad Adobe won&amp;#39;t publish a native version of flash for FreeBSD, or even better open the sources for the flash player. It&amp;#39;s strange they don&amp;#39;t, unless the sources are a real mess I don&amp;#39;t see any strong reason for not doing so. Now that rumors are found about new technologies for web graphics like svg, html 5, flash might not be so popular in the future.&lt;/p&gt;

&lt;p&gt;About the linux plugin for native firefox i don&amp;#39;t have much to say. I does not work reliable. Yes you can watch some movies in some conditions with linux-flash7 with nspluginwrapper but still with a lot of problems depending on arch/site/browser/movie version. With linux-flash9 even more problems. I realized that in the end it&amp;#39;s more frustration than satisfaction and the feeling was that I&amp;#39;m fighting the wrong battle in trying to make the linux-flash work on FreeBSD.&lt;/p&gt;

&lt;p&gt;Now I&amp;#39;m living with &lt;a href=&quot;http://www.gnu.org/software/gnash/&quot; title=&quot;Gnash&quot;&gt;gnash&lt;/a&gt; ( graphics/gnash ). Well, it&amp;#39;s not perfect but at least it&amp;#39;s open source and does play a lot of movies. And the best thing about it was that with the release of a new version ( 0.8.2 ) movies that did not work with 0.8.1 are now working so it&amp;#39;s progressing. Youtube is working pretty well also.&lt;/p&gt;

&lt;p&gt;In conclusion if you really need flash on FreeBSD try &lt;a href=&quot;http://www.gnu.org/software/gnash/&quot; title=&quot;Gnash&quot;&gt;supporting gnash.&lt;/a&gt; As an open source alternative to the flash plugin it&amp;#39;s starting to look more than promising.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>WordPress WassUp Error</title>
   <link href="http://www.erata.net/programming/wordpress-wassup-error"/>
   <updated>2008-04-07T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/wordpress-wassup-error</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve upgraded the wassup plugin to the latest version ( 1.5 ) and an error started to show in the pages:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;[ wp_wassup_tmp&amp;#39; doesn&amp;#39;t exist ]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The solution is to deactivate the plugin and then reactivate it... witch should be the right way to upgrade your plugins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I also get a syntax error from the wassup plugin, on the dashboard:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;***WordPress database error:*** [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &amp;#39;AND 1207656596&amp;#39; at line 1]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;COUNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;DISTINCT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wassup_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itemstot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wp_wassup&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wassup_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;IS&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;timestamp&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;BETWEEN&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1207656596&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It seems that the errore comes from a debug query that was left in the wassupDashChart() function. To fix the error you need to comment two lines (1631,1632) of code in wassup.php:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;// This is the function to print out a chart&amp;#39;s preview in the dashboard&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;function wassupDashChart() {&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  global $wpdb;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  $table_name = $wpdb-&amp;gt;prefix . &amp;quot;wassup&amp;quot;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  $to_date = wassup_get_time();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  $Chart = New MainItems;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  $Chart-&amp;gt;tableName = $table_name;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  $Chart-&amp;gt;to_date = $to_date;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  //$itemstot = $Chart-&amp;gt;calc_tot(&amp;quot;count&amp;quot;, $search, null, &amp;quot;DISTINCT&amp;quot;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  //print $itemstot;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  echo &amp;#39;&amp;lt;h3&amp;gt;WassUp Stats &amp;lt;cite&amp;gt;&amp;lt;a href=&amp;quot;admin.php?page=wassup&amp;quot;&amp;gt;More »&amp;lt;/a&amp;gt;&amp;lt;/cite&amp;gt;&amp;lt;/h3&amp;gt;&amp;#39;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  echo $Chart-&amp;gt;TheChart(1, &amp;quot;400&amp;quot;, &amp;quot;125&amp;quot;, &amp;quot;&amp;quot;, $wassup_options-&amp;gt;wassup_chart_type, &amp;quot;bg,s,00000000&amp;quot;, &amp;quot;dashboard&amp;quot;, &amp;quot;left&amp;quot;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;} //end function wassupDashChart&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>myWeather widget</title>
   <link href="http://www.erata.net/programming/myweather-widget"/>
   <updated>2007-12-06T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/myweather-widget</id>
   <content type="html">&lt;p&gt;To create a quick and dirty widget from myWeather wordpress plugin just add the following to the end of myweather.php&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;function widget_weather_init(){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  if ( !function_exists(&amp;#39;register_sidebar_widget&amp;#39;) )&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;    return;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  register_sidebar_widget(array(&amp;#39;Weather&amp;#39;, &amp;#39;widgets&amp;#39;), &amp;#39;widget_weather&amp;#39;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;function widget_weather($args){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  extract($args);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  echo $before_widget . $before_title . $title . $after_title;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  wp_myweather();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  echo $after_widget;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;add_action(&amp;#39;widgets_init&amp;#39;, &amp;#39;widget_weather_init&amp;#39;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Also the part where you search for the city could be added as a control for the widget but i didn&amp;#39;t relay need it to be .&lt;/p&gt;

&lt;p&gt;MyWeather plugin&amp;#39;s &lt;a href=&quot;http://www.thedeveloperinside.com/blog/myweather-20-released/&quot; title=&quot;MyWeather&quot;&gt;homepage&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Update&lt;/h3&gt;

&lt;p&gt;If you have multiple users with different credentials on your blog and you are the only administrator you can restrict the access to myWeather plugin administration interface by changing the function &lt;strong&gt;myweather&lt;em&gt;to&lt;/em&gt;admin()&lt;/strong&gt; to look like this (use 10 instead of 1 for required level) :&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;function myweather_to_admin() {&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  if (function_exists(&amp;#39;add_submenu_page&amp;#39;)) {&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;    add_submenu_page(&amp;#39;options-general.php&amp;#39;, &amp;#39;myWeather&amp;#39;,&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;    &amp;#39;myWeather&amp;#39;, 10, basename(__FILE__),&amp;#39;myweather_admin&amp;#39;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;  }&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;6&lt;/span&gt; &lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>qmake error:  sible braces mismatch %s:%d</title>
   <link href="http://www.erata.net/qt-boost/qmake-error-sible-braces-mismatch-sd"/>
   <updated>2007-07-27T00:00:00+00:00</updated>
   <id>http://www.erata.net/qt-boost/qmake-error-sible-braces-mismatch-sd</id>
   <content type="html">&lt;p&gt;I&amp;#39;ve just received this error with qmake on windows. Googling for it showed no results so after i&amp;#39;ve solved the problem i decided to put it here.&lt;/p&gt;

&lt;p&gt;The error was near a conditional block like:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; unix{
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; }
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt; win32{
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt;   QMAKE_UIC+ = -L ../bin/plugin
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;...after searching for unclosed/missing braces for a while without any result and comparing svn versions i&amp;#39;ve finally found the problem. On the QMAKE_UIC linke instead of &amp;quot;+=&amp;quot; somehow ( probably kdevelop&amp;#39;s qmake parser/generator ) got saved as &amp;quot;+ =&amp;quot; (notice the space). The problem would have been much easier to solve if the error message wasn&amp;#39;t so misleading. &lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; #bad version
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; QMAKE_UIC + = -L ../bin/plugin
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt; #good version
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; QMAKE_UIC += -L ../bin/plugin&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So if you see this error look for operators that might have a space inserted in the middle. Hope this will save somebody&amp;#39;s time.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Qmake Error Sible Braces Mismatch Sd</title>
   <link href="http://www.erata.net/qt-boost/2007/07/27/qmake-error-sible-braces-mismatch-sd/"/>
   <updated>2007-07-27T00:00:00+00:00</updated>
   <id>http://www.erata.net/qt-boost/2007/07/27/qmake-error-sible-braces-mismatch-sd</id>
   <content type="html"></content>
 </entry>
 
 <entry>
   <title>ASP.NET 2.0 and SQLServer 2000 Transactions</title>
   <link href="http://www.erata.net/net/aspnet-20-sqlserver-2000-transactions"/>
   <updated>2007-06-27T00:00:00+00:00</updated>
   <id>http://www.erata.net/net/aspnet-20-sqlserver-2000-transactions</id>
   <content type="html">&lt;p&gt;The new ADO.NET 2.0 and it&amp;#39;s typed datasets and table adapters are very useful tools for creating a DAL in you application. Still when working with SQLServer 2000 implementing transactions is a bit tricky. &lt;/p&gt;

&lt;p&gt;You can use TransactionScope but is seems to be designed for SQLServer 2005 as it will promote all transactions to distributed on SQLServer 2000 witch is a performance problem but also a bigger problem if your hosting provider does not provide distributed transactions. I&amp;#39;ve found a few solutions on the net some using reflection some using partial classes to add a method to the table adapter. Since i don&amp;#39;t like using reflection unless i absolutely have to I&amp;#39;ve come up with a solution using partial classes but trying to minimize the code you have to write for each table adapter and also trying to make is less error prone.&lt;/p&gt;

&lt;p&gt;The new ADO.NET 2.0 and it&amp;#39;s typed datasets and table adapters are very useful tools for creating a DAL in you application. Still when working with SQLServer 2000 implementing transactions is a bit tricky. &lt;/p&gt;

&lt;p&gt;First we define an interface witch the table adapters will implement:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ITransactionable&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SqlCommand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Commands&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now define a helper class that will manage all transaction operations.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TransactionHelper&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlTransaction&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BeginTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ITransactionable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BeginTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IsolationLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReadUncommitted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlTransaction&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BeginTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ITransactionable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IsolationLevel&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lvl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;State&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ConnectionState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Closed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;SqlTransaction&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trans&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BeginTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lvl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;SetTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt;   
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;SetTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ITransactionable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlTransaction&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SqlCommand&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;com&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Commands&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Transaction&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now for each table adapter that we need to use transactions:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;partial&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DemoTableAdapter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ITransactionable&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlConnection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlCommand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Commands&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CommandCollection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As you can see the code needed for each table adapter is minimal and only requires copy-pasting and changing the name of the class. If c# would support c-style macros this could be reduced to a single line of code. To use the TransactionHelper class:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c#&quot; data-lang=&quot;c#&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;....&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlTransaction&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DemoTableAdapter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DemoTableAdapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TransactionHelper&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BeginTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;....&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operations&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;....&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OtherTableAdapter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OtherTableAdapter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;TransactionHelper&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SetTransaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;....&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operations&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adapter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;....&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Commit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Rollback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;....&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Dispose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Hope it helps.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Windows Integration</title>
   <link href="http://www.erata.net/freebsd/windows-integration"/>
   <updated>2007-05-18T00:00:00+00:00</updated>
   <id>http://www.erata.net/freebsd/windows-integration</id>
   <content type="html">&lt;p&gt;Here is a preview of what you can do if you have a windows machine somewhere.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/mydesktop.png&quot; alt=&quot;My Desktop&quot; title=&quot;My Desktop&quot;&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Flash7 with native FreeBSD browsers</title>
   <link href="http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers"/>
   <updated>2007-03-18T00:00:00+00:00</updated>
   <id>http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers</id>
   <content type="html">&lt;p&gt;Finally the linux-flash7 plugin works with native firefox. If it&amp;#39;s not working for you this may help.&lt;/p&gt;

&lt;h2&gt;Update&lt;/h2&gt;

&lt;p&gt;With the nspluginwrapper port this &lt;a href=&quot;http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2007-07/msg01919.htm&quot;&gt;&lt;br&gt;
post&lt;/a&gt; may be more usefull. The if you still have problems you may try the tips below.&lt;/p&gt;

&lt;h2&gt;Step By Step HOWTO&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Use cvsup or portsnap to update your ports tree&lt;/li&gt;
&lt;li&gt;install www/linuxpluginwrapper&lt;/li&gt;
&lt;li&gt;copy libflashplayer.so and flashplayer.xpt from distfiles/flashplugin/7.0r68/install&lt;em&gt;flash&lt;/em&gt;player&lt;em&gt;7&lt;/em&gt;linux.tar.gz to /usr/local/lib/browser_plugins&lt;/li&gt;
&lt;li&gt;Fireup firefox or opera and test&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If in the future the dependency on the linux emulation layer is removed from linux-flash7 port it will be ok to install the port as you would normally do, but until then i prefer to manually unpack the two files instead of installing the hole linux-base port(s) witch is not needed anyway for the plugin to work.  &lt;/p&gt;

&lt;p&gt;If it works congratulations, if firefox crashes and opera displays just an empty box ... read on.&lt;/p&gt;

&lt;h2&gt;Fixing Plugin Crash&lt;/h2&gt;

&lt;p&gt;Here there are two things to try. (the first one is recommended)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; edit /etc/X11/xorg.conf and &lt;strong&gt;disable the Composite extension&lt;/strong&gt; and &lt;strong&gt;set the ColorDepth to 24&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt; edit /usr/local/bin/firefox and add &lt;strong&gt;export XLIB_SKIP_ARGB_VISUALS=1&lt;/strong&gt; in the beginning of the file&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I&amp;#39;ve noticed that opera still has some trouble working with the plugin and as a fix I&amp;#39;ve done a small change to the linuxpluginwrapper port. In compat_linux/linux_ioctl.c I&amp;#39;ve changed the default switch branch from:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;errno&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ENOSYS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;dprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;ioctl(fd=%d, request=%08X(on Linux), ...) = %d / ERRNO = %d&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errno&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt;      &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_ioctl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;va_arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After this change the plugin works fine but sometimes you need to reload the page for opera to display the flash content.&lt;/p&gt;

&lt;h2&gt;References&lt;/h2&gt;

&lt;p&gt;Information on fixing the crash was gathered from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href=&quot;https://launchpad.net/ubuntu/+source/flashplugin-nonfree/+bug/62988&quot;&gt;https://launchpad.net/ubuntu/+source/flashplugin-nonfree/+bug/62988&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href=&quot;http://www.kaourantin.net/#116224299860645174&quot;&gt;http://www.kaourantin.net/#116224299860645174&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;To be continued&lt;/h2&gt;

&lt;p&gt;Now that I&amp;#39;ve learned this i really have a good feeling about linux-flash9 and native browsers. I haven&amp;#39;t tested yet but i guess the fix for the crashes works also for linux-flash9 with linu-firefox and linux-opera.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>KDevelop - KDevTrollProject Problem</title>
   <link href="http://www.erata.net/freebsd/kdevelop-kdevtrollproject-problem"/>
   <updated>2007-03-17T00:00:00+00:00</updated>
   <id>http://www.erata.net/freebsd/kdevelop-kdevtrollproject-problem</id>
   <content type="html">&lt;p&gt;After updating kde to 3.5.6 and kdevelop to 3.4.0_1 ( around 15.03.2007 ) kdevelop failed to open qmake based projects. The error was &amp;quot;Error creating project management plugin KDevTrollProject&amp;quot;.&lt;/p&gt;

&lt;h2&gt;Update&lt;/h2&gt;

&lt;p&gt;On 23.03.2007 a fix has been committed to the kdevelop port so if you encounter this problem it&amp;#39;s better to update the ports tree and recompile kdevelop.&lt;/p&gt;

&lt;h2&gt;Finding why&lt;/h2&gt;

&lt;p&gt;It took me a few houers to find out that the problem was an undefined reference to a symbol in &lt;em&gt;/usr/local/lib/libkdevqmakeparser.so&lt;/em&gt;. The symbol was QMake::Lexer. Grepping to kdevelop sources i found that the libkdevqmakeparser is build in buildtools/lib/parsers/qmake. There i found that qmake_lex.cpp was not compiled and linked to the library.&lt;/p&gt;

&lt;h2&gt;Quick Fix&lt;/h2&gt;

&lt;p&gt;Below are the command lines to build qmake_lex.cpp and relink libkdevqmakeparser.so&lt;/p&gt;

&lt;p&gt;The fix_lex.sh file:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; /bin/sh /usr/local/bin/libtool --silent --tag&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CXX --mode&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;compile c++ -DHAVE_CONFIG_H  -I. -I. -I../../../.. -I../../../../lib/interfaces  -I../../../../lib/interfaces/extensions -I../../../../lib/util -I../../../../lib/widgets/propeditor  -I/usr/local/include -I/usr/X11R6/include  -I/usr/local/include  -D_THREAD_SAFE -pthread -DQT_THREAD_SUPPORT   -I/usr/local/include -I/usr/local/include  -I/usr/X11R6/include -D_GETOPT_H -D_THREAD_SAFE   -Wno-long-long -Wundef -Wall -W -Wpointer-arith -DNDEBUG -DNO_DEBUG -O2 -O2 -fno-strict-aliasing -pipe -Wno-non-virtual-dtor -fno-exceptions -fno-check-new -fno-common -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION  -MT qmake_lex.lo -MD -MP -MF &lt;span class=&quot;s2&quot;&gt;&amp;quot;.deps/qmake_lex.Tpo&amp;quot;&lt;/span&gt; -c -o qmake_lex.lo qmake_lex.cpp&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt; mv -f &lt;span class=&quot;s2&quot;&gt;&amp;quot;.deps/qmake_lex.Tpo&amp;quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;.deps/qmake_lex.Plo&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; rm -f &lt;span class=&quot;s2&quot;&gt;&amp;quot;.deps/qmake_lex.Tpo&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fi&lt;/span&gt;
/bin/sh /usr/local/bin/libtool --silent --tag&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CXX --mode&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;link c++   -Wno-long-long -Wundef -Wall -W -Wpointer-arith -DNDEBUG -DNO_DEBUG -O2 -O2 -fno-strict-aliasing -pipe -Wno-non-virtual-dtor -fno-exceptions -fno-check-new -fno-common -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION    -o libkdevqmakeparser.la -rpath /usr/local/lib -no-undefined  -L/usr/local/lib -L/usr/X11R6/lib   -D_THREAD_SAFE -pthread  -L/usr/local/lib -lkio qmakeast.lo qmakedriver.lo  qmake_yacc.lo qmake_lex.lo qmakeastvisitor.lo  -Wl,-export-dynamic -L/usr/local/lib -L/usr/X11R6/lib -ljpeg  -L/usr/X11R6/lib&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /usr/ports/devel/kdevelop
make extract patch configure
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;work/kdevelop-3.4.0/buildtools/lib/parsers/qmake
sh fix_lex.sh
cp .libs/libkdevqmakeparser.so.0 /usr/local/lib/&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I somehow have the impression that I&amp;#39;m the only one having this problem since i haven&amp;#39;t seen any reports on the mailing lists. It may be some bad combination of autotools/libtools. If I&amp;#39;m the only one having this problem then it&amp;#39;s not worth investing more time in a proper fix. If other users will report this problem then probably a patch to add the qmake_lex.cpp file to the Makefile with appropriate rules may be needed. My experience with autotools and handwritten Makefiles is close to zero (and i intend to keep it that way) but i guess the kde folks will have no problem fixing this once the problem i known.&lt;/p&gt;

&lt;p&gt;If someone else experiences this problem please leave a comment or a post a message on the freebsd mailing list&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Virtual Destructors</title>
   <link href="http://www.erata.net/programming/virtual-destructors"/>
   <updated>2006-11-18T00:00:00+00:00</updated>
   <id>http://www.erata.net/programming/virtual-destructors</id>
   <content type="html">&lt;h2&gt;When do you need to declare a destructor virtual?&lt;/h2&gt;

&lt;p&gt;Recently I’ve been involved in a thread on qt-interest mailing list about virtual destructors. A few people there suggested that you should always make the destructor of your class virtual. I strongly disagree. &lt;/p&gt;

&lt;p&gt;The argument was that if you use the virtual keyword on your destructor you will always be on the safe side. If someone inherits from your class and then deletes one of his instances of the class by a pointer to your base class you are sure his destructor gets called. So you are designing a class with value semantics (can be copied, can be assigned to) and you fear that someone will eventually inherit from your class so you make the destructor virtual. Well then why not make all the methods virtual so that if someone will inherit your class will have the possibility to customize its behavior. Is this starting to sound wrong? Well it should. &lt;/p&gt;

&lt;p&gt;Just to be clear, I’m not trying to say that declaring a destructor virtual on a class WILL cause trouble. I’ll try to explain why it’s BAD CODING STYLE to always declare you destructor virtual. A good coding style will most probably keep you away from dangers like inheriting a class that has not been meant to be used as a base class.&lt;/p&gt;

&lt;p&gt;As Herb Sutter and Andrei Alexandrescu state in “C++ Coding Standards: 101 Rules, Guidelines, and Best Practices” item 32:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be clear what kind of class you&amp;#39;re writing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Be clear to yourself and to the users of your class. The most used types of classes are value classes and polymorphic classes. As a rule of thumb:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Never try to write a class that is of both types.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These types of classes are complementary. Value types are concrete types that mimic the built-in types, which are usually instantiated on the stack and are passed around by reference or by value. Polymorphic classes are meant to be used as base classes, are usually instantiated on the heap and used via (smart) pointer. In C++ the keyword virtual means “this will be a polymorphic class” and a copy constructor and assignment operator mean “this will be a value class”.&lt;/p&gt;

&lt;h2&gt;Now when the destructor should be declared virtual?&lt;/h2&gt;

&lt;p&gt;You &lt;strong&gt;MUST&lt;/strong&gt; declare the destructor virtual &lt;strong&gt;ONLY&lt;/strong&gt; if you are creating a polymorphic class witch has a &lt;strong&gt;PUBLIC&lt;/strong&gt; destructor. That’s it. That’s the only case when you must declare the destructor virtual. If you don’t declare it virtual BAD THINGS will happen (destructors of child classes will not be called when deleting by base class).&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot; calling ~A()&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;~B()&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;///In this case ~B() will not be called.&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You &lt;strong&gt;SHULD&lt;/strong&gt; (read &lt;strong&gt;MUST&lt;/strong&gt;) &lt;strong&gt;NOT&lt;/strong&gt; declare your destructor virtual in any other case. If you declare it virtual the biggest problem is someone using your class might think that your class is a polymorphic class that can be inherited from. If this happens the code will probably work but will be awkward and difficult to write and maintain. There is also a performance hit that comes with virtual destructors but unless you are writing something where every nanosecond counts you will not care about this hit.&lt;/p&gt;

&lt;p&gt;Now what do you do if you find a nice class that is a value class (even if the author made the destructor virtual) but you want to add some custom functionality to it?&lt;/p&gt;

&lt;p&gt;Use &lt;strong&gt;FREE FUNCTIONS&lt;/strong&gt;. That’s it. Having free functions will not make your coding less Object Oriented. Free function will give you the same access level as inheriting from a value class as value classes don’t usually have protected methods. To avoid problems place the free functions in the same namespace as the class. As an example if you have a string class and want to have a method that will return the word count from the string: &lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;wordCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;///count the words&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;6&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doSomething&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;7&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// instead of str.wordCount() you will now have:&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;8&lt;/span&gt;   &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wordCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;9&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;There are lots of things to be said about class design. You should search for books written on the subject and learn about good ways of creating classes. The sad part is that until you are bitten by a bad design that you have to live with you most probably will not understand the importance of good design and coding style in general.&lt;/p&gt;

&lt;p&gt;In the end if you are an employer and want to quickly see if a candidate knows about virtual functions ask him what “static virtual functions” and “virtual constructors” have in common. (if you don’t know the answer contact me).&lt;/p&gt;

&lt;h2&gt;Updates&lt;/h2&gt;

&lt;p&gt;A very good article about &lt;a href=&quot;http://www.gotw.ca/publications/mill18.htm&quot;&gt;virtuality&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And another great article about &lt;a href=&quot;http://www.ddj.com/dept/cpp/184403760&quot;&gt;virtual functions&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&amp;quot;Virtual functions should be treated very much like data members — make them private, until design needs indicate a less restricted approach is indicated. It is much easier to promote them to a more accessible level, than it is to demote them to a more private level.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>Synchronous Http Request</title>
   <link href="http://www.erata.net/qt-boost/2006/11/08/synchronous-http-request/"/>
   <updated>2006-11-08T00:00:00+00:00</updated>
   <id>http://www.erata.net/qt-boost/2006/11/08/synchronous-http-request</id>
   <content type="html"></content>
 </entry>
 
 <entry>
   <title>Qt4 Synchronous HTTP Request</title>
   <link href="http://www.erata.net/qt-boost/synchronous-http-request"/>
   <updated>2006-11-08T00:00:00+00:00</updated>
   <id>http://www.erata.net/qt-boost/synchronous-http-request</id>
   <content type="html">&lt;h2&gt;Problem&lt;/h2&gt;

&lt;p&gt;Creating a wrapper over QHttp that can perform GET and POST requests in a synchronous way.&lt;/p&gt;

&lt;h2&gt;Solution&lt;/h2&gt;

&lt;p&gt;In Qt4 QHttp can perform HTTP requests, but the API only allows asynchronous requests. This means that you need to specify a set of slots to handle the signals that can be emitted while the request if performed. Now don&amp;#39;t get me wrong, this is event driven programming and most of the times is the right way to go especially when writing a Qt based application.  The cases when event driven operations prove difficult to use are rare and usually can be programmed using events.&lt;/p&gt;

&lt;p&gt;Recently I’ve developed a small application that had to do a number of requests in a specified order and show a message if an error was to occur. The algorithm was simple:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requestList&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;runRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For writing something like this I would like to not split the algorithm across a set of slots. So I would like to have a possibility to run a request and wait for it to finish.&lt;/p&gt;

&lt;h2&gt;Implementation&lt;/h2&gt;

&lt;p&gt;We start by creating a &lt;em&gt;SyncHTTP&lt;/em&gt; class that is derived from QHttp:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SyncHTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;Q_OBJECT&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// id of current request&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;   &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requestID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// error status of current request&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;   &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// event loop used to block until request finished&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;QEventLoop&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// structors&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SyncHTTP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;QHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requestID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SyncHTTP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hostName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quint16&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;QHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hostName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requestID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SyncHTTP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we need to implement the methods for &lt;em&gt;syncGet&lt;/em&gt; and &lt;em&gt;syncPost&lt;/em&gt; to mimic the &lt;em&gt;get&lt;/em&gt; and &lt;em&gt;post&lt;/em&gt; methods from QHttp:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// send GET request and wait until finished&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;syncGet&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QIODevice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;///connect the requestFinished signal to our finished slot&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SIGNAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requestFinished&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SLOT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;finished&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)));&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// start the request and store the requestID&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;requestID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// block until the request is finished&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// return the request status&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// send POST request and wait until finished&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;syncPost&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QIODevice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QIODevice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;///connect the requestFinished signal to our finished slot&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SIGNAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requestFinished&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SLOT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;finished&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)));&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// start the request and store the requestID&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;requestID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// block until the request is finished&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// return the request status&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;25&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;26&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;27&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;28&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;syncPost&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QByteArray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QIODevice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;29&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;30&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// create io device from QByteArray&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;31&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;QBuffer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;32&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;33&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;syncPost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;34&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;em&gt;syncGet&lt;/em&gt; and &lt;em&gt;syncPost&lt;/em&gt; functions both use the same strategy. They connect the &lt;em&gt;requestFinished&lt;/em&gt; signal from QHttp to a &lt;em&gt;finished&lt;/em&gt; slot, they ask the QHttp object to perform the request. The QHttp&amp;#39;s get/post method returns immediately with the request id that has been assigned to the current request. Now the nice part: After asking the QHttp object to perform the request we need to wait for it to finish, so we create an event loop and start it. The main event loop is now blocked and we are nor risking being called aging while executing the request. The blocking code is not using tricks like sleep or infinite loops so we don&amp;#39;t end up using 100% CPU or wasting time sleeping. Now we just need to implement the &lt;em&gt;finished&lt;/em&gt; slot to save the result and exit the loop:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;slots&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;finished&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// check to see if it&amp;#39;s the request we made&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requestID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// set status of the request&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// end the loop&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now this slot first checks to see if it&amp;#39;s being called for our request and returns if not, after that saves the error status returned by the QHttp object and exits the loop. The execution now will return in the &lt;em&gt;syncGet/syncPost&lt;/em&gt; function that will return the status to the caller.&lt;/p&gt;

&lt;h2&gt;Testing&lt;/h2&gt;

&lt;p&gt;Ok, let&amp;#39;s write a small test application. Writing real automated test cases for this kind of class is possible but not trivial so will just write a small test app.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c--&quot; data-lang=&quot;c++&quot;&gt;&lt;span class=&quot;lineno&quot;&gt; 1&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 2&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 3&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;#include &amp;quot;synchttp.h&amp;quot;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 4&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt; 5&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 6&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 7&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;QApplication&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 8&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;/// create object&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt; 9&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;SyncHTTP&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;www.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;10&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;11&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;///prepare output buffer&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;12&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;QBuffer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getOutput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;13&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;syncGet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;/search?q=erata.net&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getOutput&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;14&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;qDebug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getOutput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;15&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;16&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;QByteArray&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;QString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;q=data&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toLatin1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;17&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;QBuffer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;postOutput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;18&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;19&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;syncPost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;/search&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;postOutput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;20&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;21&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;qDebug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;postOutput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;22&lt;/span&gt; 
&lt;span class=&quot;lineno&quot;&gt;23&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;24&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now in conclusion i would like to say that i recommend using this class only when you simply need to perform a request and know if it was successful or not. On any other case, where you need to do more complicated things learn to use Qt&amp;#39;s event driven programming model.&lt;/p&gt;

&lt;p&gt;Download &lt;a href=&quot;https://gist.github.com/etishor/9019410&quot; title=&quot;Source File for SyncHTTP&quot;&gt;synchttp.h&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PS: this is my first programming HOWTO so be merciful :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The code and ideas from this article can be used without any license restrictions. You can consider it under &lt;a href=&quot;http://opensource.org/licenses/bsd-license.php&quot; title=&quot;BSD license&quot;&gt;BSD&lt;/a&gt;,&lt;a href=&quot;http://opensource.org/licenses/mit-license.php&quot;&gt;MIT&lt;/a&gt;,&lt;a href=&quot;http://opensource.org/licenses/bsl1.0.html&quot;&gt;BSL&lt;/a&gt; or whatever suites you best. Providing my name or a link to this website would be nice but is not required.&lt;/strong&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Modern Websites</title>
   <link href="http://www.erata.net/projects/modern-websites"/>
   <updated>2006-10-25T00:00:00+00:00</updated>
   <id>http://www.erata.net/projects/modern-websites</id>
   <content type="html">&lt;p&gt;This is not really a project, just my opinion on how modern websites should be done.&lt;/p&gt;

&lt;p&gt;Doing Erata.NET website I&amp;#39;ve learned the advantages of using strict XHTML ( 1.1 ) and CSS. Web design is getting closer to programing this way. You have a modular structure, an easy to follow document layout on witch you can apply styles with CSS. I&amp;#39;m not much of a designer and I&amp;#39;m happy with this style of web design because it allows me to create the structure of the website and use the style-sheets that a real designer can provide.&lt;/p&gt;

&lt;p&gt;This site was mostly tested using firefox, but should look the same in any standards compliant browser. From what I&amp;#39;ve seen in Internet Explorer there are a few thing that don&amp;#39;t look exactly the same, but i consider it a waste of time to try to fight browser stupidity. As long as you are using a bad browser you will be able to use this website, just don&amp;#39;t complain if some things don&amp;#39;t look that good. &lt;/p&gt;

&lt;p&gt;This is it for now, until I&amp;#39;ll find the time and resources to write an &amp;quot;how to start with XHTML &amp;amp; CSS&amp;quot; but I&amp;#39;d like to recommend to anyone to take the time to understand and learn how this technologies work.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Flash Plugin On Freebsd</title>
   <link href="http://www.erata.net/weblog/freebsd/2006/10/16/flash-plugin-on-freebsd/"/>
   <updated>2006-10-16T00:00:00+00:00</updated>
   <id>http://www.erata.net/weblog/freebsd/2006/10/16/flash-plugin-on-freebsd</id>
   <content type="html"></content>
 </entry>
 
 <entry>
   <title>Flash Plugin on FreeBSD</title>
   <link href="http://www.erata.net/freebsd/flash-plugin-on-freebsd"/>
   <updated>2006-10-16T00:00:00+00:00</updated>
   <id>http://www.erata.net/freebsd/flash-plugin-on-freebsd</id>
   <content type="html">&lt;h2&gt;Problem to solve&lt;/h2&gt;

&lt;p&gt;Make a recent flash player plugin work in firefox on FreeBSD 6.&lt;/p&gt;

&lt;h2&gt;Update&lt;/h2&gt;

&lt;p&gt;There is a new &lt;a href=&quot;http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers/&quot;&gt;article&lt;/a&gt; on enabling the linux-flash7 plugin with native browsers.&lt;/p&gt;

&lt;p&gt;With the release of FreeBSD 6.2 and the update on linuxpluginwrapper this tutorial has become obsolete. It&amp;#39;s only recommended if you need to stick with an older version of freebsd and/or flashplugin.&lt;/p&gt;

&lt;h2&gt;Solution&lt;/h2&gt;

&lt;p&gt;First thing to do is get &lt;a href=&quot;https://gist.github.com/etishor/9019433&quot; title=&quot;rtld dlsym hack&quot;&gt;this&lt;/a&gt; patch for /usr/src/libexec/rtld-elf/rtld.c, copy it in /usr/src and do the following: (you must have the source tree in /usr/src and the version of the sources must be the same with the version of the installed world, if they are different or you are not sure it&amp;#39;s probably best to rebuild your world ( FreeBSD world that is :) ) and kernel )&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; root#cd /usr/src
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; root#patch -p0 &amp;lt; rtld_dlsym_hack.diff
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt; root#cd libexec/rtld-elf/
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; root#make &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; make install&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After successfully installing the patch you need to fetch and unpack the linuxflashplayer7:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; root#cd /usr/ports/www/linux-flashplugin7/
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; root#make fetch
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt; root#cd /usr/local/lib/firefox/plugins/
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; root#tar zxvf /usr/ports/distfiles/flashplugin/7.0r68/install_flash_player_7_linux.tar.gz
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; root#cp install_flash_player_7_linux/libflashplayer.so libflashplayer.so
&lt;span class=&quot;lineno&quot;&gt;6&lt;/span&gt; root#cp install_flash_player_7_linux/flashplayer.xpt flashplayer.xpt&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now make sure you have the plugin files ( libflashplayer.so and flashplayer.xpt ) in /usr/local/lib/firefox/plugins.You now need to install the linuxpluginwrapper:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; root#cd /usr/ports/www/linuxpluginwrapper/ &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; make install clean&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Finally you have to change /etc/libmap.conf:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; [/usr/local/lib/firefox/plugins/libflashplayer.so]
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; libpthread.so.0 libpthread.so.2
&lt;span class=&quot;lineno&quot;&gt;3&lt;/span&gt; libdl.so.2 pluginwrapper/flash7.so
&lt;span class=&quot;lineno&quot;&gt;4&lt;/span&gt; libz.so.1 libz.so.3
&lt;span class=&quot;lineno&quot;&gt;5&lt;/span&gt; libm.so.6 libm.so.4
&lt;span class=&quot;lineno&quot;&gt;6&lt;/span&gt; libc.so.6 pluginwrapper/flash7.so&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now open your browser and go to about:plugins. Flash 7 plugins is active.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Web application security flows</title>
   <link href="http://www.erata.net/security/web-application-security-flows"/>
   <updated>2006-10-12T00:00:00+00:00</updated>
   <id>http://www.erata.net/security/web-application-security-flows</id>
   <content type="html">&lt;p&gt;Here goes... my first security related post :)&lt;/p&gt;

&lt;h3&gt;Intro&lt;/h3&gt;

&lt;p&gt;First i must say that this will not be a way to prove that your application is secure, it will only be a quick &amp;amp; dirty way of finding common bugs in web applications. The following will be a few techniques that i tend to use the first time i see an web application ( and generally a database application ). I will use PHP for the few code examples but the vulnerabilities presented are not limited to PHP, in fact are independent of the server-side programming language used.&lt;/p&gt;

&lt;h3&gt;Unexpected Input&lt;/h3&gt;

&lt;p&gt;The first and most common bug is unsanitized user input. The easy way to check for this error is to start replacing variables passed on the URL with characters that need to be escaped when used in an SQL query. Let&amp;#39;s say the after submitting some data or clicking a link in the application you end up in a page like&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;http://www.example.com/products.php?category=1&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In an vulnerable application this most probably generates a query like&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;$query=&amp;#39;SELECT * FROM products WHERE category_id=&amp;#39;.$_GET[&amp;#39;category&amp;#39;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now changing the value of the category to a special SQL character is straightforward:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;http://www.example.com/products.php?category=&amp;#39;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And if the assumption about how the variable is used is correct you will probably end up in a page containing an error message from the database server telling you that there was an error executing the query. Now the executed query looks like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;products&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;category_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Hmm... what next? Server said error, it was an error so what&amp;#39;s the big deal? Very big deal. Now let&amp;#39;s change the variable to something that actually does something.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;http://www.example.com/products.php?category=1;drop table products;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;witch will generate a query like&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;products&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;category_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;products&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Is this big deal enough ? Or maybe something like:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;http://www.example.com/products.php?category=1;insert into users values( null , &amp;#39;x&amp;#39;,password(&amp;#39;x&amp;#39;),true );&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;assuming that there is a user system in the application and a table users ( user&lt;em&gt;id , user&lt;/em&gt;name , user&lt;em&gt;password , is&lt;/em&gt;admin ) the query will become:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;products&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;category_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;into&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;x&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;x&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;which, if the assumptions are correct, will insert a new user x witch is admin.&lt;/p&gt;

&lt;p&gt;This example is only supposed to give you an idea of this attack vector on an application. Evan if this example is very simplistic I&amp;#39;m amazed of how many application i found ( and find every day ) that are vulnerable to this attack.&lt;/p&gt;

&lt;p&gt;As a habit when i see an URL that contains something like variable=value i usually try changing value to an &amp;#39; and see what happens. This takes only a few seconds. If i end up in an empty page most probably the attack works but errors are not displayed. If the application keeps working but says an error has occurred again most probably this attack works. If no error is displayed and the application keeps working as expected it only means that the particular variable that I&amp;#39;ve changed is probably checked and escaped before building the query string.&lt;/p&gt;

&lt;p&gt;Again i have to say that if you test your application like this and nothing happens it DOES NOT mean that your application is secure, only that the particular variables that you tried are probably escaped.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ll stop here for now, but just remember to change the URL every time you see a variable and do report the problem to the author or owner of the application so that maybe the web will become a safer place.&lt;/p&gt;

&lt;p&gt;... more to come soon ...&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://imgs.xkcd.com/comics/exploits_of_a_mom.png&quot; alt=&quot;Exploits of a mom&quot;&gt;&lt;/p&gt;
</content>
 </entry>
 

</feed>
