<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Oren Ellenbogen's Blog</title>
  <link rel="alternate" type="text/html" href="http://www.lnbogen.com/" />
  <link rel="self" href="http://www.lnbogen.com/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2008-02-12T13:42:18.8750000+02:00</updated>
  <author>
    <name>Oren Ellenbogen</name>
  </author>
  <subtitle>Striving for agile development</subtitle>
  <id>http://www.lnbogen.com/</id>
  <generator uri="http://www.dasblog.net" version="1.9.6264.0">DasBlog</generator>
  <entry>
    <title>Microsoft CCR: clean way to write parallel code in .Net</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/MicrosoftCCRCleanWayToWriteParallelCodeInNet.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,b23f5c68-90b9-41a0-b18b-9069bea82c77.aspx</id>
    <published>2008-02-04T06:25:12.8750000+02:00</published>
    <updated>2008-02-04T07:06:02.1875000+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.lnbogen.com/CategoryView,category,.NET.aspx" />
    <category term=".Net/Multi-Threading" label=".Net/Multi-Threading" scheme="http://www.lnbogen.com/CategoryView,category,.Net%2cMulti-Threading.aspx" />
    <category term="Microsoft CCR" label="Microsoft CCR" scheme="http://www.lnbogen.com/CategoryView,category,Microsoft%2BCCR.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Having to parallelize almost every bit of code here at Delver, some common patterns
emerged while we wrote a lot of back-end code.<br />
I remember reading about a new framework from Microsoft Robotics Division called "Microsoft
CCR" (Concurrency and Coordination Runtime) a few months ago in the <a href="http://msdn.microsoft.com/msdnmag/issues/06/09/ConcurrentAffairs/default.aspx">"concurrent
affairs" column at the MSDN Magazine</a> but I didn't pay much attention to it
at the time. Two weeks ago, it jumped back to my mind so I revisit
the article and started diving a little deeper into it, thinking about what sort of
problems it can solve in my world and if it does, where could I use it to our benefit.
If you don't know anything about the CCR, there is great public content published
already like the CCR <a href="http://msdn2.microsoft.com/en-us/library/bb905447.aspx">User
Guide</a> but I'll try to give you a 2 minutes intro of the general architecture.
The way CCR is built is very much like the SOA world, using messages to communicate
between "services". The major components are the Dispatcher which is actually an array
of OS Threads, the DispatcherQueue which holds a queue of delegates to run
so the Dispatcher can "look" at the DispatcherQueue and when it has a free OS
Thread available, it pulls one delegate out of the queue and run it. So far - we've
got a classic ThreadPool. There are some differences but I'll let you read about it
in the User Guide. The third component, which is the most important one is Port.
Think about Port as a pipe that can receive messages (FIFO style - first in,
first out) and hold them until someone will know what to do with them. The last component
is the "manager", the Arbiter; Arbiter expose a set of methods that allows you
to listen to a given pipe and if some conditions are met on the messages the
pipe contains, we can take the message(s) and transform them into a runnable
delegate placed in the DispatcherQueue. 
</p>
        <p>
One of the goals for this library is the make sure you've got much less places to
go wrong, by exposing a set of common async patterns you can easily use to guarantee
clean(er) code that is easier to read. Think about sending messages from one pipe
to another, creating a flow-based code via messages rather than spaghetti
code with a lot of messy indentation. This is a very powerful architecture.<br />
Obviously, the entire CCR framework is thread-safe by design so no need to protect
the library. A simple example:
</p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> (Dispatcher
dispatcher <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Dispatcher(5, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"my_dispatcher"</span>)) <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//5
OS threads</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> (DispatcherQueue
queue <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> DispatcherQueue(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"my_queue"</span>,
dispatcher))<br />
{<br />
    Port&lt;Uri&gt; urlsPort <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Port&lt;Uri&gt;();<br />
    <br />
    Arbiter.Activate(queue,<br />
        Arbiter.Receive(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>,
urlsPort, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">delegate</span>(Uri
uri) {<br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
some code(run async!): for example we can fetch the uri content(HTML) and persist
it to your Hard Disk..</span><br />
         })<br />
    );<br /><br />
    urlsPort.Post(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Uri(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://www.lnbogen.com"</span>));<br />
    urlsPort.Post(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Uri(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://www.delver.com"</span>));<br />
}
</p>
        </span>
        <p>
There is no need to create an array of Threads and some sort of Queue&lt;Uri&gt; in
order to pull the items. The "ThreadPool" is implemented as part of the CCR.<br />
So far no big deal right? well, it turns out that you can easily write common patterns
with much less complexity: almost no locks, less spaghetti code and much less
code in general. 
</p>
        <p>
One of the patterns we (all of us) use a lot is the "execute-and-wait-till-finish"
pattern where you've got a list of independent items you want to run in parallel,
but you want your main thread to wait for them to finish before continue. The simplest
way to achieve it is by creating an array of Thread, activating them with a delegate
and then call Join() on each one of the Threads. Let's define a few more requirements
for this pattern:
</p>
        <ol>
          <li>
We want to be able to know about all the errors that occurred during the execution. 
</li>
          <li>
We want to be able to set a timeout so each operation(inside a Thread) won't take
more than a sensible time. 
</li>
          <li>
We want to be able to know which items were timed out and when. 
</li>
          <li>
We want to be able to know which items were completed successfully. 
</li>
          <li>
BONUS: We want to avoid writing the obvious. </li>
        </ol>
        <p>
Well, in order to implement these requirements from scratch, we need to use an outer
timer with some sort of List (for example) so each thread will "register" to it when
it begins and "unregister" when it's done. The timer should be able to interrupt the
thread and be optimized to "wake up" as soon as possible (determined by the registered
threads and which thread needs to wake up first(next in line)). In addition, we need
some sort of List of exceptions to collect all the exceptions that occurred and make
sure we lock shared objects. We'll need to use Thread[] and some sort of Queue to
enqueue\dequeue items to\from it. A lot of code for a simple pattern.<br /><br />
With Microsoft CCR it's much easier. 
<br />
Assuming that we want to handle a list of strings:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">List&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt;
messagesToWorkOn <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> List&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt;();<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 0;
i &lt; 10; i++)<br />
   messagesToWorkOn.Add(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"message
"</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> i);</span>
        </p>
        <p>
Here is the final API I've implemented on top of the CCR:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> (SpawnAndWaitPattern&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt; saw <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SpawnAndWaitPattern&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt;(5, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"mythreadspool"</span>))<br />
{<br />
   AggregatedResult&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt;
result <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> saw.Execute(messagesToWorkOn, TimeSpan.FromMilliseconds(500),<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">                                             delegate</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> msg)<br />
                                             {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">                                                if</span> (msg.Contains(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"1"</span>))<br />
                                                   Thread.Sleep(2000); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
simulate time-out</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">                                                else</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (msg.Contains(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"5"</span>))<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">                                                   throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ArgumentException(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"5
is a very bad value..."</span>); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
simulate exception</span><br />
   <br />
                                                Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"The
message: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> msg <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
processed successfully."</span>);<br />
                                             });<br /><br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Done!"</span>);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Summarized
Report:\n completed results: "</span> <br />
      <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> result.SuccessfulItems.Count <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"\n
exceptions occurred: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> result.FaultedItems.Count <br />
      <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"\n
timed-out results: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> result.TimedoutItems.Count);<br />
}</span>
        </p>
        <p>
We've got 5 OS Threads, we're waiting for up to 0.5 second per item and we've got
a full result object, holding all the requirements from above.
</p>
        <p>
The code of SpawnAndWaitPattern class is quite neat and contains 0 locks (on
my behalf, the CCR manage its own locks). The CCR schedule the tasks for me; combining
it with thread-safe Port and we've got a very powerful yet simple framework
at our hands. I decided to attach the entire solution (with A LOT of
nice-green-comments) including the Ccr.Core.dll file so you could play with it:
</p>
        <p>
          <a href="http://www.lnbogen.com/content/binary/CcrPatterns.rar">CcrPatterns.rar (162.64
KB)</a>
        </p>
        <p>
Have fun.
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=b23f5c68-90b9-41a0-b18b-9069bea82c77" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Semingo, Delver, Demo, What a rush!</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/SemingoDelverDemoWhatARush.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,3fade6f7-3cc6-4286-9974-a13eed804b62.aspx</id>
    <published>2008-01-25T12:46:58.8120000+02:00</published>
    <updated>2008-02-12T13:42:18.8750000+02:00</updated>
    <category term="Life" label="Life" scheme="http://www.lnbogen.com/CategoryView,category,Life.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Alright alright, so I didn't post anything for... a decade or so. 
<br />
but I'm here (at the office that is) all day long, being a part of a great Team,
building the greatest\coolest piece of software I've ever dream of.<br /><br />
I promised myself that I'll be short this time so here it goes, Oren's 60 seconds
update:
</p>
        <ol>
          <li>
We've changed our name from Semingo to <strong>Delver</strong> (delver: <span showconjugation="on"><span style="WIDTH: 1pt"></span></span>(n)
deep thinker; one who investigates data). 
<br />
Hopefully (if God will hear his little buddy here), the phrase "To delve"
will catch up with the scary "Google-it". 
</li>
          <li>
We're going to show our product to the world at the <a href="http://www.demo.com/conferences/demo08/index.php">DEMO
conference</a> (28-30 January, yes, in 4 days!) in Palm Desert, CA.<br />
If you want to be one of our first beta users, please go to our site: <a href="http://www.delver.com">www.delver.com</a> and
register (we'll send you an email once we'll release our beta). 
</li>
          <li>
We're looking for super talented folks to join our amazing Team, interested?</li>
        </ol>
        <div>Short, to the point, no technical buzzzzz. I'm feeling violated.
</div>
        <div> 
</div>
        <div>
          <strong>update:</strong>
        </div>
        <div>here are a few links from interesting articles about us:
</div>
        <div> - <a href="http://www.delver.com/about.htm">http://www.delver.com/about.htm</a> (from
our home site)<br /></div>
        <div> - <span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Arial','sans-serif'"><a href="http://link.brightcove.com/services/link/bcpid1127798146/bclid1396518815/bctid1392526686">http://link.brightcove.com/services/link/bcpid1127798146/bclid1396518815/bctid1392526686</a> (6
minutes of live! demo\video, presented by our CEO at DEMO conference)</span></div>
        <div>
          <span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Arial','sans-serif'">
            <font face="Verdana" color="#003300">
              <span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Arial','sans-serif'"> <font face="Verdana" color="#003300">- </font><a href="http://www.somewhatfrank.com/2008/02/silicon-valley.html">http://www.somewhatfrank.com/2008/02/silicon-valley.html</a> (5
minutes demo\video from IsraelWebTour 2008)</span>
            </font>
          </span>
        </div>
        <div>
          <span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Arial','sans-serif'">
            <font face="Verdana" color="#003300"> - </font>
            <a href="http://www.readwriteweb.com/archives/delver_reinvents_search.php">http://www.readwriteweb.com/archives/delver_reinvents_search.php</a> (great summary
to understand our product)</span>
        </div>
        <div> - <a href="http://www.techcrunch.com/2008/01/28/delver-comes-out-of-stealth-with-a-new-twist-on-social-search/">http://www.techcrunch.com/2008/01/28/delver-comes-out-of-stealth-with-a-new-twist-on-social-search/</a></div>
        <div> - <a href="http://www.technologyreview.com/Infotech/20138/?a=f">http://www.technologyreview.com/Infotech/20138/?a=f</a><br />
 - <a href="http://www.webware.com/8301-1_109-9861049-2.html">http://www.webware.com/8301-1_109-9861049-2.html</a><br />
 - <a href="http://www.sdwys.com/2008/01/delver-delivers.html">http://www.sdwys.com/2008/01/delver-delivers.html</a><br />
 - <a href="http://mashable.com/2008/01/30/demo-08-roundup-2">http://mashable.com/2008/01/30/demo-08-roundup-2</a></div>
        <div> 
</div>
        <div> 
</div>
        <div>Next post - some cool multi-threading code and how to test it without wanting
to stick a nail in your eye (or someone's else eye). 
<br />
Now I'm feeling better...<br /></div>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=3fade6f7-3cc6-4286-9974-a13eed804b62" />
      </div>
    </content>
  </entry>
  <entry>
    <title>How to store billions of tasks?</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/HowToStoreBillionsOfTasks.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,bb39baf4-d670-4082-ace2-6748beeedb44.aspx</id>
    <published>2007-11-18T00:54:31.7810000+02:00</published>
    <updated>2007-11-18T01:11:31.3593750+02:00</updated>
    <category term="Design" label="Design" scheme="http://www.lnbogen.com/CategoryView,category,Design.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
Imagine that you're living with one hell of a crazy wife. Every day she's
giving you bunch of tasks. "Mow the grass", "water the plants", "take out the garbage",
"replace the light in the kitchen", "build a fence" etc. For every task you complete,
she goes bananas and create 10,000 more on the spot, all <b>related</b> to the task
itself ("build a fence" leads to "paint the fence", "put a nice sign on the fence",
"practice your wax-on, wax-off" … you get the drift). Reluctant to perform all of
these tasks but smart enough to know that you'll lose at least 50% of your property
(divorce are nasty), you start collecting these tasks (you write them on papers).
You take one paper (single task), perform it and return to your wife with a big-fat
smile of your face. She, in return, creates 10,000 new <b>related</b> tasks to the
one you've just completed, write them on paper and put it in a BIG box. Every once
in a while she's not waiting for you and adding "main" tasks to the box by herself.
After performing one task, you pick another one from the box (FIFO), without knowing
if it's a main task or not, you go to your way "eager" to perform that task as requested
(as if you have a choice). This goes on and on and on… 
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
The box is the tricky part here. Can one box hold billions of papers? hardly. So you
start collecting boxes and now it's getting harder as you need to add new boxes when
needed, find the "right" box to pull tasks from and making sure these boxes won't
break (maintenance) with time.
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
Here are a few assumptions you can take as is:
</p>
        <ol>
          <li>
            <span>
              <span>
                <span style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">
                </span>
              </span>
            </span>
            <span dir="ltr">
            </span>Your
wife is looking for perfection but only in the "main" tasks which means that if you
were to build the fence, you have to do it perfectly so each mini task related to
it is crucial. 
</li>
          <li>
Your wife tends to forget things so you can assume that occasionally, she'll add new
"main" tasks that were already performed or exist in a different box.<span><span><span style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal"></span></span></span></li>
          <li>
            <span>
              <span>
                <span style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">
                </span>
              </span>
            </span>
            <span dir="ltr">
            </span>You
can't throw away tasks "just because" as you don't know if a "mini task" will be thrown
by mistake (= your wife will be pissed off. 50% is gone.). 
</li>
          <li>
            <span>
              <span>
                <span style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">
                </span>
              </span>
            </span>
            <span dir="ltr">
            </span>Be
cool - you won't perform the same task twice. This one is on me. 
</li>
          <li>
Drinking RedBull (or XL or whatever energy drink you're familiar with) 24-7-365 you
don't need to rest. You don't need to sleep. Think robot (funny combination, for 2007). 
</li>
        </ol>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
How to store billions of tasks? 
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
I kinda like the "green feeling" of a forest. Oh right, we also need them in order
to breath (El Gor is more convincing than I. Thank God). Most importantly, it costs
a lot of money buying so many papers! And the boxes!<span>  You'll need </span>a
lot of green ones ($) - not trees but we can't "breath" without them as well). Oh
well… You're starting to build a "Boxing mechanism", hire a few guys to maintain them,
getting a VC to give you some extra $$$ and after a few months\years you got it cover!
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
What do you do if you don't have the extra $$$ or more important the extra time
to develop this kind of storage system?
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
How to store billions of tasks? You <b>don't</b>. You <b>can't</b>.  <span></span><br />
In most scenarios, when things seem too difficult to accomplish (with the given limits)
try a different angle: "If you don't like the answer, ask a different question". 
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
We know that each task creates a lot of new <b>related</b> tasks right? We also know
that keeping those new tasks is the tricky part (the BIG box problem) so what else
can be done? Let's change the question. "How do I make my wife happy?" seems like
a smarter question. If it's expensive to save those tasks why not doing these <b>related </b>tasks
on the spot instead of storing them in the box(es)? <span> </span>How is this
going to help us? Now we can throw away tasks because these tasks will be added later
on (assumption #2. Thank God your wife is not the robot). Assuming that we can save
about 1,000,000 papers in one big box – we're all set. If the box is full, we'll simply
throw away new "main" tasks, feeling good as we KNOW that we'll get to them later
on (again, assumption #2). Now all we need is one simple box with a limited amount
of papers. Less $$$ to waste and much simpler storage system to develop.
</p>
        <p class="MsoNormal" dir="ltr" style="DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left">
          <br />
Crap, it just hit me. I'm doing some cool sh$% at Semingo! Join <a href="http://www.pashabitz.com/PermaLink,guid,64f43e5b-9bb7-4a2e-bc89-0420c42b0866.aspx">us</a>!
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=bb39baf4-d670-4082-ace2-6748beeedb44" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Visual Studio .Net 2005 Colors</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/VisualStudioNet2005Colors.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,fc104328-6299-4eb1-a203-84b686aa4c5b.aspx</id>
    <published>2007-11-15T12:34:24.2650000+02:00</published>
    <updated>2007-11-15T16:01:50.9062500+02:00</updated>
    <category term=".NET/Visual Studio .Net 2005" label=".NET/Visual Studio .Net 2005" scheme="http://www.lnbogen.com/CategoryView,category,.NET%2cVisual%2BStudio%2B.Net%2B2005.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Well this is mostly a good backup-post, but heck maybe a few other (<strong>VERY COOL</strong>)
geeks will find it interesting. 
<br />
Looking for some cool IDE colors\fonts, I came up with this:
</p>
        <p>
[ Regular mode ... ]
</p>
        <p>
          <img height="445" alt="ide_colors_regular.png" src="http://www.lnbogen.com/content/binary/ide_colors_regular.png" width="696" border="0" />
        </p>
        <p>
 
</p>
        <p>
[ Marking the for loop ... ]
</p>
        <p>
          <img height="449" alt="ide_colors_marking_text.png" src="http://www.lnbogen.com/content/binary/ide_colors_marking_text.png" width="662" border="0" />
        </p>
        <p>
 
</p>
        <p>
[ Output window ]
</p>
        <p>
          <img height="230" alt="ide_colors_output.png" src="http://www.lnbogen.com/content/binary/ide_colors_output.png" width="604" border="0" />
        </p>
        <p>
          <br />
I based my colors on ZenBurn.<br />
The font I'm using is Consolas.<br />
Read all about it in <a href="http://www.codinghorror.com/blog/">Jeff Atwood</a>'s <a href="http://www.codinghorror.com/blog/archives/000682.html">post</a>.
</p>
        <p>
You can download MY version here: <a href="http://www.lnbogen.com/content/binary/OrenEllenbogen_DarkSchema.rar">OrenEllenbogen_DarkSchema.rar
(58 KB)</a></p>
        <p>
          <strong>Note:</strong> if you're using ReSharper you'll have to disable the "Highlight
current line" option. 
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=fc104328-6299-4eb1-a203-84b686aa4c5b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Can you build software like House ?</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/CanYouBuildSoftwareLikeHouse.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,8f4e3577-8db6-4890-a66d-7c124367dece.aspx</id>
    <published>2007-10-20T05:16:42.3280000+02:00</published>
    <updated>2007-10-22T14:53:51.3906250+02:00</updated>
    <category term="Management" label="Management" scheme="http://www.lnbogen.com/CategoryView,category,Management.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
What is more important to you - having the brightest dude in the world in your
team, doing his magic with God-like authority or real "together-will-conquer-the-world"
Team work? Tricky question... 
</p>
        <p>
          <img height="126" alt="house_tv_show.jpg" src="http://www.lnbogen.com/content/binary/house_tv_show.jpg" width="388" border="0" />  
<br /><br />
For those of you who don't know the TV series "House", this is your wake up call!
Go see it. Now. Seriously.<br />
Well, if you don't have the time or you're just too damn eager to read my post, we'll,
"you're an idiot!", but that's your right so I'll give you a short summary: Dr. House,
played by the genius actor Hugh Laurie, is the go-to-guy for all the rare cases where
the rest of the doctors go bananas. With his extremely cynical point of view
and shameless wittiness, combined with a very bright, analytic and (yet) creative
thinking, he manage to solve all (we'll, almost) of these cases and still being a
complete jerk to his "teammates" during the show. Just a few pearls from <a href="http://en.wikiquote.org/wiki/House_(TV_series)">Wikiquote</a> so
you'll get the drift:
</p>
        <p>
          <strong>         Dr. Cuddy:</strong> You
don't prescribe medicine based on guesses. At least we don't since Tuskeegee and Mengele. <br /><strong>         Dr. House:</strong> You're
comparing me to a Nazi? [admiringly] Nice ... 
</p>
        <dd>
          <b>Lucille</b>: I'm not pregnant. 
<dd><b>Dr. House</b>: Sorry, you don't get to make that call unless you have a stethoscope.
Union rules.<br /><p>
If you ask me, I would pick House any day. Now, if any of you know such a man, let
him know that we're at Semingo are hiring; Till then, I guess that I would stick to
a strong Team and real commitment instead of software-Nazi. 
</p><p>
I'm lying. I don't think that following someone blindly is for me. I don't believe in
this kind of leadership. I grew up at the court, playing Basketball since I was
~9, there is nothing I love more than genuine Team spirit. Facing the fact that "white
man can't jump" quite early in my life, I realized that Michael Jordan can be rest
assured, I'm not going to steal his glory. Knowing that and still being the competitive
guy that I am, there is no other choice but to build a strong Team and having fun
together. It worked for me so far.
</p><p>
Shame though, It would have been funny working with someone like House; If only life
were a TV show...
</p></dd><img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=8f4e3577-8db6-4890-a66d-7c124367dece" /></dd>
      </div>
    </content>
  </entry>
  <entry>
    <title>Scrum Clan</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/ScrumClan.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,c8ddd489-b0cb-4c08-8e47-759cbe20f3c0.aspx</id>
    <published>2007-10-10T00:47:34.5780000+02:00</published>
    <updated>2007-10-10T10:29:33.4843750+02:00</updated>
    <category term="Scrum" label="Scrum" scheme="http://www.lnbogen.com/CategoryView,category,Scrum.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://blog.karmona.com/">Moti</a> and I have <a href="http://blog.karmona.com/index.php/2007/10/09/scrum-clan/">decided</a> to
form an invite-only <strong>Scrum Clan</strong>.<br />
We would like to tag <a title="Pasha Bitz" href="http://www.pashabitz.com/">Pasha
Bitz</a> (snapshot below) as the 3rd clan member.
</p>
        <p>
          <img height="195" alt="Pasha_Scrum_Lover.jpg" src="http://www.lnbogen.com/content/binary/Pasha_Scrum_Lover.jpg" width="241" border="0" />
        </p>
        <p>
Pasha, choose carefully, you can only tag <u>one</u> Scrum-Lover like yourself to
this distinguish clan ;)
</p>
        <p>
          <strong>
            <br />
p.s </strong>- If you want to be part of the Scrum Clan, please drop a comment
and you <em>*might*</em> get an invitation...
</p>
        <p>
          <strong>
            <font size="4">                                                     </font>
          </strong>
        </p>
        <p>
          <strong>
            <font size="4">                                 </font>
            <font size="5">Scrum
Rules !</font>
          </strong>
        </p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=c8ddd489-b0cb-4c08-8e47-759cbe20f3c0" />
      </div>
    </content>
  </entry>
  <entry>
    <title>No, THAT is not Agile</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/NoTHATIsNotAgile.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,32565423-11a0-4e72-aef4-8667884ef8d7.aspx</id>
    <published>2007-09-10T20:21:03.7340000+02:00</published>
    <updated>2007-09-12T10:39:58.0312500+02:00</updated>
    <category term="Agile" label="Agile" scheme="http://www.lnbogen.com/CategoryView,category,Agile.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Let me start with an out-loud recap of this post: Agile is not something you can put
on a bread nor is it "a certain path to success". 
</p>
        <p>
          <strong>It's about STATE OF MIND.</strong>
        </p>
        <p>
If I had to describe the meaning of "Agile" to a new teammate I would say: Agile is
a constant thinking about how we, AS A TEAM, can produce working features to our users
with high quality within a short time-frame. 
<br /><br />
Don't worry:<br />
It's really OK to provide only a subset of feature(s) in one sprint. 
<br />
It's really OK to leave SOME designing\architecture issues for later on as long as
the high-level architecture is good enough (=you're comfortable with it) to answer
the big questions.<br />
It's really OK to implement only two REALLY-DONE-HIGH-QUALITY features in one sprint
over four semi-working-not-demoable features.<br /></p>
        <p>
The key here though is not really the practices, it's about the big bullets(again,
state of mind):
</p>
        <p>
1). Produce value for your customers and adjust\adopt early. 
<br />
2). Build a Team (self leadership).
</p>
        <p>
These ideas are hard to implement and require special kind of people. Putting
the Team in front of yourself is not a very job-secure attitude.  The ability
to help your teammates, shift tasks, taking ownership, critisize yourself and your
teammates and getting better, produce high quality design, tests and code - all of
it - requires versatile people with unique state of mind (and unique abilities,
of course). It's worth it. When things glue, it's a real magic; Things start to get
going by the Team, improvements and features starting to come from the developers\QA\Graphic
Designer, adjustments are made on a regular basis, changes are welcome and productivity
is <strong>celebrated</strong>. 
</p>
        <p>
You can feel something is going right. 
<br />
That's Agile.
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=32565423-11a0-4e72-aef4-8667884ef8d7" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Making WCF Proxy useable</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/MakingWCFProxyUseable.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,76dbf68b-8dd6-4ebb-ab89-11a7b93f58d5.aspx</id>
    <published>2007-09-06T00:23:59.4060000+02:00</published>
    <updated>2007-09-10T16:26:37.7812500+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.lnbogen.com/CategoryView,category,.NET.aspx" />
    <category term="TDD" label="TDD" scheme="http://www.lnbogen.com/CategoryView,category,TDD.aspx" />
    <category term="WCF" label="WCF" scheme="http://www.lnbogen.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The way WCF proxies are designed is to live until shi* happens. 
<br /><br />
Let's assume that we have a CalcualtorService with one method named Divide(int a,
int b). Sasha, a cool programmer-dude, trying to produce some usefull software
writes:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> MyCalcualtorForm
: Form {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><br />
   private</span> CalculatorProxy _calc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> CalculatorProxy();<br /><br />
   Calc_Click(...) {<br />
      _calc.Divide(firstNumber, secondNumber);<br />
   }<br />
}<br /></span>
        </p>
        <p>
What is the first error you can think of that could happen? Yep, DivideByZeroException.<br />
Once the proxy gets an exception, it enters into a "Faulted" state which makes the
proxy unusable(=you cannot use it again). 
<br />
The quickest solution is to work "by the book" and create a new instance each and
every time we need to call the service:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Calc_Click(...)
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   using</span> (CalculatorProxy
calc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> CalculatorProxy())<br />
      calc.Divide(firstNumber, secondNumber);<br />
}<br /></span>
        </p>
        <p>
But what's bad in this solution?
</p>
        <ol>
          <li>
Performance - you pay (not a lot but neither little) for each creation of the proxy.
Sure, it will probably not be your bottleneck, but heck, why is it useful? Most of
the time the proxy will not throw an exception and yet we need to create it every
time just to avoid the faulted state scenario.  
</li>
          <li>
Design - If we declare this exception BY CONTRACT, I would expect that the proxy will
still be usable afterwards. Do we really want to return Enum\int\string as status
instead of throwing exception just because of poor design? 
</li>
          <li>
TDD - you know that I'm in love with it. Now imagine Dependency Injection. Component
A recieve ICalculatorProxy and use it to... calculate something. Working "by the book"
is no good as we want to recieve an instance of the proxy from the outside in
order to mock it. Right, so we inject a proxy from the outside (got to love
Windsor) and life is pretty sweeet. Darn! Wait! one poor (even by design) exception
and our proxy goes dead. Very un-TDDish of Microsoft.</li>
        </ol>
        <p>
I had to come with a solution as no one will take TDD away from me. I present
to you ProtectedProxy: this little IL-code-at-the-end-of-the-day will able
you to recover from faulted state by creating a new proxy on each exception thus making
your proxy... useable (couldn't think about a better word to describe it). Think about
a situation where your proxy is trying to call the service but the service is down; In
Semingo, we decided that we want to keep trying until the service is up. Via ProtectedProxy,
you can determine how many times do you want to recover and when you should finally
kill the proxy. Oh yea, ProtectedProxy uses Windsor in order to create new proxies
if needed and logging messages to log4net. Good stuff.
</p>
        <p>
In the example above, all Sasha had to do was to:<br />
1). Initialize the _calc field by:<br />
        ProtectedProxy&lt;ICalculatorProxy&gt;
_calc = new ProtectedProxy&lt;ICalculatorProxy&gt;(new CalculatorProxy());<br />
2). call _calc via:<br />
        _calc.Instance.Divide(firstNumber, secondNumber);<br /><br />
But enough said, code please:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Written by Oren Ellenbogen (07.08.07) - trying to protect our proxies so they could
recover from:</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
(A) The service is not up yet, but we want to try again later.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
(B) The service throws (ANY) exception, we still want our proxy to function (bubble
the exception, but still keep on working).</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Microsoft intended to use a NEW proxy per call, but for TDD this is not ideal as we
would like to inject proxies from outside as mocks</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
in order to simulate multiple scenarios. </span>
            <br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#region</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span>
            <br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Reflection;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.ServiceModel;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> Castle.Core.Resource;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> Castle.Windsor;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> Castle.Windsor.Configuration.Interpreters;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> log4net; 
<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#endregion</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">namespace</span> Semingo.Services.Proxies.Helpers<br />
{<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   <br />
   <font color="#0000ff">public</font><font color="#0000ff">interface</font> IProxy
: ICommunicationObject { <br />
      <font color="#0000ff">bool</font> Ping();<br />
   }</span>
        </p>
        <div>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   </span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
Protect proxy from entering Faulted state by re-creating the proxy via Windsor Container
on Faulted.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
IMPORTANT: that even if a fatal exception is raised by the service (for example: the
service is not up yet), the proxy will be raised again. <br />
   /// Use it wisely (TIP: you CAN determine the number of 'recovery'
attempts).</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
&lt;/summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
&lt;typeparam name="I"&gt;The proxy interface to protect&lt;/typeparam&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
&lt;remarks&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
The way WCF works is that ANY exception on the service will cause the proxy to enter
"faulted" state which means you can not use it anymore.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
Imagine a service of CalculatorService that expose the method float Divide(int a,
int b). Sending b=0 will raise an exception in the service</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
and the proxy will get into faulted state. This is not ideal as the proxy itself should
be used again.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   ///
&lt;/remarks&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> ProtectedProxy&lt;I&gt;
: IDisposable<br />
      where I : <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font color="#000000">IProxy</font></span><br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">readonly</span> ILog
_logger <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span> I
_instance;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">readonly</span> IWindsorContainer
_container;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> _faultedCounter <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 0;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> _disposed <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">false</span>;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">const</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> AlertableNumberOfFaultedTimes <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 10; <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span> ProtectedProxy(I
instance)<br />
         : <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>(CreateXmlBasedWindsorContainer(),
instance)<br />
      {   <br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span> ProtectedProxy(IWindsorContainer
container, I instance)<br />
      {<br />
         _container <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> container;<br />
         ShieldInstance(instance);<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
&lt;summary&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
Returns the number of faults this proxy had so far</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
&lt;/summary&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> NumberOfFaults<br />
      {<br />
         get { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> _faultedCounter;
}<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span> I
Instance<br />
      {<br />
         get<br />
         {<br />
            ThrowIfInstanceAlreadyDisposed(); <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            if</span> (_instance.State
== CommunicationState.Faulted || _instance.State == CommunicationState.Closed || _instance.State
== CommunicationState.Closing)<br />
               {<br />
                  _logger.Warn(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Notice:
The proxy state is invalid ("</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> communicationObj.State <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">").
The Faulted event should have been raised and handle this state - this need to be
checked."</span>);<br />
                  HandleFaultedInstance();<br />
               }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            return</span> _instance;<br />
         }<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Close()<br />
      {<br />
         Dispose();<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ThrowIfInstanceAlreadyDisposed()<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         if</span> (_disposed)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ObjectDisposedException(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"The
protected proxy for the type: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _instance.GetType().FullName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
was closed. Cannot return a live instance of this type."</span>);<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ShieldInstance(I
instance)<br />
      {<br />
         _instance <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> instance; <br />
         _instance.Faulted += <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">delegate</span> {
HandleFaultedInstance(); };<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> HandleFaultedInstance()<br />
      {<br />
         ThrowIfInstanceAlreadyDisposed(); <br /><br />
         _faultedCounter++; <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         if</span> (_faultedCounter
&gt;= AlertableNumberOfFaultedTimes)<br />
            _logger.Warn(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ALERT!
The proxy for the type "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _instance.GetType().FullName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
got faulted for the "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _faultedCounter <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
time. Recreating the proxy but we must verify if this is valid."</span>);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         else</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (_logger.IsDebugEnabled)<br />
            _logger.Debug(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Proxy
for type "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _instance.GetType().FullName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
got faulted (current state: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ((ICommunicationObject)_instance).State <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">")
- recreating the proxy. Number of faulted instances so far: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _faultedCounter <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"."</span>); <br /><br />
         ProxyHelper.CloseProxy(_instance); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
close current proxy</span><br />
         ShieldInstance(_container.Resolve&lt;I&gt;()); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
re-create the proxy, faulted proxies are no good for further use.</span><br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span> IWindsorContainer
CreateXmlBasedWindsorContainer()<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         try</span><br />
         {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> WindsorContainer(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> XmlInterpreter(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ConfigResource(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"castle"</span>)));<br />
         }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         catch</span> (Exception
err)<br />
         {<br />
            _logger.Warn(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Unable
to create xml based windsor container, using empty one."</span>, err);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> WindsorContainer(); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
for testing (the proxy will be mocked anyway).</span><br />
         }<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      #region</span> IDisposable
Members <br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///&lt;summary&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///Performs
application-defined tasks associated with freeing, releasing, or resetting unmanaged
resources.</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///&lt;/summary&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Dispose()<br />
      {<br />
         Dispose(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>);<br />
         GC.SuppressFinalize(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>);<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      protected</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">virtual</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Dispose(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> disposing)<br />
      {<br />
         _logger.Info(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Attempting
to dispose the protected proxy for the type: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _instance.GetType().FullName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">",
disposed already? "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> _disposed); <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         if</span> (_disposed) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span>; <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         if</span> (disposing)<br />
         {<br />
            ProxyHelper.CloseProxy(_instance);<br />
         } <br /><br />
         _disposed <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>;<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      #endregion</span><br />
   }<br /><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> ProxyHelper<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">readonly</span> ILog
_logger <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> CloseProxy(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> proxy)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         if</span> (proxy
== <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span>; <br />
         CloseProxy(proxy <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span> ICommunicationObject);<br />
      } <br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
&lt;summary&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
Close the proxy in a safe manner (will not throw exception)</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
&lt;/summary&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      ///
&lt;param name="proxy"&gt;The proxy to close&lt;/param&gt;</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> CloseProxy(ICommunicationObject
proxy)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         if</span> (proxy
== <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span>; <br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         try</span><br />
         {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            if</span> (proxy.State
== CommunicationState.Closing || proxy.State == CommunicationState.Closed || proxy.State
== CommunicationState.Faulted)<br />
               proxy.Abort();<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            else</span><br />
               proxy.Close();<br />
         }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         catch</span> (CommunicationException)<br />
         {<br />
            proxy.Abort();<br />
         }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         catch</span> (TimeoutException)<br />
         {<br />
            proxy.Abort();<br />
         }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         catch</span> (Exception
err)<br />
         {<br />
            _logger.Error(err);<br />
            proxy.Abort();<br />
         }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         finally</span><br />
         {<br />
            proxy <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br />
      }<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   }<br />
}</span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <br />
          </span>
        </div>
        <p>
Hours of joy...
</p>
        <p>
Almost forgot, on the next post - "How to TDD WCF code" - stay tuned...
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=76dbf68b-8dd6-4ebb-ab89-11a7b93f58d5" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Continuous Integration as Quality Reflection</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/ContinuousIntegrationAsQualityReflection.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,e802c6ec-cc1b-4c21-8e17-c7b802772e85.aspx</id>
    <published>2007-09-03T14:42:23.6870000+02:00</published>
    <updated>2007-09-03T15:01:22.8593750+02:00</updated>
    <category term="Agile" label="Agile" scheme="http://www.lnbogen.com/CategoryView,category,Agile.aspx" />
    <category term="Management" label="Management" scheme="http://www.lnbogen.com/CategoryView,category,Management.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the most common question in moving towards Agile Development is <strong>"</strong>Where
should I start from?<strong>"</strong>. If you'll ask me, setup a Continuous Integration
(aka "CC") would be the first thing you should start with.
</p>
        <p>
          <strong>
            <u>Step 1 (Check for compilation bugs): Code Quality ~= 30%</u>
          </strong>
        </p>
        <p>
The CC should be able to identify check-ins to your source control, get the latest
source and compile it. The output should be either "green" (Everything compiles successfully
with 0 warnings) or "red" (more than one warning or compilation errors). In addition
to the fast feedback, the output should also include the files that were changed from
the last build (and by whom, so people could know where to look).
</p>
        <p>
The immediate value is priceless. the ability to SEE whether your source-code
is stable enough to allow other programmers perform Get Latest and continue their
work and the "fail-fast" attitude can save you a lot of time in the long run. It's
important to realize though that even if the code compiles without warnings,
it still doesn't mean that you could count on the quality of the code.
</p>
        <p>
          <strong>
            <u>Step 2 (Check for component-based quality): Code Quality ~= 70%<a href="http://www.lnbogen.com/content/binary/CC.jpg" atomicselection="true"><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="95" src="http://www.lnbogen.com/content/binary/CC.jpg" width="124" align="right" border="0" /></a></u>
          </strong>
        </p>
        <p>
If you can go one extra mile, write a few automated tests (via one of the available
XUnit frameworks) for your components. This means that you are able to inject
the component's dependencies from the outside and simulate mini use-cases on component's
level. This step is crucial even if you write those after the code
itself was written. Let the CC run them if Step 1 is OK. This should allow
you to catch the majority of your bugs (I'll leave the "how to write good
tests" to another post). If all is green, you know that the system behaves as expected,
at least to some extent.
</p>
        <p>
This step is not trivial as it requires you to design for testability and invest in
proper testing. Don't let go of this step though, automated tests on this
level will make your life much easier. It will take your code one (major) step
ahead in "write code that could be changed". Agile is all about that state of mind.
</p>
        <p>
          <strong>
            <u>Step 3 (Check for integration-based quality): Code Quality ~= 80% </u>
          </strong>
        </p>
        <p>
          <a href="http://www.lnbogen.com/content/binary/FailingCC.jpg" atomicselection="true">
            <img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="330" src="http://www.lnbogen.com/content/binary/FailingCC.jpg" width="406" align="right" border="0" />
          </a>
        </p>
        <p>
Now that you're components are behaving as expected, you should try to write
a few (automated, of course) tests that simulate the entire flow of 2 or more
components (DB is a component as well) in the system. As the system
grows and more uses cases are added, you should try to improve these tests as they
give a solid proof that the SYSTEM works.
</p>
        <p>
          <strong>
            <u>Step 4 (Make everything visible): Code Quality ~= 90%</u>
          </strong>
        </p>
        <p>
The state &amp; quality of your source control should be visible to the Team and Management
as you want to insure IMMEDIATE response time in case someone check-ins
a low quality code (on any level). Fixing a failing test three days after the
change itself is a bad symptom of low visibility or low perception, by the Team, regarding
the importance of the quality of the system.
</p>
        <p>
          <strong>
            <u>Step 5 (Automated deployment): Code Quality ~= 95%</u>
          </strong>
        </p>
        <p>
After successful build you would like to deploy the latest source on a dedicated environment
which the developers could play with before deploying to another (testing?) environment.
This won't be a stable environment, but at least it will give a quick look at the
current state of the system - the way customers would see it.
</p>
        <p>
          <strong>
            <u>Step 6 (Procedures checking): Code Quality &gt; 95%:</u>
          </strong>
        </p>
        <p>
You can add many more checks to the flow, such as Tests Coverage or FxCop. Leave
those to the end. From my experience, Time .vs. Value in these features will vary
from team to team. You'll gain much more from investing in Steps 2-3.
</p>
        <p>
 
</p>
        <h2>
          <strong>
            <u>Semingo CC:</u>
          </strong>
        </h2>
        <p>
Each developer &amp; manager on our team have a CCTray(the little red circle
in the little picture above) which is either Red(source control is damaged),
Yellow(Build in action) or Green(Life is sweet). We're using Cruise Control.Net, CCTray,
MSBuild (and TFS plugin) and NUnit to perform all of the above. 
</p>
        <p>
A few teasers:
</p>
        <p>
* Image of Steve Urkel (from the famous Family Matters TV series) is shown for failing
build.
</p>
        <p>
* <a href="http://www.lnbogen.com/content/binary/GoodCC.jpg" atomicselection="true"><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="215" src="http://www.lnbogen.com/content/binary/GoodCC.jpg" width="530" align="right" border="0" /></a>On
the right you can find <a href="http://www.pashabitz.com/">Pasha</a> (with a V sign
I've added), one of our finest hackers modeling a successful build. You
can also notice the 582 green tests (including Integration tests) and 2 changes
made by Sagie since the last build.
</p>
        <p>
* Going to NUnit Details, you can get the full details:<br /><br /><a href="http://www.lnbogen.com/content/binary/UnitTestsCC.jpg" atomicselection="true"><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="140" src="http://www.lnbogen.com/content/binary/UnitTestsCC.jpg" width="465" border="0" /></a></p>
        <p>
 
</p>
        <p>
I had to cut the pictures in order to keep a sane width for the post, but you can
get the drift.
</p>
        <p>
btw - Aviel, yet another Semingo hacker add a "Doh!" (Simpson) each time the
CC is red on his computer. It can be quite funny (and scary, if fully concentrated
on code).
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=e802c6ec-cc1b-4c21-8e17-c7b802772e85" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Another day at the office</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/AnotherDayAtTheOffice.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,2c70c358-1410-46b0-9b57-f8a39aeb0fe2.aspx</id>
    <published>2007-07-26T19:32:25.8900000+02:00</published>
    <updated>2007-07-31T14:26:07.7500000+02:00</updated>
    <category term="@ff Topic" label="@ff Topic" scheme="http://www.lnbogen.com/CategoryView,category,%40ff%2BTopic.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A few pearls from the office:
</p>
        <ul>
          <li>
            <a href="http://www.pashabitz.com/">Pasha</a>: Damn, I like TDD so much. Writing a
5 minutes piece of code takes about a day (sarcastic tone, of course).<br /></li>
          <li>
Aviel: in my case, code does not come from my head but rather from my heart.<br /><a href="http://www.pashabitz.com/">Pasha</a>: I saw your code. It comes from your
ass.<br /></li>
          <li>
Me: Integration environment is the Tamagochi of an Agile Team<br /></li>
          <li>
(Phone ringing, Pasha answers) 
<br />
Robert: I'm Robert. 
<br /><a href="http://www.pashabitz.com/">Pasha</a>: I'm Robert. 
<br />
Robert: I'm Robert. 
<br /><a href="http://www.pashabitz.com/">Pasha</a>: I'm not Robert, I'm Pasha. 
<br />
Robert: Oh, My bad. 
<br /><a href="http://www.pashabitz.com/">Pasha</a>: Bye then. 
<br />
(end of conversation).</li>
        </ul>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=2c70c358-1410-46b0-9b57-f8a39aeb0fe2" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Semicrum - Implementing Scrum at Semingo</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/SemicrumImplementingScrumAtSemingo.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,e6060063-54a8-44cb-ba97-5d9a83446011.aspx</id>
    <published>2007-07-14T17:51:27.3280000+02:00</published>
    <updated>2007-07-20T14:37:06.0000000+02:00</updated>
    <category term="Agile" label="Agile" scheme="http://www.lnbogen.com/CategoryView,category,Agile.aspx" />
    <category term="Scrum" label="Scrum" scheme="http://www.lnbogen.com/CategoryView,category,Scrum.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
After almost 1.5 months of Scrum at Semingo (a baby startup), I decided to expose
the way we work at the moment and talk about the adjustments we've made in order to
suit Scrum to our needs.
</p>
        <p>
I'll start with our implementation to the Daily Stand-up Meeting. No doubt,
our meetings are pretty funny (most of the time) and create the right vibe for the
Team. The one thing I love most about our meetings is that by the end of the meeting,
I know what is the general work-plan for each member in my Team. 
<br /><br />
Now it's easy to know what I'm planning to complete today (I spend 5-10 minutes
planning my day before the meeting), when &amp; if I need to finish something
earlier (or at least decide about interfaces after the meeting) in order to integrate
with others, help out or ask for someone's else help(code review for example), stay
after the meeting in order to talk about something that pop up during the meeting,
remove impediments (if I can) and most importantly - have a good laugh before
the day begins.
</p>
        <p>
          <strong>
            <font size="3">Daily Stand-up Meeting (aka DSM) structure at Semingo:</font>
          </strong>
        </p>
        <p>
          <strong>When:</strong> <br />
Every day at 10:30. 
<br /><strong>Where:</strong><br />
Meetings room.<br /><strong>Time Box:</strong><br />
15 minutes.<br /><strong>Attendants:</strong> <br />
Pigs only (Chickens can (only) listen)<br /><strong>On the table: <br /></strong>Each Pig answer these 4(!) questions:<br />
(1) What have I done since the last DSM ?<br />
(2) What am I planning to do until the next DSM ?<br />
(3) Impediments - what bothers me to work ?<br />
(4) Am I on track?<br />
     If someone feels that one of his tasks won't be finished
as planned, a flag is raised so the Team could assist. <br />
     The same goes if someone feels that he's going
to finish before the expected time. <br />
     This means that he could help out someone else or take a
few extra tasks we did not plan for the current iteration.<br /><strong><br />
Notes:<br /></strong>Only one Pig talks at a time and he leads the conversation if reasonable
questions comes up. He (alone) has the power to stop a conversation if he
feels the conversation stray from the DSM path. Team members can decide to talk about
an issue that was raised during the DSM just after the meeting is finished.
</p>
        <p>
          <strong>What next (DSM planned improvements)?</strong>
          <br />
(1) You late, you get (punished, that is): each team member that late to the DSM must
wear the "I was late to DSM, I will serve you coffee today" sign on his
shirt.<br />
(2) Red-Back on track: If the conversation is getting out of control (too many jokes,
drill-down conversations, more than 1 Pig talk etc) - the red button is clicked and
each Team member is being electrified with 120V. Well no, but it could have been a
nice feature right? Clicking the red button will make a nice GONG!! so we could move
on. The Team agree to listen to the GONG and get back on track, so we could finish
in time and keeping the DSM productive.
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=e6060063-54a8-44cb-ba97-5d9a83446011" />
      </div>
    </content>
  </entry>
  <entry>
    <title>What I am doing to become a better developer</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/WhatIAmDoingToBecomeABetterDeveloper.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,055de749-53f4-4fe4-b223-9b77ca49a280.aspx</id>
    <published>2007-07-13T20:52:36.1560000+02:00</published>
    <updated>2007-07-15T20:20:45.3750000+02:00</updated>
    <category term="Life" label="Life" scheme="http://www.lnbogen.com/CategoryView,category,Life.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Gosh, I did not know <a href="http://codebetter.com/blogs/raymond.lewallen/default.aspx">Raymond
Lewallen</a> was reading my blog (I guess I should start writing some meaningful stuff
and stop playing around ;)) but I'm more than happy to raise up to <a href="http://codebetter.com/blogs/raymond.lewallen/archive/2007/07/11/what-i-am-doing-to-become-a-better-developer.aspx">the
challenge</a> and talk about what I am doing in order to go to the next level.
</p>
        <p>
In one of my post, <a href="http://www.lnbogen.com/WhatItTakesToBecomeAGreatDeveloper.aspx">What
it takes to become a great developer</a>, I mentioned the notion of "Be Eager To Learn".
I don't consider myself as a good developer due to my natural skills (I don't
think that I'm mediocre, but certainly not Larry Page). Starting 8 years ago
as a little teenager at 15, I had to work my ass off in order to keep up and show
the rest of the people I was working with that I'm just as good as they are. Reaching
this goal, I wanted to show myself that I can be the best guy at the company. 
</p>
        <p>
Eight years passed and a lot have changed, but I'm still very much eager to get better
and more versatile. One thing I'll always keep with me, as it proved it self
so far, is the no-fear attitude and the (sometimes) ridiculous optimism. I'm
not afraid of doing new things or changing positions when an "offer you can't refuse"
knocks on my door. Life is short and you most grow each and every day. I'm still the
same team player guy, although I can get over confident (aka arrogant) or raise my
voice here and there. I care about my teammates and know when to say "I'm sorry".
I work with my heart and hopefully my current and future teammates will forgive me
for my faults.
</p>
        <p>
I think that in the last few years I've learned a lot about myself, about the things
that really intrigued me, that push me to excel. I love coding, I love talking with
people, mentoring, lecturing about technologies or Agile methodologies, but most
of all - I enjoy taking ownership of projects I participate in and making
them successful. I'm looking to surround myself with people smarter than me,
those that have natural gifts in them, and making them better.
</p>
        <p>
          <strong>Things I should do</strong>
        </p>
        <p>
I should try to get more organized in planning my time. I read a lot of books about
self management but I don't feel like I'm practicing them as much as I should. I should
really invest more time in myself, trying to set goals and constantly reviewing them.
I'm leading the Agile a la Scrum at Semingo so I hope to use this work &amp; review notion
more in my life.
</p>
        <p>
I should learn more about Agile, Scrum and XP. I've read a few great books
about Agile\Scrum\Management but I still have a lot of unanswered questions. I know
that these methodologies only offer some solutions but I don't believe we should enforce
them. I believe in making our own Agile process at Semingo. That said, I do want
to read more books from people with different experience, different ideas and best
practices I could learn from.
</p>
        <p>
I should definitely write more posts! (particularly about Agile\Scrum)
</p>
        <p>
          <strong>Things I want to do</strong>
        </p>
        <p>
TDD: getting better in it and start lecturing about it more.<br />
Multi-threading: This one is a new set of skills I'm developing at my current job.
Looking at the near future, this skill is crucial as a developer.<br />
WCF: I need to use it in my current job and I have a lot of catch up to do.<br />
Lecturing: At least 4-5 lectures a year looks like a solid goal at the moment.<br /><br />
Most of all, I want to make Semingo the best place to work at, to bring more amazing
guys&amp;gals to work with us and making an application that will change the way millions
of people work.<br /><strong><br />
Things I won't do</strong></p>
        <p>
I think that it's getting clear to me that I do not want to be an external coach.
I don't see myself coaching a team for a 2-3 months and then shifting to another team.
I enjoy working with people and I take pride and strength in making things complete.
</p>
        <p>
I won't stop talking and writing about software, practices and people as long as I
have keyboard and working set of 1-N fingers available. Count on it!
</p>
        <p>
          <strong>
            <br />
Tagging these folks</strong>
        </p>
        <p>
          <a href="http://www.pashabitz.com/">Pasha Bitz</a>, <a href="http://www.human-debugger.net/">Shani
Raba</a>, <a href="http://doronsharp.spaces.live.com/">Doron Yaacoby</a>, <a href="http://www.eranachum.com/">Eran
Nachum</a>, <a href="http://www.kenegozi.com/blog/">Ken Egozi</a></p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=055de749-53f4-4fe4-b223-9b77ca49a280" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Bring lock back until 12, it has a busy day tomorrow</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/BringLockBackUntil12ItHasABusyDayTomorrow.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,5fd4e00e-f09b-4348-b2c3-c8b2c7248f27.aspx</id>
    <published>2007-07-12T11:44:41.6090000+02:00</published>
    <updated>2007-07-13T20:11:46.6718750+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.lnbogen.com/CategoryView,category,.NET.aspx" />
    <category term=".Net/Multi-Threading" label=".Net/Multi-Threading" scheme="http://www.lnbogen.com/CategoryView,category,.Net%2cMulti-Threading.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the downsides of using <font color="#0000ff">lock</font> is obviously
performance. While locking an object, any other thread trying to acquire the
lock on that object will wait in line. This can open up a deep hole to performance
hit. Rule of thumb while working with locks is to acquire it as late as possible and
release it as soon as possible. To demonstrate the order of magnitude bad usage
of locks can affect your performance, I decided to write a little demo. <br />
So let's assume we have a component that is responsible for executing tasks while
getting new ones in the process (on different threads). I tried to make this example
as simple as possible. Let's start with our "task" class:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Task<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> _id;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> _name;<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span> Task(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> id, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name) {<br />
      _id <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> id;<br />
      _name <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> name;<br />
   }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> Id { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
getter, setter </span>}<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Name { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
getter, setter </span>}<br />
}</span>
        </p>
        <p>
We have a TasksRunner that's responsible for getting new tasks and saving it to internal
list and executing the current tasks every X milliseconds (via timer). In order
to simulate a real-life process, I've made sure that executing a single task is expensive. Let's
start with the non-optimized solution:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> TasksRunner<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   private</span> List&lt;Task&gt;
_tasks;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   private</span> System.Timers.Timer
_handleTasksTimer;<br /><br />
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> TasksRunner()<br />
   {<br />
      _tasks <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> List&lt;Task&gt;();<br /><br />
      _handleTasksTimer <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Timer(200); <br />
      _handleTasksTimer.Elapsed += <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> System.Timers.ElapsedEventHandler(_handleTasksTimer_Elapsed);<br />
      _handleTasksTimer.Start();<br />
   }<br /></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font color="#0000ff">   public</font>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> AddTask(Task
t)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      lock</span> (_tasks)<br />
      {<br />
         _tasks.Add(t);<br />
         Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Task
added, id: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> t.Id <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">",
name: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> t.Name);<br />
      }<br />
   }<br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   //Execute
the (delta) tasks in a thread from the ThreadPool</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> _handleTasksTimer_Elapsed(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
System.Timers.ElapsedEventArgs e)<br />
   {<br />
      ExecuteCurrentTasks();<br />
   }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ExecuteCurrentTasks()<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      lock</span> (_tasks)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         foreach</span> (Task
t <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> _tasks)<br />
            ExecuteSingleTask(t);<br />
         <br />
         _tasks.Clear();<br />
      }<br />
   }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ExecuteSingleTask(Task
t)<br />
   {<br />
      Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Handling
task, id: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> t.Id <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">",
name: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> t.Name);<br />
      Thread.Sleep(1000); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//simulate
long run</span><br />
   }<br />
}</span>
        </p>
        <p>
AddTask will acquire the lock on _tasks and add the new task to the list while ExecuteCurrentTasks
will acquire the lock (on _tasks) and simulate real execution on the task. Notice
that during the execution, calling AddTask will wait until the current execution will
be finished. Using <a href="http://weblogs.asp.net/rosherove/default.aspx">Roy</a>'s <a href="http://weblogs.asp.net/rosherove/archive/2007/06/25/threadtester-with-new-ability-stopwhentrue-and-thread-polling.aspx">ThreadTester</a>,
we can run the following in order to notice the behavior so far:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Main(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
args)<br />
{<br />
   TasksRunner runner <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> TasksRunner();<br />
   ThreadTester threadTester <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ThreadTester();<br />
   threadTester.RunBehavior <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> ThreadRunBehavior.RunUntilAllThreadsFinish;<br /><br />
   Stopwatch watch <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Stopwatch();<br />
   watch.Start();<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   int</span> numberOfTasksToCreate <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 100;<br />
   threadTester.AddThreadAction(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">delegate</span><br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         for</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> j <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 0;
j &lt; numberOfTasksToCreate; j++) <br />
         {<br />
            runner.AddTask(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Task(j, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"job
"</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> j));<br />
            Thread.Sleep(100);<br />
         }<br />
      });<br /><br />
   threadTester.StartAllThreads(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span>.MaxValue); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//wait,
no matter how long</span><br /><br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Total
time so far (milliseconds): "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> watch.ElapsedMilliseconds);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Tasks
added so far: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> runner.TasksAdded);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Tasks
executed so far: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> runner.TasksExecuted);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Waiting
for tasks to end..."</span>);<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   while</span> (runner.TasksExecuted
&lt; numberOfTasksToCreate)<br />
      Thread.Sleep(1000);<br /><br />
   runner.Shutdown();<br /><br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"done!"</span>);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Total
time so far (milliseconds): "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> watch.ElapsedMilliseconds);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Tasks
added so far: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> runner.TasksAdded);<br />
   Console.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Tasks
executed so far: "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> runner.TasksExecuted);<br />
}</span>
        </p>
        <p>
Running this test will give us a very poor result for adding &amp; executing
100 tasks takes around ~99 seconds. 
</p>
        <p>
No doubt, the lock on _tasks while executing each and every task in the list is too
expensive as we're depend on ExecuteSingleTask (which is expensive by itself). This
way, each new task we're trying to add must wait until the current execution
is finished. An elegant solution to this problem, suggested by my teammate <a href="http://www.tomergabel.com/">Tomer
Gabel</a>, is to use a temporal object to point to the current tasks thus freeing
the lock much quicker. So here is an optimized version of ExecuteCurrentTasks:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ExecuteCurrentTasks()<br />
{<br />
   List&lt;Task&gt; copyOfTasks <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   lock</span> (_tasks)<br />
   {<br />
      copyOfTasks <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> _tasks;<br />
      _tasks <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> List&lt;Task&gt;();<br />
   }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   foreach</span> (Task
t <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> copyOfTasks)<br />
      ExecuteSingleTask(t);<br />
}</span>
        </p>
        <p>
This little refactoring give us around ~11 seconds for adding &amp; executing 100
tasks. 
</p>
        <p>
Smoking!
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=5fd4e00e-f09b-4348-b2c3-c8b2c7248f27" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Designing for testability overcomes the need for testing</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/DesigningForTestabilityOvercomesTheNeedForTesting.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,2c40bad0-de27-44db-ad35-a9ff92c3a4c6.aspx</id>
    <published>2007-07-09T15:30:39.9060000+02:00</published>
    <updated>2007-07-09T22:41:35.4531250+02:00</updated>
    <category term="TDD" label="TDD" scheme="http://www.lnbogen.com/CategoryView,category,TDD.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In my previous post, <a href="http://www.lnbogen.com/HowToMockStaticClassOrStaticMemberForTesting.aspx">"How
to mock static class or static member for testing"</a>, Eli replied that mocking
static data can be easily achieved via <a href="www.typemock.com">TypeMock</a> with
no extra work around it. Although Eli raised a valid point while TypeMock is
a very strong framework that you should check out, I still believe that designing
for testability overcomes the basic need for testing your code. Trying to use some
sort of powerful Profiler-based framework in order to mock your "wires"
is a great thing, but I would use it only if refactoring the code will take
too much time or effort that will beat the value of performing the change. 
</p>
        <p>
I would like to make my teammates think toward testability while designing the API.
</p>
        <p>
Breaking your code so it will be easily tested will make things a little bit more
complex in terms of dependency injection (object A will need to get IB in its constructor
in order to work rather then creating new instance of B inside of it), but the allegedly
weakness of breaking your code, making you stray from the pure OOP you've learned
in "OOP for dummies" courses at the university, is the exact strength I
see in TDD. Designing the code by writing use-cases, playing with the API, breaking
classes for Single Responsibility and constant refactoring wins the purpose of
testing solely or pure OO code. Don't get me wrong, pure OO is nice on the surface,
but don't get fooled by it. You write code to create successful software, not
successful practice of old paradigms. 
</p>
        <p>
TDD constantly demands to re-design the system and refactor it to fit the needs the
system invocate, having the tests will back you up in the path. This way you
can follow the guidelines of a sane development process:<br />
1). Design the general architecture (the big picture)<br />
2). Agree on interfaces between components<br />
3). Unit-test user stories (use-cases) and drill down into the design by
each test.<br />
4). Build Integration tests to connect between components.<br /><br />
and so on...
</p>
        <p>
Now, if you want to refactor existing code or add new behaviors, it's simple:<br />
1). Refactor the code.<br />
2). See that everything compiles.<br />
3). Run unit &amp; integrations tests.<br />
4). If all is good - check-in your source.
</p>
        <p>
Claiming that TDD-OO is not pure OO is fine by me. I would prefer TDD-OO based code
on pure OO any day.
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=2c40bad0-de27-44db-ad35-a9ff92c3a4c6" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Photos from the office</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/PhotosFromTheOffice.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,9b63928e-832b-40aa-8017-632501cf3177.aspx</id>
    <published>2007-07-08T21:39:03.9840000+02:00</published>
    <updated>2007-07-08T22:45:28.2968750+02:00</updated>
    <category term="@ff Topic" label="@ff Topic" scheme="http://www.lnbogen.com/CategoryView,category,%40ff%2BTopic.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.pashabitz.com/">Pasha Bitz</a>, friend, teammate, hacker and gifted(?)
photographer took some photos on our last Daily Standup Meeting and a few more at
our offices:
</p>
        <p>
          <strong>Daily Standup Meeting (I'm on the left, Sagie(aka Flash)  is
on the right):</strong>
        </p>
        <p>
          <img alt="semingo_standupMeeting_1.jpg" src="http://www.lnbogen.com/content/binary/semingo_standupMeeting_1.jpg" border="0" />
        </p>
        <p>
          <strong>Our office door (notice: it's beta 0.1):</strong>
        </p>
        <p>
          <img alt="semingo_liveInFun.jpg" src="http://www.lnbogen.com/content/binary/semingo_liveInFun.jpg" border="0" />
        </p>
        <p>
          <strong>
            <br />
And finally, the new setup, although it's far from being ready &amp; not updated (I've
got 2 22' inch LCD at the moment):</strong>
        </p>
        <p>
          <img alt="semingo_laptop.jpg" src="http://www.lnbogen.com/content/binary/semingo_laptop.jpg" border="0" />
        </p>
        <p>
          <br />
More pictures we'll be posted soon... 
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=9b63928e-832b-40aa-8017-632501cf3177" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Lnbogen Simpson avatar</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/LnbogenSimpsonAvatar.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,5d8cc77f-833c-45c9-a4eb-350996fc66a8.aspx</id>
    <published>2007-07-06T13:41:13.4840000+02:00</published>
    <updated>2007-07-06T18:11:55.4218750+02:00</updated>
    <category term="@ff Topic" label="@ff Topic" scheme="http://www.lnbogen.com/CategoryView,category,%40ff%2BTopic.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
You must admit, I'm a pretty cool (yellow) geek:
</p>
        <p>
          <img height="443" alt="OrenAsSimpson.jpg" src="http://www.lnbogen.com/content/binary/OrenAsSimpson.jpg" width="262" border="0" />
        </p>
        <p>
You can create your own avatar <a href="http://www.simpsonsmovie.com/main.html">here</a>.
</p>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=5d8cc77f-833c-45c9-a4eb-350996fc66a8" />
      </div>
    </content>
  </entry>
  <entry>
    <title>How to set a free TDD-enabled environment</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/HowToSetAFreeTDDenabledEnvironment.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,252c1122-b3c7-405b-8c8a-a5a604ae1886.aspx</id>
    <published>2007-07-06T01:13:07.6710000+02:00</published>
    <updated>2007-07-06T13:17:29.8281250+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.lnbogen.com/CategoryView,category,.NET.aspx" />
    <category term="TDD" label="TDD" scheme="http://www.lnbogen.com/CategoryView,category,TDD.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <div>
          <font size="3">
            <u>
              <br />
Download and install the following:</u>
          </font>
        </div>
        <div> 
</div>
        <div>
          <strong>Testing framework:<br /></strong>
        </div>
        <div>
        </div>
        <div>   <a href="http://www.nunit.org/index.php?p=download">NUnit</a> (version:
2.4.1 or newer)
</div>
        <div> 
</div>
        <div>
          <strong>Code Coverage tool:</strong>
        </div>
        <div> 
</div>
        <div>   <a href="http://ncover.org/SITE/files/default.aspx">NCover</a> (version
1.5.8 or newer) 
</div>
        <div> 
</div>
        <div>
          <strong>Visual Studio .Net integration tool:</strong>
        </div>
        <div> 
</div>
        <div>   <a href="http://www.testdriven.net/download_release.aspx?LicenceType=Personal">TestDriven.Net</a> (version
2.7.* or newer)
</div>
        <div> 
</div>
        <div>
          <br />
          <u>
            <font color="#000000" size="3">
              <br />
Making it play together:</font>
          </u>
        </div>
        <div>
          <u>
            <font color="#000000" size="3">
            </font>
          </u> 
</div>
        <div>
          <font color="#000000">First of all, let me apologize for the lame example, it's
kinda late for me to get creative.</font>
        </div>
        <div>Let's create a Class Library named "Calculator.Library.Tests" and write the following
test in it:
</div>
        <div>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">[TestFixture]<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> CalculatorTests<br />
{<br />
   [Test]<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Divide_TwoValidNumbers()<br />
   {<br />
      Calculator c <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Calculator();<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      int</span> expected <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 3;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      int</span> actual <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> c.Divide(6,
2);<br /><br />
      Assert.AreEqual(expected, actual);<br />
   }<br />
}</span>
          </p>
        </div>
        <div> 
</div>
        <div>Now we'll create another project(Class Library) named "Calculator.Library"
and write the following code in it:
</div>
        <div>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Calculator<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> Divide(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> a, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> b)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      if</span> (b
== 0)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> DivideByZeroException(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"err"</span>);<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      return</span> a <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/</span> b;<br />
   }<br />
}</span>
          </p>
        </div>
        <div>
          <strong>
            <br />
            <br />
Quick run of our test (print to console output):</strong>
          <br />
          <br />
Put the cursor in the test-method(Add_TwoValidNumbers) or in the test-class(CalculatorTests) -&gt; right-click
-&gt; Run Test(s). 
<br /></div>
        <div>
          <strong>
            <br />
Run tests and see results in a "nice"(depends on your definition for nice) UI:</strong>
        </div>
        <div> 
</div>
        <div>Right-click on the project "Calculator.Library.Tests" -&gt; Test With -&gt; NUnit
2.4
</div>
        <div> 
</div>
        <div>
          <strong>View Code Coverage:</strong>
        </div>
        <div>
          <strong>
          </strong> 
</div>
        <div>Right-click on the test-method\test-class\test-project -&gt; Test With -&gt;
Coverage. A new application named NCoverExplorer will be open - there
you could explore the coverage of the code. As default, you'll see the coverage
in your tests as well which is not interesting. This can be easily fixed by changing
the settings in NCoverExplorer -&gt; View -&gt; Options... -&gt; Exclusions (Tab)
-&gt; pattern: "*.Tests" -&gt; Add. 
</div>
        <div> 
</div>
        <div>You can see that we have 75% coverage at the moment:
</div>
        <div> 
</div>
        <div>
          <img alt="ncoverexplorer.JPG" src="http://www.lnbogen.com/content/binary/ncoverexplorer.JPG" border="0" />
        </div>
        <div> 
</div>
        <div> 
</div>
        <div>We can now add the following test to check the missed path (and then simply call
Test With -&gt; Coverage again):
</div>
        <div>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">[Test]<br />
[ExpectedException(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">typeof</span>(DivideByZeroException))]<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Divide_TryToDivideByZero_ThrowsException()<br />
{<br />
   Calculator c <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Calculator();<br />
   c.Divide(6, 0);<br />
}</span>
          </p>
        </div>
        <div> 
</div>
        <div>Easy, Fast, Free and (almost) Fully Integrated in my development environment. 
<br />
Life is pretty good.
</div>
        <img width="0" height="0" src="http://www.lnbogen.com/aggbug.ashx?id=252c1122-b3c7-405b-8c8a-a5a604ae1886" />
      </div>
    </content>
  </entry>
  <entry>
    <title>How to mock static class or static member for testing</title>
    <link rel="alternate" type="text/html" href="http://www.lnbogen.com/HowToMockStaticClassOrStaticMemberForTesting.aspx" />
    <id>http://www.lnbogen.com/PermaLink,guid,73284481-0870-459a-a76b-876d5daaef43.aspx</id>
    <published>2007-07-04T13:12:18.1090000+02:00</published>
    <updated>2007-07-04T15:50:18.0625000+02:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.lnbogen.com/CategoryView,category,.NET.aspx" />
    <category term="TDD" label="TDD" scheme="http://www.lnbogen.com/CategoryView,category,TDD.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the problems with static members or static classes is that you can't mock them
for proper unit-testing. Instead of taking this fact for granted, let's demonstrate
it. Assume that we have the following classes (please note, this is just an example,
not production code or anything that I'll be proud of later on):
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> CsvDataExtractor 
<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> _documentPath;<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> CsvDataExtractor(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> documentPath)<br />
    {<br />
        _documentPath <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> document;<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> ExtractFullName()<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> content <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> CsvDocumentReader.GetContent(_documentPath);<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> fullName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
extract full name logic</span><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> fullName;<br />
    }<br />
}<br /><br /><br />
[Test]<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ExtractFullName_DocumentHasFirstNameAndLastNameOnly()<br />
{<br />
    CsvDataExtractor extractor <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> CsvDataExtractor(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"c:\test.csv"</span>);<br />
    <br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> result <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> extractor.ExtractFullName();<br />
    <br />
    