<?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>Alex James Brown &#187; c#</title>
	<atom:link href="http://www.alexjamesbrown.com/tags/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alexjamesbrown.com</link>
	<description>My Words. By Me.</description>
	<lastBuildDate>Wed, 04 Jan 2012 01:02:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Joe Blogs Wrapper V2 &#8211; Help required</title>
		<link>http://www.alexjamesbrown.com/development/joe-blogs-wrapper-v2-help-required/</link>
		<comments>http://www.alexjamesbrown.com/development/joe-blogs-wrapper-v2-help-required/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 01:14:26 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[JoeBlogs]]></category>
		<category><![CDATA[Wordpress. Open Source]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/?p=669</guid>
		<description><![CDATA[I’m on the verge of being able to release a second, much improved version of the Joe Blogs WordPress &#38; MetaWeblog API Wrapper. Some very brief details below, and a ...]]></description>
			<content:encoded><![CDATA[<p>I’m on the verge of being able to release a second, much improved version of the Joe Blogs WordPress &amp; MetaWeblog API Wrapper.</p>
<p>Some very brief details below, and a cry for help <em>(or several cries!)</em></p>
<p><strong></strong></p>
<h3>New Features / Improvements</h3>
<p><strong>Friendlier API      <br /></strong>Instead of having to deal with the XML-RPC interfaces directly, I’ve added a “friendly” layer of classes on top.     <br />The WordPressWrapper class has helper methods, with friendly properties, for doing things like uploading files etc…</p>
<ul>
<li><strong>More examples        <br /></strong>The sample project (console application) included in the project demonstrates all methods and features of the library.       </li>
<li><strong>Better documentation        <br /></strong>XML RPC Comments on all the public properties and methods </li>
</ul>
<h3>Help required</h3>
<p>I need help with some of the following, both for this version, and subsequent versions</p>
<ul>
<li><strong>PHP WordPress Re-install script        <br /></strong>Script (configured as CRON job) to “refresh” test install of WordPress (every couple of hours or something) </li>
<li><strong>Unit Tests        <br /></strong>Need better code coverage., and more integration tests       <br />I’m not TDD expert, so unfortunately, a lot of this will be retro-fitting unit tests into the current code. </li>
<li><strong>WordPress Plugin development        <br /></strong>I plan to release an “extended” version of XML RPC – with some enhanced methods in, for use with JoeBlogs – for example “GetRecentPosts” </li>
<li><strong>ASP.Net Demo Project        <br /></strong>Eventually, and ASP.net MVC “blog” project, running from WordPress – for no other reason than “it can be done” </li>
<li><strong>Moving project to GitHub        <br /></strong>See below </li>
<li><strong>General code improvement        <br /></strong>Refactoring, performance enhancements, etc… </li>
<li><strong>Logo Designed        <br /></strong>‘cos every cool open source project has to have a cool logo, right? </li>
<li><strong>Website</strong>       <br />I’ve dipped my hand into my pocket, and bought joeblogswrapper.org (under £7 – <a href="http://bit.ly/godaddydomainregistration+" target="_blank">GoDaddy</a>)       <br />Will have a site dedicated to it on there soon. Obvious CMS choice would be WordPress, but if anyone can think of a better option for Wiki style pages, I’m all ears       <br />(Media wiki..? What are the benefits?) </li>
</ul>
<h3>Mailing List</h3>
<p>I’ve created a Google Group – <a href="http://groups.google.com/group/joeblogs/">http://groups.google.com/group/joeblogs/</a>     <br />Please, sign up on there for announcements (I’ll announce when the next versions of the wrapper are available)</p>
<h3>GitHub</h3>
<p>I really like the idea of moving this project over to <a href="https://github.com/alexjamesbrown/JoeBlogs" target="_blank">GitHub</a>.</p>
<p>Problem is, I have absolutely no experience using Git.</p>
<p>I’ve tried following the instructions, and got as far as some files imported into my repository.. but I can’t get it to work, or commit my changes.</p>
<p>If anyone would like to offer their hand-holding expertise on getting this moved over (and training me on committing files etc…) then I’ll gladly move it to GitHub, which long term, I believe could be beneficial to the overall development of the project.</p>
<h3>Get in touch</h3>
<p>If you’d like to help with ANY of the above (or anything I’ve missed for that matter) please <a href="http://www.alexjamesbrown.com/contact/">get in touch</a>, or use the <a href="http://groups.google.com/group/joeblogs/">Google Group</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/joe-blogs-wrapper-v2-help-required/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C# &#8211; String.Concat vs String.Join</title>
		<link>http://www.alexjamesbrown.com/development/c-string-concat-vs-string-join/</link>
		<comments>http://www.alexjamesbrown.com/development/c-string-concat-vs-string-join/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 13:53:16 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/uncategorized/c-string-concat-vs-string-join/</guid>
		<description><![CDATA[I had a quick Google search for a comparison between string.concat and string.join, but I couldn’t find anything. Say you want to construct the sentence “The quick brown fox jumps ...]]></description>
			<content:encoded><![CDATA[<p>I had a quick Google search for a comparison between <strong>string.concat</strong> and <strong>string.join</strong>, but I couldn’t find anything.</p>
<p>Say you want to construct the sentence <em>“The quick brown fox jumps over the lazy dog”</em></p>
<p>This is comprised of 9 words, 8 spaces.</p>
<h3>Using string.concat:</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c4a800a4-b114-40ce-8e63-91fec60fdc87" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public void CreateSentanceUsingStringConcat()
{
    string space = " ";
    string the = "the";
    string quick = "quick";
    string brown = "brown";
    string fox = "fox";
    string jumps = "jumps";
    string over = "over";
    string lazy = "lazy";
    string dog = "dog";

    var result = string.Concat(the, space, quick, space, brown, space, fox, space, jumps, space, over, space, the, space, lazy, space, dog);
}</pre>
</div>
<h3>Using string.join</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6e6a1782-7795-490c-a575-7366cba41e3b" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">public void CreateSentanceUsingStringJoin()
{
    var result = string.Join(space, the, quick, brown, fox, jumps, over, the, lazy, dog);
}</pre>
</div>
<p>With <strong>string.concat</strong>, we must explicitly add the separator (in our case, space) between each string. </p>
<p>String.join however, allows us to specify the separator as the first parameter.</p>
<h3>Performance</h3>
<p>I wrote a small benchmark test on the two (see bottom of this post for code)</p>
<p>We can see <strong>string.concat</strong> consistently performs better</p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="string.join - 516ms / string.concat - 329ms" border="0" alt="string.join - 516ms / string.concat - 329ms" src="http://www.alexjamesbrown.com/wp-content/uploads/image31.png" width="160" height="142" /> </p>
<h3>Benchmark Code:</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:dc08e592-61fa-4042-aa3a-864e2d434587" class="wlWriterEditableSmartContent">
<pre class="brush: c#;">class Program
{
    const int m = 1000000;

    const string space = " ";
    const string the = "the";
    const string quick = "quick";
    const string brown = "brown";
    const string fox = "fox";
    const string jumps = "jumps";
    const string over = "over";
    const string lazy = "lazy";
    const string dog = "dog";

    const string expected = "the quick brown fox jumps over the lazy dog";

    static void Main()
    {
        Console.WriteLine("Pass #1");
        Go();
        Console.WriteLine();
        Console.WriteLine("Pass #2");
        Go();
        Console.WriteLine();
        Console.WriteLine("Pass #3");
        Go();

        Console.Read();
    }

    private static void Go()
    {
        Stopwatch s1 = Stopwatch.StartNew();

        for (int i = 0; i &lt; m; i++)
            string.Concat(the, space, quick, space, brown, space, fox, space, jumps, space, over, space, the, space, lazy, space, dog);

        s1.Stop();

        Stopwatch s2 = Stopwatch.StartNew();
        for (int i = 0; i &lt; m; i++)
            string.Join(space, the, quick, brown, fox, jumps, over, the, lazy, dog);

        s2.Stop();

        Console.WriteLine("string.join - {0}", s1.ElapsedMilliseconds);
        Console.WriteLine("string.concat- {0}", s2.ElapsedMilliseconds);
    }
}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/c-string-concat-vs-string-join/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing DataCash 3D Secure with ASP.net</title>
		<link>http://www.alexjamesbrown.com/development/implementing-datacash-3d-secure-with-asp-net/</link>
		<comments>http://www.alexjamesbrown.com/development/implementing-datacash-3d-secure-with-asp-net/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 13:04:50 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[datacash]]></category>
		<category><![CDATA[payment processing]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/?p=446</guid>
		<description><![CDATA[This is an article I’ve been meaning to write for a while now… Mainly, to help others out, who are struggling with the near non-existent documentation provided by Datacash, when ...]]></description>
			<content:encoded><![CDATA[<p>This is an article I’ve been meaning to write for a while now…</p>
<p>Mainly, to help others out, who are struggling with the near non-existent documentation provided by Datacash, when trying to plug 3D Secure into my ASP.net application.</p>
<p>I’m sure you’re already familiar with what 3D Secure is, so I won’t go in to too much detail, nor will I go into much detail with regards to the process.</p>
<p>The purpose of this article is to get you familiar with <em>how</em> to send the details to the DataCash MPI, receive a response, and display and use the 3D Secure window in an iFrame (or framed window for that matter)</p>
<p><strong>Please note:</strong><br />
<small>This code is for tutorial purposes only. It’s dirty, crude, buggy, and not refactored in any way shape or form.<br />
I simplified the code down to bare bones, in order to better explain each element.<br />
Obviously, it comes without warranty… it <em>should</em> work as expected, but has no logging, error trapping or any of that good stuff… and when dealing with online payments, you really should take more care!</small></p>
<h3>Code</h3>
<p><strong><span class="Apple-style-span" style="font-size: 11px;">Update &#8211; 8th September, 2011:</span></strong></p>
<p><a href="http://alexjamesbrown.com.s3.amazonaws.com/wp-content/uploads/github.png"><img class="alignleft size-full wp-image-814" title="github" src="http://alexjamesbrown.com.s3.amazonaws.com/wp-content/uploads/github.png" alt="GitHub" width="100" height="45" /></a>I&#8217;ve now <a href="https://github.com/alexjamesbrown/Datacash-3DSecure" target="_blank">hosted the code on GitHub</a></p>
<p><strong>You will need to edit the web.config to add your own VTID and Password</strong></p>
<h3>Donate</h3>
<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=MVCXSJJ3QU4QJ"><img style="margin: 0px 25px 10px 0px; display: inline; border-width: 0px;" title="btn_donate_SM" src="http://www.alexjamesbrown.com/wp-content/uploads/btn_donate_SM.gif" alt="btn_donate_SM" width="74" height="21" align="left" border="0" /></a>I don’t normally do this, but this article took me literally months to pull together, so any small contribution would be gratefully received!</p>
<hr />
<h3>Payment Page</h3>
<p>This is the functionality that processes payment – for example, allows the customer to enter their credit card details etc…</p>
<p>The mark-up is fairly straight forward.</p>
<p>Two things to note are the body, and the form tag:</p>
<pre class="brush: html;gutter:false;">&lt;body id="myBody" runat="server"&gt;</pre>
<p>Note that the body tag is runat server</p>
<pre class="brush: html;">&lt;form id="MainForm" runat="server"&gt;</pre>
<p>Note that  the name is “MainForm” – we will need this later.</p>
<p>Since in this tutorial, I’m showing how to use an iFrame, I have this bit of code, below the payBtn:</p>
<pre class="brush: html;">&lt;asp:Panel ID="ACSFramePanel" runat="server" Visible="false"&gt;
    Please verify.....&lt;br /&gt;
    &lt;br /&gt;
    &lt;iframe src="" name="ACSFrame" width="450" height="400" frameborder="0" /&gt;
&lt;/asp:Panel&gt;</pre>
<p>Line 4 of the above is basically where the 3D Secure frame will appear.</p>
<p>I wrapped it in a Panel, so that we can hide it, while the customer enters their card details etc…</p>
<p>Now, let’s look at some of the code-behind:</p>
<pre class="brush: c#;gutter:false;">private Config config;
private Agent agent;

//this would be our order id / reference in production
private string ourReference = Guid.NewGuid().ToString("n").Substring(0, 8);

protected void Page_Load(object sender, EventArgs e)
{
    config = new Config(AppDomain.CurrentDomain.BaseDirectory + "datacash.conf"); // would probably need to come from web.config
    agent = new Agent(config);
}</pre>
<p>In the above code, Config and Agent are both DataCash objects.</p>
<p>In the Page_Load event, we basically set these two objects up.</p>
<p><strong>config</strong> is set from an xml file (located in the project root) called datacash.conf – this can of course be located anywhere you like (and called anything you like)</p>
<p><strong>agent </strong>is then set using the defined config object.</p>
<p>The config file looks like this:</p>
<pre class="brush: xml;">&lt;Configuration&gt;
  &lt;logfile&gt;datacash.log&lt;/logfile&gt;
  &lt;logging&gt;5&lt;/logging&gt;
  &lt;Obscure&gt;
    &lt;element&gt;Transaction.CardTxn.Card.pan&lt;/element&gt;
    &lt;element&gt;Authentication.password&lt;/element&gt;
    &lt;element&gt;Transaction.CardTxn.Card.Cv2Avs.cv2&lt;/element&gt;
  &lt;/Obscure&gt;

  &lt;!--this would be for the live server--&gt;
  &lt;!--&lt;host&gt;https://mars.transaction.datacash.com/Transaction&lt;/host&gt;--&gt;

  &lt;host&gt;https://testserver.datacash.com/Transaction&lt;/host&gt;
  &lt;port&gt;443&lt;/port&gt;
  &lt;timeout&gt;90&lt;/timeout&gt;
  &lt;setstrict&gt;true&lt;/setstrict&gt;
&lt;/Configuration&gt;</pre>
<p>Of course, this doesn’t <em>have</em> to be done in Page_Load – in “the real world” this would all be part of a payment helper class. But for demo purposes, it’s fine in the Page_Load – just means we have to repeat ourselves on other pages…</p>
<p>Next, we assume the user fills out the form, and presses the Pay button.</p>
<h3>Sending the request to DataCash</h3>
<pre class="brush: c#;">protected void payBtn_Click(object sender, EventArgs e)
{
    //so they don't press the button twice.
    payBtn.Enabled = false;

    //get browser info (for 3d secure stuff)
    var browser = Request.Browser.Browser;

    var request = buildAuthDataCashDocument(
        ourReference,
        cardNumber.Text,
        expiryMonth.Text,
        expiryYear.Text,
        startMonth.Text,
        startYear.Text,
        issueNumber.Text,
        secCode.Text,
        billingAddress1.Text,
        billingAddress2.Text,
        billingAddress3.Text,
        billingAddress4.Text,
        billingAddressPostCode.Text,
        browser);

    //send the request document to the agent.
    //todo: could implement some kind of error trapping / retry here
    var authResponse = agent.send(request);

    //get the datacash transaction reference (just in case we need to try authorizing the payment without 3D Secure)
    var datacashRef = authResponse.get("Response.datacash_reference");

    //get the response code
    var responseCode = authResponse.get("Response.status");</pre>
<p>This code basically generates a XML document with the payment authorisation request, and submits it to DataCash.</p>
<p>I refactored buildAuthDataCashDocument as it was pretty large, and made the code a bit <em>too</em> dirty, even for this demo!</p>
<p>Couple of bits of note within buildAuthDataCashDocument are:</p>
<pre class="brush: c#;">request.set("Request.Authentication.client", ConfigurationManager.AppSettings["DataCashVtid"]);
request.set("Request.Authentication.password", ConfigurationManager.AppSettings["DataCashPassword"]);</pre>
<p>This basically sets the VTID and Password from config (in our case, web.config) which looks like:</p>
<pre class="brush: xml;gutter:false;auto-links:false;toolbar:false;">&lt;appSettings&gt;
   &lt;add key="DataCashVtid" value="99******"/&gt;
   &lt;add key="DataCashPassword" value="bK*******"/&gt;
&lt;/appSettings&gt;</pre>
<p>Also, within buildAuthDataCashDocument is:</p>
<pre class="brush: c#;">request.set("Request.Transaction.TxnDetails.ThreeDSecure.verify", "yes");
request.set("Request.Transaction.TxnDetails.ThreeDSecure.merchant_url", "www.crocus.co.uk"); //or whatever brand??
request.set("Request.Transaction.TxnDetails.ThreeDSecure.purchase_desc", "Items from Crocus"); //or some other short sumary
request.set("Request.Transaction.TxnDetails.ThreeDSecure.purchase_datetime", DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));</pre>
<p>This is important, for 3D Secure – Fairly self explanatory.</p>
<p>After building our request Document, we need to send it to DataCash, and get another Document back – as a response.</p>
<p>To do that, it’s as simple as:</p>
<pre class="brush: c#;">var authResponse = agent.send(request);</pre>
<p>This sets authResponse to the response Document.</p>
<p>We can then use the .get() method on authResponse to retrieve elements from it.</p>
<p>We are most interested in <strong>Response.datacash_reference</strong> and <strong>Response.status</strong></p>
<p>The datacash_reference is unique to each and every transaction processed, so it is useful for later things like refunds, reporting etc…</p>
<p><strong>Response.status</strong> is the DataCash status code for this transaction.</p>
<p>It’s from this, that we determine how to proceed.</p>
<pre class="brush: c#;">switch (responseCode)
{
    //handle 3DS error responses....`
    //Basically, if it's one of these, the transaction is screwed, and shouldn't proceed....
    case "151": 		//	3DS Invalid Transaction type
    case "152": 		//	3DS Manual Authorization not supported
    case "153": 		//	3DS verify element missing
    case "154": 		//	3DS Invalid verify value
    case "155": 		//	3DS field missing
    case "156": 		//	3DS Invalid Browser.device_category
    case "157": 		//	3DS Merchant not enabled
    case "159": 		//	3DS No VERes from DS
    case "160": 		//	3DS Invalid VERes from DS
    case "161": 		//	3DS call auth centre

        //log the error here
        break; //- throw them out of transaction process. Should redirec

    case "56": //speed limit - too many transactions on that card number in short space of time
        break;

    //3ds payer verification required....
    case "60":
    case "150":
        show3DSIframe(authResponse);
        Response.Clear();
        break;
}</pre>
<p>I won’t go in to too much detail, as the comments kind of speak for themselves…</p>
<p>Basically, if you get a <strong>60</strong> or <strong>150</strong> then the transaction requires you to show the 3D Secure window.</p>
<h3>Showing the 3D Secure iFrame</h3>
<p>I’ll spend a bit of time on show3DSIframe, as this is the part that caused me the most hassle – How to actually display the ACS in an iFrame, especially in ASP.net</p>
<pre class="brush: c#;">private void show3DSIframe(Document doc)
{
    ACSFramePanel.Visible = true;

    //this is the data cash reference number for this transaction
    var dataCashReference = doc.get("Response.datacash_reference");

    //this is the url of the ACS - the page generated by the bank, that contains the
    //boxes where the customer enters information etc...
    var acsUrl = doc.get("Response.CardTxn.ThreeDSecure.acs_url");

    //this is a long message / code that is generated for the transaction
    var pareq = doc.get("Response.CardTxn.ThreeDSecure.pareq_message");</pre>
<p>Ok, so in the markup from Part 1, you may remember I wrapped the iFrame in a Panel, called ACSFRamePanel. Now, we need to set the visibility to true.</p>
<p>These first few lines are self explanatory – we need to get the <strong>dataCashReference</strong>, <strong>acsUrl</strong> (the URL of the 3D Secure page – this is usually returned by the customers issuing bank) and the <strong>pareq</strong> – this is a long string, that&#8217;s a bit like a password for the transaction.</p>
<p>These elements are retrieved from the passed in DataCash Document.</p>
<p>We then need to create our Term URL – This is basically a URL that the 3D Secure window POSTs back to:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:46726e71-84a2-4bfc-9dff-92a39d65f426" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: c#;">var termUrlPrefix = Request.ServerVariables["HTTPS"] == "ON" ? "https://" : "http://";

//termUrl is where the ACS page posts back to.
var termUrl = string.Format("{0}{1}",
    termUrlPrefix,
    Request.Url.Authority + "/3DSResponse.aspx");</pre>
</div>
<p>In our demo case, it’s just on our local host machine – this could however, for example, be something like <em>www.myUrl.com/checkout/3DSresponse.aspx</em></p>
<p>This next part is the important part.</p>
<p>This set’s the required hidden fields (PaReq and TermUrl) on our form.</p>
<p>We then register another hidden form &#8211; “MD” – This is <strong>our</strong> order number / reference for this transaction – so we can retrieve it from our database, and update the status when we come out the other side of 3D Secure.</p>
<p>The next line generates a little bit of JavaScript that basically causes this form to submit itself to the acs url.</p>
<p>The result of this, is then output to the target (parameter 3 in our string.format) – ACSFrame.</p>
<p><small><strong>Remember we called our form “MainForm”</strong></small> <img src='http://www.alexjamesbrown.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Then, myBody.Attributes.Add inserts the resulting JavaScript to the onLoad function of our body tag.</p>
<p><small><strong>Remember we made runat server earlier</strong></small></p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d448a460-0b9a-4864-a1b7-a74bfee554e9" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: c#;">//ClientScript.RegisterHiddenField adds a hidden field to the form...
ClientScript.RegisterHiddenField("PaReq", pareq);
ClientScript.RegisterHiddenField("TermUrl", termUrl);

//this is the data cash reference, and our reference -
//so we can update the order on the other side of the verification (paid, failed etc...)
ClientScript.RegisterHiddenField("MD", dataCashReference + "|" + ourReference);

var js = string.Format("javascript: document.{0}.action='{1}'; document.{2}.target=\"{3}\"; document.{4}.submit();",
    MainForm.ID,
    acsUrl,
    MainForm.ID,
    "ACSFrame",
    MainForm.ID
);

//since the body tag of this page is called myBody, and is runat=server, we can access
//it here, and inject our javascript.
myBody.Attributes.Add("onLoad", js);</pre>
</div>
<p>And there we have it – the 3D Secure window is displayed in an iFrame</p>
<p>I’ll edit this post with a link to 3DSResponse.aspx when I finish that article…</p>
<p>Hope this helps! Feel free to <img src='http://www.alexjamesbrown.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><img style="margin: 0px 25px 10px 0px; display: inline; border-width: 0px;" title="btn_donate_SM" src="http://www.alexjamesbrown.com/wp-content/uploads/btn_donate_SM1.gif" alt="btn_donate_SM" width="74" height="21" border="0" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/implementing-datacash-3d-secure-with-asp-net/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating a new post in WordPress using the JoeBlogs library</title>
		<link>http://www.alexjamesbrown.com/development/creating-a-new-post-in-wordpress-using-the-joeblogs-library/</link>
		<comments>http://www.alexjamesbrown.com/development/creating-a-new-post-in-wordpress-using-the-joeblogs-library/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 20:33:08 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[JoeBlogs]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/development/creating-a-new-post-in-wordpress-using-the-joeblogs-library/</guid>
		<description><![CDATA[A few people have recently been asking how the NewPost method works within JoeBlogs First, you need to create an instance of Post. Then, set the following properties: dateCreated Fairly ...]]></description>
			<content:encoded><![CDATA[<p>A few people have recently been asking how the NewPost method works within <a href="http://www.alexjamesbrown.com/projects/joe-blogs/" target="_blank">JoeBlogs</a></p>
<p>First, you need to create an instance of Post.</p>
<p>Then, set the following properties:</p>
<p><strong>dateCreated     <br /></strong>Fairly self explanatory, but you should set this to today&#8217;s date (or whatever date you wish the post to be set as published)</p>
<p><strong>title     <br /></strong>The title of the post</p>
<p><strong>description     <br /></strong>The body of the post.    <br />This can of course contain HTML</p>
<p><strong>categories     <br /></strong>This is a string array of categories to associate with the post</p>
<p><strong>mt_keywords     <br /></strong>Another string array, representing the tags for the post</p>
<p>Then, using your presumably already instantiated Wrapper class, you can call the NewPost method, which takes the above Post object as a parameter, and a <em>boolean – </em>indicating if the post is to be set as published. Note – if this is set to false, the post is set in draft mode.</p>
<p>Here’s some sample code:</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">//create a new post
var post = new Post();

//since this is a struct, we can't have a constructor that does this!
post.dateCreated=DateTime.Now;
post.title=&quot;This is a title&quot;;
post.description=&quot;this is the body of the post. it &lt;strong&gt;could&lt;/strong&gt; be html.&quot;;

//create the post!
wp.NewPost(post,true);</pre>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/creating-a-new-post-in-wordpress-using-the-joeblogs-library/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>NVelocity template with decimal to two decimal places</title>
		<link>http://www.alexjamesbrown.com/development/nvelocity-template-with-decimal-to-two-decimal-places/</link>
		<comments>http://www.alexjamesbrown.com/development/nvelocity-template-with-decimal-to-two-decimal-places/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 15:34:11 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[nVelocity]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/geek/development/dotnet/nvelocity-template-with-decimal-to-two-decimal-places/</guid>
		<description><![CDATA[I wanted to be able to output a decimal value from an object in my NVelocity template. For example, the value of the decimal was: 3.40000 to represent 3.4. The ...]]></description>
			<content:encoded><![CDATA[<p>I wanted to be able to output a decimal value from an object in my <a title="NVelocity" href="http://www.castleproject.org/others/nvelocity" target="_blank">NVelocity</a> template.</p>
<p>For example, the value of the decimal was: 3.40000 to represent 3.4.</p>
<p>The end result:</p>
<blockquote><p>Total Order Value: 3.40 GBP</p>
</blockquote>
<p>I needed to display this as currency format. Sure, I could of used this <a href="http://www.howtogeek.com/howto/programming/format-a-string-as-currency-in-c/" target="_blank">String.Format method</a>, but that adds £ or $ or whatever (depending on your environment setup) to the start of the resulting string.</p>
<p>In the end, I used ToString with “N2” formatter.</p>
<p>So, in my nVelocity template, here is what I would use:</p>
<blockquote><p>Total Order Value: $Order.GrandTotal.ToString(&quot;N2&quot;) GBP</p>
</blockquote>
<p>There are some other alternatives discussed here:    <br /><a title="http://stackoverflow.com/questions/1048643/format-a-double-value-like-currency-but-without-the-currency-sign-c" href="http://stackoverflow.com/questions/1048643/format-a-double-value-like-currency-but-without-the-currency-sign-c">http://stackoverflow.com/questions/1048643/format-a-double-value-like-currency-but-without-the-currency-sign-c</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/nvelocity-template-with-decimal-to-two-decimal-places/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Ternary conditional operator – Question mark in an if statement</title>
		<link>http://www.alexjamesbrown.com/development/c-ternary-conditional-operator-question-mark-in-an-if-statement/</link>
		<comments>http://www.alexjamesbrown.com/development/c-ternary-conditional-operator-question-mark-in-an-if-statement/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 16:21:08 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/?p=346</guid>
		<description><![CDATA[I’m all for shortening the amount of code we write, if it makes it more readable. One enhancement I make use of in C# is the ternary conditional operator. Consider ...]]></description>
			<content:encoded><![CDATA[<p>I’m all for shortening the amount of code we write, if it makes it more readable.</p>
<p>One enhancement I make use of in C# is the ternary conditional operator.</p>
<p>Consider the following block of code:</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">            string input = "hi";
            bool saidHello;

            if (input = "hello")
            {
                saidHello = true;
            }
            else
            {
                saidHello = false;
            }</pre>
<p>In this example, we can see, the saidHello boolean value would be <em>false</em>,  as the input string actually said ‘hi’ rather than hello.</p>
<p>This could be shortened down to a single line like so (or 2, if we count the input initialisation)</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; highlight: [2]; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">            string input = "hi";
            var saidHello = input == "hello" ? true : false;</pre>
<p>This makes use of the ternary operator – the ? (and of course <a href="http://www.alexjamesbrown.com/geek/development/dotnet/var-keyword-in-c-implicitly-typed-variable/" target="_blank">var – as explained in another article</a>)</p>
<p>the ? acts as a ‘then’ and the : acts as an else…</p>
<p>So you can think of it as something like below:</p>
<p>saidHello equals (if input equals hello then) true, else false.</p>
<p>These can of course be nested, as <a href="http://weblogs.asp.net/dburke/archive/2004/03/26/97195.aspx" target="_blank">explained in this article</a>, however in my opinion, this kind of defeats the whole point of this from my point of view – to increase readability of code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/c-ternary-conditional-operator-question-mark-in-an-if-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JoeBlogs – Typo in dummy URL fixed</title>
		<link>http://www.alexjamesbrown.com/development/joeblogs-typo-in-dummy-url-fixed/</link>
		<comments>http://www.alexjamesbrown.com/development/joeblogs-typo-in-dummy-url-fixed/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 09:23:50 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[JoeBlogs]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/geek/development/dotnet/joeblogs-typo-in-dummy-url-fixed/</guid>
		<description><![CDATA[I’ve recently had a few comments that the JoeBlogs wrapper wasn’t working – and they were getting an “invalid response” or more specifically “Response XML not valid XML-RPC – missing ...]]></description>
			<content:encoded><![CDATA[<p>I’ve recently had a few comments that the JoeBlogs wrapper wasn’t working – and they were getting an “invalid response” or more specifically “Response XML not valid XML-RPC – missing methodResponse element.”</p>
<p>It seems that I had a typo in my comments in JoeBlogs.TestHarness/Program.cs on line 15:</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">//typically http://www.yourdomain.com/xmlprc.php (if your wordpress blog is installed in root dir)</pre>
<p>The problem, is the xmlprc.php – this should be xmlrpc.php. </p>
<p>Those of you that copy pasted / uncommented out that line, would be executing requests against a file that didn’t exist on your server!</p>
<p>I’ve changed this typo, and committed to Codeplex: revision #<a href="http://joeblogs.codeplex.com/SourceControl/changeset/view/27138">27138</a></p>
<p>Thanks to Felix for pointing this out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/joeblogs-typo-in-dummy-url-fixed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reverse GeoCoding with Google API and C#</title>
		<link>http://www.alexjamesbrown.com/development/reverse-geocoding-with-google-api-and-c/</link>
		<comments>http://www.alexjamesbrown.com/development/reverse-geocoding-with-google-api-and-c/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:51:37 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/geek/development/dotnet/reverse-geocoding-with-google-api-and-c/</guid>
		<description><![CDATA[I needed to write a function to get a set of co-ordinates from an address, supplied as a string. Using the Google API, I came up with this: First, I ...]]></description>
			<content:encoded><![CDATA[<p>I needed to write a function to get a set of co-ordinates from an address, supplied as a string.    <br />Using the <a href="http://code.google.com/apis/maps/documentation/services.html" target="_blank">Google API</a>, I came up with this:</p>
<p>First, I created a <a href="http://msdn.microsoft.com/en-us/library/ah19swz4%28VS.71%29.aspx" target="_blank">struct</a>, to represent the lat and lon co-ordinates:</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public struct Coordinate
{
	private double _latitude;
	private double _longitude;

	public Coordinate(double latitude, double longitude)
	{
		_latitude = latitude;
		_longitude = longitude;
	}

	public double Latitude { get { return _latitude; } set { _latitude = value; } }
	public double Longitude { get { return _longitude; } set { _longitude = value; } }
}</pre>
<p>This is a simple representation of a set of latitude and longitude co-ordinates.</p>
<p>The main method, which returns the above Coordinate struct is:</p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; highlight: 5; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public static Coordinate GetCoordinates(string address)
{
	using (var client = new WebClient())
	{
		Uri uri = YOUR_URI_HERE;

		/* The first number is the status code,
		* the second is the accuracy,
		* the third is the latitude,
		* the fourth one is the longitude.
		*/
		string[] geocodeInfo = client.DownloadString(uri)		.Split(',');

		return new Coordinate(
			Convert.ToDouble(geocodeInfo[2]),
			Convert.ToDouble(geocodeInfo[3]));
	}
}</pre>
<p>On line 5, you need to specify your Google API URL, in the format of:</p>
<p><a href="http://maps.google.com/maps/geo?q=ADDRESS">http://maps.google.com/maps/geo?q=ADDRESS</a> GOES HERE&amp;output=csv&amp;key=YOUR KEY HERE</p>
<p>And that’s it!</p>
<p>Obviously, there are usage restrictions when using the Google API for this, as outlined on the documentation pages</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/reverse-geocoding-with-google-api-and-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using JoeBlogs -metaWeblog API Wrapper</title>
		<link>http://www.alexjamesbrown.com/development/using-joeblogs/</link>
		<comments>http://www.alexjamesbrown.com/development/using-joeblogs/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 15:28:07 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[JoeBlogs]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/geek/development/dotnet/using-joeblogs/</guid>
		<description><![CDATA[Step 1 Download the latest release of JoeBlogs from Codeplex (Click the Downloads tab, and select the latest download) Step 2 Unzip the contents of the downloaded zip file. (I ...]]></description>
			<content:encoded><![CDATA[<h3>Step 1</h3>
<p>Download the latest release of <a href="http://joeblogs.codeplex.com" target="_blank">JoeBlogs from Codeplex</a><br />
(Click the Downloads tab, and select the latest download)</p>
<h3>Step 2</h3>
<p>Unzip the contents of the downloaded zip file.<br />
(I usually copy DLLs I am going to use into a “lib” folder at the root of my solution)</p>
<h3>Step 3</h3>
<p><strong><br />
</strong>Add a reference to BOTH CookComputing.XmlRpcV2.dll AND JoeBlogs.dll</p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" src="http://www.alexjamesbrown.com/wp-content/uploads/UsingJoeBlogs_E688/image.png" border="0" alt="image" width="482" height="406" /></p>
<p>Include AlexJamesBrown.JoeBlogs in your class, with using / Imports:</p>
<p><strong>C#</strong></p>
<pre class="brush: csharp; auto-links: false; collapse: false; first-line: 1; gutter: false; html-script: false; light: true; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">using AlexJamesBrown.JoeBlogs;</pre>
<p><strong>VB</strong></p>
<pre class="brush: vb; auto-links: false; collapse: false; first-line: 1; gutter: false; html-script: false; light: true; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Imports AlexJamesBrown.JoeBlogs</pre>
<h3>Step 4:</h3>
<p>Instantiate a new Wrapper object.</p>
<p>So far, the available wrappers are:</p>
<p>MetaWeblogWrapper</p>
<p>WordPressWrapper</p>
<p><strong>C#</strong></p>
<pre class="brush: csharp; auto-links: false; collapse: false; first-line: 1; gutter: false; html-script: false; light: true; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">WordPressWrapper wrapper = new WordPressWrapper(Url, Username, Password);</pre>
<p><strong>VB</strong></p>
<pre class="brush: vb; auto-links: false; collapse: false; first-line: 1; gutter: false; html-script: false; light: true; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Dim wrapper As New WordPressWrapper(Url, Username, Password)</pre>
<p><em>Please note -</em></p>
<p>The above example has the Url, Username and Password strings omitted. Simply replace them with the relevant information.</p>
<h3>Step 5</h3>
<p>You can now take full advantage of all the methods on your instantiated wrapper.</p>
<p><strong>C#</strong></p>
<pre class="brush: csharp; auto-links: false; collapse: false; first-line: 1; gutter: false; html-script: false; light: true; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">string Url = "www.alexjamesbrown.com";
string User = "MyUser"; //enter your username
string Password = "MyPassword"; //enter your password

var wp = new WordPressWrapper(Url, User, Password);

//a few test functions...
var userBlogs = wp.GetUserBlogs();
var tags = wp.GetTags();
var categories = wp.GetCategories();

var authors = wp.GetAuthors();</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/using-joeblogs/feed/</wfw:commentRss>
		<slash:comments>67</slash:comments>
		</item>
		<item>
		<title>Why Are Interfaces Useful?</title>
		<link>http://www.alexjamesbrown.com/development/why-are-interfaces-useful/</link>
		<comments>http://www.alexjamesbrown.com/development/why-are-interfaces-useful/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 16:36:53 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/?p=274</guid>
		<description><![CDATA[Interfaces, usually prefixed by “I” are useful in software engineering, for a number of reasons. Primarily, they allow you to create “pluggable” code. By this, I mean that your code ...]]></description>
			<content:encoded><![CDATA[<p>Interfaces, usually prefixed by “I” are useful in software engineering, for a number of reasons.    <br />Primarily, they allow you to create “pluggable” code.     <br />By this, I mean that your code is easier to manage, easier to maintain, easier to change the way certain parts of your application work, without changing the entire way it works.</p>
<p>Lets look at an example.</p>
<p>Our application is an photo sharing web application, allowing users to view and upload photos.    <br />The main functions of the site, are handled by our ImageManager class. This facilitates the retrieval, and storing of images. Fairly integral to the application.</p>
<p>As we are designing our application using <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank">SoC (Separation of Concerns)</a>, all our ImageManager class will do, is <strong>get</strong>, or <strong>put </strong>images. (in reality, we should really have a separate concern for each operation – get &amp; put)     <br />It doesn’t care about storing user details or meta data, against the image in a database, nor does it care about checking to see if a user can view that image or anything like that.     <br />It purely puts, or gets, an image.</p>
<p>Now. this operation sounds simple, to get an image, I just need to connect to my file store, and retrieve my image?    <br />Yes. But what if, one day, you need to be able to switch where you store your images.     <br />For example..on day 1, you are storing your images on the file system, in a directory within your web application project.     <br />This works fine, especially during beta testing, however as demand grows, the strain on your server and your bandwidth become a problem, and you need to change where images are stored.</p>
<p>You also want to be able to use a storage service, such as <a href="https://s3.amazonaws.com" target="_blank">Amazon S3</a> to store your images.     <br />(I’m not going to go into how S3 or any other service works in this article, it’s just an example.)</p>
<p>Luckily, we have a couple of ImageManagers….    <br />FileSystemImageManager, and S3ImageManager</p>
<p>Both of which, implement our interface – IImageManager (notice the prefix &quot;I”)</p>
<p>Here’s the interface:</p>
<p><strong>C#</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public interface IImageManager
{
  void PutImage(Image image, string fileName);
  Image GetImage(string fileName);
}</pre>
<p><strong>VB</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Public Interface IImageManager
  Sub PutImage(ByVal image As Image, ByVal fileName As String)
  Function GetImage(ByVal fileName As String) As Image
End Interface</pre>
<p>Note the empty method signatures… </p>
<p>Interfaces contain no logic – they are simply a contract that each implementation agrees to follow.</p>
<p>So lets have a look at an implementation of IImageManager:</p>
<p><strong>C#</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">public class FileSystemImageManager : IImageManager
{
  public void PutImage(Image image, string fileName)
  {
    //code to save the image on the file system
  }

  public Image GetImage(string fileName)
  {
    //code to get the image from the file system
  }
}</pre>
<p><strong>VB</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Public Class FileSystemImageManager
    Implements IImageManager
    Public Sub PutImage(ByVal image As Image, ByVal fileName As String)
        'code to save the image on the file system
    End Sub

    Public Function GetImage(ByVal fileName As String) As Image
        'code to get the image from the file system
    End Function
End Class</pre>
<p>The FileSystemImageManager implements IImageManager (indicated by the : in c#) </p>
<p>note, in visual studio, you can right on your interface implementation declaration and select Implement Interface – this will create the required method signatures within your class.</p>
<p><a href="http://www.alexjamesbrown.com/wp-content/uploads/WhyAreInterfacesUseful_F3A0/interfaceTutorial1.jpg" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Implement Interface" border="0" alt="Implement Interface" src="http://www.alexjamesbrown.com/wp-content/uploads/WhyAreInterfacesUseful_F3A0/interfaceTutorial1_thumb.jpg" width="412" height="56" /></a></p>
<p>Our class now conforms to IImageManager. </p>
<p>But – there’s no code! That doesnt <em>technically</em> matter.</p>
<p>As long as you’ve implemented each method (even by throwing a <a href="http://msdn.microsoft.com/en-us/library/system.notimplementedexception.aspx" target="_blank">NotImplementedException</a>), your class will compile.</p>
<p><strong>So what’s the point?</strong></p>
<p>Well, we now have a FileSystemImageManager class, that (after you’ve added your code) gets and puts images on the file system.</p>
<p>In our application, we can do something like:</p>
<p><strong>C#</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">      //get the image:
      IImageManager imageManager = new FileSystemImage();
      var image = imageManager.GetImage(&quot;my_filename&quot;);</pre>
<p><strong>VB</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">'get the image:
Dim imageManager As IImageManager = New FileSystemImage()
Dim image = imageManager.GetImage(&quot;my_filename&quot;)</pre>
<p>“Great” you say….</p>
<p>But that means you can “swap out” your functionality, really easily.</p>
<p>Instead of declaring imageManager as a new FileSystemImage() we could have another class, that implements IImageManager called “FlickrImage”<br />
  <br />This could then use Flickr to get and put images <em>(obviously additional functionality would be required to authenticate against Flickr API)</em></p>
<p>I’ll expand this tutorial at a later stage to explain how to effectively use config, factory patterns, IoC etc…</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/development/why-are-interfaces-useful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

