<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6185233035130315338</id><updated>2012-01-14T19:35:12.054+01:00</updated><category term='Literal'/><category term='LINQ'/><category term='databindings'/><category term='Windows Mobile'/><category term='Service behavior'/><category term='tricks'/><category term='winforms'/><category term='Group By'/><category term='IntelliTrace'/><category term='textchanged'/><category term='Subversion'/><category term='lambda expression'/><category term='UserControl'/><category term='debugger'/><category term='migration'/><category term='Entity Framework 4.0'/><category term='Contracts'/><category term='delay'/><category term='generic list'/><category term='ASP.NET'/><category term='Web Reference'/><category term='C#'/><category term='HTTP 400 Bad Request'/><category term='datetimepicker'/><category term='data source'/><category term='params'/><category term='timer'/><category term='WCF'/><category term='TFS 2010'/><category term='InformationBox'/><category term='.NET 4.0'/><category term='Visual Studio 2010 beta 2'/><category term='BindingSource'/><category term='XtraReports'/><category term='SSRS 2008'/><category term='cross-thread'/><category term='invoke'/><category term='Exceptions'/><category term='Faults'/><category term='Training'/><category term='VisualSVN'/><category term='Entity Framework'/><category term='.NET'/><category term='binding'/><title type='text'>Break it, fix it</title><subtitle type='html'>A few thoughts about WCF, LINQ and .NET in general</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-625607162063518865</id><published>2011-08-08T14:51:00.000+02:00</published><updated>2011-08-08T14:51:00.853+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='datetimepicker'/><title type='text'>DateTimePicker and DateTime.MaxValue</title><content type='html'>For some unknown reason, the Winforms DateTimePicker control does not allow for dates higher than 9998-12-31. Trying to set the DateTimePicker MaxDate property of DateTime.MaxValue will result in an exception. This is a limitation imposed by the component itself.&lt;br /&gt;&lt;br /&gt;Good news is there is a small trick to overcome this limitation. It requires to update the static MaxDateTime property to an arbitrary value (DateTime.MaxValue in our case). Lets put up some reflection code for that purpose: &lt;br /&gt;&lt;br /&gt;&lt;pre style="background: white; color: black; font-family: Consolas;"&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;dtpType&amp;nbsp;=&amp;nbsp;&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;DateTimePicker&lt;/span&gt;);&lt;br /&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;field&amp;nbsp;=&amp;nbsp;dtpType.GetField(&lt;span style="color: #a31515;"&gt;"MaxDateTime"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;BindingFlags&lt;/span&gt;.Public&amp;nbsp;|&amp;nbsp;&lt;span style="color: #2b91af;"&gt;BindingFlags&lt;/span&gt;.Static);&lt;br /&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&amp;nbsp;(field&amp;nbsp;!=&amp;nbsp;&lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field.SetValue(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;DateTimePicker&lt;/span&gt;(),&amp;nbsp;&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.MaxValue);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Just copy and paste this code into the startup method. Basically it needs to run before any DateTimePicker control is created.&lt;br /&gt;&lt;br /&gt;Please note that running this code can have side effects because it is not known why this limitation is present in the first place. Use it at your own risk.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-625607162063518865?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/625607162063518865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2011/08/datetimepicker-and-datetimemaxvalue.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/625607162063518865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/625607162063518865'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2011/08/datetimepicker-and-datetimemaxvalue.html' title='DateTimePicker and DateTime.MaxValue'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-7576786158637313731</id><published>2010-09-13T15:28:00.001+02:00</published><updated>2010-09-13T15:29:58.145+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='UserControl'/><category scheme='http://www.blogger.com/atom/ns#' term='Literal'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Create UserControl with inline content</title><content type='html'>Let's say you want to create a user control that contains some literal text:&lt;br /&gt;&lt;pre style='color:#000000;background:#ffffff;'&gt;&lt;span style='color:#7f0055; '&gt;&amp;lt;&lt;/span&gt;&lt;span style='color:#7f0055; '&gt;uc1:InlineContent&lt;/span&gt;&lt;span style='color:#7f0055; '&gt;&gt;&lt;/span&gt;&lt;br /&gt;    This is some standard text message&lt;br /&gt;&lt;span style='color:#7f0055; '&gt;&amp;lt;/&lt;/span&gt;&lt;span style='color:#7f0055; '&gt;uc1:InlineContent&lt;/span&gt;&lt;span style='color:#7f0055; '&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Here is the simplest UserControl that matches this description:&lt;br /&gt;&lt;pre style='color:#000000;background:#ffffff;'&gt;&lt;span style='color:#7f0055; font-weight:bold; '&gt;using&lt;/span&gt; System.Web.UI;&lt;br /&gt;&lt;br /&gt;[ParseChildren(ChildrenAsProperties = &lt;span style='color:#7f0055; font-weight:bold; '&gt;true&lt;/span&gt;,&lt;br /&gt;               DefaultProperty = &lt;span style='color:#2a00ff; '&gt;"&lt;/span&gt;&lt;span style='color:#2a00ff; '&gt;Content&lt;/span&gt;&lt;span style='color:#2a00ff; '&gt;"&lt;/span&gt;)]&lt;br /&gt;&lt;span style='color:#7f0055; font-weight:bold; '&gt;public&lt;/span&gt; partial &lt;span style='color:#7f0055; font-weight:bold; '&gt;class&lt;/span&gt; InlineContent : System.Web.UI.UserControl&lt;br /&gt;{&lt;br /&gt;    [PersistenceMode(&lt;br /&gt;        PersistenceMode.EncodedInnerDefaultProperty)]&lt;br /&gt;    &lt;span style='color:#7f0055; font-weight:bold; '&gt;public&lt;/span&gt; &lt;span style='color:#7f0055; font-weight:bold; '&gt;string&lt;/span&gt; Content { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-7576786158637313731?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/7576786158637313731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2010/09/create-usercontrol-with-inline-content.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/7576786158637313731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/7576786158637313731'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2010/09/create-usercontrol-with-inline-content.html' title='Create UserControl with inline content'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-1197919617878730639</id><published>2010-09-06T20:00:00.002+02:00</published><updated>2010-09-06T20:15:37.111+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='timer'/><category scheme='http://www.blogger.com/atom/ns#' term='textchanged'/><category scheme='http://www.blogger.com/atom/ns#' term='delay'/><title type='text'>Adding a delay before processing Textbox events</title><content type='html'>Typical scenario: You provide the user with a TextBox he can use to type a filter over a big chunk of data that takes a lot of time to process. Most of the time, you would handle the TextChanged event of the TextBox and issue a filter operation over the data source using the character(s) available in the TextBox. Typical problem: The user complains because he has to wait between the key strokes even if he already knows a filter that would allow the search to take place in a matter of a few seconds. Solution: Introduce a delay between the last key stroke and the processing using a timer. Walkthough: Create a new Winforms project with a Form. Add a TextBox (named textBox), a ListBox (named listBox). To mimic a very slow data source, we will create a dummy class:  &lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;  &lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    &lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;br /&gt;&lt;pre style="background-color: transparent; border-bottom-color: rgb(204, 204, 204); border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-left-style: none; border-right-style: none; border-top-color: rgb(204, 204, 204); border-top-style: none; border-top-width: 1px; border-width: initial; font-family: 'Bitstream Vera Sans Mono', monospace; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="k" style="color: #007020; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span class="nc" style="color: #0e84b5; font-weight: bold;"&gt;VerySlowDataAccess&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span class="kt" style="color: #902000;"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span class="nf" style="color: #06287e;"&gt;VerySlowDataAccess&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;br /&gt;        &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br /&gt;            &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"AAAAAA7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br /&gt;            &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br /&gt;            &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s" style="color: #4070a0;"&gt;"BBBBBB8"&lt;/span&gt;&lt;br /&gt;        &lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span class="kt" style="color: #902000;"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="nf" style="color: #06287e;"&gt;GetItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt" style="color: #902000;"&gt;string&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m" style="color: #40a070;"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="k" style="color: #007020; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StartsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="n"&gt;ToArray&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;      &lt;br /&gt;&lt;div&gt;Now we can build our very simple form to highlight the concept. Go back the form, add a timer attribute using the System.Threading.Timer and not the System.Windows.Forms.Timer (very important).       &lt;br /&gt;&lt;/div&gt;&lt;pre style="background-color: transparent; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium; white-space: normal;"&gt;&lt;br /&gt;&lt;pre style="background-color: transparent; border-bottom-color: rgb(204, 204, 204); border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-left-style: none; border-right-style: none; border-top-color: rgb(204, 204, 204); border-top-style: none; border-top-width: 1px; border-width: initial; font-family: 'Bitstream Vera Sans Mono', monospace; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="k" style="color: green; font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium; font-weight: normal; white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: medium; font-weight: normal; white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;private&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt; &lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;  &lt;/span&gt;  &lt;/pre&gt;Then create a thread safe method to populate the ListBox based on the textbox value. By thread-safe, I actually UI-thread safe. &lt;br /&gt;&lt;pre style="background-color: transparent; border-bottom-color: rgb(204, 204, 204); border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-left-style: none; border-right-style: none; border-top-color: rgb(204, 204, 204); border-top-style: none; border-top-width: 1px; border-width: initial; font-family: 'Bitstream Vera Sans Mono', monospace; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="k" style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span class="k" style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span class="nf" style="color: blue;"&gt;LoadData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;br /&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="k" style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k" style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InvokeRequired&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="k" style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k" style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LoadData&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="k" style="color: green; font-weight: bold;"&gt;else&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="k" style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;listBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt;        &lt;span class="k" style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;listBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddRange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;VerySlowDataAccess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;textBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;}&lt;/span&gt; &lt;br /&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;Next step is to initialize the timer in the Form constructor. We will hook it up with our LoadData method and set the timeout to Infinite to deactivate it (for now): &lt;br /&gt;&lt;/div&gt;&lt;pre style="background-color: transparent; border-bottom-color: rgb(204, 204, 204); border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-left-style: none; border-right-style: none; border-top-color: rgb(204, 204, 204); border-top-style: none; border-top-width: 1px; border-width: initial; font-family: 'Bitstream Vera Sans Mono', monospace; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="k" style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span class="nf" style="color: blue;"&gt;MainForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="n"&gt;InitializeComponent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt;    &lt;span class="n"&gt;timer&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k" style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;LoadData&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="k" style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Timeout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Infinite&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Timeout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Infinite&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;Last but not least, as you may expect, we will add the handler for the TextChanged event of the TextBox. &lt;br /&gt;&lt;/div&gt;&lt;pre style="background-color: transparent; border-bottom-color: rgb(204, 204, 204); border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-left-style: none; border-right-style: none; border-top-color: rgb(204, 204, 204); border-top-style: none; border-top-width: 1px; border-width: initial; font-family: 'Bitstream Vera Sans Mono', monospace; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium; white-space: normal;"&gt;&lt;br /&gt;&lt;pre style="background-color: transparent; border-bottom-color: rgb(204, 204, 204); border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-left-style: none; border-right-style: none; border-top-color: rgb(204, 204, 204); border-top-style: none; border-top-width: 1px; border-width: initial; font-family: 'Bitstream Vera Sans Mono', monospace; font-size: 11px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="k" style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span class="k" style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span class="nf" style="color: blue;"&gt;textBox_TextChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt" style="color: #b00040;"&gt;object&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EventArgs&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="c1" style="color: #408080; font-style: italic;"&gt;// 250ms is the maximum time between key strokes before the delegate is called (LoadData in that case)&lt;/span&gt;&lt;br /&gt;    &lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Change&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m" style="color: #666666;"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Timeout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Infinite&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;So, what is happening here? Basically what we do is simply reset the timer every time the text is changed. Then after the 250 ms delay and if no key was pressed, the delegate will be called, thus refreshing the ListBox. This works because we always set the timer's repeat time to Infinite, it will fire only once after a key stroke sequence. The delay is arbitrarily set to 250 ms. Based on my own experience, it is sufficient for a regular user (with Internet-grade typing skills) and it is not so long as to be noticeable. Possible improvements:    &lt;br /&gt;&lt;ul&gt;&lt;li&gt;Prevent the load to be triggered again until it is finished. A thread-safe boolean in the LoadData method can do the job here.     &lt;br /&gt;&lt;/li&gt;&lt;li&gt;Encapsulate all this behavior into a black-box control.     &lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-1197919617878730639?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/1197919617878730639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2010/09/add-delay-before-processing-on-textbox.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/1197919617878730639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/1197919617878730639'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2010/09/add-delay-before-processing-on-textbox.html' title='Adding a delay before processing Textbox events'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-5841800552663680947</id><published>2010-02-02T21:14:00.004+01:00</published><updated>2010-02-02T21:19:08.181+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio 2010 beta 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Training'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><title type='text'>Visual Studio 2010 Training Kit</title><content type='html'>For those who are looking for a good place to start with .NET 4.0 and Visual Studio 2010, you can download from Microsoft a complete training kit containing a whole lot of first class information about the next major .NET release and its sidekick. :)&lt;br /&gt;&lt;br /&gt;Here is the link to the download page : &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-5841800552663680947?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/5841800552663680947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2010/02/visual-studio-2010-training-kit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5841800552663680947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5841800552663680947'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2010/02/visual-studio-2010-training-kit.html' title='Visual Studio 2010 Training Kit'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-5429574259752103450</id><published>2009-12-15T20:20:00.003+01:00</published><updated>2009-12-15T20:35:44.621+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='debugger'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio 2010 beta 2'/><category scheme='http://www.blogger.com/atom/ns#' term='IntelliTrace'/><title type='text'>Things I love about Visual Studio 2010: IntelliTrace</title><content type='html'>IntelliTrace is the next step in evolution for debuggers. It allows you to track everything that is happening during a debug session. It can track actions like clicking on a button, reading for a file, executing an ADO.NET call (including the actual call !) and a lot of other things.&lt;br /&gt;You can think of IntelliTrace as some sort of log for all actions of the program.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LIFP9Hng0QY/SyfkZdEzvPI/AAAAAAAAATA/USljhEQSpLc/s1600-h/VS2010-IntelliTrace.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="http://2.bp.blogspot.com/_LIFP9Hng0QY/SyfkZdEzvPI/AAAAAAAAATA/USljhEQSpLc/s320/VS2010-IntelliTrace.png" alt="" id="BLOGGER_PHOTO_ID_5415548202888969458" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can also record the call stack for each event but it will slow down the debugging experience and you won't be able to use the "Edit and Continue" feature anymore, but it will allow to have much more details about the execution context of each event.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-5429574259752103450?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/5429574259752103450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/12/things-i-love-about-visual-studio-2010.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5429574259752103450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5429574259752103450'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/12/things-i-love-about-visual-studio-2010.html' title='Things I love about Visual Studio 2010: IntelliTrace'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_LIFP9Hng0QY/SyfkZdEzvPI/AAAAAAAAATA/USljhEQSpLc/s72-c/VS2010-IntelliTrace.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-4079983185368516420</id><published>2009-10-27T21:53:00.005+01:00</published><updated>2011-06-09T21:15:25.145+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TFS 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='SSRS 2008'/><title type='text'>SSL problem when installing TFS 2010</title><content type='html'>I had this error when trying to install TFS 2010 Beta 2 on a shiny new Windows Server 2008 R2 :&lt;br /&gt;&lt;blockquote&gt;TFxxxxxx: SQL Server Reporting Services is configured to require a secure connection, however no HTTPS URL is configured with a valid certificate&lt;/blockquote&gt;&lt;br /&gt;So first thing was to remove the SSL binding from the report server (using the Reporting Services Configuration Manager), but it did not change anything from the TFS configuration checker point of view.&lt;br /&gt;The fact is this checker does not care about whether SSL is actually in use for the report server, it simply checks IF SSL can be enabled in the report server. That means that you must completely disable SSL and this can only be done by modifying the .config file of the report server.&lt;br /&gt;&lt;br /&gt;Just navigate to your report server folder (usually \MSRS10.MSSQLSERVER\Reporting Services\ReportServer), open the rsreportserver.config file for editing and locate the parameter named SecureConnectionLevel and set its value to 0 to deactivate security).&lt;br /&gt;&lt;br /&gt;Re-run the configuration checker and it should not complain anymore.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-4079983185368516420?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/4079983185368516420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/10/ssl-problem-when-installing-tfs-2010.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4079983185368516420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4079983185368516420'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/10/ssl-problem-when-installing-tfs-2010.html' title='SSL problem when installing TFS 2010'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-6420092172749322665</id><published>2009-06-02T23:27:00.002+02:00</published><updated>2009-06-02T23:39:34.958+02:00</updated><title type='text'>Entity Framework 4.0 and POCO</title><content type='html'>One of the thing that annoyed me most in Entity Framework 1.0 was the lack of support for POCO. I like to use a specific vertical layer for entities, and I like those entities to have only properties and to be POCO to say it simply. The problem in EF 1.0 is that entities are forced to inherit from a class. I could also use the IPOCO interfaces but it was a lot of code for little benefit.&lt;br /&gt;The great thing I love in EF 4.0 (even if it is a beta) is that I can generate the edmx file without generating the classes. So basically, I have a EDMX file containing all the XML stuff (conceptual model, physical model and mappings) and I create my classes that Object Services will use. That way, I can put real POCOs in my entity layer.&lt;br /&gt;&lt;br /&gt;This is an entity that I can create and use with EF (and the corresponding EDMX) :&lt;br /&gt;&lt;div class="format-code"&gt;public class Client&lt;br /&gt;{&lt;br /&gt;    public int ID { get; set; }&lt;br /&gt;    public string FirstName { get; set; }&lt;br /&gt;    public string LastName { get; set; }&lt;br /&gt;    public Address Address { get; set; }&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;EF will manage the related entities the same way it does with generated entities. That means, you can also benefit from the lazy-loading or deferred-loading mecanism, and change tracking.&lt;br /&gt;&lt;br /&gt;As a side note, EF 4.0 nows supports complex types (even in the designer).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-6420092172749322665?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/6420092172749322665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/06/entity-framework-40-and-poco.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/6420092172749322665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/6420092172749322665'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/06/entity-framework-40-and-poco.html' title='Entity Framework 4.0 and POCO'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-1153821234291375397</id><published>2009-05-29T10:20:00.004+02:00</published><updated>2009-05-29T10:48:42.424+02:00</updated><title type='text'>WCF tuning tips</title><content type='html'>To obtain significantly better response time and decreased the load on the service, you apply a set of best practices depending on your needs.&lt;br /&gt;1. If you do not need sessions in your services, you may want to disable them to reduce the memory consumption of the service.&lt;br /&gt;2. If you are transfering large amounts of data between client and server, the minimum is to enable MTOM enconding. MTOM is an optimized encoding for transmitting binary data. And even better than MTOM, you can also use streaming for the data transfers. Streaming avoids loading the complete message in memory which is what happens when you do not use streaming. Performance will be vastly increased when dealing with large amounts of binary data.&lt;br /&gt;3. If you have control over client and server, you may also want to choose a more efficient but less interoperable binding (like NetTcpBinding for example). This will avoid the overhead that comes with all the WS-* protocols.&lt;br /&gt;4. Be carefull when modifying the instance and concurrency mode. A single instance and a single thread will avoid concurrency issues but will only serve one request at a time. Multiple instances and multiple threads per instances will enable much more requests to be processed simultaneously but it will need a really good concurrency management system. Depending on the constraints, the "good" solution lies between those two models.&lt;br /&gt;&lt;br /&gt;These are the basic checks you can apply on your services.&lt;br /&gt;Happy coding :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-1153821234291375397?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/1153821234291375397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/05/wcf-tuning-tips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/1153821234291375397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/1153821234291375397'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/05/wcf-tuning-tips.html' title='WCF tuning tips'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-3801774232619820938</id><published>2009-05-14T07:48:00.003+02:00</published><updated>2009-05-14T07:53:40.253+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data source'/><category scheme='http://www.blogger.com/atom/ns#' term='XtraReports'/><category scheme='http://www.blogger.com/atom/ns#' term='BindingSource'/><title type='text'>Databinding and XtraReport</title><content type='html'>I had a problem recently using object data sources in my XtraReports. I was assigning an object hierarchy to the DataSource property and was getting weird exceptions.&lt;br /&gt;The problem is XtraReport does not handle well one object as a data source, it prefers to have a collection of objects.&lt;br /&gt;The simple fix was to use a BindingSource as the data source and assign my object to the BindingSource's DataSource property. And yes, I should have been using a BindingSource from the start, I know :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-3801774232619820938?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/3801774232619820938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/05/databinding-and-xtrareport.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/3801774232619820938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/3801774232619820938'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/05/databinding-and-xtrareport.html' title='Databinding and XtraReport'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-5508408538137903854</id><published>2009-05-14T07:24:00.004+02:00</published><updated>2009-05-14T07:36:52.749+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework 4.0'/><title type='text'>Some news about EF 4.0</title><content type='html'>The ADO.NET team posted a list of the upcoming features of Entity Framework 4.0. We will get automatic lazy-loading, POCO and much more. This is definitely something you want to read.&lt;br /&gt;Click on the title to read the complete article.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-5508408538137903854?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://blogs.msdn.com/adonet/archive/2009/05/11/update-on-the-entity-framework-in-net-4-and-visual-studio-2010.aspx' title='Some news about EF 4.0'/><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/5508408538137903854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/05/some-news-about-ef-40.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5508408538137903854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5508408538137903854'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/05/some-news-about-ef-40.html' title='Some news about EF 4.0'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-4233694629619698333</id><published>2009-04-23T14:56:00.004+02:00</published><updated>2009-04-23T18:01:25.544+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web Reference'/><category scheme='http://www.blogger.com/atom/ns#' term='HTTP 400 Bad Request'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>400 Bad Request when trying to add a Web Reference</title><content type='html'>This morning, I had a hard time adding a Web Reference in my CF application pointing to a WCF service. I checked the service several times, re-built it several times as well, but each time I got a HTTP 400 Bad Request when clicking the "Go" button of the Add Web Reference wizard.&lt;br /&gt;And then, I copied/pasted the URL one more time deleting the mex part at the end but leaving the ending slash. And it worked. I had removed the ending slash and thus caused this annoying behavior. I lost 5 minutes over such a stupid problem...&lt;br /&gt;&lt;br /&gt;Hope it will help one of you someday :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-4233694629619698333?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/4233694629619698333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/04/400-bad-request-when-trying-to-add-web.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4233694629619698333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4233694629619698333'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/04/400-bad-request-when-trying-to-add-web.html' title='400 Bad Request when trying to add a Web Reference'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-5269059746334924830</id><published>2009-04-22T20:36:00.002+02:00</published><updated>2009-04-22T20:43:35.342+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows Mobile'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Accessing a WCF service using Compact Framework</title><content type='html'>A few constraints when connecting to a WCF service from a Compact Framework application :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;The binding must be set to basicHttpBinding, CF does not know what to do with a wsHttpBinding.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The XmlSerializerFormat attribute must be set on the service contract, the default WCF serialization is not suitable for the CF. It would throw an exception when deserializing.&lt;/li&gt;&lt;li&gt;Make sure you configure your endpoints correctly, "localhost" is not accessible from the mobile device (emulated or not), you can use ppp_peer as the hostname in the CF WCF proxy (a lot of CFs, I know).&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Happy CF coding :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-5269059746334924830?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/5269059746334924830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/04/accessing-wcf-service-using-compact.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5269059746334924830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5269059746334924830'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/04/accessing-wcf-service-using-compact.html' title='Accessing a WCF service using Compact Framework'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-1063801091355586616</id><published>2009-04-10T17:12:00.002+02:00</published><updated>2009-04-10T17:22:18.629+02:00</updated><title type='text'>Change the deployment URL of a ClickOnce application</title><content type='html'>I use ClickOnce everyday for several internal applications. Recently, I had to move the publishing website to a new host.&lt;br /&gt;Here is how you can acheive a completely transparent move without annoying your users or forcing them to uninstall and reinstall the application.&lt;br /&gt;&lt;br /&gt;First, you need to publish the deployment files on the new server. The deployment configuration is as follows :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Publishing folder : URL on the new server&lt;/li&gt;&lt;li&gt;Installation Folder : URL on the new server&lt;/li&gt;&lt;li&gt;Updates Folder : URL on the new server&lt;/li&gt;&lt;li&gt;Revision : &lt;span style="font-weight: bold;"&gt;last revision + 2&lt;/span&gt; (very important)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Then you need to deploy a new version on the old server with an updates folder on the new server. This way, next time the application launches, it will get the new version from the new server, and voila. Here is the configuration for the last deployment on the old server :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Publishing folder : URL on the old server&lt;/li&gt;&lt;li&gt;Installation Folder : URL on the old server&lt;/li&gt;&lt;li&gt;Updates Folder : URL on the &lt;span style="font-weight: bold;"&gt;new&lt;/span&gt; server&lt;/li&gt;&lt;li&gt;Revision : &lt;span style="font-weight: bold;"&gt;last revision + 1&lt;/span&gt; (very important)&lt;/li&gt;&lt;/ul&gt;Enjoy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-1063801091355586616?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/1063801091355586616/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/04/change-deployment-url-of-clickonce.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/1063801091355586616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/1063801091355586616'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/04/change-deployment-url-of-clickonce.html' title='Change the deployment URL of a ClickOnce application'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-6833280981146530249</id><published>2009-04-10T14:15:00.003+02:00</published><updated>2009-04-10T14:22:01.157+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VisualSVN'/><category scheme='http://www.blogger.com/atom/ns#' term='migration'/><category scheme='http://www.blogger.com/atom/ns#' term='Subversion'/><title type='text'>Migrate a SVN repository using VisualSVN Server</title><content type='html'>Today, I needed to relocate a SVN repository to a fancy new virtual server. I was planning on painful command lines and dumps and all the nerdy stuff. But in fact migrating using VisualSVN Server was surprisingly easy.&lt;br /&gt;First I installed VisualSVN Server on the new host, then stopped the service on the old host. I copied the repositories files from the old server to the new one. And started the service after doing a little configuration (svn address, authentication mode, etc.). And then, I relocated my working copies using the svn relocate command (from TortoiseSVN).&lt;br /&gt;&lt;br /&gt;Could it be easier ? I don't think so.&lt;br /&gt;Happy source control :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-6833280981146530249?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/6833280981146530249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/04/migrate-svn-repository-using-visualsvn.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/6833280981146530249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/6833280981146530249'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/04/migrate-svn-repository-using-visualsvn.html' title='Migrate a SVN repository using VisualSVN Server'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-6507016543083975662</id><published>2009-03-19T20:25:00.003+01:00</published><updated>2009-03-19T20:47:46.892+01:00</updated><title type='text'>Code Contracts</title><content type='html'>A few days ago I discovered Code Contracts. It is a tool and a framework that enables us to define constraints on parameters and return values.&lt;br /&gt;For example, here is a simple code :&lt;div class="format-code"&gt;///&amp;lt;summary&amp;gt;&lt;br /&gt;/// Dummy base class&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;public class Entity&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Simple cache&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;static class Cache&lt;br /&gt;{&lt;br /&gt;   private static Dictionary&amp;lt;int,Entity&amp;gt; cachedEntities = new Dictionary&amp;lt;int,Entity&amp;gt;();&lt;br /&gt; &lt;br /&gt;   public static Entity GetCachedEntity(int entityId)&lt;br /&gt;   {&lt;br /&gt;       Contract.Requires(cachedEntities.Keys.Contains(entityId));&lt;br /&gt;       Contract.Ensures(Contract.Result&amp;lt;Entity&amp;gt;() != null);&lt;br /&gt;&lt;br /&gt;       return cachedEntities[entityId];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // ...&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Notice the use of the Contract class (in the System.Diagnostics.Contracts namespace of the Microsoft.Code Contracts assembly). This class contains methods that we can use to define input constraints (Requires) and output constraints (Ensures).&lt;br /&gt;The Code Contracts framework can perform a static analysis at compile time, and verify if the callers satisfy the requirements. It can also inject code into the method to enable dynamic constraint checking. If a constraint is not satisfied, a ContractException will be thrown at runtime.&lt;br /&gt;This is configurable from the properties of the project in Visual Studio (for example).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-6507016543083975662?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/6507016543083975662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/03/code-contracts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/6507016543083975662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/6507016543083975662'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/03/code-contracts.html' title='Code Contracts'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-482069309683330815</id><published>2009-03-12T23:14:00.004+01:00</published><updated>2009-03-12T23:20:19.845+01:00</updated><title type='text'>TechDays 2009</title><content type='html'>I just came back from the TechDays in Belgium and I saw some truly amazing things coming soon (some are in CTP) like from example :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Windows Azure,&lt;/li&gt;&lt;li&gt;PEX,&lt;/li&gt;&lt;li&gt; Code Contracts,&lt;/li&gt;&lt;li&gt;C# 4.0 and dynamic programing&lt;/li&gt;&lt;li&gt;Geneva,&lt;/li&gt;&lt;li&gt;and many more.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;The one that I found the most interesting was the Geneva Framework/Server for claims based authentication and federated security.&lt;br /&gt;&lt;br /&gt;I also got to play (a little) with Microsoft Surface and the only word that can describe it is "Uber-cool" (and expensive unfortunately) :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-482069309683330815?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/482069309683330815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/03/techdays-2009.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/482069309683330815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/482069309683330815'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/03/techdays-2009.html' title='TechDays 2009'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-9172369262380516836</id><published>2009-02-25T23:07:00.005+01:00</published><updated>2009-02-25T23:19:03.865+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Group By'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Simple file content summary</title><content type='html'>A few days ago, I was reviewing some old samples to teach C# and I came across one that instructed the user to write a simple program. The goal was to read a text file and display on the Console a small summary containing, for example, the number of characters and the number of lines. The solution provided for this exercise was to iterate over the content of the file character by character and increment a few counters based of Char.IsSomething tests.&lt;br /&gt;&lt;br /&gt;Here is a much cooler way to do that using a LINQ query :&lt;br /&gt;&lt;div class="format-code"&gt;string content = File.ReadAllText(path);&lt;br /&gt;&lt;br /&gt;var contentByGroups = &lt;br /&gt;    from c in content&lt;br /&gt;    group c by Char.GetUnicodeCategory(c) into groups&lt;br /&gt;    select new { Category = groups.Key,&lt;br /&gt;                Count = groups.Count() };&lt;br /&gt;&lt;br /&gt;foreach (var group in contentByGroups)&lt;br /&gt;{&lt;br /&gt;    Console.WriteLine("Category {0} : {1}",&lt;br /&gt;                      group.Category,&lt;br /&gt;                      group.Count);&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The Char.GetUnicodeCategory is used to get the corresponding category of each character of the file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-9172369262380516836?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/9172369262380516836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/simple-file-content-summary.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/9172369262380516836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/9172369262380516836'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/simple-file-content-summary.html' title='Simple file content summary'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-9095803799502761923</id><published>2009-02-25T22:25:00.005+01:00</published><updated>2009-02-25T22:52:58.443+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='invoke'/><category scheme='http://www.blogger.com/atom/ns#' term='cross-thread'/><title type='text'>Thread-safe form method</title><content type='html'>If you use threads in a winforms application, you probably have already encountered the classic InvalidOperationException saying that you are trying to make an illegal cross-thread operation. This is because you cannot modify a control from a thread other than the one that created it.&lt;br /&gt;Here is a simple way to write your methods in the form to avoid that exception :&lt;br /&gt;&lt;div class="format-code"&gt;void SomeMethod(SomeType parameter)&lt;br /&gt;{&lt;br /&gt;    if (this.InvokeRequired)&lt;br /&gt;    {&lt;br /&gt;        this.BeginInvoke(new MethodInvoker(delegate()&lt;br /&gt;             { this.SomeMethod(parameter); }));&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        // Do what SomeMethod is supposed to do.&lt;br /&gt;    }&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;You can use Invoke instead of BeginInvoke if you want to make an asynchronous call to the delegate.&lt;br /&gt;Notice the anonymous method (delegate() {...}) used to invoke the same instruction in the correct thread.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-9095803799502761923?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/9095803799502761923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/thread-safe-form-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/9095803799502761923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/9095803799502761923'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/thread-safe-form-method.html' title='Thread-safe form method'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-8168769278282104984</id><published>2009-02-16T21:02:00.009+01:00</published><updated>2009-02-16T22:23:54.076+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='lambda expression'/><category scheme='http://www.blogger.com/atom/ns#' term='generic list'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Converting a List using a lambda expression</title><content type='html'>Here is a little construct I use when I need to convert a List&amp;lt;T&amp;gt; to a List&amp;lt;U&amp;gt; or when I need to pass a list of concatenated values as a string.&lt;br /&gt;First, to convert a List&amp;lt;T&amp;gt; to a List&amp;lt;U&amp;gt; :&lt;br /&gt;&lt;br /&gt;&lt;div class="format-code"&gt;List&amp;lt;Guid&amp;gt; guidList = // Initialize list here or get it as a parameter or whatever :)&lt;br /&gt;List&amp;lt;String&amp;gt; stringList = guidList.ConvertAll&amp;lt;String&amp;gt;(g =&gt; g.ToString());&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;It is really simple, I just use the ConvertAll method parameterized with the target type and pass it the lambda responsible for converting from the source type (Guid) to the target type (String). This example is obvious but the important thing is the combination of ConvertAll and a lambda.&lt;br /&gt;&lt;br /&gt;For the second use ("passing a list of concatenated values as a string"), it is also really simple :&lt;br /&gt;&lt;div class="format-code"&gt;String stringValue = String.Join(&lt;br /&gt;    " separator ",&lt;br /&gt;    myGenericList.ConvertAll&amp;lt;String&amp;gt;(&lt;br /&gt;        /* Insert lambda here that return a string value */).ToArray());&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The trick is simply to call ToArray on the converted list to be able to pass it to the String.Join method.&lt;br /&gt;&lt;br /&gt;You can also use a extension method like this one :&lt;br /&gt;&lt;div class="format-code"&gt;public static class ListExtensions&lt;br /&gt;{&lt;br /&gt;  public static String Join&amp;lt;T&amp;gt;(this List&amp;lt;T&amp;gt; list, string separator)&lt;br /&gt;  {&lt;br /&gt;    return String.Join(&lt;br /&gt;        separator,&lt;br /&gt;        list.ConvertAll&amp;lt;String&amp;gt;(t =&gt; t.ToString()).ToArray());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;And then just write something like that:&lt;br /&gt;&lt;div class="format-code"&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;  List&amp;lt;DateTime&amp;gt; list = new List&amp;lt;DateTime&amp;gt; { DateTime.Now, DateTime.Today };&lt;br /&gt;&lt;br /&gt;  String joinedList = list.Join(", ");&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Happy coding :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-8168769278282104984?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/8168769278282104984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/convert-list-using-lambda-expression.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/8168769278282104984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/8168769278282104984'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/convert-list-using-lambda-expression.html' title='Converting a List&lt;T&gt; using a lambda expression'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-895983677190605594</id><published>2009-02-07T17:26:00.015+01:00</published><updated>2009-02-16T22:14:15.170+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Service behavior'/><category scheme='http://www.blogger.com/atom/ns#' term='Faults'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Handling exceptions the right way in WCF (part 2)</title><content type='html'>In my &lt;a href="http://johannblais.blogspot.com/2009/02/handling-exception-right-way-in-wcf.html"&gt;previous post&lt;/a&gt; I talked about FaultExceptions and how they are transmitted from the server to the client.&lt;br /&gt;First, let's have a look at the sample service contract :&lt;br /&gt;&lt;div class="format-code"&gt;[ServiceContract]&lt;br /&gt;public interface ITimeService&lt;br /&gt;{&lt;br /&gt;    [OperationContract]&lt;br /&gt;    [FaultContract(typeof(TimeExceptionDetails))]&lt;br /&gt;    DateTime GetTime();&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;The service implementation :&lt;br /&gt;&lt;div class="format-code"&gt;public class TimeService : ITimeService&lt;br /&gt;{&lt;br /&gt;    #region ITimeService Members&lt;br /&gt;&lt;br /&gt;    public DateTime GetTime()&lt;br /&gt;    {&lt;br /&gt;        return DateTime.Now;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;And the Fault details class :&lt;br /&gt;&lt;div class="format-code"&gt;public class TimeExceptionDetails&lt;br /&gt;{&lt;br /&gt;    public static readonly TimeExceptionDetails Default = new TimeExceptionDetails();&lt;br /&gt;&lt;br /&gt;    [DataMember]&lt;br /&gt;    public String Message { get; private set; }&lt;br /&gt;&lt;br /&gt;    public TimeExceptionDetails()&lt;br /&gt;    {&lt;br /&gt;        this.Message = "There is a problem in the spacetime continuum, Marty";&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public TimeExceptionDetails(String message)&lt;br /&gt;    {&lt;br /&gt;        this.Message = message;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now we'll how to ease the process of creating FaultExceptions by using the IErrorHandler interface. This interface allows the customization of exceptions and provide a centralized location for responding to exceptions in a very generic way.&lt;br /&gt;This interface contains two methods :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;HandleError&lt;/li&gt;&lt;li&gt;ProvideFault&lt;/li&gt;&lt;/ul&gt;The first one is called each time an exception is raised by the service (logging for example). The second one is more subtle, it allows to change the message that will be sent to the caller. Here for example you could create a FaultException, generate the corresponding message and set it as the message to be sent.&lt;br /&gt;The following code is a simple implementation of the IErrorHandler interface. It simply create a new FaultException and send it to the caller.&lt;br /&gt;&lt;div class="format-code"&gt;public class TimeServiceBehavior : IErrorHandler&lt;br /&gt;{&lt;br /&gt;    #region IErrorHandler Members&lt;br /&gt;&lt;br /&gt;    public bool HandleError(Exception error)&lt;br /&gt;    {&lt;br /&gt;        // Log the error here&lt;br /&gt;        EventLog.WriteEntry("TimeService", error.ToString());&lt;br /&gt;&lt;br /&gt;        // Let the other ErrorHandler do their jobs&lt;br /&gt;        return true;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void ProvideFault(Exception error, MessageVersion version, ref Message fault)&lt;br /&gt;    {&lt;br /&gt;        if (error is FaultException)&lt;br /&gt;            return;&lt;br /&gt;&lt;br /&gt;        // Creates the exception we want to send back to the client&lt;br /&gt;        var exception = new FaultException&amp;lt;TimeExceptionDetails&amp;gt;(&lt;br /&gt;             TimeExceptionDetails.Default,&lt;br /&gt;             new FaultReason(TimeExceptionDetails.Default.Message));&lt;br /&gt;&lt;br /&gt;        // Creates a message fault&lt;br /&gt;        var messageFault = exception.CreateMessageFault();&lt;br /&gt;&lt;br /&gt;        // Creates the new message based on the message fault&lt;br /&gt;        fault = Message.CreateMessage(version, messageFault, exception.Action);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;The implementation here is really simple, you will probably need to add some logic in the ProvideFault method to distinguish between technical exception and business exceptions and create the appropriate type of fault.&lt;br /&gt;&lt;br /&gt;The next step is to associate this error handler with the service. Each ChannelDispatcher of a ServiceHost have a property named ErrorHandlers that contains a list of error handlers applied to the channel. One easy way to add a error handler to the channel dispatcher is to create a ServiceBehavior. To create a new service behavior, we simply need to implement IServiceBehavior in the TimeServiceBehavior class :&lt;br /&gt;&lt;div class="format-code"&gt;public class TimeServiceBehavior : IErrorHandler, IServiceBehavior&lt;br /&gt;{&lt;br /&gt;    #region IErrorHandler Members&lt;br /&gt;&lt;br /&gt;    [...]&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;    #region IServiceBehavior Members&lt;br /&gt;&lt;br /&gt;    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection&amp;lt;ServiceEndpoint&amp;gt; endpoints, BindingParameterCollection bindingParameters)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)&lt;br /&gt;    {&lt;br /&gt;        // Adds a TimeServiceErrorHandler to each ChannelDispatcher&lt;br /&gt;        foreach (var channelDispatcherBase in serviceHostBase.ChannelDispatchers)&lt;br /&gt;        {&lt;br /&gt;            var channelDispatcher = channelDispatcherBase as ChannelDispatcher;&lt;br /&gt;            channelDispatcher.ErrorHandlers.Add(new TimeServiceBehavior());&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;The only method of interest here is ApplyDispatchBehavior used to apply a specific behavior on the dispatchers (which is exactly what we are trying to achieve here).&lt;br /&gt;Unfortunately, in its current state, our service behavior is not easy to use unless we are creating the service host and all its configuration by hand. For example, it is not possible to use our behavior from a configuration file.&lt;br /&gt;&lt;br /&gt;Let's make this service behavior a little more developer friendly. We have two possible solutions :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Make it compatible with the file-based configuration infrastructure (app/web.config),&lt;/li&gt;&lt;li&gt;Make it an attribute that can decorate our service implementation.&lt;/li&gt;&lt;/ul&gt;We will implement the app.config version first. We simply need to create a class that inherit from BehaviorExtensionElement. This class will allow us to add our service behavior as an extension in the App/Web.config file. Here is the TimeServiceBehaviorElement class :&lt;br /&gt;&lt;div class="format-code"&gt;public class TimeServiceBehaviorElement : BehaviorExtensionElement&lt;br /&gt;{&lt;br /&gt;    public override Type BehaviorType&lt;br /&gt;    {&lt;br /&gt;        get { return typeof(TimeServiceBehavior); }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected override object CreateBehavior()&lt;br /&gt;    {&lt;br /&gt;        return new TimeServiceBehavior();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The code is pretty straight-forward, it just links our service behavior to a configuration element.&lt;br /&gt;&lt;br /&gt;Here is an example of a configuration file making use of the TimeServiceBehavior :&lt;br /&gt;&lt;div class="format-code"&gt;&amp;lt;system.serviceModel&amp;gt;&lt;br /&gt;  &amp;lt;services&amp;gt;&lt;br /&gt;    [...]&lt;br /&gt;  &amp;lt;/services&amp;gt;&lt;br /&gt;  &amp;lt;behaviors&amp;gt;&lt;br /&gt;    &amp;lt;serviceBehaviors&amp;gt;&lt;br /&gt;      &amp;lt;behavior name="WcfErrorSample.Service1Behavior"&amp;gt;&lt;br /&gt;        &amp;lt;serviceMetadata httpGetEnabled="true" /&amp;gt;&lt;br /&gt;        &amp;lt;serviceDebug includeExceptionDetailInFaults="false" /&amp;gt;&lt;br /&gt;        &amp;lt;timeService /&amp;gt;&lt;br /&gt;      &amp;lt;/behavior&amp;gt;&lt;br /&gt;    &amp;lt;/serviceBehaviors&amp;gt;&lt;br /&gt;  &amp;lt;/behaviors&amp;gt;&lt;br /&gt;  &amp;lt;extensions&amp;gt;&lt;br /&gt;    &amp;lt;behaviorExtensions&amp;gt;&lt;br /&gt;      &amp;lt;add name="timeService" type="WcfErrorSample.TimeServiceBehaviorElement,&lt;br /&gt;WcfErrorSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&amp;gt;&lt;br /&gt;    &amp;lt;/behaviorExtensions&amp;gt;&lt;br /&gt;  &amp;lt;/extensions&amp;gt;&lt;br /&gt;&amp;lt;/system.serviceModel&amp;gt;&lt;/div&gt;&lt;br /&gt;That's it for the configuration model. Now let's make the behavior a little easier to use from a developer perspective. We are simply going to make the service behavior a custom attribute. This attribute will then be applied on the service itself. To transform the behavior into an attribute, TimeServiceBehavior will now inherit from Attribute, that's it :&lt;br /&gt;&lt;div class="format-code"&gt;public class TimeServiceBehavior : Attribute, IErrorHandler, IServiceBehavior&lt;br /&gt;{&lt;br /&gt;    [...]&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;Now, the service implementation is decorated with our attribute :&lt;br /&gt;&lt;div class="format-code"&gt;[TimeServiceBehavior]&lt;br /&gt;public class TimeService : ITimeService&lt;br /&gt;{&lt;br /&gt;    [...]&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;This will have exactly the same effect than the configuration based implementation.&lt;br /&gt;&lt;br /&gt;You can implement both solutions for your behaviors and have the choice of using one way or another depending on your policy ("all in config", "fixed service behavior", etc.).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-895983677190605594?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/895983677190605594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/handling-exceptions-right-way-in-wcf.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/895983677190605594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/895983677190605594'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/handling-exceptions-right-way-in-wcf.html' title='Handling exceptions the right way in WCF (part 2)'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-9184287784518937751</id><published>2009-02-05T13:57:00.003+01:00</published><updated>2009-02-16T22:13:16.117+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='binding'/><category scheme='http://www.blogger.com/atom/ns#' term='winforms'/><category scheme='http://www.blogger.com/atom/ns#' term='databindings'/><title type='text'>Binding two Windows Forms controls</title><content type='html'>Recently, I came across a small windows application where the developer had difficulties to activate controls based on a another one. Typical example is when you want to activate a textbox sitting next to a checkbox. The developer chose to use the CheckedChanged event of the Checkbox, and to modify the Enabled property of the Textbox accordingly. The problem is you have to properly initialize the CheckState, and Enabled property of the controls to keep them both in sync from the beginning.&lt;br /&gt;&lt;br /&gt;Then I showed him how to bind two controls directly. Most developers know about binding a control to datasource, but few of them know that it is also possible to bind to another control.&lt;br /&gt;&lt;br /&gt;The following line shows how to do that :&lt;br /&gt;&lt;div class="format-code"&gt;myTextbox.DataBindings.Add("Enabled", myCheckbox, "Checked");&lt;/div&gt;&lt;br /&gt;This line simply binds the Enabled property of the Textbox to the Checked property of the Checkbox. By doing that, there is no need to initialize each property nor to respond to any event.&lt;br /&gt;The only drawback is that there is no designer support. You have to create the binding manually, the designer only supports binding to data. Usually, I put this line in a InitializeBinding method (called just after InitializeComponent).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-9184287784518937751?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/9184287784518937751/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/binding-two-windows-forms-controls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/9184287784518937751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/9184287784518937751'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/binding-two-windows-forms-controls.html' title='Binding two Windows Forms controls'/><author><name>Johann Blais</name><uri>https://profiles.google.com/104670749681827142100</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-aEmpKDIcodY/AAAAAAAAAAI/AAAAAAAAAAA/iOAJgGlTm0o/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-5124801515313288245</id><published>2009-02-04T21:06:00.008+01:00</published><updated>2009-02-16T22:15:49.887+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='params'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='InformationBox'/><title type='text'>Methods taking variable number of args (part 2)</title><content type='html'>In my &lt;a href="http://johannblais.blogspot.com/2009/02/methods-taking-variable-number-of-args.html"&gt;previous post&lt;/a&gt;, I talked about the choice I made about taking a variable number of parameters. At that time, I used a simple &lt;span class="Apple-style-span" style="font-style: italic;"&gt;params object[]&lt;/span&gt;, and the logic was built into the method (in the constructor of the underlying form in fact, but it is not relevant here).&lt;div&gt;The problem with this approach is how to handle parameters with the same type but different meanings. A very simple example is the caption and the text of the InformationBox. Both are strings but how to differenciate between the two. I had to force the first parameter to be the text, but it was beginning to look like the MessageBox.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For those who are familiar with C# 3.0, you may have already guessed what I could have used if .NET 3.5 had been available at that time. I could have used object initializers. It is a simple constructor syntax that allow the developer to specify only the properties he (or she) wants to define.&lt;/div&gt;&lt;div&gt;For example, assuming the Client class is already defined with two properties "Name" and "FirstName" :&lt;/div&gt;&lt;div class="format-code"&gt;var myClient = new Client { Name = "Blais", FirstName = "Johann" };&lt;/div&gt;&lt;br /&gt;So basically, I could have changed the API a little to use this particular syntax. The main benefit would have been to throw away the "guessing part" of the Show method because the value would directly reference the property.&lt;div&gt;The main disadvantage is that (internally) the parameter validation would have taken place later in the process. The params approach allows the parameters to be validated on the spot and not when we start the process of showing the window. I am aware that this particular point is subject to discussion but as the only developer of the component, I tend to agree with myself. :)&lt;div&gt;I did not change this behavior in the last release because I did not want to introduce breaking changes in the API given the potentially important number of existing users.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-5124801515313288245?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/5124801515313288245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/methods-taking-variable-number-of-args_04.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5124801515313288245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/5124801515313288245'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/methods-taking-variable-number-of-args_04.html' title='Methods taking variable number of args (part 2)'/><author><name>Johann Blais</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-3163871187004197497</id><published>2009-02-04T20:14:00.009+01:00</published><updated>2009-02-16T22:16:26.666+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='params'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='InformationBox'/><title type='text'>Methods taking variable number of args (part 1)</title><content type='html'>A few months ago, I started a small project on &lt;a href="http://www.codeplex.com/InfoBox/"&gt;Codeplex&lt;/a&gt;, its goal was simple : providing an alternative to the default Windows Forms MessageBox. One of the things that annoyed me with the MessageBox was to be forced to provide values for parameters I did not want to change.&lt;br /&gt;Here is a little example :&lt;br /&gt;&lt;div class="format-code"&gt;MessageBox.Show("Text", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);&lt;/div&gt;&lt;br /&gt;Clearly in this case, I should not have to specify the third parameter since it is already the default value.&lt;br /&gt;&lt;br /&gt;So basically, I needed to create a method (&lt;span style="font-style:italic;"&gt;Show&lt;/span&gt; in this case) that take a variable number of parameters. The problem was with the types of the parameters, I have a whole lot of different types.&lt;br /&gt;&lt;br /&gt;At that time, I had two ways to achieve that :&lt;div&gt;&lt;ul&gt;&lt;li&gt;Providing an overload of Show for each combination of parameters.&lt;/li&gt;&lt;li&gt;Using params and the only type shared by all the parameters : object.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;The first one is nice when you have two parameters, but in InformationBox we are now dealing with up to 25 parameters at the same time (note : the number of possibilities is 29 digits long).&lt;/div&gt;&lt;div&gt;So I went for the second solution and this is the currently implemented in the 0.8 release. What I do is simply iterate over every parameter and affect it to the corresponding property based on its type.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Next time we'll see how I would have achieved my goal by using the C# 3.0 features.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-3163871187004197497?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/3163871187004197497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/methods-taking-variable-number-of-args.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/3163871187004197497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/3163871187004197497'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/methods-taking-variable-number-of-args.html' title='Methods taking variable number of args (part 1)'/><author><name>Johann Blais</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-4687454716738047047</id><published>2009-02-04T11:34:00.010+01:00</published><updated>2009-02-16T22:17:37.578+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Contracts'/><category scheme='http://www.blogger.com/atom/ns#' term='Exceptions'/><category scheme='http://www.blogger.com/atom/ns#' term='Faults'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Handling exceptions the right way in WCF (part 1)</title><content type='html'>Control over exceptions is very important in WCF because exceptions can contain a lot of information about the internals of your service potentially leading to security issues. WCF allows to define not only data, service or message contracts but also fault contracts. Fault contracts are used to materialize potential exceptions in the metadata of your service.&lt;br /&gt;&lt;br /&gt;To do that, you just have to declare on your service contract which exception might be raised by a specific method.&lt;br /&gt;&lt;br /&gt;Here is a simple service contract :&lt;br /&gt;&lt;div class="format-code"&gt;[ServiceContract]&lt;br /&gt;public interface IService1&lt;br /&gt;{&lt;br /&gt;   [OperationContract]&lt;br /&gt;   [FaultContract(typeof(SomeFault))]&lt;br /&gt;   void DoSomething();&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Here, we are telling the WCF runtime to expose a fault contract in the service metadata. The object containing the fault detail is named SomeFault. Here is the definition of the SomeFault class :&lt;br /&gt;&lt;div class="format-code"&gt;[DataContract]&lt;br /&gt;public class SomeFault&lt;br /&gt;{&lt;br /&gt;   [DataMember]&lt;br /&gt;   public String SomeInfo { get; set; }&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;As you see, SomeFault is a data contract. Its use is only to transfer data through the wire, nothing more, nothing less.&lt;br /&gt;&lt;br /&gt;Then you just have to throw exceptions of the right type. You may have already noticed that if an exception is thrown on the service side, you get a simple FaultException on the client side.&lt;br /&gt;Now that we have defined a fault contract, the following code demonstrates how to properly throw an exception from the service :&lt;br /&gt;&lt;div class="format-code"&gt;throw new FaultException&amp;lt;SomeFault&amp;gt;(new SomeFault { SomeInfo = "Some useful data" });&lt;/div&gt;&lt;br /&gt;We are simply throwing a generic exception based on the fault contract defined earlier.&lt;br /&gt;Then for the client perspective, we will be able to catch the same type of FaultException. For example :&lt;br /&gt;&lt;div class="format-code"&gt;try&lt;br /&gt;{&lt;br /&gt;   proxyInstance.DoSomething();&lt;br /&gt;}&lt;br /&gt;catch(FaultException&amp;lt;SomeFault&amp;gt; ex)&lt;br /&gt;{&lt;br /&gt;   // SomeInfo is accessible here&lt;br /&gt;   Debug.Print(ex.Detail.SomeInfo);&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;This is possible because the proxy generator (either "Add service reference" or svcutil.exe) produces client side equivalents of the fault contract (SomeFault in this case). This was made possible by including the fault contract in the metadata (adding the FaultContractAttribute on the service contract).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Note :&lt;/span&gt; it is very important that you deactivate the IncludeExceptionDetailsInFault on the production server to avoid disclosing sensitive exception details (like the stack trace).&lt;br /&gt;&lt;br /&gt;Next time we will see how it is possible to automate parts of this process by using the IErrorHandler interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-4687454716738047047?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/4687454716738047047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/handling-exception-right-way-in-wcf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4687454716738047047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4687454716738047047'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/handling-exception-right-way-in-wcf.html' title='Handling exceptions the right way in WCF (part 1)'/><author><name>Johann Blais</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-4133057357796914636</id><published>2009-02-04T09:09:00.006+01:00</published><updated>2009-02-16T22:18:36.631+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Get newly added entities in an Entity Framework query</title><content type='html'>A few days ago, a colleague of mine ran into a little problem using Entity Framework. He was adding new entities to the context and then wanted to display these entities. Unfortunately, since the new entities are only in memory, they are not fetched by the query.&lt;br /&gt;In fact, you have to use the ObjectStateManager accessible from the context to query in-memory entities. This object manages the entity cache in the context.&lt;br /&gt;&lt;br /&gt;You can use the following code to obtain every entity already in the cache. Assuming the type of the objects you want to query is Client :&lt;br /&gt;&lt;div class="format-code"&gt;var listInMemory =&lt;br /&gt;  context.ObjectStateManager&lt;br /&gt;         .GetObjectStateEntries(EntityState.Added)&lt;br /&gt;         .Select(e =&gt; e.Entity).OfType&amp;lt;Client&amp;gt;().ToList();&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;listInMemory will contain only the new added entities from the current context. You can combine EntityState values to retrieve entities in different states.&lt;br /&gt;&lt;br /&gt;You can also use an Union construct to add those entities to the list of entities returned by a standard Entity query. For example :&lt;br /&gt;&lt;div class="format-code"&gt;var completeList =&lt;br /&gt; context.Clients.AsEnumerable()&lt;br /&gt;        .Union(context.ObjectStateManager.GetObjectStateEntries&lt;br /&gt;                          (EntityState.Added)&lt;br /&gt;                      .Select(e =&gt; e.Entity)&lt;br /&gt;                      .OfType&amp;lt;client&amp;gt;()).ToList();&lt;/div&gt;&lt;br /&gt;You may also want to filter out the deleted records from the context.Clients by using a Where clause just before the AsEnumerable(). I leave that as an exercice to the reader :)&lt;br /&gt;&lt;br /&gt;Note the use of AsEnumerable(). It is related to the way LINQ to Entities handles comparisons (for the Union method in this case). You can find more information about comparisons &lt;a href="http://msdn.microsoft.com/en-us/library/bb738686.aspx"&gt;on the MSDN&lt;/a&gt;.&lt;/client&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-4133057357796914636?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/4133057357796914636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/get-newly-added-entities-in-entity.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4133057357796914636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4133057357796914636'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/get-newly-added-entities-in-entity.html' title='Get newly added entities in an Entity Framework query'/><author><name>Johann Blais</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6185233035130315338.post-4060589310202631910</id><published>2009-02-04T09:02:00.001+01:00</published><updated>2009-02-16T22:19:20.783+01:00</updated><title type='text'>Welcome</title><content type='html'>This blog will enable me to post a few tips and tricks I learned playing with the latest technologies. I will mostly talk about WCF, LINQ and also about a few interesting (I hope) things I want to share with everyone :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6185233035130315338-4060589310202631910?l=johannblais.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://johannblais.blogspot.com/feeds/4060589310202631910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://johannblais.blogspot.com/2009/02/welcome.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4060589310202631910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6185233035130315338/posts/default/4060589310202631910'/><link rel='alternate' type='text/html' href='http://johannblais.blogspot.com/2009/02/welcome.html' title='Welcome'/><author><name>Johann Blais</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
