<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Jesper Niedermann's .NET Blog</title>
    <link>http://www.niedermann.dk/</link>
    <description>about .NET and related technologies</description>
    <language>en-us</language>
    <copyright>Jesper Niedermann</copyright>
    <lastBuildDate>Sun, 13 Jun 2010 17:20:02 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>jesper@niedermann.dk</managingEditor>
    <webMaster>jesper@niedermann.dk</webMaster>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=cbfce837-1ab4-46ce-ba51-b67ab69cc1dc</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,cbfce837-1ab4-46ce-ba51-b67ab69cc1dc.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,cbfce837-1ab4-46ce-ba51-b67ab69cc1dc.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=cbfce837-1ab4-46ce-ba51-b67ab69cc1dc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Imagine that you want to make an extension for Visual Studio 2010 that creates new
custom right click menus for the Solution Explorer. Imagine that you could do it by
just implementing a good old .NET interface like this:
</p>
        <pre class="c#" name="code">public class MenuManager : IMenuManager<br />
{<br />
public IEnumerable&lt;IMenuItem&gt; GetMenus(ContextLevels menuForLevel)<br />
{<br />
var menuItems = new List&lt;IMenuItem&gt;();<br />
var menuItem1 = new MenuItem("My Menu1");<br />
menuItems.Add(menuItem1);<br />
var menuItem2 = new MenuItem("My Menu2");<br />
menuItems.Add(menuItem2);<br />
return menuItems;<br />
}<br /><br />
public string MainMenu()<br />
{<br />
return "My Main Menu";<br />
}<br />
}</pre>
        <p>
 
</p>
        <p>
Well it turns out you can. In <a href="http://mme.codeplex.com/" target="_blank">MME</a> I
have helped you do exactly that. No more using the convoluted add-in model of Visual
Studio to accomplish this goal. And it is also much simpler than using GAX/GAT (that
can do so much more to be fair).
</p>
        <p>
You can easily install MME, either by downloading directly from <a href="http://mme.codeplex.com/" target="_blank">Codeplex</a> or
by installing directly from the Extension Manager in Visual Studio 2010 (you can find
it under the Tools menu).
</p>
        <p>
MME does not work for the Express editions of VS.
</p>
        <p>
I also recommend installing the MME MenuManager template which you can also find in
the Extension Manager.
</p>
        <p>
At codeplex you can read more about <a href="http://mme.codeplex.com/wikipage?title=implementing&amp;referringTitle=Documentation" target="_blank">implementing</a> and <a href="http://mme.codeplex.com/wikipage?title=deploying&amp;referringTitle=Documentation" target="_blank">deploying</a> MME’s
and also get further insight on the <a href="http://mme.codeplex.com/wikipage?title=Architecture&amp;referringTitle=Documentation" target="_blank">architecture.</a></p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=cbfce837-1ab4-46ce-ba51-b67ab69cc1dc" />
      </body>
      <title>Right Click menus for Visual Studio 2010</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,cbfce837-1ab4-46ce-ba51-b67ab69cc1dc.aspx</guid>
      <link>http://www.niedermann.dk/2010/06/13/RightClickMenusForVisualStudio2010.aspx</link>
      <pubDate>Sun, 13 Jun 2010 17:20:02 GMT</pubDate>
      <description>&lt;p&gt;
Imagine that you want to make an extension for Visual Studio 2010 that creates new
custom right click menus for the Solution Explorer. Imagine that you could do it by
just implementing a good old .NET interface like this:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;public class MenuManager : IMenuManager&lt;br&gt;
{&lt;br&gt;
public IEnumerable&amp;lt;IMenuItem&amp;gt; GetMenus(ContextLevels menuForLevel)&lt;br&gt;
{&lt;br&gt;
var menuItems = new List&amp;lt;IMenuItem&amp;gt;();&lt;br&gt;
var menuItem1 = new MenuItem("My Menu1");&lt;br&gt;
menuItems.Add(menuItem1);&lt;br&gt;
var menuItem2 = new MenuItem("My Menu2");&lt;br&gt;
menuItems.Add(menuItem2);&lt;br&gt;
return menuItems;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public string MainMenu()&lt;br&gt;
{&lt;br&gt;
return "My Main Menu";&lt;br&gt;
}&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Well it turns out you can. In &lt;a href="http://mme.codeplex.com/" target="_blank"&gt;MME&lt;/a&gt; I
have helped you do exactly that. No more using the convoluted add-in model of Visual
Studio to accomplish this goal. And it is also much simpler than using GAX/GAT (that
can do so much more to be fair).
&lt;/p&gt;
&lt;p&gt;
You can easily install MME, either by downloading directly from &lt;a href="http://mme.codeplex.com/" target="_blank"&gt;Codeplex&lt;/a&gt; or
by installing directly from the Extension Manager in Visual Studio 2010 (you can find
it under the Tools menu).
&lt;/p&gt;
&lt;p&gt;
MME does not work for the Express editions of VS.
&lt;/p&gt;
&lt;p&gt;
I also recommend installing the MME MenuManager template which you can also find in
the Extension Manager.
&lt;/p&gt;
&lt;p&gt;
At codeplex you can read more about &lt;a href="http://mme.codeplex.com/wikipage?title=implementing&amp;amp;referringTitle=Documentation" target="_blank"&gt;implementing&lt;/a&gt; and &lt;a href="http://mme.codeplex.com/wikipage?title=deploying&amp;amp;referringTitle=Documentation" target="_blank"&gt;deploying&lt;/a&gt; MME’s
and also get further insight on the &lt;a href="http://mme.codeplex.com/wikipage?title=Architecture&amp;amp;referringTitle=Documentation" target="_blank"&gt;architecture.&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=cbfce837-1ab4-46ce-ba51-b67ab69cc1dc" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,cbfce837-1ab4-46ce-ba51-b67ab69cc1dc.aspx</comments>
      <category>Tools</category>
      <category>Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=91776158-a7f1-490d-a36f-dd9def7cf9ee</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,91776158-a7f1-490d-a36f-dd9def7cf9ee.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,91776158-a7f1-490d-a36f-dd9def7cf9ee.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=91776158-a7f1-490d-a36f-dd9def7cf9ee</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Windows developers who are used to click events in WinForms, WPF or Silverlight might
miss click and double click events, but because of the game loop where everything
is drawn and updated every few milliseconds an event based approach is probably not
a good idea in most cases. Not so much because of the performance of an event based
approach, but more because the complexity is overwhelming. If several users clicks
and double clicks several keys on the keyboard simultaneously, how would you decide
which of these are clicked and in which order, and further more it is not obvious
to subscribers of the events that they are in the game loop, so they might do code
which performs inadequately.
</p>
        <p>
I have made a few generic classes that expands the MouseState, GamePadState and KeyboardState
in order to make click “events” available. But of course I utilize the standard polling
mechanism in XNA which is to call GetState() on each device.
</p>
        <p>
The approach is that I call my own version of GetState() in the main game loop. My
GetState() method first enqueues the state in a Queue, and then dequeues all states
older than 500 ms, before the state is returned. In this way a historical map of user
interactions is maintained at all times.
</p>
        <p>
Now I can simply check if a key or button was clicked by checking if the key was pressed
and then released “historically”. Similarly I can check for double click by checking
if the key or button was pressed, then released, then pressed again and then released
again.
</p>
        <p>
Now you probably realize why I go back 500 ms. It is because this is the standard
time in which a double click should be executed.
</p>
        <p>
I have used this approach in the game Protect the Carrot at <a href="http://ptc.codeplex.com">http://ptc.codeplex.com</a> and
it works like a charm (The url for the game does not work today, since the game will
only be published in a few weeks).
</p>
        <p>
Here is the implementation of the MouseExtended class which uses this approach:
</p>
        <pre class="c#" name="code">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using Microsoft.Xna.Framework.Input;<br />
using Microsoft.Xna.Framework;<br /><br />
namespace PTC.Input<br />
{<br />
public class MouseExtended : InputDeviceExtended&lt;MouseState&gt;<br />
{<br />
private static MouseExtended m_Current;<br />
public static MouseExtended Current<br />
{<br />
get<br />
{<br />
if (m_Current == null)<br />
{<br />
m_Current = new MouseExtended();<br />
}<br />
return m_Current;<br />
}<br />
}<br /><br />
public MouseState GetState(GameTime currentTime)<br />
{<br />
DequeueOldStates(currentTime);<br />
MouseState state = Mouse.GetState();<br />
EnqueueNewState(currentTime, state);<br />
return state;<br />
}<br /><br />
private bool ClickCount(MouseButton checkButton, int requiredCount)<br />
{<br />
ButtonState found = ButtonState.Released;<br />
int count = 0;<br />
foreach (InputStateExtended&lt;MouseState&gt; stateExt in RecordedStates)<br />
{<br />
if (found == ButtonState.Pressed &amp;&amp; 
<br />
ButtonStateToCheck(stateExt.State, checkButton) == ButtonState.Released)<br />
{<br />
count++;<br />
if (count &gt;= requiredCount)<br />
return true;<br />
}<br />
found = ButtonStateToCheck(stateExt.State, checkButton);<br />
}<br />
return false;<br />
}<br /><br />
private ButtonState ButtonStateToCheck(MouseState state, MouseButton checkButton)<br />
{<br />
switch (checkButton)<br />
{<br />
case MouseButton.Left:<br />
return state.LeftButton;<br />
case MouseButton.Middle:<br />
return state.MiddleButton;<br />
case MouseButton.Right:<br />
return state.RightButton;<br />
case MouseButton.XButton1:<br />
return state.XButton1;<br />
case MouseButton.XButton2:<br />
return state.XButton2;<br />
default:<br />
return state.LeftButton;<br />
}<br />
}<br /><br />
public bool WasSingleClick(MouseButton checkButton)<br />
{<br />
return(ClickCount(checkButton, 1));<br />
}<br /><br />
public bool WasDoubleClick(MouseButton checkButton)<br />
{<br />
return (ClickCount(checkButton, 2));<br />
}<br /><br />
}<br />
}</pre>
        <p>
And here is the generic InputDeviceExtended class which MouseExtended inherits:
</p>
        <pre class="c#" name="code">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using Microsoft.Xna.Framework;<br />
using Microsoft.Xna.Framework.Audio;<br />
using Microsoft.Xna.Framework.Content;<br />
using Microsoft.Xna.Framework.GamerServices;<br />
using Microsoft.Xna.Framework.Graphics;<br />
using Microsoft.Xna.Framework.Input;<br />
using Microsoft.Xna.Framework.Media;<br />
using Microsoft.Xna.Framework.Net;<br />
using Microsoft.Xna.Framework.Storage;<br /><br />
namespace PTC.Input<br />
{<br />
public class InputDeviceExtended&lt;S&gt; where S : struct<br />
{<br />
private Queue&lt;InputStateExtended&lt;S&gt;&gt; m_RecordedStates = new Queue&lt;InputStateExtended&lt;S&gt;&gt;();<br /><br />
public Queue&lt;InputStateExtended&lt;S&gt;&gt; RecordedStates<br />
{<br />
get { return m_RecordedStates; }<br />
}<br /><br />
private Stack&lt;InputStateExtended&lt;S&gt;&gt; m_StatesForReuse = new Stack&lt;InputStateExtended&lt;S&gt;&gt;();<br /><br />
protected void EnqueueNewState(GameTime time, S state)<br />
{<br />
if (!state.Equals(m_CurrentState))<br />
{<br />
m_CurrentState = state;<br />
m_RecordedStates.Enqueue(CreateState(time, state));<br />
}<br />
}<br /><br />
private S m_CurrentState;<br />
public S CurrentState<br />
{<br />
get { return m_CurrentState; }<br />
}<br /><br />
protected void DequeueOldStates(GameTime currentTime)<br />
{<br />
InputStateExtended&lt;S&gt; state = null;<br />
if (m_RecordedStates.Count &gt; 0)<br />
{<br />
state = m_RecordedStates.Peek();<br />
}<br />
if (state != null &amp;&amp; state.StateTime &lt; currentTime.TotalRealTime.Subtract(new
TimeSpan(0, 0, 0, 0, InputDeviceConstants.ClickCountTimeMS)))<br />
{<br />
m_StatesForReuse.Push(m_RecordedStates.Dequeue());<br />
DequeueOldStates(currentTime);<br />
}<br />
}<br /><br />
private InputStateExtended&lt;S&gt; CreateState(GameTime time, S state)<br />
{<br />
if (m_StatesForReuse.Count &gt; 0)<br />
{<br />
//Reuses the object to fight of the GC<br />
InputStateExtended&lt;S&gt; stateExt = m_StatesForReuse.Pop();<br />
stateExt.StateTime = time.TotalRealTime;<br />
stateExt.State = state;<br />
return stateExt;<br />
}<br />
else<br />
{<br />
return new InputStateExtended&lt;S&gt;(time, state);<br />
}<br />
}<br />
}<br />
}</pre>
        <p>
Notice that the Recorded States are reused. When dequeued from the queue the are added
to a reuse stack. This is a standard trick to fight of the Garbage Collector, by always
keeping a reference to objects on the heap they never become garbage + they are reused
so the memory use will not explode.
</p>
        <p>
I have also implemented the necessary extended classes for the Keyboard and the gamepad.
I have included them in the attachment to this post. I have not tested the GamepadExtended
class since I do not own a Gamepad, but it is implemented exactly as the keyboard
and mouse classes and ought to work. 
</p>
        <p>
To wire up the new classes you just add the relevant Getstate() calls to the Update
game loop like so:
</p>
        <pre class="c#" name="code">protected override void Update(GameTime gameTime)<br />
{<br />
KeyboardExtended.Current.GetState(gameTime);<br />
MouseExtended.Current.GetState(gameTime);<br />
base.Update(gameTime);<br />
}</pre>
        <p>
And then you can check for click and double click “events”. For instance you check
for double click of the left mouse button like this:
</p>
        <pre class="c#" name="code">if(MouseExtended.Current.WasDoubleClick(MouseButton.Left)))<br />
{<br />
//Do double click reaction<br />
}</pre>
        <p>
Hope you like the stuff.And look out for the amazing “Protect The Carrot” game within
the next month or so, at <a href="http://ptc.codeplex.com">http://ptc.codeplex.com</a></p>
        <p>
In InputDeviceExtended.zip I have included the code for all the InputDevice classes.
</p>
        <p>
        </p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:f7cf6f0f-1ed3-4885-8873-f8eaf969cb75" class="wlWriterEditableSmartContent">
          <p>
            <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ClickanddoubleclickinXNAGames_EF42/InputDeviceExtended.zip" target="_blank">InputDeviceExtended.zip</a>
          </p>
        </div>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=91776158-a7f1-490d-a36f-dd9def7cf9ee" />
      </body>
      <title>Click and double click in XNA Games</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,91776158-a7f1-490d-a36f-dd9def7cf9ee.aspx</guid>
      <link>http://www.niedermann.dk/2010/05/12/ClickAndDoubleClickInXNAGames.aspx</link>
      <pubDate>Wed, 12 May 2010 20:38:51 GMT</pubDate>
      <description>&lt;p&gt;
Windows developers who are used to click events in WinForms, WPF or Silverlight might
miss click and double click events, but because of the game loop where everything
is drawn and updated every few milliseconds an event based approach is probably not
a good idea in most cases. Not so much because of the performance of an event based
approach, but more because the complexity is overwhelming. If several users clicks
and double clicks several keys on the keyboard simultaneously, how would you decide
which of these are clicked and in which order, and further more it is not obvious
to subscribers of the events that they are in the game loop, so they might do code
which performs inadequately.
&lt;/p&gt;
&lt;p&gt;
I have made a few generic classes that expands the MouseState, GamePadState and KeyboardState
in order to make click “events” available. But of course I utilize the standard polling
mechanism in XNA which is to call GetState() on each device.
&lt;/p&gt;
&lt;p&gt;
The approach is that I call my own version of GetState() in the main game loop. My
GetState() method first enqueues the state in a Queue, and then dequeues all states
older than 500 ms, before the state is returned. In this way a historical map of user
interactions is maintained at all times.
&lt;/p&gt;
&lt;p&gt;
Now I can simply check if a key or button was clicked by checking if the key was pressed
and then released “historically”. Similarly I can check for double click by checking
if the key or button was pressed, then released, then pressed again and then released
again.
&lt;/p&gt;
&lt;p&gt;
Now you probably realize why I go back 500 ms. It is because this is the standard
time in which a double click should be executed.
&lt;/p&gt;
&lt;p&gt;
I have used this approach in the game Protect the Carrot at &lt;a href="http://ptc.codeplex.com"&gt;http://ptc.codeplex.com&lt;/a&gt; and
it works like a charm (The url for the game does not work today, since the game will
only be published in a few weeks).
&lt;/p&gt;
&lt;p&gt;
Here is the implementation of the MouseExtended class which uses this approach:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;using System;&lt;br&gt;
using System.Collections.Generic;&lt;br&gt;
using System.Linq;&lt;br&gt;
using System.Text;&lt;br&gt;
using Microsoft.Xna.Framework.Input;&lt;br&gt;
using Microsoft.Xna.Framework;&lt;br&gt;
&lt;br&gt;
namespace PTC.Input&lt;br&gt;
{&lt;br&gt;
public class MouseExtended : InputDeviceExtended&amp;lt;MouseState&amp;gt;&lt;br&gt;
{&lt;br&gt;
private static MouseExtended m_Current;&lt;br&gt;
public static MouseExtended Current&lt;br&gt;
{&lt;br&gt;
get&lt;br&gt;
{&lt;br&gt;
if (m_Current == null)&lt;br&gt;
{&lt;br&gt;
m_Current = new MouseExtended();&lt;br&gt;
}&lt;br&gt;
return m_Current;&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public MouseState GetState(GameTime currentTime)&lt;br&gt;
{&lt;br&gt;
DequeueOldStates(currentTime);&lt;br&gt;
MouseState state = Mouse.GetState();&lt;br&gt;
EnqueueNewState(currentTime, state);&lt;br&gt;
return state;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private bool ClickCount(MouseButton checkButton, int requiredCount)&lt;br&gt;
{&lt;br&gt;
ButtonState found = ButtonState.Released;&lt;br&gt;
int count = 0;&lt;br&gt;
foreach (InputStateExtended&amp;lt;MouseState&amp;gt; stateExt in RecordedStates)&lt;br&gt;
{&lt;br&gt;
if (found == ButtonState.Pressed &amp;amp;&amp;amp; 
&lt;br&gt;
ButtonStateToCheck(stateExt.State, checkButton) == ButtonState.Released)&lt;br&gt;
{&lt;br&gt;
count++;&lt;br&gt;
if (count &amp;gt;= requiredCount)&lt;br&gt;
return true;&lt;br&gt;
}&lt;br&gt;
found = ButtonStateToCheck(stateExt.State, checkButton);&lt;br&gt;
}&lt;br&gt;
return false;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private ButtonState ButtonStateToCheck(MouseState state, MouseButton checkButton)&lt;br&gt;
{&lt;br&gt;
switch (checkButton)&lt;br&gt;
{&lt;br&gt;
case MouseButton.Left:&lt;br&gt;
return state.LeftButton;&lt;br&gt;
case MouseButton.Middle:&lt;br&gt;
return state.MiddleButton;&lt;br&gt;
case MouseButton.Right:&lt;br&gt;
return state.RightButton;&lt;br&gt;
case MouseButton.XButton1:&lt;br&gt;
return state.XButton1;&lt;br&gt;
case MouseButton.XButton2:&lt;br&gt;
return state.XButton2;&lt;br&gt;
default:&lt;br&gt;
return state.LeftButton;&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public bool WasSingleClick(MouseButton checkButton)&lt;br&gt;
{&lt;br&gt;
return(ClickCount(checkButton, 1));&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public bool WasDoubleClick(MouseButton checkButton)&lt;br&gt;
{&lt;br&gt;
return (ClickCount(checkButton, 2));&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
And here is the generic InputDeviceExtended class which MouseExtended inherits:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;using System;&lt;br&gt;
using System.Collections.Generic;&lt;br&gt;
using System.Linq;&lt;br&gt;
using Microsoft.Xna.Framework;&lt;br&gt;
using Microsoft.Xna.Framework.Audio;&lt;br&gt;
using Microsoft.Xna.Framework.Content;&lt;br&gt;
using Microsoft.Xna.Framework.GamerServices;&lt;br&gt;
using Microsoft.Xna.Framework.Graphics;&lt;br&gt;
using Microsoft.Xna.Framework.Input;&lt;br&gt;
using Microsoft.Xna.Framework.Media;&lt;br&gt;
using Microsoft.Xna.Framework.Net;&lt;br&gt;
using Microsoft.Xna.Framework.Storage;&lt;br&gt;
&lt;br&gt;
namespace PTC.Input&lt;br&gt;
{&lt;br&gt;
public class InputDeviceExtended&amp;lt;S&amp;gt; where S : struct&lt;br&gt;
{&lt;br&gt;
private Queue&amp;lt;InputStateExtended&amp;lt;S&amp;gt;&amp;gt; m_RecordedStates = new Queue&amp;lt;InputStateExtended&amp;lt;S&amp;gt;&amp;gt;();&lt;br&gt;
&lt;br&gt;
public Queue&amp;lt;InputStateExtended&amp;lt;S&amp;gt;&amp;gt; RecordedStates&lt;br&gt;
{&lt;br&gt;
get { return m_RecordedStates; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private Stack&amp;lt;InputStateExtended&amp;lt;S&amp;gt;&amp;gt; m_StatesForReuse = new Stack&amp;lt;InputStateExtended&amp;lt;S&amp;gt;&amp;gt;();&lt;br&gt;
&lt;br&gt;
protected void EnqueueNewState(GameTime time, S state)&lt;br&gt;
{&lt;br&gt;
if (!state.Equals(m_CurrentState))&lt;br&gt;
{&lt;br&gt;
m_CurrentState = state;&lt;br&gt;
m_RecordedStates.Enqueue(CreateState(time, state));&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private S m_CurrentState;&lt;br&gt;
public S CurrentState&lt;br&gt;
{&lt;br&gt;
get { return m_CurrentState; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
protected void DequeueOldStates(GameTime currentTime)&lt;br&gt;
{&lt;br&gt;
InputStateExtended&amp;lt;S&amp;gt; state = null;&lt;br&gt;
if (m_RecordedStates.Count &amp;gt; 0)&lt;br&gt;
{&lt;br&gt;
state = m_RecordedStates.Peek();&lt;br&gt;
}&lt;br&gt;
if (state != null &amp;amp;&amp;amp; state.StateTime &amp;lt; currentTime.TotalRealTime.Subtract(new
TimeSpan(0, 0, 0, 0, InputDeviceConstants.ClickCountTimeMS)))&lt;br&gt;
{&lt;br&gt;
m_StatesForReuse.Push(m_RecordedStates.Dequeue());&lt;br&gt;
DequeueOldStates(currentTime);&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private InputStateExtended&amp;lt;S&amp;gt; CreateState(GameTime time, S state)&lt;br&gt;
{&lt;br&gt;
if (m_StatesForReuse.Count &amp;gt; 0)&lt;br&gt;
{&lt;br&gt;
//Reuses the object to fight of the GC&lt;br&gt;
InputStateExtended&amp;lt;S&amp;gt; stateExt = m_StatesForReuse.Pop();&lt;br&gt;
stateExt.StateTime = time.TotalRealTime;&lt;br&gt;
stateExt.State = state;&lt;br&gt;
return stateExt;&lt;br&gt;
}&lt;br&gt;
else&lt;br&gt;
{&lt;br&gt;
return new InputStateExtended&amp;lt;S&amp;gt;(time, state);&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
Notice that the Recorded States are reused. When dequeued from the queue the are added
to a reuse stack. This is a standard trick to fight of the Garbage Collector, by always
keeping a reference to objects on the heap they never become garbage + they are reused
so the memory use will not explode.
&lt;/p&gt;
&lt;p&gt;
I have also implemented the necessary extended classes for the Keyboard and the gamepad.
I have included them in the attachment to this post. I have not tested the GamepadExtended
class since I do not own a Gamepad, but it is implemented exactly as the keyboard
and mouse classes and ought to work. 
&lt;/p&gt;
&lt;p&gt;
To wire up the new classes you just add the relevant Getstate() calls to the Update
game loop like so:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;protected override void Update(GameTime gameTime)&lt;br&gt;
{&lt;br&gt;
KeyboardExtended.Current.GetState(gameTime);&lt;br&gt;
MouseExtended.Current.GetState(gameTime);&lt;br&gt;
base.Update(gameTime);&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
And then you can check for click and double click “events”. For instance you check
for double click of the left mouse button like this:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;if(MouseExtended.Current.WasDoubleClick(MouseButton.Left)))&lt;br&gt;
{&lt;br&gt;
//Do double click reaction&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
Hope you like the stuff.And look out for the amazing “Protect The Carrot” game within
the next month or so, at &lt;a href="http://ptc.codeplex.com"&gt;http://ptc.codeplex.com&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In InputDeviceExtended.zip I have included the code for all the InputDevice classes.
&lt;/p&gt;
&lt;p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:f7cf6f0f-1ed3-4885-8873-f8eaf969cb75" class="wlWriterEditableSmartContent"&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ClickanddoubleclickinXNAGames_EF42/InputDeviceExtended.zip" target="_blank"&gt;InputDeviceExtended.zip&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=91776158-a7f1-490d-a36f-dd9def7cf9ee" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,91776158-a7f1-490d-a36f-dd9def7cf9ee.aspx</comments>
      <category>.NET</category>
      <category>Tips &amp; Tricks</category>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=75f4c0a6-612f-47d7-a2e7-518675fec14a</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,75f4c0a6-612f-47d7-a2e7-518675fec14a.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,75f4c0a6-612f-47d7-a2e7-518675fec14a.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=75f4c0a6-612f-47d7-a2e7-518675fec14a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In Microsoft CRM you have no choice when doing updates to the database. You have to
use the CRM Web Service. 
</p>
        <p>
Microsoft does not support direct SQL updates of the underlying SQL Server tables,
because of the behind the scenes CRM magic.
</p>
        <p>
The Web Service is OK for small amounts of data. But recently I had a case where I
had to code an import of a spreadsheet with up to 100.000 rows into CRM.
</p>
        <p>
This would result in 600.000 web service calls, since there was 5 retrieves for each
updates. The first tests showed that each web service call would be about 1,5 seconds
even though they were done internally on the CRM server a fast quad-core 64 bit machine.
This would be 900.000 seconds or 250 hours, more than 10 consecutive days.
</p>
        <p>
Too slow for our particular business need.
</p>
        <p>
Fortunately <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(VS.71).aspx" target="_blank">UnsafeAuthenticatedConnectionSharing</a> came
to the rescue.
</p>
        <pre class="xml" name="code">proxy.OnGetWebRequest += (sender, e) =&gt;<br />
{<br />
e.WebRequest.ConnectionGroupName = InitUserId.ToString();<br />
e.WebRequest.UnsafeAuthenticatedConnectionSharing = true;<br />
};</pre>
        <p>
On the CrmService proxy you set the <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(VS.71).aspx" target="_blank">UnsafeAuthenticatedConnectionSharing</a> to
true. This just means that other calls to the web service will use the same connection
to the database, and without reauthenticating. Which means that the next call with <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(VS.71).aspx" target="_blank">UnsafeAuthenticatedConnectionSharing</a> set
to true, will use the same connection. And will be assumed to be the same user. <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.connectiongroupname.aspx" target="_blank">ConnectionGroupName</a> is
a convenient way to split up the connections so that we don’t accidentally reuse connections
between different users. This can be done simply by using the guid of the current
CRM User.
</p>
        <p>
And now the important thing. This makes the web service call take 3/100 seconds. About
50 times faster ! The 600.000 calls can be done in 5 hours. Of course this speed was
only attained because all calls where done internally on the CRM Server.
</p>
        <p>
So why are these two settings not the default ? I don’t know. Perhaps because if you
have a site with millions of users the amount of memory used up by each connection
will be too big. But on a typical CRM site I would guess there would not be enough
users to make this a problem. 
</p>
        <p>
But to be safe, if you just use the 2 properties in the areas that need performance
with little concurrency between users you will be OK.
</p>
        <p>
This and other performance best practices for CRM can be seen on <a href="http://technet.microsoft.com/en-us/library/bb955073.aspx" target="_blank">technet</a>.
But I don’t think any will outperform this one.
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=75f4c0a6-612f-47d7-a2e7-518675fec14a" />
      </body>
      <title>Fast bulk updates and inserts in Microsoft CRM 4.0</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,75f4c0a6-612f-47d7-a2e7-518675fec14a.aspx</guid>
      <link>http://www.niedermann.dk/2010/03/07/FastBulkUpdatesAndInsertsInMicrosoftCRM40.aspx</link>
      <pubDate>Sun, 07 Mar 2010 14:39:19 GMT</pubDate>
      <description>&lt;p&gt;
In Microsoft CRM you have no choice when doing updates to the database. You have to
use the CRM Web Service. 
&lt;/p&gt;
&lt;p&gt;
Microsoft does not support direct SQL updates of the underlying SQL Server tables,
because of the behind the scenes CRM magic.
&lt;/p&gt;
&lt;p&gt;
The Web Service is OK for small amounts of data. But recently I had a case where I
had to code an import of a spreadsheet with up to 100.000 rows into CRM.
&lt;/p&gt;
&lt;p&gt;
This would result in 600.000 web service calls, since there was 5 retrieves for each
updates. The first tests showed that each web service call would be about 1,5 seconds
even though they were done internally on the CRM server a fast quad-core 64 bit machine.
This would be 900.000 seconds or 250 hours, more than 10 consecutive days.
&lt;/p&gt;
&lt;p&gt;
Too slow for our particular business need.
&lt;/p&gt;
&lt;p&gt;
Fortunately &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(VS.71).aspx" target="_blank"&gt;UnsafeAuthenticatedConnectionSharing&lt;/a&gt; came
to the rescue.
&lt;/p&gt;
&lt;pre class="xml" name="code"&gt;proxy.OnGetWebRequest += (sender, e) =&amp;gt;&lt;br&gt;
{&lt;br&gt;
e.WebRequest.ConnectionGroupName = InitUserId.ToString();&lt;br&gt;
e.WebRequest.UnsafeAuthenticatedConnectionSharing = true;&lt;br&gt;
};&lt;/pre&gt;
&lt;p&gt;
On the CrmService proxy you set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(VS.71).aspx" target="_blank"&gt;UnsafeAuthenticatedConnectionSharing&lt;/a&gt; to
true. This just means that other calls to the web service will use the same connection
to the database, and without reauthenticating. Which means that the next call with &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.unsafeauthenticatedconnectionsharing(VS.71).aspx" target="_blank"&gt;UnsafeAuthenticatedConnectionSharing&lt;/a&gt; set
to true, will use the same connection. And will be assumed to be the same user. &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.connectiongroupname.aspx" target="_blank"&gt;ConnectionGroupName&lt;/a&gt; is
a convenient way to split up the connections so that we don’t accidentally reuse connections
between different users. This can be done simply by using the guid of the current
CRM User.
&lt;/p&gt;
&lt;p&gt;
And now the important thing. This makes the web service call take 3/100 seconds. About
50 times faster ! The 600.000 calls can be done in 5 hours. Of course this speed was
only attained because all calls where done internally on the CRM Server.
&lt;/p&gt;
&lt;p&gt;
So why are these two settings not the default ? I don’t know. Perhaps because if you
have a site with millions of users the amount of memory used up by each connection
will be too big. But on a typical CRM site I would guess there would not be enough
users to make this a problem. 
&lt;/p&gt;
&lt;p&gt;
But to be safe, if you just use the 2 properties in the areas that need performance
with little concurrency between users you will be OK.
&lt;/p&gt;
&lt;p&gt;
This and other performance best practices for CRM can be seen on &lt;a href="http://technet.microsoft.com/en-us/library/bb955073.aspx" target="_blank"&gt;technet&lt;/a&gt;.
But I don’t think any will outperform this one.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=75f4c0a6-612f-47d7-a2e7-518675fec14a" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,75f4c0a6-612f-47d7-a2e7-518675fec14a.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=0a44a9f8-67aa-45a8-aea4-d644321cd0f7</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,0a44a9f8-67aa-45a8-aea4-d644321cd0f7.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,0a44a9f8-67aa-45a8-aea4-d644321cd0f7.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=0a44a9f8-67aa-45a8-aea4-d644321cd0f7</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the <a href="http://www.niedermann.dk/2009/10/20/Windows7ContestFinished.aspx" target="_blank">Day
View</a> project I needed to open a Windows 7 Sticky Note programmatically and write
to it. Unfortunately I found out that there is not an API for the Sticky Notes application.
At least not a managed one.
</p>
        <p>
So I had to fake it and make my own API. I have made a small class that basicly uses
Process.Start to open the program, and SendKeys to write to the Note.
</p>
        <p>
Here it is:
</p>
        <pre class="c#" name="code">using System;<br />
using System.Diagnostics;<br />
using System.IO;<br />
using System.Runtime.InteropServices;<br />
using System.Threading;<br />
using System.Windows.Forms;<br /><br />
namespace DayView<br />
{<br />
public class StickyNote<br />
{<br />
private const string m_ProcessName = "StikyNot";<br />
private readonly string m_ProcessFileName = Path.Combine(Environment.SystemDirectory,
"StikyNot.exe");<br />
private event EventHandler m_Activated = delegate { };<br />
[DllImport("user32.dll")]<br />
[return: MarshalAs(UnmanagedType.Bool)]<br />
static extern bool SetForegroundWindow(IntPtr hWnd);<br /><br />
public void Activate()<br />
{<br />
bool makeNewNote = true;<br />
Process p = FindProcess();<br />
if (p == null)<br />
{<br />
p = StartProcess();<br />
if (!NoteContainsText(p.MainWindowHandle))<br />
{<br />
makeNewNote = false;<br />
}<br />
}<br />
var state = new StickyNoteState();<br />
state.MakeNewNote = makeNewNote;<br />
state.StickyNoteProcess = p;<br />
ThreadPool.QueueUserWorkItem(Activate, state);<br />
}<br /><br />
private void Activate(object state)<br />
{<br />
var stickyNoteState = state as StickyNoteState;<br />
if (stickyNoteState.MakeNewNote)<br />
{<br />
NewNote(stickyNoteState.StickyNoteProcess);<br />
}<br />
OnActivated();<br />
}<br /><br />
private Process StartProcess()<br />
{<br />
var startInfo = new ProcessStartInfo(m_ProcessFileName);<br />
Process p = Process.Start(startInfo);<br />
Thread.Sleep(200); //This is an annoying hack. I haven't been able to find another
way to be sure the process is started.<br />
return p;<br />
}<br /><br />
private void NewNote(Process p)<br />
{<br />
SetForegroundWindow(p.MainWindowHandle);<br />
Signal("^n"); 
<br />
}<br /><br />
/// &lt;summary&gt;<br />
/// Weird hack to find out if note contains text.<br />
/// &lt;/summary&gt;<br />
/// &lt;returns&gt;&lt;/returns&gt;<br />
private bool NoteContainsText(IntPtr handle)<br />
{<br />
string textOfClipboard = Clipboard.GetText();<br />
Signal("^a");<br />
Signal("^c");<br />
Signal("{RIGHT}");<br />
string noteText = Clipboard.GetText().Trim();<br />
if (textOfClipboard == null)<br />
{<br />
Clipboard.SetText(textOfClipboard);<br />
}<br />
return !string.IsNullOrEmpty(noteText);<br />
}<br /><br />
private Process FindProcess()<br />
{<br />
Process[] processes = Process.GetProcessesByName(m_ProcessName);<br />
if(processes != null &amp;&amp; processes.Length &gt; 0)<br />
{<br />
return processes[0];<br />
}<br />
return null;<br />
}<br /><br />
internal void OnActivated()<br />
{<br />
m_Activated(this, new EventArgs());<br />
}<br /><br />
public event EventHandler Activated<br />
{<br />
add { m_Activated += value; }<br />
remove { m_Activated -= value; }<br />
}<br /><br />
public void Signal(string message)<br />
{<br />
SendKeys.SendWait(message);<br />
SendKeys.Flush();<br />
}<br />
}<br /><br />
public class StickyNoteState<br />
{<br />
public bool MakeNewNote { get; set; }<br />
public Process StickyNoteProcess { get; set; }<br /><br />
}<br />
}</pre>
        <p>
It works OK. The only really buggy thing in the code is in line 47, where I have to
use a Thread.Sleep in order to make sure the note is loaded before I write to it.
Unfortunately this is necessary because the Process class does not provide an event
to signal when it has finished loading. I arbitrarily chose 200 milliseconds for the
Sleep. Larger values might be necessary on slower computers.
</p>
        <p>
In order to use the class you have to configure SendKeys in your app.config like this:
</p>
        <pre class="xml" name="code">&lt;?xml version="1.0" encoding="utf-8" ?&gt;<br />
&lt;configuration&gt;<br />
&lt;appSettings&gt;<br />
&lt;add key="SendKeys" value="SendInput"/&gt;<br />
&lt;/appSettings&gt;<br />
&lt;/configuration&gt;</pre>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=0a44a9f8-67aa-45a8-aea4-d644321cd0f7" />
      </body>
      <title>API for Sticky Notes in Windows 7</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,0a44a9f8-67aa-45a8-aea4-d644321cd0f7.aspx</guid>
      <link>http://www.niedermann.dk/2009/11/13/APIForStickyNotesInWindows7.aspx</link>
      <pubDate>Fri, 13 Nov 2009 23:28:10 GMT</pubDate>
      <description>&lt;p&gt;
In the &lt;a href="http://www.niedermann.dk/2009/10/20/Windows7ContestFinished.aspx" target="_blank"&gt;Day
View&lt;/a&gt; project I needed to open a Windows 7 Sticky Note programmatically and write
to it. Unfortunately I found out that there is not an API for the Sticky Notes application.
At least not a managed one.
&lt;/p&gt;
&lt;p&gt;
So I had to fake it and make my own API. I have made a small class that basicly uses
Process.Start to open the program, and SendKeys to write to the Note.
&lt;/p&gt;
&lt;p&gt;
Here it is:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;using System;&lt;br&gt;
using System.Diagnostics;&lt;br&gt;
using System.IO;&lt;br&gt;
using System.Runtime.InteropServices;&lt;br&gt;
using System.Threading;&lt;br&gt;
using System.Windows.Forms;&lt;br&gt;
&lt;br&gt;
namespace DayView&lt;br&gt;
{&lt;br&gt;
public class StickyNote&lt;br&gt;
{&lt;br&gt;
private const string m_ProcessName = "StikyNot";&lt;br&gt;
private readonly string m_ProcessFileName = Path.Combine(Environment.SystemDirectory,
"StikyNot.exe");&lt;br&gt;
private event EventHandler m_Activated = delegate { };&lt;br&gt;
[DllImport("user32.dll")]&lt;br&gt;
[return: MarshalAs(UnmanagedType.Bool)]&lt;br&gt;
static extern bool SetForegroundWindow(IntPtr hWnd);&lt;br&gt;
&lt;br&gt;
public void Activate()&lt;br&gt;
{&lt;br&gt;
bool makeNewNote = true;&lt;br&gt;
Process p = FindProcess();&lt;br&gt;
if (p == null)&lt;br&gt;
{&lt;br&gt;
p = StartProcess();&lt;br&gt;
if (!NoteContainsText(p.MainWindowHandle))&lt;br&gt;
{&lt;br&gt;
makeNewNote = false;&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
var state = new StickyNoteState();&lt;br&gt;
state.MakeNewNote = makeNewNote;&lt;br&gt;
state.StickyNoteProcess = p;&lt;br&gt;
ThreadPool.QueueUserWorkItem(Activate, state);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private void Activate(object state)&lt;br&gt;
{&lt;br&gt;
var stickyNoteState = state as StickyNoteState;&lt;br&gt;
if (stickyNoteState.MakeNewNote)&lt;br&gt;
{&lt;br&gt;
NewNote(stickyNoteState.StickyNoteProcess);&lt;br&gt;
}&lt;br&gt;
OnActivated();&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private Process StartProcess()&lt;br&gt;
{&lt;br&gt;
var startInfo = new ProcessStartInfo(m_ProcessFileName);&lt;br&gt;
Process p = Process.Start(startInfo);&lt;br&gt;
Thread.Sleep(200); //This is an annoying hack. I haven't been able to find another
way to be sure the process is started.&lt;br&gt;
return p;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private void NewNote(Process p)&lt;br&gt;
{&lt;br&gt;
SetForegroundWindow(p.MainWindowHandle);&lt;br&gt;
Signal("^n"); 
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
/// &amp;lt;summary&amp;gt;&lt;br&gt;
/// Weird hack to find out if note contains text.&lt;br&gt;
/// &amp;lt;/summary&amp;gt;&lt;br&gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br&gt;
private bool NoteContainsText(IntPtr handle)&lt;br&gt;
{&lt;br&gt;
string textOfClipboard = Clipboard.GetText();&lt;br&gt;
Signal("^a");&lt;br&gt;
Signal("^c");&lt;br&gt;
Signal("{RIGHT}");&lt;br&gt;
string noteText = Clipboard.GetText().Trim();&lt;br&gt;
if (textOfClipboard == null)&lt;br&gt;
{&lt;br&gt;
Clipboard.SetText(textOfClipboard);&lt;br&gt;
}&lt;br&gt;
return !string.IsNullOrEmpty(noteText);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private Process FindProcess()&lt;br&gt;
{&lt;br&gt;
Process[] processes = Process.GetProcessesByName(m_ProcessName);&lt;br&gt;
if(processes != null &amp;amp;&amp;amp; processes.Length &amp;gt; 0)&lt;br&gt;
{&lt;br&gt;
return processes[0];&lt;br&gt;
}&lt;br&gt;
return null;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
internal void OnActivated()&lt;br&gt;
{&lt;br&gt;
m_Activated(this, new EventArgs());&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public event EventHandler Activated&lt;br&gt;
{&lt;br&gt;
add { m_Activated += value; }&lt;br&gt;
remove { m_Activated -= value; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public void Signal(string message)&lt;br&gt;
{&lt;br&gt;
SendKeys.SendWait(message);&lt;br&gt;
SendKeys.Flush();&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public class StickyNoteState&lt;br&gt;
{&lt;br&gt;
public bool MakeNewNote { get; set; }&lt;br&gt;
public Process StickyNoteProcess { get; set; }&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
It works OK. The only really buggy thing in the code is in line 47, where I have to
use a Thread.Sleep in order to make sure the note is loaded before I write to it.
Unfortunately this is necessary because the Process class does not provide an event
to signal when it has finished loading. I arbitrarily chose 200 milliseconds for the
Sleep. Larger values might be necessary on slower computers.
&lt;/p&gt;
&lt;p&gt;
In order to use the class you have to configure SendKeys in your app.config like this:
&lt;/p&gt;
&lt;pre class="xml" name="code"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;br&gt;
&amp;lt;configuration&amp;gt;&lt;br&gt;
&amp;lt;appSettings&amp;gt;&lt;br&gt;
&amp;lt;add key="SendKeys" value="SendInput"/&amp;gt;&lt;br&gt;
&amp;lt;/appSettings&amp;gt;&lt;br&gt;
&amp;lt;/configuration&amp;gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=0a44a9f8-67aa-45a8-aea4-d644321cd0f7" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,0a44a9f8-67aa-45a8-aea4-d644321cd0f7.aspx</comments>
      <category>.NET</category>
      <category>Tips &amp; Tricks</category>
      <category>Windows 7</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=d70452c9-013d-49b4-82cc-b5290ae51893</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=d70452c9-013d-49b4-82cc-b5290ae51893</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am currently developing the game Klimakonflikt with 5 other guys. It is a Retro
arcade game, Pac-man style, with nice 2D Graphics and music. Here is a screenshot
from the game:
</p>
        <p>
          <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="klimakonflikt_screenshot" border="0" alt="klimakonflikt_screenshot" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_thumb_1.png" width="415" height="295" />
          </a>
        </p>
        <p>
The current release, documentation and source code can be downloaded from here <a href="http://klimakonflikt.codeplex.com" target="_blank">http://klimakonflikt.codeplex.com</a> 
</p>
        <p>
The game is inherently for 2 players but we are working on the single player edition.
The AI in the current release is pretty daft, but in the next release it will be much
improved. Also we are working on a WPF leveleditor, powerups and other fun stuff.
</p>
        <p>
One of my co-developers Jakob has released a blog about the game and XNA development
in general at <a href="http://xnafan.net" target="_blank">http://xnafan.net</a></p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=d70452c9-013d-49b4-82cc-b5290ae51893" />
      </body>
      <title>Retro XNA Game Klimakonflikt under development</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</guid>
      <link>http://www.niedermann.dk/2009/11/13/RetroXNAGameKlimakonfliktUnderDevelopment.aspx</link>
      <pubDate>Fri, 13 Nov 2009 23:11:29 GMT</pubDate>
      <description>&lt;p&gt;
I am currently developing the game Klimakonflikt with 5 other guys. It is a Retro
arcade game, Pac-man style, with nice 2D Graphics and music. Here is a screenshot
from the game:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="klimakonflikt_screenshot" border="0" alt="klimakonflikt_screenshot" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_thumb_1.png" width="415" height="295"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The current release, documentation and source code can be downloaded from here &lt;a href="http://klimakonflikt.codeplex.com" target="_blank"&gt;http://klimakonflikt.codeplex.com&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The game is inherently for 2 players but we are working on the single player edition.
The AI in the current release is pretty daft, but in the next release it will be much
improved. Also we are working on a WPF leveleditor, powerups and other fun stuff.
&lt;/p&gt;
&lt;p&gt;
One of my co-developers Jakob has released a blog about the game and XNA development
in general at &lt;a href="http://xnafan.net" target="_blank"&gt;http://xnafan.net&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=d70452c9-013d-49b4-82cc-b5290ae51893" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</comments>
      <category>.NET</category>
      <category>Games &amp; Puzzles</category>
      <category>WPF</category>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=6ed1b80e-0272-4cf6-91f1-b963906577bf</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,6ed1b80e-0272-4cf6-91f1-b963906577bf.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,6ed1b80e-0272-4cf6-91f1-b963906577bf.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=6ed1b80e-0272-4cf6-91f1-b963906577bf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last friday (the 9th) just one day before the deadline I finished my application for
the <a href="http://code7contest.com" target="_blank">Windows 7 Contest</a>. "DayView"
here is the description I made for the contest: 
</p>
        <p>
"DayView provides an overview of the appointments in all your calendars by a clever
use of the Windows 7 Task bar. It shows your appointments, and you can scroll through
them with toolbar buttons, and create Sticky Notes for the most important appointments.
DayView uses MEF for a plugable architecture. It comes with plugins for Outlook and
Sunbird."
</p>
        <p>
Now I just have to wait for the evaluation the 26th of october. I have not yet decided
whether I will continue working on DayView or move on to other stuff.
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=6ed1b80e-0272-4cf6-91f1-b963906577bf" />
      </body>
      <title>Windows 7 Contest finished</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,6ed1b80e-0272-4cf6-91f1-b963906577bf.aspx</guid>
      <link>http://www.niedermann.dk/2009/10/20/Windows7ContestFinished.aspx</link>
      <pubDate>Tue, 20 Oct 2009 21:11:16 GMT</pubDate>
      <description>&lt;p&gt;
Last friday (the 9th) just one day before the deadline I finished my application for
the &lt;a href="http://code7contest.com" target="_blank"&gt;Windows 7 Contest&lt;/a&gt;. "DayView"
here is the description I made for the contest: 
&lt;/p&gt;
&lt;p&gt;
"DayView provides an overview of the appointments in all your calendars by a clever
use of the Windows 7 Task bar. It shows your appointments, and you can scroll through
them with toolbar buttons, and create Sticky Notes for the most important appointments.
DayView uses MEF for a plugable architecture. It comes with plugins for Outlook and
Sunbird."
&lt;/p&gt;
&lt;p&gt;
Now I just have to wait for the evaluation the 26th of october. I have not yet decided
whether I will continue working on DayView or move on to other stuff.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=6ed1b80e-0272-4cf6-91f1-b963906577bf" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,6ed1b80e-0272-4cf6-91f1-b963906577bf.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=e0b4bd51-4730-4be3-a518-cd95a234e1d0</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=e0b4bd51-4730-4be3-a518-cd95a234e1d0</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I must admit that I have never understood why it was fun to solve Sudoku's. But as
a programmer I was fascinated with the idea of making the perfect Sudoku puzzle generator
algorithm from the very first time I heard of Sudoku. Of course I wanted to make it
so general that it could not only make the boring old 9x9 sudoku. But sodukus of any
size 4x4, 9x9, 16x16, 25x25 and so on...
</p>
        <p>
This resulted in a .NET 1.1 WinForms program 4-5 years ago in which I could randomly
generate all sudoku combinations from 4x4 to 36x36. I created an algorithm that started
in the upper left corner and put in a random number then moving to the next square
put in a new random number from the remaining numbers. This meant that the algorithm
had to backtrack when coming to a deadend where no number was valid. This approach
guaranteed that all possible Sudokus could be generated, but it was extremely slow.
Well for 9x9 sudokus it was less than a second but for 36x36 sudokus it was around
16 hours :O)
</p>
        <p>
A few weeks ago I thought it was time to try out <a href="http://silverlight.net" target="_blank">Silverlight</a> and
make a small program to test Microsofts "new" programming platform, but I had to come
up with an idea for a small program. And for some reason Sudoku popped up again.
</p>
        <p>
And I came up with a novel idea for an extremely fast generator (try it <a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank">here</a>).
It has been said that no ideas are new anymore and I am pretty sure that I am not
the first to think of this since the algorithm is pretty obvious. I start with a valid
Sudoku as a template and then apply transformations of the columns, the rows and the
numbers themselves. 
</p>
        <p>
To generate a valid Sudoku I first generate the template. The template is generated
by starting with 1 in the upper left corner and then counting upwards. Next I go to
the 4th row and start in the second column counting from 1 again like this:
</p>
        <p>
          <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1.jpg">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s1" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1_thumb.jpg" width="243" border="0" />
          </a>
        </p>
        <p>
Next I go to the 7th row and the 3rd columm and so on. So I add 3 rows (the square
root of 9) each time. In a 16x16 sudoku I add 4 rows each time. The final template
is generated in a few milliseconds even in a 400x400 Sudoku. The final template for
a 9x9 sudoku looks like this:
</p>
        <p>
          <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2.jpg">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s2" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2_thumb.jpg" width="217" border="0" />
          </a>
        </p>
        <p>
The template is itself a valid Sudoku.
</p>
        <p>
Now I make the transformation using an observation I have made. In any valid Sudoku
I can make another valid Sudoku by switching the columns within each block of 3 columns.
As indicated in red colour for the first block above.
</p>
        <p>
Secondly I can do the same for the rows.
</p>
        <p>
And last I can transform the numbers themselves so that all 1's are transformed to
a number from 1 to 9. all 2's are transformed to one of the remaining 8 numbers and
so on.
</p>
        <p>
I could also have applied a 4th transformation  that switched the big blocks
as columns and rows, but I don't think that it will add much value.
</p>
        <p>
In all this the entire puzzle can be generated in milliseconds for even extremely
big Sudokus.
</p>
        <p>
Try it out yourself at <a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank">http://www.niedermann.dk/Sudoku/Sudoku.aspx</a></p>
        <h2>A few calculations
</h2>
        <h1>
        </h1>
        <p>
Now for some thoughts on completeness.
</p>
        <p>
A 4x4 Sudoku has 4x3x2x3x2x2 = 288 possible combinations. Not counting combinations
for empty tiles. In my original algorithm I was sure I covered all these combinations.
</p>
        <p>
When using my new algorithm I can generate 2x2x2x2x4x3x2 = 384 possible transformations
for a 4x4 Sudoku. This is more than the number of possible Sudokus. Which means that
some of these transformations must result in the same Sudokus. And furthermore I do
not know if there are Sudokus not covered by the transformations. 
</p>
        <p>
In a 9x9 Sudoku there are 1,83493E+21 possible Sudokus and I can generate 264.539.520
of those or 2.380.855.680 if I had used the extra big block transformations. Not complete
at all, but on the other hand a very large amount of Sudokus and at lightning speed.
</p>
        <h2>Empty tiles
</h2>
        <p>
A Sudoku isn't really a Sudoku without the empty tiles left for the person to fill
out.
</p>
        <p>
I just generate the empty tiles by choosing them at random. This method could probably
lead to either very boring Sudokus or Sudokus that are impossible to solve. One day
I might device some clever algorithm for emptying tiles in a more interesting fashion
:O)
</p>
        <h2>Silverlight
</h2>
        <p>
My conlusions on this my very first silverlight project is that it is extremely easy
to make something appealing in silverlight. On the other hand there are som downsides.
It is difficult to communicate between different silverlight hosts. I can only pass
strings. When you hit the print button I open another browser window. And I actually
have to serialize the Sudoku Grid and deserialize it again in the print window.
</p>
        <p>
Another downside is that is not really browser agnostic. I have tried with 3 browsers
IE8, IE7 and Firefox 3.5. Right now the only one working properly is IE8. In IE7 the
new browser I open for printing has no menu, and so you cannot really print :O) In
Firefox the silverlighthost cannot be resized, which is apparently a known issue.
But it is a problem in the Sudoku generator because I offer Sudokus of any size. This
means that in Firefox only 4x4 and 9x9 Sudokus will look good.
</p>
        <p>
BTW: The rendering of a very large Sudoku takes some time of course even though the
generation is over in milliseconds. 
</p>
        <p>
For my next silverlight project I think I will try out Prism and also the Out-of-browser
experience.
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=e0b4bd51-4730-4be3-a518-cd95a234e1d0" />
      </body>
      <title>Extremely fast Sudokus of any size programmed in silverlight 3</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</guid>
      <link>http://www.niedermann.dk/2009/08/03/ExtremelyFastSudokusOfAnySizeProgrammedInSilverlight3.aspx</link>
      <pubDate>Mon, 03 Aug 2009 21:16:48 GMT</pubDate>
      <description>&lt;p&gt;
I must admit that I have never understood why it was fun to solve Sudoku's. But as
a programmer I was fascinated with the idea of making the perfect Sudoku puzzle generator
algorithm from the very first time I heard of Sudoku. Of course I wanted to make it
so general that it could not only make the boring old 9x9 sudoku. But sodukus of any
size 4x4, 9x9, 16x16, 25x25 and so on...
&lt;/p&gt;
&lt;p&gt;
This resulted in a .NET 1.1 WinForms program 4-5 years ago in which I could randomly
generate all sudoku combinations from 4x4 to 36x36. I created an algorithm that started
in the upper left corner and put in a random number then moving to the next square
put in a new random number from the remaining numbers. This meant that the algorithm
had to backtrack when coming to a deadend where no number was valid. This approach
guaranteed that all possible Sudokus could be generated, but it was extremely slow.
Well for 9x9 sudokus it was less than a second but for 36x36 sudokus it was around
16 hours :O)
&lt;/p&gt;
&lt;p&gt;
A few weeks ago I thought it was time to try out &lt;a href="http://silverlight.net" target="_blank"&gt;Silverlight&lt;/a&gt; and
make a small program to test Microsofts "new" programming platform, but I had to come
up with an idea for a small program. And for some reason Sudoku popped up again.
&lt;/p&gt;
&lt;p&gt;
And I came up with a novel idea for an extremely fast generator (try it &lt;a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank"&gt;here&lt;/a&gt;).
It has been said that no ideas are new anymore and I am pretty sure that I am not
the first to think of this since the algorithm is pretty obvious. I start with a valid
Sudoku as a template and then apply transformations of the columns, the rows and the
numbers themselves. 
&lt;/p&gt;
&lt;p&gt;
To generate a valid Sudoku I first generate the template. The template is generated
by starting with 1 in the upper left corner and then counting upwards. Next I go to
the 4th row and start in the second column counting from 1 again like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s1" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1_thumb.jpg" width="243" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Next I go to the 7th row and the 3rd columm and so on. So I add 3 rows (the square
root of 9) each time. In a 16x16 sudoku I add 4 rows each time. The final template
is generated in a few milliseconds even in a 400x400 Sudoku. The final template for
a 9x9 sudoku looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s2" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2_thumb.jpg" width="217" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The template is itself a valid Sudoku.
&lt;/p&gt;
&lt;p&gt;
Now I make the transformation using an observation I have made. In any valid Sudoku
I can make another valid Sudoku by switching the columns within each block of 3 columns.
As indicated in red colour for the first block above.
&lt;/p&gt;
&lt;p&gt;
Secondly I can do the same for the rows.
&lt;/p&gt;
&lt;p&gt;
And last I can transform the numbers themselves so that all 1's are transformed to
a number from 1 to 9. all 2's are transformed to one of the remaining 8 numbers and
so on.
&lt;/p&gt;
&lt;p&gt;
I could also have applied a 4th transformation&amp;nbsp; that switched the big blocks
as columns and rows, but I don't think that it will add much value.
&lt;/p&gt;
&lt;p&gt;
In all this the entire puzzle can be generated in milliseconds for even extremely
big Sudokus.
&lt;/p&gt;
&lt;p&gt;
Try it out yourself at &lt;a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank"&gt;http://www.niedermann.dk/Sudoku/Sudoku.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;h2&gt;A few calculations
&lt;/h2&gt;
&lt;h1&gt;
&lt;/h1&gt;
&lt;p&gt;
Now for some thoughts on completeness.
&lt;/p&gt;
&lt;p&gt;
A 4x4 Sudoku has 4x3x2x3x2x2 = 288 possible combinations. Not counting combinations
for empty tiles. In my original algorithm I was sure I covered all these combinations.
&lt;/p&gt;
&lt;p&gt;
When using my new algorithm I can generate 2x2x2x2x4x3x2 = 384 possible transformations
for a 4x4 Sudoku. This is more than the number of possible Sudokus. Which means that
some of these transformations must result in the same Sudokus. And furthermore I do
not know if there are Sudokus not covered by the transformations. 
&lt;/p&gt;
&lt;p&gt;
In a 9x9 Sudoku there are 1,83493E+21 possible Sudokus and I can generate 264.539.520
of those or 2.380.855.680 if I had used the extra big block transformations. Not complete
at all, but on the other hand a very large amount of Sudokus and at lightning speed.
&lt;/p&gt;
&lt;h2&gt;Empty tiles
&lt;/h2&gt;
&lt;p&gt;
A Sudoku isn't really a Sudoku without the empty tiles left for the person to fill
out.
&lt;/p&gt;
&lt;p&gt;
I just generate the empty tiles by choosing them at random. This method could probably
lead to either very boring Sudokus or Sudokus that are impossible to solve. One day
I might device some clever algorithm for emptying tiles in a more interesting fashion
:O)
&lt;/p&gt;
&lt;h2&gt;Silverlight
&lt;/h2&gt;
&lt;p&gt;
My conlusions on this my very first silverlight project is that it is extremely easy
to make something appealing in silverlight. On the other hand there are som downsides.
It is difficult to communicate between different silverlight hosts. I can only pass
strings. When you hit the print button I open another browser window. And I actually
have to serialize the Sudoku Grid and deserialize it again in the print window.
&lt;/p&gt;
&lt;p&gt;
Another downside is that is not really browser agnostic. I have tried with 3 browsers
IE8, IE7 and Firefox 3.5. Right now the only one working properly is IE8. In IE7 the
new browser I open for printing has no menu, and so you cannot really print :O) In
Firefox the silverlighthost cannot be resized, which is apparently a known issue.
But it is a problem in the Sudoku generator because I offer Sudokus of any size. This
means that in Firefox only 4x4 and 9x9 Sudokus will look good.
&lt;/p&gt;
&lt;p&gt;
BTW: The rendering of a very large Sudoku takes some time of course even though the
generation is over in milliseconds. 
&lt;/p&gt;
&lt;p&gt;
For my next silverlight project I think I will try out Prism and also the Out-of-browser
experience.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=e0b4bd51-4730-4be3-a518-cd95a234e1d0" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</comments>
      <category>Games &amp; Puzzles</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=7c2564c2-8b2c-4c16-837e-9f0e56f43786</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,7c2564c2-8b2c-4c16-837e-9f0e56f43786.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,7c2564c2-8b2c-4c16-837e-9f0e56f43786.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=7c2564c2-8b2c-4c16-837e-9f0e56f43786</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just released version 1.2 of <a href="http://solzip.codeplex.com/" target="_blank">SolZip</a> my
convenient tool for Zipping Visual Studio 2008 solutions
</p>
        <p>
The major is a single install for SolZipMME, so you won't have to install <a href="http://managedmenuextension.codeplex.com/" target="_blank">ManagedMenuExtensions</a> beforehand.
</p>
        <p>
The release notes are here:
</p>
        <ol>
          <li>
Bug Fix: when multiple projects where referering to the same file it was added to
the archive multiple times.</li>
          <li>
SolZipMME uses SaveFileDialog instead of FolderBrowserDialog for Zip files.</li>
          <li>
A single file installer for SolZipMME.</li>
          <li>
Clipboard functionality now works on Vista / Windows Server 2008.</li>
          <li>
SolZipGuidance changed. The menu will no longer appear on projects that are not C#
projects. SolZipMME not changed.</li>
          <li>
Support for $(SolutionDir) and $(ProjectDir) placeholders added</li>
          <li>
Now works on Windows Vista even if UAC is not turned off</li>
        </ol>
        <p>
Enjoy...
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=7c2564c2-8b2c-4c16-837e-9f0e56f43786" />
      </body>
      <title>Version 1.2 of SolZip released</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,7c2564c2-8b2c-4c16-837e-9f0e56f43786.aspx</guid>
      <link>http://www.niedermann.dk/2009/07/15/Version12OfSolZipReleased.aspx</link>
      <pubDate>Wed, 15 Jul 2009 15:05:27 GMT</pubDate>
      <description>&lt;p&gt;
Just released version 1.2 of &lt;a href="http://solzip.codeplex.com/" target="_blank"&gt;SolZip&lt;/a&gt; my
convenient tool for Zipping Visual Studio 2008 solutions
&lt;/p&gt;
&lt;p&gt;
The major is a single install for SolZipMME, so you won't have to install &lt;a href="http://managedmenuextension.codeplex.com/" target="_blank"&gt;ManagedMenuExtensions&lt;/a&gt; beforehand.
&lt;/p&gt;
&lt;p&gt;
The release notes are here:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Bug Fix: when multiple projects where referering to the same file it was added to
the archive multiple times.&lt;/li&gt;
&lt;li&gt;
SolZipMME uses SaveFileDialog instead of FolderBrowserDialog for Zip files.&lt;/li&gt;
&lt;li&gt;
A single file installer for SolZipMME.&lt;/li&gt;
&lt;li&gt;
Clipboard functionality now works on Vista / Windows Server 2008.&lt;/li&gt;
&lt;li&gt;
SolZipGuidance changed. The menu will no longer appear on projects that are not C#
projects. SolZipMME not changed.&lt;/li&gt;
&lt;li&gt;
Support for $(SolutionDir) and $(ProjectDir) placeholders added&lt;/li&gt;
&lt;li&gt;
Now works on Windows Vista even if UAC is not turned off&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Enjoy...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=7c2564c2-8b2c-4c16-837e-9f0e56f43786" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,7c2564c2-8b2c-4c16-837e-9f0e56f43786.aspx</comments>
      <category>Tools</category>
      <category>Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=5feb4e6f-48b5-444f-9057-d2b8be5ef199</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,5feb4e6f-48b5-444f-9057-d2b8be5ef199.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,5feb4e6f-48b5-444f-9057-d2b8be5ef199.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=5feb4e6f-48b5-444f-9057-d2b8be5ef199</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just released version 1.1 of <a href="http://solzip.codeplex.com/" target="_blank">SolZip</a> which
can be downloaded from the <a href="http://solzip.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29427" target="_blank">download
page</a> at the SolZip site.
</p>
        <p>
The new action packed version contains one major improvement, one bug fix, and a few
name changes:
</p>
        <ol>
          <li>
Now Source Control bindings for TFS and SCC can be removed from sln and csproj files.
The default for all 3 UI's is that the bindings are removed, but you can optionally
choose not to remove them. Feel free to contact me if you need bindings from other
source control vendors removed.</li>
          <li>
A bug fixed that made WinZip clients give a warning when unzipping certain archives
made by SolZip. The warning was given when there was .. (2 dots) in a path in one
of the zipped files.</li>
          <li>
The Name SunZip.exe for the commandline tool was changed to SolZip.exe. Because SunZip
sounded too much like UnZip.</li>
          <li>
The Name SolutionZipper changed to SolZip everywhere. Except for SolutionZipper.dll
which has been changed to SolZipBasis.dll</li>
        </ol>
        <p>
In the next version I will try to include <a href="http://managedmenuextension.codeplex.com/" target="_blank">ManagedMenuExtensions</a> in
the install so you won't have to run more than one setup to install SolZipMME.
</p>
        <p>
Enjoy the new version :O)
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=5feb4e6f-48b5-444f-9057-d2b8be5ef199" />
      </body>
      <title>Version 1.1 of SolZip released</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,5feb4e6f-48b5-444f-9057-d2b8be5ef199.aspx</guid>
      <link>http://www.niedermann.dk/2009/06/29/Version11OfSolZipReleased.aspx</link>
      <pubDate>Mon, 29 Jun 2009 19:44:48 GMT</pubDate>
      <description>&lt;p&gt;
I just released version 1.1 of &lt;a href="http://solzip.codeplex.com/" target="_blank"&gt;SolZip&lt;/a&gt; which
can be downloaded from the &lt;a href="http://solzip.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29427" target="_blank"&gt;download
page&lt;/a&gt; at the SolZip site.
&lt;/p&gt;
&lt;p&gt;
The new action packed version contains one major improvement, one bug fix, and a few
name changes:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Now Source Control bindings for TFS and SCC can be removed from sln and csproj files.
The default for all 3 UI's is that the bindings are removed, but you can optionally
choose not to remove them. Feel free to contact me if you need bindings from other
source control vendors removed.&lt;/li&gt;
&lt;li&gt;
A bug fixed that made WinZip clients give a warning when unzipping certain archives
made by SolZip. The warning was given when there was .. (2 dots) in a path in one
of the zipped files.&lt;/li&gt;
&lt;li&gt;
The Name SunZip.exe for the commandline tool was changed to SolZip.exe. Because SunZip
sounded too much like UnZip.&lt;/li&gt;
&lt;li&gt;
The Name SolutionZipper changed to SolZip everywhere. Except for SolutionZipper.dll
which has been changed to SolZipBasis.dll&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
In the next version I will try to include &lt;a href="http://managedmenuextension.codeplex.com/" target="_blank"&gt;ManagedMenuExtensions&lt;/a&gt; in
the install so you won't have to run more than one setup to install SolZipMME.
&lt;/p&gt;
&lt;p&gt;
Enjoy the new version :O)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=5feb4e6f-48b5-444f-9057-d2b8be5ef199" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,5feb4e6f-48b5-444f-9057-d2b8be5ef199.aspx</comments>
      <category>Tools</category>
      <category>Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=07d7124e-a714-47c3-a4d4-85bfef5e976a</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,07d7124e-a714-47c3-a4d4-85bfef5e976a.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,07d7124e-a714-47c3-a4d4-85bfef5e976a.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=07d7124e-a714-47c3-a4d4-85bfef5e976a</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here is my take on the Best practice Dispose pattern for most situations. It is heavily
influenced by Juval Löwy from IDesigns book "<a href="http://www.amazon.co.uk/Programming-NET-Components-Applications-Component-Oriented/dp/0596102070/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1245356943&amp;sr=8-2" target="_blank">Programming
.NET Components</a>", and some other sources which I no longer remember, since I made
it a few years ago and have stuck to it ever since. Here it is:
</p>
        <pre class="c#" name="code">public class Class1 : IDisposable<br />
{<br />
private bool m_IsDisposed;<br /><br />
~Class1()<br />
{<br />
Dispose(false);<br />
}<br /><br /><br />
[MethodImpl(MethodImplOptions.Synchronized)]<br />
public void Dispose()<br />
{<br />
Dispose(true);<br />
GC.SuppressFinalize(this);<br />
}<br /><br />
private void Dispose(bool isDisposing)<br />
{<br />
if (m_IsDisposed)<br />
return;<br /><br />
if (isDisposing)<br />
{<br />
FreeManagedRessources();<br />
}<br />
FreeUnmanagedRessources();<br />
m_IsDisposed = true;<br />
}<br /><br />
protected virtual void FreeManagedRessources()<br />
{<br />
//Free managed ressources here. Typically by calling Dispose on them<br />
}<br /><br />
protected virtual void FreeUnmanagedRessources()<br />
{<br />
//Free unmanaged ressources here.<br />
}<br />
}</pre>
        <p>
Another thing is that you can inherit the class and override the FreeManagedRessources
and FreeUnmanagedRessources as needed.
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=07d7124e-a714-47c3-a4d4-85bfef5e976a" />
      </body>
      <title>Best practice Dispose Pattern C#</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,07d7124e-a714-47c3-a4d4-85bfef5e976a.aspx</guid>
      <link>http://www.niedermann.dk/2009/06/18/BestPracticeDisposePatternC.aspx</link>
      <pubDate>Thu, 18 Jun 2009 20:38:51 GMT</pubDate>
      <description>&lt;p&gt;
Here is my take on the Best practice Dispose pattern for most situations. It is heavily
influenced by Juval Löwy from IDesigns book "&lt;a href="http://www.amazon.co.uk/Programming-NET-Components-Applications-Component-Oriented/dp/0596102070/ref=sr_1_2?ie=UTF8&amp;amp;s=books&amp;amp;qid=1245356943&amp;amp;sr=8-2" target="_blank"&gt;Programming
.NET Components&lt;/a&gt;", and some other sources which I no longer remember, since I made
it a few years ago and have stuck to it ever since. Here it is:
&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;public class Class1 : IDisposable&lt;br&gt;
{&lt;br&gt;
private bool m_IsDisposed;&lt;br&gt;
&lt;br&gt;
~Class1()&lt;br&gt;
{&lt;br&gt;
Dispose(false);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
[MethodImpl(MethodImplOptions.Synchronized)]&lt;br&gt;
public void Dispose()&lt;br&gt;
{&lt;br&gt;
Dispose(true);&lt;br&gt;
GC.SuppressFinalize(this);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
private void Dispose(bool isDisposing)&lt;br&gt;
{&lt;br&gt;
if (m_IsDisposed)&lt;br&gt;
return;&lt;br&gt;
&lt;br&gt;
if (isDisposing)&lt;br&gt;
{&lt;br&gt;
FreeManagedRessources();&lt;br&gt;
}&lt;br&gt;
FreeUnmanagedRessources();&lt;br&gt;
m_IsDisposed = true;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
protected virtual void FreeManagedRessources()&lt;br&gt;
{&lt;br&gt;
//Free managed ressources here. Typically by calling Dispose on them&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
protected virtual void FreeUnmanagedRessources()&lt;br&gt;
{&lt;br&gt;
//Free unmanaged ressources here.&lt;br&gt;
}&lt;br&gt;
}&lt;/pre&gt;
&lt;p&gt;
Another thing is that you can inherit the class and override the FreeManagedRessources
and FreeUnmanagedRessources as needed.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=07d7124e-a714-47c3-a4d4-85bfef5e976a" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,07d7124e-a714-47c3-a4d4-85bfef5e976a.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=bfa592b2-d186-48c8-a6bf-98ecbc4c8df8</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,bfa592b2-d186-48c8-a6bf-98ecbc4c8df8.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,bfa592b2-d186-48c8-a6bf-98ecbc4c8df8.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=bfa592b2-d186-48c8-a6bf-98ecbc4c8df8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just released a new codeplex project <a href="http://solzip.codeplex.com/" target="_blank">SolutionZipper</a> which
makes it a breeze to zip compress your visual studio solutions and projects. "What's
wrong with WinZip you might Ask". Well WinZip has no knowledge of Visual Studio Solutions,
which means it will compress everything in the folder, including bin / obj folders
and other random debris.
</p>
        <p>
I accomplish the compression by using the following algorithm:
</p>
        <p>
1. Iterate over all items and projects in the sln file and zip each of these.<br />
2. Zip the sln file itself.<br />
3. Iterate over all items in the csproj files and zip each of these. The iteration
is done using Linq to Xml of course.<br />
4. Zip the csproj file itself.
</p>
        <p>
As you might have guessed SolutionZipper only works for C# projects, and is only tested
with VS2008.
</p>
        <p>
I offer three UI's for SolutionZipper
</p>
        <p>
          <a href="http://solzip.codeplex.com/Wiki/View.aspx?title=SunZip" target="_blank">SunZip</a> -
A commandline tool. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://solzip.codeplex.com/Wiki/View.aspx?title=SolZipMME" target="_blank">SolZipMME</a> -
Providing Right click menus for Visual Studio 2008 using <a href="http://managedmenuextension.codeplex.com" target="_blank">Managed
Menu Extensions</a> . 
</p>
        <p>
  
</p>
        <p>
          <a href="http://solzip.codeplex.com/Wiki/View.aspx?title=SolZipGuidance" target="_blank">SolZipGuidance</a> -
Providing Right click menus for Visual Studio 2008 using Guidance Automation (GAX). 
</p>
        <p>
  
</p>
        <p>
For the actual zipping I use the excellent open source framework <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib" target="_blank">SharpZipLib</a>.
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=bfa592b2-d186-48c8-a6bf-98ecbc4c8df8" />
      </body>
      <title>Compression of Visual Studio Solutions and Projects made easy</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,bfa592b2-d186-48c8-a6bf-98ecbc4c8df8.aspx</guid>
      <link>http://www.niedermann.dk/2009/06/15/CompressionOfVisualStudioSolutionsAndProjectsMadeEasy.aspx</link>
      <pubDate>Mon, 15 Jun 2009 21:46:31 GMT</pubDate>
      <description>&lt;p&gt;
I just released a new codeplex project &lt;a href="http://solzip.codeplex.com/" target="_blank"&gt;SolutionZipper&lt;/a&gt; which
makes it a breeze to zip compress your visual studio solutions and projects. "What's
wrong with WinZip you might Ask". Well WinZip has no knowledge of Visual Studio Solutions,
which means it will compress everything in the folder, including bin / obj folders
and other random debris.
&lt;/p&gt;
&lt;p&gt;
I accomplish the compression by using the following algorithm:
&lt;/p&gt;
&lt;p&gt;
1. Iterate over all items and projects in the sln file and zip each of these.&lt;br&gt;
2. Zip the sln file itself.&lt;br&gt;
3. Iterate over all items in the csproj files and zip each of these. The iteration
is done using Linq to Xml of course.&lt;br&gt;
4. Zip the csproj file itself.
&lt;/p&gt;
&lt;p&gt;
As you might have guessed SolutionZipper only works for C# projects, and is only tested
with VS2008.
&lt;/p&gt;
&lt;p&gt;
I offer three UI's for SolutionZipper
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://solzip.codeplex.com/Wiki/View.aspx?title=SunZip" target="_blank"&gt;SunZip&lt;/a&gt; -
A commandline tool. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://solzip.codeplex.com/Wiki/View.aspx?title=SolZipMME" target="_blank"&gt;SolZipMME&lt;/a&gt; -
Providing Right click menus for Visual Studio 2008 using &lt;a href="http://managedmenuextension.codeplex.com" target="_blank"&gt;Managed
Menu Extensions&lt;/a&gt; . 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://solzip.codeplex.com/Wiki/View.aspx?title=SolZipGuidance" target="_blank"&gt;SolZipGuidance&lt;/a&gt; -
Providing Right click menus for Visual Studio 2008 using Guidance Automation (GAX). 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
For the actual zipping I use the excellent open source framework &lt;a href="http://www.icsharpcode.net/OpenSource/SharpZipLib" target="_blank"&gt;SharpZipLib&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=bfa592b2-d186-48c8-a6bf-98ecbc4c8df8" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,bfa592b2-d186-48c8-a6bf-98ecbc4c8df8.aspx</comments>
      <category>Tools</category>
      <category>Visual Studio</category>
    </item>
  </channel>
</rss>