<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.2" -->
<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/"
	>

<channel>
	<title>cmb-web.co.uk</title>
	<link>http://www.cmb-web.co.uk</link>
	<description></description>
	<pubDate>Thu, 05 Aug 2010 20:17:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>
	<language>en</language>
			<item>
		<title>Formatting text directly in XAML</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/08/formatting-text-directly-in-xaml/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/08/formatting-text-directly-in-xaml/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 11:00:48 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/08/formatting-text-directly-in-xaml/</guid>
		<description><![CDATA[You can format text strings directly in the XAML code of a WPF application.
For example, you can use standard .NET formatting such as currency and date:
&#60;TextBlock Text="{Binding Amount, StringFormat={}{0:C}}"/&#62;
&#60;TextBlock Text="{Binding Date, StringFormat={}{0:dd/MM/yyyy}}"/&#62;
The empty {} after the StringFormat= escapes the text before the formatting string.
You can add text in front of the formatting string too, e.g.
StringFormat=Amount: [...]]]></description>
			<content:encoded><![CDATA[<p>You can format text strings directly in the XAML code of a WPF application.</p>
<p>For example, you can use standard .NET formatting such as currency and date:</p>
<p><code>&lt;TextBlock Text="{Binding Amount, StringFormat={}{0:C}}"/&gt;</code><br />
<code>&lt;TextBlock Text="{Binding Date, StringFormat={}{0:dd/MM/yyyy}}"/&gt;</code></p>
<p>The empty <em>{}</em> after the <code>StringFormat=</code> escapes the text before the formatting string.</p>
<p>You can add text in front of the formatting string too, e.g.<br />
<code>StringFormat=Amount: {0:C}</code><br />
in which case you don&#8217;t need to escape the string with the <em>{}</em>.</p>
<p>More advanced formatting options can be acheived using a multi-binding, for example:</p>
<p><code>&lt;TextBlock&gt;</code><br />
<code>  &lt;TextBlock.Text&gt;</code><br />
<code>    &lt;MultiBinding StringFormat="Date {0} Time {1}"&gt;</code><br />
<code>      &lt;Binding Path="DueDate" /&gt;</code><br />
<code>      &lt;Binding Path="DueTime" /&gt;</code><br />
<code>    &lt;/MultiBinding&gt;</code><br />
<code>  &lt;/TextBlock.Text&gt;</code><br />
<code>&lt;/TextBlock&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/08/formatting-text-directly-in-xaml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unit testing internal methods</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/08/unit-testing-internal-methods/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/08/unit-testing-internal-methods/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 11:00:29 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/08/unit-testing-internal-methods/</guid>
		<description><![CDATA[When unit testing applications you write tests for the exposed public methods.  Philosophically this is correct as you need to test the functionality exposed by your class to the consuming application, and any private or internal functions that use functionality that also needs testing should be discrete from this class.  This functionality should be [...]]]></description>
			<content:encoded><![CDATA[<p>When unit testing applications you write tests for the exposed public methods.  Philosophically this is correct as you need to test the functionality exposed by your class to the consuming application, and any private or internal functions that use functionality that also needs testing should be discrete from this class.  This functionality should be &#8216;injected&#8217; into the class using some form of unit-testable framework; such as dependency injection using interfaces, allowing them to be tested separately.</p>
<p>However, there are occasions when you want to hide methods from external consumers for good reason, but still need to unit test them.  For example, producing a library to distribute to third-parties.</p>
<p>To do this with .NET you can mark the assembly with <code>InternalsVisibleTo</code> and specifiy the public key of the project allowed to view your internals.</p>
<p>For example, I have a project called <code>MyNewProject</code> and a project containing units tests for this called <code>MyNewProjectTests</code>, I can add the following code to the <code>assembly.cs</code> file in <code>MyNewProject</code> with the public key of the test project:</p>
<p><code>[assembly: InternalsVisibleTo("MyNewProject, PublicKey=0024...")]</code></p>
<p><em>Note, I&#8217;ve not included the entire public key here.</em></p>
<p>Now the internal methods are visible to the test project we have one more task. The unit test frameworks <em>Rhino Mocks</em> and <em>Moq</em> use a proxy class called <code>DynamicProxyGenAssembly2</code> to represent your object when testing. We therefore need to expose the internals to this class also. We do this in the same way with another entry in the <code>assembly.cs</code> file:</p>
<p><code>[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024")]</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/08/unit-testing-internal-methods/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Android numeric input</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/07/android-numeric-input/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/07/android-numeric-input/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 15:13:20 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Android]]></category>

		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/07/android-numeric-input/</guid>
		<description><![CDATA[To restrict the input for an EditText to a numeric value, you can add the following to the layout file:
&#60;EditText
...
android:singleLine="true"
android:inputType="numberDecimal"
...
&#62;
Then use, for example, Double.parseDouble(&#8230;) to retrieve the value in code.
Incidentally, the documentation recommends avoiding floats and using double instead.
]]></description>
			<content:encoded><![CDATA[<p>To restrict the input for an EditText to a numeric value, you can add the following to the layout file:</p>
<p><code>&lt;EditText</code><br />
<code>...</code><br />
<code>android:singleLine="true"</code><br />
<code>android:inputType="numberDecimal"</code><br />
<code>...</code><br />
<code>&gt;</code></p>
<p>Then use, for example, Double.parseDouble(&#8230;) to retrieve the value in code.</p>
<p>Incidentally, the documentation recommends <a href="http://developer.android.com/guide/practices/design/performance.html#avoidfloat" title="Avoid floating point numbers in Android">avoiding floats</a> and using double instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/07/android-numeric-input/feed/</wfw:commentRss>
		</item>
		<item>
		<title>main.out.xml: Error parsing XML: no element found</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/04/mainoutxml-error-parsing-xml-no-element-found/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/04/mainoutxml-error-parsing-xml-no-element-found/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 07:50:10 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Android]]></category>

		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/04/mainoutxml-error-parsing-xml-no-element-found/</guid>
		<description><![CDATA[When you build and run your Android application in Eclipse you can get the following error message:
...res\layout\main.out.xml:1: error: Error parsing XML: no element found
This occurs when you try and run the application from the main.xml layout file. The application cannot run from here and needs to be run from the java file.
The answer is to [...]]]></description>
			<content:encoded><![CDATA[<p>When you build and run your Android application in Eclipse you can get the following error message:</p>
<p><code>...res\layout\main.out.xml:1: error: Error parsing XML: no element found</code></p>
<p>This occurs when you try and run the application from the <code>main.xml</code> layout file. The application cannot run from here and needs to be run from the java file.</p>
<p>The answer is to ensure that a java file is selected when you hit run, as you should run the java not the xml file.  The easiest way to ensure you don&#8217;t do this is to use the<code> Run History</code> options in Eclipse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/04/mainoutxml-error-parsing-xml-no-element-found/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Error registering WCF host in Windows Vista (HTTP could not register URL http://+:80)</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/03/error-registering-wcf-host-in-windows-vista-http-could-not-register-url-http80/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/03/error-registering-wcf-host-in-windows-vista-http-could-not-register-url-http80/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 19:37:10 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/03/error-registering-wcf-host-in-windows-vista-http-could-not-register-url-http80/</guid>
		<description><![CDATA[This is an error encountered by one of my team when trying to run up a WCF host on a Windows Vista machine.  The actual exception is an
AddressAccessDeniedException
with the error message
HTTP could not register URL http://+:80/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details)
The Microsoft site (http://go.microsoft.com/fwlink/?LinkId=70353) does have [...]]]></description>
			<content:encoded><![CDATA[<p>This is an error encountered by one of my team when trying to run up a WCF host on a Windows Vista machine.  The actual exception is an</p>
<p><code>AddressAccessDeniedException</code></p>
<p>with the error message</p>
<p><code>HTTP could not register URL http://+:80/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details)</code></p>
<p>The Microsoft site (<a href="http://go.microsoft.com/fwlink/?LinkId=70353" title="http://go.microsoft.com/fwlink/?LinkId=70353">http://go.microsoft.com/fwlink/?LinkId=70353</a>) does have a solution to the problem using <code>httpcfg</code> and <code>netsh</code>. However the far simpler solution is to run Visual Studio as Administrator</p>
<p>You can do that by right-clicking the shortcut for Visual Studio and selecting <code>Run as adminstrator</code>, or to permanently run as Administrator, right-click and select Properties. Find the Compatibility tab and check the <code>Run this program as administrator</code> checkbo€x.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/03/error-registering-wcf-host-in-windows-vista-http-could-not-register-url-http80/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# Image from a byte array (and back again)</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/03/c-image-from-a-byte-array-and-back-again/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/03/c-image-from-a-byte-array-and-back-again/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 12:27:05 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/03/c-image-from-a-byte-array-and-back-again/</guid>
		<description><![CDATA[Quick code sample for transforming a .NET System.Drawing.Image into a byte array:
public byte[] imageToByteArray(Image imageIn)
{
    MemoryStream ms = new MemoryStream();
    imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
    return ms.ToArray();
}
and conversely, turning a byte array into an image:
public Image byteArrayToImage(byte[] byteArrayIn)
{
    MemoryStream ms = new MemoryStream(byteArrayIn);
    Image returnImage = Image.FromStream(ms);
    return returnImage;
}

]]></description>
			<content:encoded><![CDATA[<p>Quick code sample for transforming a .NET <code>System.Drawing.Image</code> into a byte array:</p>
<p><code>public byte[] imageToByteArray(Image imageIn)<br />
{<br />
    MemoryStream ms = new MemoryStream();<br />
    imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);<br />
    return ms.ToArray();<br />
}<br />
</code>and conversely, turning a byte array into an image:</p>
<p><code>public Image byteArrayToImage(byte[] byteArrayIn)<br />
{<br />
    MemoryStream ms = new MemoryStream(byteArrayIn);<br />
    Image returnImage = Image.FromStream(ms);<br />
    return returnImage;<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/03/c-image-from-a-byte-array-and-back-again/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Class not registered error in Windows 7 for ActiveX control</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/01/class-not-registered-error-in-windows-7-for-activex-control/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/01/class-not-registered-error-in-windows-7-for-activex-control/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 08:59:28 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/01/class-not-registered-error-in-windows-7-for-activex-control/</guid>
		<description><![CDATA[I recently had cause to use an ActiveX control in a Windows Forms project.  I was actually building a WPF application, that required a specific control that was ActiveX based.  This is not a very pretty thing; I wrapped the control in a Windows Forms user control within a WPF User Control.
Anyhow, this worked fine on [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had cause to use an ActiveX control in a Windows Forms project.  I was actually building a WPF application, that required a specific control that was ActiveX based.  This is not a very pretty thing; I wrapped the control in a Windows Forms user control within a WPF User Control.</p>
<p>Anyhow, this worked fine on my XP machine but not on my Windows 7 machine.  The solution would compile, but when I tried to instantiate the control I received the following error in Visual Studio:</p>
<p><code>Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))</code></p>
<p>On the line:</p>
<p><code>((System.ComponentModel.ISupportInitialize)(this.myControl)).EndInit();</code></p>
<p>The reason was that the Windows 7 machine is 64-bit, while the XP one was 32-bit.  The projects in the solutions need to be built to target the x86 platform.  This is an option on the project properties, found from:</p>
<p><code>Project -&gt; Properties -&gt; Build -&gt; Platform Target</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/01/class-not-registered-error-in-windows-7-for-activex-control/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET MVC nested master pages</title>
		<link>http://www.cmb-web.co.uk/index.php/2010/01/aspnet-mvc-nested-master-pages/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2010/01/aspnet-mvc-nested-master-pages/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 21:33:03 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2010/01/aspnet-mvc-nested-master-pages/</guid>
		<description><![CDATA[Creating nested master pages in ASP.NET MVC is straight forward, but slightly different to that in normal ASP.NET.
First, delete the two code behind files. 
Second, you need to alter the page header to remove the references to the codefile and alter the inherits.
Change the standard file from:
&#60;%@ Master Language=&#8221;C#&#8221; MasterPageFile=&#8221;~/Views/Shared/Site.master&#8221; AutoEventWireup=&#8221;true&#8221; CodeFile=&#8221;Normal.master.cs&#8221; Inherits=&#8221;Master_Normal&#8221; %&#62;
To the following:
&#60;%@ [...]]]></description>
			<content:encoded><![CDATA[<p>Creating nested master pages in ASP.NET MVC is straight forward, but slightly different to that in normal ASP.NET.</p>
<p>First, delete the two code behind files. </p>
<p>Second, you need to alter the page header to remove the references to the codefile and alter the inherits.</p>
<p>Change the standard file from:</p>
<p><font size="2">&lt;%<font size="2" color="#0000ff"><font size="2" color="#0000ff">@</font></font><font size="2"> </font><font size="2" color="#a31515"><font size="2" color="#a31515">Master</font></font><font size="2"> </font><font size="2" color="#ff0000"><font size="2" color="#ff0000">Language</font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=&#8221;C#&#8221;</font></font><font size="2"> </font><font size="2" color="#ff0000"><font size="2" color="#ff0000">MasterPageFile</font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=&#8221;~/Views/Shared/Site.master&#8221;</font></font><font size="2"> </font><font size="2" color="#ff0000"><font size="2" color="#ff0000">AutoEventWireup</font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=&#8221;true&#8221; </font></font><font size="2" color="#ff0000"><font size="2" color="#ff0000">CodeFile</font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=&#8221;Normal.master.cs&#8221;</font></font><font size="2"> </font><font size="2" color="#ff0000"><font size="2" color="#ff0000">Inherits</font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=&#8221;Master_Normal&#8221;</font></font><font size="2"> %&gt;</font></font></p>
<p>To the following:</p>
<p><font size="2">&lt;%<font color="#0000ff"><font color="#0000ff">@</font></font> <font color="#a31515"><font color="#a31515">Master</font></font> <font color="#ff0000"><font color="#ff0000">Language</font></font><font color="#0000ff"><font color="#0000ff">=&#8221;C#&#8221;</font></font> <font color="#ff0000"><font color="#ff0000">MasterPageFile</font></font><font color="#0000ff"><font color="#0000ff">=&#8221;~/Views/Shared/Site.master&#8221;</font></font> <font color="#ff0000"><font color="#ff0000">Inherits</font></font><font color="#0000ff"><font color="#0000ff">=&#8221;System.Web.Mvc.ViewMasterPage&#8221;</font></font> %&gt;</font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2010/01/aspnet-mvc-nested-master-pages/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SQLCMD mode in SQL Server Management Studio</title>
		<link>http://www.cmb-web.co.uk/index.php/2009/08/sqlcmd-mode-in-sql-server-management-studio/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2009/08/sqlcmd-mode-in-sql-server-management-studio/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 18:00:55 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2009/08/sqlcmd-mode-in-sql-server-management-studio/</guid>
		<description><![CDATA[In Microsoft SQL Server 2005, Microsoft introduced the command line tool sqlcmd to replace osql.
The SQL Server Management Studio allows you to run your scripts in &#8217;sqlcmd mode&#8217; in the query window.  This allows you to take advantage of the syntax colour coding and variables, while developing and testing sqlcmd scripts.  By default it is [...]]]></description>
			<content:encoded><![CDATA[<p>In Microsoft SQL Server 2005, Microsoft introduced the command line tool <em>sqlcmd </em>to replace <em>osql</em>.</p>
<p>The SQL Server Management Studio allows you to run your scripts in &#8217;sqlcmd mode&#8217; in the query window.  This allows you to take advantage of the syntax colour coding and variables, while developing and testing sqlcmd scripts.  By default it is turned off, but you can enable it from the &#8216;Query&#8217; menu for a specific query window.</p>
<p>One important thing to remember about using <em>sqlcmd</em>, is that it uses OLEDB, while Management Studio users the .NET SqlClient.  It is possible, therefore, to obtain different results when the scripts are actually run with <em>sqlcmd</em> at the command line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2009/08/sqlcmd-mode-in-sql-server-management-studio/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Executing multiple SQL statements with SqlCommand</title>
		<link>http://www.cmb-web.co.uk/index.php/2009/08/executing-multiple-sql-statements-with-sqlcommand/</link>
		<comments>http://www.cmb-web.co.uk/index.php/2009/08/executing-multiple-sql-statements-with-sqlcommand/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 14:15:19 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.cmb-web.co.uk/index.php/2009/08/executing-multiple-sql-statements-with-sqlcommand/</guid>
		<description><![CDATA[If you try and execute a number of sql statements in one go using the SqlCommand object, you will receive a SqlException: &#8220;Incorrect syntax near&#8230;&#8221; when you call the ExecuteNonQuery().
This is because the &#8220;GO&#8221; statements cannot be executed within the script. The simple way around this is to break the script into parts by splitting [...]]]></description>
			<content:encoded><![CDATA[<p>If you try and execute a number of sql statements in one go using the SqlCommand object, you will receive a SqlException: &#8220;Incorrect syntax near&#8230;&#8221; when you call the <code>ExecuteNonQuery().</code></p>
<p>This is because the &#8220;GO&#8221; statements cannot be executed within the script. The simple way around this is to break the script into parts by splitting the string on the &#8220;GO&#8221; statements. Then you can execute the individual commands.</p>
<p>Some sample code:</p>
<p><code>using(SqlConnection connection = new SqlConnection(connectionString))<br />
{<br />
  string[] commands = sql.Split(new string[]{"GO\r\n", "GO ", "GO\t"},<br />
              StringSplitOptions.RemoveEmptyEntries );<br />
  foreach (string c in commands)<br />
  {<br />
     command = new SqlCommand(c, connection);<br />
     command.ExecuteNonQuery();<br />
  }</code><code>}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmb-web.co.uk/index.php/2009/08/executing-multiple-sql-statements-with-sqlcommand/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
