<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Richard Dutton &#187; Software Development</title>
	<atom:link href="http://www.dutton.me.uk/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dutton.me.uk</link>
	<description>Software Engineering, Photography, Travel, Stuff...</description>
	<lastBuildDate>Sat, 13 Feb 2010 08:45:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Handling events from within a ControlTemplate in WPF</title>
		<link>http://www.dutton.me.uk/2010/02/13/handling-events-from-within-a-controltemplate-in-wpf/</link>
		<comments>http://www.dutton.me.uk/2010/02/13/handling-events-from-within-a-controltemplate-in-wpf/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 07:00:42 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[events inside a ControlTemplate]]></category>
		<category><![CDATA[events within a ControlTemplate]]></category>
		<category><![CDATA[GetTemplateChild]]></category>
		<category><![CDATA[OnApplyTemplate]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RoutedEvent]]></category>
		<category><![CDATA[RoutedEventhandler]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=323</guid>
		<description><![CDATA[Here&#8217;s an interesting one that had me stumped for a few hours.
Following on from my previous post, where I explained how to create a ControlTemplate to style a TextBox in WPF, I&#8217;ve got an object, TextEntryBox, which dervies from a TextBox (it provides some custom event handlers when text is entered, but to all intents [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting one that had me stumped for a few hours.</p>
<p>Following on from my <a href="http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/" target="_blank">previous post</a>, where I explained how to create a ControlTemplate to style a TextBox in WPF, I&#8217;ve got an object, TextEntryBox, which dervies from a TextBox (it provides some custom event handlers when text is entered, but to all intents and purposes, it&#8217;s a regular TextBox).</p>
<p>I wanted to style my TextEntryBox, this time including a button within my ControlTemplate (this will eventually toggle an on-screen keyboard pop-up, but that&#8217;s another blog post!). I came up with this:<br />
<span id="more-323"></span></p>
<pre name="code" class="xml">
<Style TargetType="{x:Type my:EntryTextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type my:EntryTextBox}">
                <DockPanel>
                    <Border BorderThickness="1"
                    	HorizontalAlignment="Stretch"
                    	BorderBrush="DarkGray"
                    	Background="White"
                    	Width="100">
                        <DockPanel>
                            <Button x:Name="PART_KeyboardPopupButton"
                            	DockPanel.Dock="Right"
                            	Width="15"
                            	Height="10"/>
                            <ScrollViewer Margin="0"
                            	Background="Transparent"
                            	HorizontalAlignment="Stretch"
                            	x:Name="PART_ContentHost"/>
                        </DockPanel>
                    </Border>
                </DockPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</pre>
<p>All&#8217;s well and good, until I want to try and handle the Click event for that button within my TextEntryBox class. Even Matthew MacDonald&#8217;s &#8220;Pro WPF in C# 2008&#8243; which has proved a lifesaver for all things WPF since I&#8217;ve been working with this technology only had the following words of wisdom;</p>
<blockquote><p>&#8220;You can&#8217;t attach event handlers in the control template. Instead, you&#8217;ll need to give your elements recognizable names and attach event handlers to them programmatically in the control constructor&#8221;</p></blockquote>
<p>But whatever I tried I couldn&#8217;t access the event in my constructor, until I remembered the seperation between the visual and logical trees in WPF.</p>
<p>The template is applied at runtime, and so elements contained within it it are part of the visual tree. My class, and therefore my class&#8217; constructor is executed within the logical tree, so I needed to attach my event handler after the template had been applied. You can do this by overriding OnApplyTemplate in your class, obtain the template that&#8217;s being applied, and then you have access to the named button&#8217;s events, like this:</p>
<pre name="code" class="c-sharp">
public override void OnApplyTemplate()
{
    DependencyObject d = GetTemplateChild("PART_KeyboardPopupButton");
    if (d != null)
    {
        (d as Button).Click += new RoutedEventHandler(KeyboardPopupButton_Click);
    }

    base.OnApplyTemplate();
}
</pre>
<p>Note the null check, as someone could have applied a completely different template to the object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2010/02/13/handling-events-from-within-a-controltemplate-in-wpf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to create a ControlTemplate for a WPF TextBox</title>
		<link>http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/</link>
		<comments>http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 06:00:10 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[ContentHost]]></category>
		<category><![CDATA[ControlTemplate]]></category>
		<category><![CDATA[PART_ContentHost]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ScrollViewer]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[TextBox]]></category>
		<category><![CDATA[x:Name]]></category>
		<category><![CDATA[x:Name="Part_ContentHost"]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=325</guid>
		<description><![CDATA[This is a short post, but has one specific piece of information I want to keep.
Q: If you want to create a ControlTemplate to provide a custom style for a TextBox, how do you specify where the text goes when it&#8217;s used in WPF?
A: The answer was hidden in the depths of the MSDN Documentation. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short post, but has one specific piece of information I want to keep.</p>
<p>Q: If you want to create a ControlTemplate to provide a custom style for a TextBox, how do you specify where the text goes when it&#8217;s used in WPF?</p>
<p>A: The answer was hidden in the depths of the MSDN Documentation. You have to include a &lt;ScrollViewer&gt; within your ControlTemplate with an x:Name value of &#8220;PART_ContentHost&#8221;.</p>
<p>Here&#8217;s a noddy example:</p>
<pre name="code" class="xml">
<Style TargetType="{x:Type TextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBox}">
                <DockPanel>
                    <Border BorderThickness="1"
                               BorderBrush="DarkGray"
                               Background="White"
                               Width="100">
                        <DockPanel>
                            <ScrollViewer Background="Transparent"
                                               HorizontalAlignment="Stretch"
                                               x:Name="PART_ContentHost"/>
                        </DockPanel>
                    </Border>
                </DockPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Personal Route Logging with MobileMe&#8217;s Find My iPhone</title>
		<link>http://www.dutton.me.uk/2009/09/27/personal-route-logging-with-mobilemes-find-my-iphone/</link>
		<comments>http://www.dutton.me.uk/2009/09/27/personal-route-logging-with-mobilemes-find-my-iphone/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 15:16:13 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[find my iphone]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[mobileme]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=276</guid>
		<description><![CDATA[Although I&#8217;m struggling to achieve a happy co-existence between Google&#8217;s Calendars and Contacts and my MobileMe subscription (still fighting dupes and funny syncs with the wrong numbers being associated with the wrong contacts etc&#8230; but that&#8217;s for another blog post!), one part of MobileMe I was keen to do something with was their &#8220;Locate My [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.apple.com/mobileme/whats-new/"><img class="alignright" title="Find My iPhone" src="http://images.apple.com/mobileme/whats-new/images/find_iphone_map_20090909.png" alt="" width="299" height="318" /></a>Although I&#8217;m struggling to achieve a happy co-existence between Google&#8217;s Calendars and Contacts and my MobileMe subscription (still fighting dupes and funny syncs with the wrong numbers being associated with the wrong contacts etc&#8230; but that&#8217;s for another blog post!), one part of MobileMe I was keen to do something with was their &#8220;Locate My iPhone&#8221; feature. Regular apps aren&#8217;t allowed to run in the background on the iPhone, making any form of auto-updating tracking application all a bit &#8220;manual&#8221;  (e.g. Google Latitude on the iPhone), Apple have provided the ability to get the location of your iPhone automatically, but as it&#8217;s <a href="http://www.apple.com/mobileme/whats-new/" target="_blank">officially</a> being touted as a feature to use when you&#8217;ve lost your iPhone it&#8217;s tucked away within the &#8220;Account Settings&#8221; section of the MobileMe web page.</p>
<p>This was screaming out to be screen-scraped and <span id="more-276"></span>developer Tyler Hall has stepped up to the plate with <a href="http://clickontyler.com/blog/2009/06/sosumi-a-mobileme-scraper/" target="_blank">Sosumi &#8211; A MobileMe Scraper</a>. Using Sosumi is literally a case of including the class in your PHP, instantiating it with your MobileMe username and password and calling its locate method which returns an object containing the current latitude, longitude and result accuracy, it&#8217;s as simple as that!</p>
<p>At the moment I&#8217;ve got a cron job on my server hitting this every five minutes and logging to a database. If the data hasn&#8217;t changed since the last logged entry, a counter is incremented and timestamp_last is set. A very simple Google Map displays these locations as points on a map but I&#8217;ve got loads of ideas of stuff to play about with, such as:</p>
<ul>
<li>Plot the reported accuracy of each location as a circle on the map, more Google Maps fiddling.</li>
<li>Modify which points are mapped based on time and date ranges through the webpage, some PHP + AJAX experience.</li>
<li>Store locations of common places I visit, then for each point logged (taking into account the accuracy range) I can programatically work out where I am.  Could then auto-generate &#8220;Richard is at work&#8221;, &#8220;Richard is at home&#8221;, etc&#8230; reports for my blog/twitter/facebook etc&#8230; =).</li>
</ul>
<p>Bit sad I know, but it seemed too good for a total sync-monkey like myself and I&#8217;ll never pass up an opportunity, however contrived, for a PHP mash-up!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/09/27/personal-route-logging-with-mobilemes-find-my-iphone/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>All quiet on the blogging front&#8230;</title>
		<link>http://www.dutton.me.uk/2009/08/13/all-quiet-on-the-blogging-front/</link>
		<comments>http://www.dutton.me.uk/2009/08/13/all-quiet-on-the-blogging-front/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 22:03:34 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[General Rantings]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[NDIS]]></category>
		<category><![CDATA[NDIS 5.1]]></category>
		<category><![CDATA[network driver]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[windows driver]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=250</guid>
		<description><![CDATA[I know I&#8217;ve been pretty quiet as far as technical blog posts are concerned but I&#8217;ve not abandoned this blog, I&#8217;ve been working over the last few months entirely on Windows network driver development (NDIS 5.1), something which I profess to having absolutely no prior experience with so there really wasn&#8217;t anything relevant to blog [...]]]></description>
			<content:encoded><![CDATA[<p>I know I&#8217;ve been pretty quiet as far as technical blog posts are concerned but I&#8217;ve not abandoned this blog, I&#8217;ve been working over the last few months entirely on Windows network driver development (NDIS 5.1), something which I profess to having absolutely no prior experience with so there really wasn&#8217;t anything relevant to blog about.</p>
<p>I&#8217;ve been making notes throughout the whole experience and so plan to post them shortly with the aim of helping anyone else who finds themselves in a similar situation and needs to get up to speed with Windows network driver development (NDIS 5.1). I am by no means an expert but want to share what I&#8217;ve learnt so far.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/08/13/all-quiet-on-the-blogging-front/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#&#8217;s Null-Coalescing (??) Operator</title>
		<link>http://www.dutton.me.uk/2009/04/22/cs-null-coalescing-operator/</link>
		<comments>http://www.dutton.me.uk/2009/04/22/cs-null-coalescing-operator/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 07:31:10 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# operator]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[null coalescing]]></category>
		<category><![CDATA[null coalescing operator]]></category>
		<category><![CDATA[nullable]]></category>
		<category><![CDATA[nullable type]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=212</guid>
		<description><![CDATA[Although I&#8217;ve always been a big fan of the ternary operator, kudos goes to the Refactoriser (you know who you are!) for pointing me in the direction of an even more effective way of obfsuca^H^H^H tidying up my code; the ?? operator.
The null-coalescing operator (to call it by its more catchy name) allows you to [...]]]></description>
			<content:encoded><![CDATA[<p>Although I&#8217;ve always been a big fan of the <a href="http://msdn.microsoft.com/en-us/library/ty67wk28(VS.80).aspx" target="_blank">ternary operator</a>, kudos goes to the Refactoriser (you know who you are!) for pointing me in the direction of an even more effective way of obfsuca^H^H^H tidying up my code; the <a href="http://msdn.microsoft.com/en-us/library/ms173224(VS.80).aspx" target="_blank">?? operator</a>.</p>
<p>The null-coalescing operator (to call it by its more catchy name) allows you to provide an alternative value in the event that the reference type object (or nullable value type) you are trying to access evaluates to null. So instead of having to do something like this:</p>
<pre name="code" class="csharp">
            int? myNullableInt = null;
            int myInt;

            if (myNullableInt == null)
            {
                myInt = -1;
            }
            else
            {
                myInt = (int)myNullableInt;
            }
</pre>
<p>You can do this in-line:</p>
<pre name="code" class="csharp">
myInt = myNullableInt ?? -1;
</pre>
<p>Apologies for the heavily contrived and quite pointless example, but at least it gets the syntax down and should make it apparent how useful this operator can be when dealing with a mixture of nullable and non-nullable types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/04/22/cs-null-coalescing-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a function call on another thread using the C# Dispatcher class</title>
		<link>http://www.dutton.me.uk/2009/03/30/making-a-function-call-on-another-thread-with-the-c-dispatcher-class/</link>
		<comments>http://www.dutton.me.uk/2009/03/30/making-a-function-call-on-another-thread-with-the-c-dispatcher-class/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 18:00:09 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Dispatcher]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=181</guid>
		<description><![CDATA[There may be a situation when you need to execute a function on a different thread, such as ensuring that calls across the interface between a multi-threaded dll and its single-threaded user are made on the same, single thread.  To achive this, you can use the target thread&#8217;s Dispatcher object as follows:

Create a delegate [...]]]></description>
			<content:encoded><![CDATA[<p>There may be a situation when you need to execute a function on a different thread, such as ensuring that calls across the interface between a multi-threaded dll and its single-threaded user are made on the same, single thread.  To achive this, you can use the target thread&#8217;s Dispatcher object as follows:</p>
<ol>
<li>Create a delegate of the function you wish to be able to call:
<pre name="code" class="c-sharp">
public delegate void MyDelegate(int i, string str);
public class TargetThreadClass
{
    public TargetThreadClass()
    {
        MyDelegate del = new MyDelegate(this.FuncToExec);
    }
    public void FuncToExec(int i, string str)
    {
       // Do something
   }
}</pre>
</li>
<li>Within the target thread, create an instance of a Dispatcher object and set it to the thread&#8217;s current dispatcher:
<pre name="code" class="c-sharp">
Dispatcher UserDispatcher = Dispatcher.CurrentDispatcher;</pre>
<p>Then pass this dispatcher, along with the delegate into the source thread.</li>
<li>Then to call FuncToExec on the target thread, use:
<pre name="code" class="c-sharp">
UserDispatcher.Invoke(del, new object[] { 123, "arg string"});</pre>
<p>Where the first parameter of Invoke is the delegate itself and the second an array of the delegate&#8217;s parameters (if any), in this example the delegate takes an int and a string.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/03/30/making-a-function-call-on-another-thread-with-the-c-dispatcher-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DoshTracker Update #2 &#8211; Ext JS and Google Maps API Integration</title>
		<link>http://www.dutton.me.uk/2009/03/06/doshtracker-update-2-ext-js-and-google-maps-api-integration/</link>
		<comments>http://www.dutton.me.uk/2009/03/06/doshtracker-update-2-ext-js-and-google-maps-api-integration/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 08:38:31 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Doshtracker]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=154</guid>
		<description><![CDATA[Shea Frederick on the extjs blog has produced a component which extends Panel and integrates with the Google Maps API here allowing you to display google maps anywhere you can use a Panel, that includes windows, viewports and layouts. This is great for the DoshTracker development as I can use this code to form the [...]]]></description>
			<content:encoded><![CDATA[<p>Shea Frederick on the extjs blog has produced a component which extends Panel and integrates with the Google Maps API <a href="http://extjs.com/blog/2008/07/01/integrating-google-maps-api-with-extjs/" target="_blank">here</a> allowing you to display google maps anywhere you can use a Panel, that includes windows, viewports and layouts. This is great for the DoshTracker development as I can use this code to form the basis of the mapping displays, saving me a lot of code hacking and fiddling.</p>
<p>The issues I am having at the moment revolve around Google&#8217;s geocoding of UK postcode data. For those who don&#8217;t know, geocoding is the process of turning an address into longitude and latitude location information which can then be displayed on a map. It can be a bit hit or miss, especially in the UK where the physical area covered by a single postcode can vary widely but prior to Google providing this feature in its API, the only way of achieving this was to buy a horrendously expensive license from the Royal Mail (who <strong>own</strong> our postcodes, <a href="http://gisconsultancy.com/blog/politics/the-royal-mail-paf-that-old-chestnut" target="_blank">apparently</a>?!?!?) making this an unfeasible option for DoshTracker.</p>
<p>It appears that the results you get back through the API functions are sometimes different to those you&#8217;d get typing in the same postcode into maps.google.com, a fact that they confirm in their <a href="http://googlemapsapi.blogspot.com/2007/07/uk-geocoding-now-available-in-maps-api.html" target="_blank">original press release</a> when they state that &#8220;(the) geocoder is not using the same resources as maps.google.com and may not return the same results&#8221;,  but hats off to them anyway for providing the feature in the first place. For privacy reasons, I don&#8217;t intend on displaying either the full postcode or a map at a sufficient zoom level to work out the precise location of notes entered into the system, so it may be that the accuracy provided by Google will suffice, but I&#8217;m designing the system to allow me to use other geocoding services in future.</p>
<p>In order to do this, I&#8217;ve separated the geocoding from the actual map display. A lot of code I&#8217;ve seen so far calls the geocoding functions when drawing the map in order to set the map center dynamically. This is unnecessary for me as DoshTracker will be using maps to display previously entered locations and so I plan to only geocode the hit&#8217;s location when the new note or hit is added to the system and then to store that information in the database. This not only reduces the number of calls to the Google Maps API (reducing the chances of me exceeding their acceptable policies) but also means that I can substitute the geocoding component in the future with only minimal code changes.</p>
<p>I&#8217;m just ironing our a few bugs in the display but I&#8217;ll be adding a new tab to the <a href="http://www.doshtracker.co.uk" target="_blank">DoshTracker homepage</a> over the weekend to allow you guys to test the geocoder. I&#8217;ll be logging the geocoded results to a database for use in the eventual system so please feel free to geocode all of your common locations and let me know what you think. I&#8217;m particularly interested in feedback on the map zoom level and the accuracy of the results you get.</p>
<p>Update (13/03/2009): The most up to date version of this component is now being hosted <a href="http://code.google.com/p/ext-ux-gmappanel/" target="_blank">here</a> at Google Code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/03/06/doshtracker-update-2-ext-js-and-google-maps-api-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Excel .xls spreadsheets with PHP</title>
		<link>http://www.dutton.me.uk/2009/03/02/creating-excel-xls-spreadsheets-with-php/</link>
		<comments>http://www.dutton.me.uk/2009/03/02/creating-excel-xls-spreadsheets-with-php/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 12:52:25 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Microsoft Excel]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[spreadsheet]]></category>
		<category><![CDATA[spreadsheet generation]]></category>
		<category><![CDATA[xls]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=131</guid>
		<description><![CDATA[A web-based statistics system I&#8217;m developing for a client needs the facility to dynamically generate Excel spreadsheets. The system runs on a Linux platform with a typical Apache, MySQL and PHP install and is hosted on a virtual server at a commercial hosting company so access to anything Microsoft or COM-like wasn&#8217;t an option and [...]]]></description>
			<content:encoded><![CDATA[<p>A web-based statistics system I&#8217;m developing for a client needs the facility to dynamically generate Excel spreadsheets. The system runs on a Linux platform with a typical Apache, MySQL and PHP install and is hosted on a virtual server at a commercial hosting company so access to anything Microsoft or COM-like wasn&#8217;t an option and I only had a basic PHP install available. Most web searches come up with solutions that rely on PEAR (such as the Spreadsheet_Excel_Writer module) but my hosts&#8217; PHP didn&#8217;t support PEAR and they wouldn&#8217;t let me install it.</p>
<p>Finally I came across Johann Hanne&#8217;s port of the <a href="http://search.cpan.org/dist/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm" target="_blank">Perl Spreadsheet::WriteExcel module</a> on <a href="http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/" target="_blank">his website</a> and it&#8217;s working brilliantly without any additional dependencies! Although his documentation is a little thin on the ground, he does provide some example scripts to get you going and as it&#8217;s a direct port, you can still refer to the original Perl documentation. In particular the reference pages on cell number format strings <a href="http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.25/doc/number_formats1.html" target="_blank">here</a> and <a href="http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.25/doc/number_formats2.html" target="_blank">here</a> were most useful when tweaking the output.</p>
<p>Creating a simple spreadsheet in PHP is as simple as importing the writeexcel classes and setting up a new workbook and worksheet:</p>
<pre name="code" class="php">
require_once "class.writeexcel_workbook.inc.php";
require_once "class.writeexcel_worksheet.inc.php";

$fname = tempnam("/tmp", "simple.xls");
$workbook = &#038;new writeexcel_workbook($fname);
$worksheet = &#038;$workbook->addworksheet();
</pre>
<p>&#8230;then use the write($row, $column, $token) function to put values into cells:</p>
<pre name="code" class="php">
# Write some text
$worksheet->write(0, 0,  "Hi Excel!");
# Write some numbers
$worksheet->write(1, 0,  3);
</pre>
<p>&#8230;and tidy up and return it, in this example through the browser, but you could always copy the file from the /tmp folder to somewhere more permanent and do what you want with it:</p>
<pre name="code" class="php">
$workbook->close();
header("Content-Type: application/x-msexcel; name=\"example.xls\"");
header("Content-Disposition: inline; filename=\"example.xls\"");
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);
</pre>
<p>&#8230;and there you go, automatically generated Excel spreadsheets through PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/03/02/creating-excel-xls-spreadsheets-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Non-blocking keyboard input in C#</title>
		<link>http://www.dutton.me.uk/2009/02/24/non-blocking-keyboard-input-in-c/</link>
		<comments>http://www.dutton.me.uk/2009/02/24/non-blocking-keyboard-input-in-c/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 17:30:39 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[console keyboard input]]></category>
		<category><![CDATA[Console.KeyAvailable]]></category>
		<category><![CDATA[Console.ReadKey]]></category>
		<category><![CDATA[non-blocking]]></category>
		<category><![CDATA[non-blocking keyboard input]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=109</guid>
		<description><![CDATA[I know this one is pretty noddy, but these posts are as much a way of me storing code snippets I might need quickly in the future as any form of &#8216;public service&#8217; so I&#8217;ll post it anyway.
I quite frequently want to capture key presses in my apps, and to do this I use Console.ReadKey [...]]]></description>
			<content:encoded><![CDATA[<p>I know this one is pretty noddy, but these posts are as much a way of me storing code snippets I might need quickly in the future as any form of &#8216;public service&#8217; so I&#8217;ll post it anyway.</p>
<p>I quite frequently want to capture key presses in my apps, and to do this I use Console.ReadKey which returns a nice ConsoleKeyInfo object to tell me what&#8217;s just been pressed. The problem is this call blocks until a key has been pressed and sometimes I don&#8217;t want to block out the main execution thread or have to create a separate thread *just* to handle the keyboard input.</p>
<p>This is where Console&#8217;s KeyAvailable property comes in.  It returns true if there is a key press available in the input stream without blocking allowing you to do something like:</p>
<pre name="code" class="c-sharp">
while (true)
{
    if (Console.KeyAvailable)
    {
        ConsoleKeyInfo key = Console.ReadKey(true);
        switch (key.Key)
        {
            case ConsoleKey.F1:
                Console.WriteLine("You pressed F1!");
                break;
            default:
                break;
        }
    }
    // Do something more useful
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/02/24/non-blocking-keyboard-input-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trust issues working on a network share in Visual Studio 2008</title>
		<link>http://www.dutton.me.uk/2009/02/14/trust-issues-working-on-a-network-share-in-visual-studio-2008/</link>
		<comments>http://www.dutton.me.uk/2009/02/14/trust-issues-working-on-a-network-share-in-visual-studio-2008/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 00:12:55 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Microsoft Visual Studio 2008]]></category>
		<category><![CDATA[Network share]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=62</guid>
		<description><![CDATA[An unfortunate combination of my rear-wheeled drive car and the mini-ice age which hit us here in Northamptonshire left me stranded and working from home earlier this week. Not a problem I thought, as I had previously taken the liberty of backing up my current source onto the USB stick I carry with me and [...]]]></description>
			<content:encoded><![CDATA[<p>An unfortunate combination of my rear-wheeled drive car and the mini-ice age which hit us here in Northamptonshire left me stranded and working from home earlier this week. Not a problem I thought, as I had previously taken the liberty of backing up my current source onto the USB stick I carry with me and already had a VMWare Fusion image with XP and MS Visual Studio 2008 on my MacBook.</p>
<p>So in went the USB key, project folder copied to my &#8220;Documents&#8221; folder and the XP virtual machine opened. But after browsing to the network drive which VMWare maps onto my OS X &#8220;Documents&#8221; folder and opening the solution file, I was greeted with something that looks like this:</p>
<p><img class="alignnone size-full wp-image-70" title="Visual Studio 2008 - Network Share Project Not Trusted Dialog" src="http://www.dutton.me.uk/wp-content/uploads/2009/02/vsnetworkprojnottrusted.png" alt="Visual Studio 2008 - Network Share Project Not Trusted Dialog" width="413" height="226" /></p>
<p>A quick google search for this error message brought me to <a href="http://msdn.microsoft.com/en-us/library/bs2bkwxc.aspx" target="&lt;/a&gt;_blank">this MSDN article</a> which looked promising, but despite having a full VS 2008 SP1 install on my machine I couldn&#8217;t find Mscorcfg.msc anywhere, and the suggested Caspol.exe command just didn&#8217;t work!</p>
<p>According to <a href="http://msdn.microsoft.com/en-us/library/2bc0cxhc.aspx" target="&lt;/a&gt;_blank">this article</a>, I needed to install the .NET Framework 2.0 Software Development Kit (SDK) (x86) from <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=FE6F2099-B7B4-4F47-A244-C96D69C35DEC&amp;displaylang=en" target="&lt;/a&gt;_blank">here</a> to then get the &#8220;Microsoft .NET Framework 2.0 Configuration&#8221; tool which should help. Once all 300+mb of it was downloaded and installed it then appeared in my Control Panel -&gt; Administrative Tools, progress at last!</p>
<p>In the tool, expand &#8220;My Computer&#8221; and select &#8220;Runtime Security Policy&#8221; to get the following:</p>
<p><img class="alignnone size-full wp-image-79" title="Microsoft .NET Framework 2.0 Configuration Tool" src="http://www.dutton.me.uk/wp-content/uploads/2009/02/net-framework-2-configuration.png" alt="Microsoft .NET Framework 2.0 Configuration Tool" width="746" height="536" /></p>
<p>From here I was then able to select &#8220;Adjust Zone Security&#8221; to be taken to the &#8220;Security Adjustment Wizard&#8221;. After selecting whether I want to make changes to the computer or current user only (I chose computer) and clicking &#8220;Next&#8221;, I was taken to the important part, the zone security level settings. The problem with trusted network shares appears to be caused by the &#8220;Local Intranet&#8221; zone defaulting to one &#8220;notch&#8221; below &#8220;Full Trust&#8221;, causing all sorts of havoc to my VS2008 security. By moving the slider up to &#8220;Full Trust&#8221; for the &#8220;Local Intranet&#8221; zone and clicking &#8220;Next&#8221; and then &#8220;Finish&#8221; to close the wizard I was then able to successfully load, compile and debug VS2008 projects located on a network share.</p>
<p>I must admit that I&#8217;m still not 100% convinced that this is either the correct or even a safe solution so please exercise caution when changing zone security settings, especially on networks with internet access, and feel free to set me straight in the comments if this is far off the mark, but in the meantime it has at least enabled me to perform the tasks I have been able to carry out with every other IDE I&#8217;ve ever used and develop code on a network share!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2009/02/14/trust-issues-working-on-a-network-share-in-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
