<?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>GrinGod [dot] Com &#187; Programming</title>
	<atom:link href="http://www.gringod.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gringod.com</link>
	<description>Randomised nonsense.</description>
	<lastBuildDate>Tue, 10 Feb 2015 23:15:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Beating CRM2011 Anti-XSS with a Web Resource Shim</title>
		<link>http://www.gringod.com/2012/11/14/beating-crm2011-anti-xss-with-a-web-resource-shim/</link>
		<comments>http://www.gringod.com/2012/11/14/beating-crm2011-anti-xss-with-a-web-resource-shim/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 22:57:46 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[Microsoft CRM]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[dynamics]]></category>
		<category><![CDATA[micr]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://www.gringod.com/?p=898</guid>
		<description><![CDATA[Background In Microsoft Dynamics CRM weâ€™ve got several places that documents relating to an account can be uploaded to SharePoint.Â  Some are custom solutions developed whilst we were using CRM4 and others are using the built-in CRM2011 SharePoint integration. To keep things simple for users, I have created a SharePoint web part that allows them [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2>Background</h2>
<p>In Microsoft Dynamics CRM weâ€™ve got several places that documents relating to an account can be uploaded to SharePoint.Â  Some are custom solutions developed whilst we were using CRM4 and others are using the built-in CRM2011 SharePoint integration.</p>
<p>To keep things simple for users, I have created a SharePoint web part that allows them to see a consolidated view of documents relating to each account.Â  This web part has a menu against each document that allows users to open the record that the document was uploaded against.</p>
<h2>The Problem</h2>
<p>Previously, I was just opening the CRM record in an Internet Explorer (IE) window and everything was fine.Â  However, now CRM has got a nifty Xrm.Utility.openEntityForm() JavaScript function that will open entity forms in either an IE or Outlook window, depending on which client the user is using to access CRM.</p>
<p>If you are using a CRM Web Page WebResource, youâ€™ve got the option of either including ClientGlobalContext.js.aspx or using parent.Xrm to access the Microsoft Xrm JavaScript object model.Â  Unfortunately, Crm is on one website address and SharePoint is another website address.Â  Therefore, although SharePoint is being displayed in CRM using an iFrame, Anti-XSS (Cross Site Scripting) prevents the use of parent.Xrm in the SharePoint page.</p>
<h2>The Solution</h2>
<p>Given that the Xrm JavaScript object model needs to be used from a page in CRM the solution I came up with is to use a WebResource html page that will act as a shim for SharePoint:</p>
<pre class="brush: jscript; html-script: true; title: ; notranslate">
!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Xrm Shim&lt;/title&gt;
    &lt;base&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../ClientGlobalContext.js.aspx&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../c5_javascript/lib/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        $(function () {
            var data = Xrm.Page.context.getQueryStringParameters();
            Xrm.Utility.openEntityForm(data.typename, data.id);
        });
    &lt;/script&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>I then updated my SharePoint web part to run the following script when the user clicks the CRM Record menu item:</p>
<pre class="brush: csharp; title: ; notranslate">
crmRecordMenuItem.ClientOnClickScript =
    string.Format(@&quot;ifrm = document.createElement('IFRAME');
Â Â Â Â     ifrm.setAttribute('src', '{0}/{1}/WebResources/xrmshim.htm?typename=%DocTypeName%&amp;amp;id=%CRMDocID%');
Â Â Â Â Â Â   ifrm.style.width = 1+'px';
Â Â Â Â Â Â   ifrm.style.height = 1+'px';
Â Â Â Â Â Â   document.body.appendChild(ifrm);&quot;, crmUrl, crmOrgName);
</pre>
<p>This creates an iFrame that loads from html shim from CRM which in turn calls Xrm.Utility.openEntityForm using the typename and id passed from SharePoint in the query string parameters.</p>
<p>The shim is simple enough that it can be used on any page that is hosted on any site other that CRM.Â  It could be extended to call any Xrm object model methods provided by ClientGlobalContext.js.aspx.</p>
 <img src="http://www.gringod.com/?feed-stats-post-id=898" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2012/11/14/beating-crm2011-anti-xss-with-a-web-resource-shim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VisendoSMTPExtender Management Web Service</title>
		<link>http://www.gringod.com/2009/05/15/visendosmtpextender-management-web-service/</link>
		<comments>http://www.gringod.com/2009/05/15/visendosmtpextender-management-web-service/#comments</comments>
		<pubDate>Fri, 15 May 2009 16:16:56 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://www.gringod.com/?p=760</guid>
		<description><![CDATA[Background: For work, I&#8217;m using a Windows 2008 Server virtual machine for doing all my SharePoint and .Net development on.Â  As it has got all of the cool stuff I&#8217;m working on, it is also the machine that I use to demo what I can do to clients.Â  Recently I&#8217;ve had a bit of a [&#8230;]]]></description>
				<content:encoded><![CDATA[<h3>Background:</h3>
<p>For work, I&#8217;m using a Windows 2008 Server virtual machine for doing all my SharePoint and .Net development on.Â  As it has got all of the cool stuff I&#8217;m working on, it is also the machine that I use to demo what I can do to clients.Â  Recently I&#8217;ve had a bit of a serge in the number of clients wanting to see Nintex Workflow 2007 (NFW2007) for SharePoint.</p>
<p>One of the cool features of NWF2007 is the whole Lazy Approval system, whereby users don&#8217;t have to go into SharePoint to approve to decline requests, they can just reply to the notification email with &#8220;approved&#8221;, &#8220;declined&#8221;, &#8220;ok&#8221;, &#8220;yes&#8221;, &#8220;no&#8221; or any other recognised wordÂ as the first line of the email.Â  In or to demonstrate this I need to setup and email system on my local machine.Â  The SMTP (sending) side of things is easy as it is built in to Windows 2008.Â  However, POP3 is a bit of a problem.Â  Previous version of IIS had a simple POP3 service but that has been dropped in IIS7.Â  The Microsoft way would be to install Exchange Server but that is a little too heavyweight for what I am trying to acheive.Â  Luckily a company called <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3dlYmxvZ3MuYXNwLm5ldC9ocHJlaXNodWJlci9hcmNoaXZlLzIwMDgvMDQvMzAvdmlzZW5kby1zbXRwLXBvcDMtZXh0ZW5kZXItZm9yLXdpbmRvd3MtMjAwOC1zZXJ2ZXIuYXNweA%3D%3D&#038;feed-stats-url-post-id=760">Visendo provides a free solution </a>to plug the gap.Â  So now I can demo Nintex notification features.</p>
<p>Another feature I also wanted to demonstrate was setting up Active Directory accounts and then using those new accounts.Â  Nintex has got actions that allow you to interact with Active Directory but to then do anything usefull with the account required modifying xml config files and restarting the Visendo service.Â  But Nintex can call web services, so I&#8217;ve created a web service that has an AddAccount and DeleteAccount methods to update the Visendo configuration and restart the service.</p>
<h3>Download:</h3>
<p>I&#8217;ve made the source code forÂ this web service freely available should anyone else want to have this sort of functionality: <a rel=\"attachment wp-att-759\" href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5ncmluZ29kLmNvbS8yMDA5LzA1LzE1L3Zpc2VuZG9zbXRwZXh0ZW5kZXItbWFuYWdlbWVudC13ZWItc2VydmljZS92aXNlbmRvc210cHNlcnZpY2Uv&#038;feed-stats-url-post-id=760">VisendoSMTPService</a>.Â  The code is written against .Net 3.5 and is provided &#8220;as is&#8221; with no sort of warranty and is most definitely NOT recommended for live systems.Â  The code is released under a <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5zZXMvQlNELw%3D%3D&#038;feed-stats-url-post-id=760">BSD License</a>.</p>
 <img src="http://www.gringod.com/?feed-stats-post-id=760" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2009/05/15/visendosmtpextender-management-web-service/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The SharePoint Adrenalin Moment</title>
		<link>http://www.gringod.com/2009/03/10/the-sharepoint-adrenalin-moment/</link>
		<comments>http://www.gringod.com/2009/03/10/the-sharepoint-adrenalin-moment/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 20:20:31 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.gringod.com/?p=719</guid>
		<description><![CDATA[I&#8217;ve been developing with SharePoint for about 9 month now, and by developing I don&#8217;t mean airy-fairy SharePoint Designer drag-and-drop, I mean proper getting your hands dirty in code because SharePoint doesn&#8217;t have an *cough* out of the box *cough* feature that does what you want. Mostly, deployment is done in two stages, firstly to [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been developing with SharePoint for about 9 month now, and by developing I don&#8217;t mean airy-fairy SharePoint Designer drag-and-drop, I mean proper getting your hands dirty in code because SharePoint doesn&#8217;t have an <em>*cough*</em> out of the box <em>*cough*</em> feature that does what you want.</p>
<p>Mostly, deployment is done in two stages, firstly to a UAT box and then to a Live box. Â Obviously the most efficient way to do this is to bundle your features into a solution which can easily be deployed onto any number of machines. Â But, it does mean you have to make sure you&#8217;ve got everything right. Â Untangling mistakes in your code can be a right royal pain in the arse.</p>
<p>By the time you&#8217;ve developed your solution, tested it out, deployed it to UAT and tested it again you should be fairly confident that when you come to deploy it on the Live server things should go pretty smoothly. Â And, touch wood, to date things have gone smoothly.</p>
<p>But I still can&#8217;t get over that rush ofÂ adrenalineÂ that comes with clicking &#8220;Activate Feature&#8221; after deploying the solution on Live. Â In the second or two whilst the page waits to reload my mind runs through all the possible things that could go wrong and how long it would take me to unpick the changes my code might have got half way though. Â Then the page finally loads&#8230;..</p>
<p>&#8230;.. &#8220;Feature Activated&#8221;, phew! Â Time for a lie down to clam my nerves.</p>
 <img src="http://www.gringod.com/?feed-stats-post-id=719" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2009/03/10/the-sharepoint-adrenalin-moment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CRM 4 iFrame Printing</title>
		<link>http://www.gringod.com/2009/02/25/crm-4-iframe-printing/</link>
		<comments>http://www.gringod.com/2009/02/25/crm-4-iframe-printing/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 20:16:05 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.gringod.com/?p=711</guid>
		<description><![CDATA[Last year I was working with a client to develop some ISV add-ins for Microsoft Dynamics CRM.Â  Recently I was alerted to the fact that one of them &#8211; a seperate aspx page that loads in an iFrame on the account details panel &#8211; wasn&#8217;t printing correctly. It displayed correctly in the normal view form, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Last year I was working with a client to develop some ISV add-ins for Microsoft Dynamics CRM.Â  Recently I was alerted to the fact that one of them &#8211; a seperate aspx page that loads in an iFrame on the account details panel &#8211; wasn&#8217;t printing correctly.</p>
<p>It displayed correctly in the normal view form, appeared correctly on the print preview form but when actually printed it was collapsed down to one or two pixels high.</p>
<p>After doing a bit of research, I found <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL2Jsb2dzLmluZXRpdW0uY29tL2Jsb2dzL3ZidWxsaW5nZXIvYXJjaGl2ZS8yMDA3LzA2LzExL2lmcmFtZS1wcmludC1zdHlsZXMtaW4tY3JtLmFzcHg%3D&#038;feed-stats-url-post-id=711">this post by Vince Bullinger</a>, in which he gets around the problem by, as far as I can tell, modifying a core CRM css file.Â  Whilst this will work, it should be noted that any modification to core CRM files is not supported and will almost certainly break or be lost by updates and hotfixes.</p>
<p>Another problem with the code Vince Bullinger gives is that the iFrames a fixed height and that applies to ALL ISV iFrames.Â  However, with this knowledge I was able toÂ  come up with my own solution that uses a bit of Javascript to ensure that iFrames are printed and at the correct height to display all the content:</p>
<pre style="padding-left: 30px;">&lt;%@ Page Language="C#" AutoEventWireup="true"
    CodeBehind="Summary.aspx.cs" Inherits="CRMWeb.SummaryStatus.Summary" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   Â "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
Â Â Â  &lt;title&gt;Summary Status&lt;/title&gt;
Â Â Â  &lt;style type="text/css"&gt;
Â Â Â Â Â Â Â  #pageWrapper
Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â  position: absolute;
Â Â Â Â Â Â Â Â Â Â Â  top: 0;
Â Â Â Â Â Â Â Â Â Â Â  left: 0;
Â Â Â Â Â Â Â  }
Â Â Â  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
Â Â Â  &lt;div id="pageWrapper"&gt;
Â Â Â  &lt;form id="form1" runat="server"&gt;
Â Â  Â Â Â  Â &lt;!-- content goes here --&gt;
Â Â Â  &lt;/form&gt;
Â Â Â  &lt;/div&gt;
Â Â Â  &lt;script language="javascript" type="text/javascript"&gt;
Â Â Â Â Â Â Â  var dh = document.getElementById("pageWrapper").offsetHeight;
Â Â Â Â Â Â Â  document.parentWindow.frameElement.height = dh;
Â Â Â Â Â Â Â  document.parentWindow.frameElement.style.display = "block";
Â Â Â Â Â Â Â  document.parentWindow.frameElement.style.height = dh + "px";
Â Â Â  &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>This solutions requires that you surround the content of your page with a div, in this case <em>&lt;div id=&#8221;pageWrapper&#8221;&gt;&lt;/div&gt;</em>.Â  This is used by the block of Javascript at the end.</p>
<p>The purpose of the Javascript is to use the <em>pageWrapper</em> div to find out the height of the content.Â  This height is then used to set the height of the iFrame that contains the page and to set the <em>display</em> style of the iFrame to <em>block</em>.</p>
<p>It probably doesn&#8217;t require the iFrame <em>height</em> and the iFrames <em>style.height </em>both being set but I decided to take a belts and braces approach.</p>
<p>In addition to ensuring the iFrame content is printed, I am also planning on implementing the code on Vince Bullingers page for loading a specific css stylesheet for printing.</p>
<p><a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5kb3RuZXRraWNrcy5jb20va2ljay8%2FdXJsPWh0dHA6Ly93d3cuZ3JpbmdvZC5jb20vMjAwOS8wMi8yNS9jcm0tNC1pZnJhbWUtcHJpbnRpbmcv&#038;feed-stats-url-post-id=711"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.gringod.com/2009/02/25/crm-4-iframe-printing/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
 <img src="http://www.gringod.com/?feed-stats-post-id=711" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2009/02/25/crm-4-iframe-printing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Try&#8230;Catch For No Reason</title>
		<link>http://www.gringod.com/2008/08/11/trycatch-for-no-reason/</link>
		<comments>http://www.gringod.com/2008/08/11/trycatch-for-no-reason/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 13:49:24 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[Exceptions]]></category>

		<guid isPermaLink="false">http://www.gringod.com/2008/08/11/trycatch-for-no-reason/</guid>
		<description><![CDATA[Iâ€™ve seen this time and time again and Iâ€™m sure just about every developer out there has seem the same sort of thing: try { //many lines of code catch (Exception ex) { throw new Exception(&#34;Something went wrong dude!&#34;); } This is probably the single most un-helpful piece of code a developer can write.&#160; All [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Iâ€™ve seen this time and time again and Iâ€™m sure just about every developer out there has seem the same sort of thing:</p>
<blockquote><pre class="csharpcode"><span class="kwrd">try</span> {
    <span class="rem">//many lines of code</span>
<span class="kwrd">catch</span> (Exception ex) {
    <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(<span class="str">&quot;Something went wrong dude!&quot;</span>);
}</pre>
</blockquote>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>This is probably the single most un-helpful piece of code a developer can write.&#160; All you are doing is making you life and future developers lives harder when it comes to debugging.&#160; The whole point of the tryâ€¦catch block is for times when you know an exception may happen and it allows you to gracefully handle it without the whole system crashing to the ground.</p>
<p>So lets have a closer look at whatâ€™s wrong with this code:</p>
<p><span id="more-679"></span></p>
<h1>Too many lines wrapped</h1>
<p>You wrap code in a tryâ€¦catch block the idea is to only wrap the code that is likely to throw an exception.&#160; Whilst it isnâ€™t impossible, it does make identifying the offending line of code harder to find.&#160; This may sound like a trivial reason to complain but when you have to deal with this day after day it does get a little tedious.</p>
<h1>Indiscriminate exception handling</h1>
<p>By catching exceptions of type Exception youâ€™re really saying to developers that come after you â€œI donâ€™t care enough about this code to know what exceptions might happen.â€?&#160; In many instances different exception types can be handled in different ways.&#160; Iâ€™m betting that the default response of most developers that catch Exception will be to throw a cryptic message at the user and drop out of whatever the method was â€“ probably without clean up resources either.</p>
<p>It is possible to have multiple catch blocks that catch different exception types if you think that there are multiple types of exceptions that might be thrown:</p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">try</span> {
    File.WriteAllText<span class="str">&quot;(@&quot;</span>c:\test.txt<span class="str">&quot;, &quot;</span>Hello world!&quot;);
}
<span class="kwrd">catch</span> (FileNotFoundException ex) {
    <span class="rem">// do something</span>
}
<span class="kwrd">catch</span> (SecurityException ex) {
    <span class="rem">// do something else</span>
}</pre>
</blockquote>
<p>This means that you can handle different exceptions in different ways.&#160; Also, any type of Exception that you donâ€™t handle gets passed up the call stack.</p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h1>The exception isnâ€™t handled</h1>
<p>In this particular instance the exception isnâ€™t handled, so why on earth put the tryâ€¦catch block there in the first place?!&#160; If all youâ€™re going to do is throw a new exception or re-throw the old exception without doing anything youâ€™re better off leaving out the tryâ€¦catch block.&#160; It just adds overhead to instances when it runs through without exception.</p>
<h1>Original exception is masked</h1>
<p>Again, in this example a new exception is thrown.&#160; If you must do this then at least include the original exception as the inner exception (the exception that cause the new exception to be thrown).&#160; The Exception class even has a constructor to help with this:</p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">public</span> Exception( <span class="kwrd">string</span> message, Exception inner )</pre>
</blockquote>
<p>Alternatively, you can throw the original exception.</p>
<h1>New exception is generalised</h1>
<p>By throwing the base Exception class you are forcing developers that use your code to have to catch exceptions of type Exception â€“ see above for why this can be bad.&#160; If you canâ€™t find a built-in exception class to use, and there are many, create your own.&#160; Visual Studio 2008 has a code snippet for creating an exception class, all you have to do is fill-in the blanks.</p>
<h1>In an ideal worldâ€¦</h1>
</p>
<p>â€¦ Iâ€™d like .Net to have a similar method to java of having to specify (use attributes) what exceptions a method throws or catches.&#160; This allows you to easily find out what exceptions may originate in a method your code calls, and let other developers know what exceptions your code doesnâ€™t handle.&#160; It also allows for pretty good compile time exception checking.&#160; It means extra code has to be written but I think it results in better code.</p>
 <img src="http://www.gringod.com/?feed-stats-post-id=679" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2008/08/11/trycatch-for-no-reason/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Character Counter</title>
		<link>http://www.gringod.com/2008/02/08/character-counter/</link>
		<comments>http://www.gringod.com/2008/02/08/character-counter/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 15:13:43 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[.net2]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[bsd license]]></category>
		<category><![CDATA[character counter]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.gringod.com/2008/02/08/character-counter/</guid>
		<description><![CDATA[Whilst reading an article I was curious about the number of commas and full-stops that the author used &#8211; when you become an editor of a newsletter you start to think about things like this.&#160; After hunting around the various utilities on my system I discovered that I didn&#8217;t have anything that could easily do [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Whilst reading an article I was curious about the number of commas and full-stops that the author used &#8211; when you become an editor of a newsletter you start to think about things like this.&nbsp; After hunting around the various utilities on my system I discovered that I didn&#8217;t have anything that could easily do this.&nbsp; So, I did what any self-respecting programmer would do and threw together a quick app to do it for me.</p>
<p>I have made both the <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5ncmluZ29kLmNvbS93cC11cGxvYWRzL3NvZnR3YXJlL0NoYXJhY3RlckNvdW50ZXJfc3JjLnppcA%3D%3D&#038;feed-stats-url-post-id=615">source code</a> and <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5ncmluZ29kLmNvbS93cC11cGxvYWQvc29mdHdhcmUvQ2hhcmFjdGVyQ291bnRlcl9iaW4uemlw&#038;feed-stats-url-post-id=615">pre-compiled binary</a> available for download under a <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5zZXMvQlNELw%3D%3D&#038;feed-stats-url-post-id=615">BSD license</a> (<font color="#008000">share</font>, <font color="#008000">remix</font>, <font color="#800000">no endorsement</font>).&nbsp; It is written in C# and requires the .Net 2.0 framework, if you want to compile the source you will probably require MS Visual Studio (Express should be ok), although it may work with <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5pY3NoYXJwY29kZS5uZXQvT3BlblNvdXJjZS9TRC8%3D&#038;feed-stats-url-post-id=615">SharpDevelop</a> or <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5tb25vLXByb2plY3QuY29tL01haW5fUGFnZQ%3D%3D&#038;feed-stats-url-post-id=615">Mono</a>.</p>
<p>It is a console application (sorry, no pretty GUI this time) that reads the contents of input.txt (in the same directory as the app), it then counts the occurrences of each character and outputs the results to the console. Simple!</p>
<p>If you make any improvements to the code please leave a comment and/or email the changes to me: gringod [at] gmail [dot] com.</p>
<p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:39c46d67-44ab-4f86-8e8d-f0aba1be91e8" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvY3NoYXJw&#038;feed-stats-url-post-id=615" rel=\"tag\">csharp</a>,<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvcHJvZ3JhbW1pbmc%3D&#038;feed-stats-url-post-id=615" rel=\"tag\">programming</a>,<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvY2hhcmFjdGVyJTIwY291bnRlcg%3D%3D&#038;feed-stats-url-post-id=615" rel=\"tag\">character counter</a>,<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3Mvc291cmNlJTIwY29kZQ%3D%3D&#038;feed-stats-url-post-id=615" rel=\"tag\">source code</a>,<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvYXBwbGljYXRpb24%3D&#038;feed-stats-url-post-id=615" rel=\"tag\">application</a>,<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvLm5ldDI%3D&#038;feed-stats-url-post-id=615" rel=\"tag\">.net2</a>,<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvYnNkJTIwbGljZW5zZQ%3D%3D&#038;feed-stats-url-post-id=615" rel=\"tag\">bsd license</a></div></p>
 <img src="http://www.gringod.com/?feed-stats-post-id=615" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2008/02/08/character-counter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test Driven Porting</title>
		<link>http://www.gringod.com/2007/11/20/test-driven-porting/</link>
		<comments>http://www.gringod.com/2007/11/20/test-driven-porting/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 15:34:33 +0000</pubDate>
		<dc:creator><![CDATA[gringod]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Bell Ringing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Test-Driven-Development]]></category>
		<category><![CDATA[Test-Driven-Porting]]></category>

		<guid isPermaLink="false">http://www.gringod.com/2007/11/20/test-driven-porting/</guid>
		<description><![CDATA[Technorati Tags: Test-Driven-Development , Test-Driven-Porting , .Net , C# , C++ , Programming Recently I&#8217;ve had reason to take an code library written in C++ and port it to C#.&#xA0; Whilst I dabbled in C++ on a compilers course at university, I hated it then and I still hate it now.&#xA0; I personally think it&#8217;s [&#8230;]]]></description>
				<content:encoded><![CDATA[<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:00c73987-59b1-4d1a-a2cb-32b32ed5f479" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags:  		<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvVGVzdC1Ecml2ZW4tRGV2ZWxvcG1lbnQv&#038;feed-stats-url-post-id=605" rel=\"tag\">Test-Driven-Development</a> 		,  		<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvVGVzdC1Ecml2ZW4tUG9ydGluZy8%3D&#038;feed-stats-url-post-id=605" rel=\"tag\">Test-Driven-Porting</a> 		,  		<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvLk5ldC8%3D&#038;feed-stats-url-post-id=605" rel=\"tag\">.Net</a> 		,  		<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvQyMv&#038;feed-stats-url-post-id=605" rel=\"tag\">C#</a> 		,  		<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvQysrLw%3D%3D&#038;feed-stats-url-post-id=605" rel=\"tag\">C++</a> 		,  		<a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvUHJvZ3JhbW1pbmcv&#038;feed-stats-url-post-id=605" rel=\"tag\">Programming</a> 		</div>
<p>Recently I&#8217;ve had reason to take an code library written in C++ and port it to C#.&#xA0; Whilst I dabbled in C++ on a compilers course at university, I hated it then and I still hate it now.&#xA0; I personally think it&#8217;s an abomination and should be consigned to the great garbage collector in the sky.&#xA0;&#xA0; Whilst I can just about read the C++ syntax there is a lot that I don&#8217;t understand about it.</p>
<p>The library I was porting had semi reasonable documentation outlining what classes exist and their methods and a brief description of the overall usage.&#xA0; This gave me a good starting point, however the documentation didn&#8217;t include example usages and expected results, for this I was forced to delve into the code.</p>
<p>One development paradigm I have been interested in but have been unable to find a decent project to test it on is Test-Driven-Development and this seemed like the perfect project to try it on.&#xA0; So I set to work on the first iteration getting the test set up.&#xA0;&#xA0; Without knowing exactly what results I should be expecting I was finding it hard going, so once again I dived back into the old code.</p>
<p>Thankfully, the developers of the C++ library had create a fairly comprehensive set of unit tests and with my limited C++ knowledge and a text editor with RegEx Find &amp; Replace I was quickly able to convert their unit tests into NUnit based unit tests.</p>
<p>For example, what started out life as:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">void</span> test_row_multiply_change(<span class="kwrd">void</span>)</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre class="alt"><span class="lnum"> 3: </span> row r;</pre>
<pre><span class="lnum"> 4: </span> RINGING_TEST( ( r *= change( 6, <span class="str">&quot;X&quot;</span> ) ) == <span class="str">&quot;214365&quot;</span> );</pre>
<pre class="alt"><span class="lnum"> 5: </span> RINGING_TEST( ( r *= change( 6, <span class="str">&quot;1&quot;</span> ) ) == <span class="str">&quot;241635&quot;</span> );</pre>
<pre><span class="lnum"> 6: </span> RINGING_TEST( ( r *= change( 8, <span class="str">&quot;X&quot;</span> ) ) == <span class="str">&quot;42615387&quot;</span> );</pre>
<pre class="alt"><span class="lnum"> 7: </span> RINGING_TEST( ( r *= change( 5, <span class="str">&quot;3&quot;</span> ) ) == <span class="str">&quot;24651387&quot;</span> );</pre>
<pre><span class="lnum"> 8: </span>&#xA0;</pre>
<pre class="alt"><span class="lnum"> 9: </span> RINGING_TEST( row( <span class="str">&quot;214365&quot;</span> ) * change( 7, <span class="str">&quot;5&quot;</span> ) == row( <span class="str">&quot;1234675&quot;</span> ) );</pre>
<pre><span class="lnum"> 10: </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Quickly became:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span>[Test]</pre>
<pre><span class="lnum"> 2: </span><span class="kwrd">public</span> <span class="kwrd">void</span> TestMultiplicationByChange()</pre>
<pre class="alt"><span class="lnum"> 3: </span>{</pre>
<pre><span class="lnum"> 4: </span> Row r = <span class="kwrd">new</span> Row();</pre>
<pre class="alt"><span class="lnum"> 5: </span> Assert.AreEqual((Row)<span class="str">&quot;214365&quot;</span>, r *= <span class="kwrd">new</span> Change(6, <span class="str">&quot;X&quot;</span>) );</pre>
<pre><span class="lnum"> 6: </span> Assert.AreEqual((Row)<span class="str">&quot;241635&quot;</span>, r *= <span class="kwrd">new</span> Change(6, <span class="str">&quot;1&quot;</span>));</pre>
<pre class="alt"><span class="lnum"> 7: </span> Assert.AreEqual((Row)<span class="str">&quot;42615387&quot;</span>, r *= <span class="kwrd">new</span> Change(8, <span class="str">&quot;X&quot;</span> ));</pre>
<pre><span class="lnum"> 8: </span> Assert.AreEqual((Row)<span class="str">&quot;24651387&quot;</span>, r *= <span class="kwrd">new</span> Change(5, <span class="str">&quot;3&quot;</span>));</pre>
<pre class="alt"><span class="lnum"> 9: </span>&#xA0;</pre>
<pre><span class="lnum"> 10: </span> Assert.AreEqual((Row)<span class="str">&quot;1234675&quot;</span>, <span class="kwrd">new</span> Row(<span class="str">&quot;214365&quot;</span>) * <span class="kwrd">new</span> Change(7, <span class="str">&quot;5&quot;</span>));</pre>
<pre class="alt"><span class="lnum"> 11: </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, with a full set of unit tests at my disposal I was quickly able to bash away at the library and very quickly got working code without the need to trawl through ghastly C++ code.</p>
<p>Hooray for Test-Driven-Development and three cheers for Test-Driven-Porting.</p>
<p><font size="1">ps. The library I&#8217;m porting is an open source library for Bell Ringing &#8211; yes I know I&#8217;m a geek but anyone that has followed everything else in this post must also be a geek ;-).&#xA0; Once I&#8217;m finished I will be releasing my code under an open source license as well, I just need to pick the right one.</font></p>
<p><font size="1">pps. I may have exaggerated my hate of C++ a little.&#xA0; I believe all languages have their place, even the </font><a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL2Vzb3RlcmljLnZveGVscGVyZmVjdC5uZXQvd2lraS9MYW5ndWFnZV9saXN0&#038;feed-stats-url-post-id=605"><font size="1">esoteric languages</font></a><font size="1"> like </font><a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL2xvbGNvZGUuY29tLw%3D%3D&#038;feed-stats-url-post-id=605"><font size="1">LOLCode</font></a><font size="1">.</font></p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:cf502d0c-443d-4be4-88e5-3d2832bfad62" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.gringod.com/?feed-stats-url=aHR0cDovL3d3dy5kb3RuZXRraWNrcy5jb20va2ljay8%2FdXJsPWh0dHA6Ly93d3cuZ3JpbmdvZC5jb20vMjAwNy8xMS8yMC90ZXN0LWRyaXZlbi1wb3J0aW5nLw%3D%3D&#038;feed-stats-url-post-id=605"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.gringod.com/2007/11/20/test-driven-porting/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
 <img src="http://www.gringod.com/?feed-stats-post-id=605" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2007/11/20/test-driven-porting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
