tag:blogger.com,1999:blog-66915796765717165372024-03-13T17:03:47.252+00:00Project 20A reference blog containing posts added during my time at Esendex.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.comBlogger158125tag:blogger.com,1999:blog-6691579676571716537.post-15308677331834790542008-03-06T21:20:00.000+00:002008-03-06T21:22:39.597+00:00That's All FolksToday marks the end of an era for me. After more than 4 years at Esendex I feel that now is a good time to move on to pastures new. It's my last day today, and this will be the last post of this blog as well.<br /><br />I first set this up to chart the experiences and knowledge gained during my work at Esendex, and now that work has come to an end I feel it is also fitting that this blog should as well.<br /><br />I shall keep blogging though. I recently remembered that way back in 2004 I reserved <a href="http://iandykes.blogspot.com/">iandykes.blogspot.com</a> so I've resurrected that one and intend to keep it updated from now on.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-39795562095144494602008-02-25T20:28:00.002+00:002008-02-26T12:34:35.369+00:00Cool CG Animated Short FilmA <a href="http://www.youtube.com/watch?v=FFuitd30vH4">CG 3D animated short film</a>, apparently created by just one person. Amazing level of detail, and raised a few smiles as well. Looks very polished and professional.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-66906725092316239452008-02-22T14:03:00.003+00:002008-02-22T14:08:43.097+00:00A Brief Introduction to RESTIf you're looking for information on <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REpresentational State Transfer</a>, then check out <a href="http://www.infoq.com/articles/rest-introduction">A Brief Introduction to REST</a> at <a href="http://www.infoq.com/rest/">InfoQ</a>. I particularly like:<br /><blockquote>The next principle we’re going to look at has a formal description that is a little intimidating: “Hypermedia as the engine of application state”, sometimes abbreviated as HATEOAS. (Seriously — I’m not making this up.)</blockquote>Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-81431888725980403722008-02-21T09:07:00.006+00:002008-02-21T09:30:58.366+00:00Assigning Basic Authorization HTTP Header to HttpWebRequest<div style="margin: 0px; padding: 5px; float: right;"><br /><script type="text/javascript">digg_url ='http://devproj20.blogspot.com/2008/02/assigning-basic-authorization-http.html';</script><br /><br /><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script><br /></div><br /><br />If you're making a call to a HTTP resource that requires a <a href="http://en.wikipedia.org/wiki/Basic_authentication_scheme">Basic Authorization HTTP header</a>, you can use the following code:<br /><br /><span style="font-size:85%;"><span style="font-family:courier new;">HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url-here");</span><br /><span style="font-family:courier new;">request.Credentials = new NetworkCredential("username", "password");</span></span><br /><br />Then post the request in the usual way.<br /><br />The confusion comes because <span style="font-weight: bold;">on the first call the HTTP header will not be present</span> on the request. The framework is relying on the first call receiving a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">401 response</a>, with a <a href="http://freesoft.org/CIE/RFC/1945/65.htm"><span style="font-style: italic;">WWW-Authenticate</span></a> header present, giving a <span style="font-style: italic;">Basic realm=<realm-name> </span> value. A second call will then be made with the correct headers in place.<br /><br />If you are just consuming the resource, chances are the server will respond in a way that allows this behaviour. However, if it doesn't respond with a 401, or that 401 response doesn't contain the <span style="font-style: italic;">WWW-Authenticate</span> header (or you just don't want to make 2 calls), then you have to manually add the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">Authorization header</a> to the request:<br /><br /><span style="font-size:85%;"><span style="font-family:courier new;">byte[] authBytes = Encoding.UTF8.GetBytes("user:password".ToCharArray()); </span><br /><span style="font-family:courier new;">request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);</span></span>Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com8tag:blogger.com,1999:blog-6691579676571716537.post-46479168479137098082008-02-20T16:13:00.005+00:002008-02-20T16:57:54.133+00:00Writing XML with UTF-8 Encoding using XmlTextWriter and StringWriter<div style="margin: 0px; padding: 5px; float: right;"><br /><script type="text/javascript">digg_url ='http://devproj20.blogspot.com/2008/02/writing-xml-with-utf-8-encoding-using.html';</script><br /><br /><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script><br /></div><br /><br />If you want to use XmlTextWriter to write XML into a StringBuilder you can create the XmlTextWriter like this:<br /><br /><span style="font-size:85%;"><span style="font-family:courier new;">StringBuilder builder = new StringBuilder();</span><br /><span style="font-family:courier new;">XmlWriter writer = new XmlTextWriter(new StringWriter(builder));</span></span><br /><br />But this generates a declaration on the resulting XML with the encoding of UTF-16 (the encoding of a .Net String). There doesn't seem to be a straightforward way of making this declaration UTF-8 in this set up.<br /><br />You can, of course, use a MemoryStream instead of a StringWriter, and then use Encoding.UTF8.GetString(...) to convert the bytes to a string, but doing this made the resulting string have non-printable characters in it, which we don't want.<br /><br /><a href="http://www.thescripts.com/forum/thread307901.html">The solution is to subclass StringWriter and override the Encoding property</a>. Sounds a bit overkill for a solution, but it works very well. Just create the following class (based on Jon Skeet's class):<span style=";font-family:courier new;font-size:85%;" ><br /><pre><br />public class StringWriterWithEncoding : StringWriter<br />{<br />Encoding encoding;<br /><br />public StringWriterWithEncoding (StringBuilder builder, Encoding encoding)<br />:base(builder)<br />{<br />this.encoding = encoding;<br />}<br /><br />public override Encoding Encoding<br />{<br />get { return encoding; }<br />}<br />}<br /></pre><br /></span>Then use StringWriterWithEncoding instead of StringWriter in your XmlTextWriter.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com9tag:blogger.com,1999:blog-6691579676571716537.post-7673967163463554862008-02-20T11:28:00.006+00:002008-02-20T11:49:55.773+00:00This operation requires IIS integrated pipeline mode<div style="margin: 0px; padding: 5px; float: right;"><br /><script type="text/javascript">digg_url ='http://devproj20.blogspot.com/2008/02/this-operation-requires-iis-integrated.html';</script><br /><br /><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script><br /></div><br /><br />If you're getting an error message<br /><br /><span style="color: rgb(255, 0, 0);font-family:courier new;" >This operation requires IIS integrated pipeline mode</span><br /><br />when trying to add headers to a HttpResponse object in an ASP.Net web application, chances are you're trying something like this:<br /><br /><span style="font-family:courier new;">response.Headers["myHeader"] = "someValue";</span><br /><br />or<br /><br /><span style="font-family:courier new;">response.Headers.Add("myHeader", "someValue");</span><br /><br />A quick Google reveals mentions of bugs in the 3.5 framework, but I'm using .Net 2. Nevertheless you can work around this problem by adding your header this way instead:<br /><br /><span style="font-weight: bold;font-family:courier new;" >response.AddHeader("myHeader", "someValue");</span><br /><br />And your code should now add the header successfully.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com27tag:blogger.com,1999:blog-6691579676571716537.post-52039746942723396332008-02-11T16:00:00.000+00:002008-02-11T16:05:24.893+00:0050 Open Source Alternatives to Proprietary Programs<a href="http://whdb.com/2008/the-top-50-proprietary-programs-that-drive-you-crazy-and-their-open-source-alternatives/">The Top 50 Proprietary Programs that Drive You Crazy — and Their Open Source Alternatives</a><br /><br />Decent list of open source software for pretty much anything you want to do on your computer.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-24157329500407821452008-02-05T15:08:00.001+00:002008-02-20T11:49:43.537+00:00Custom ThreadPoolLast year in a post from the last day at Tech Ed I mentioned a talk about building <a href="http://devproj20.blogspot.com/2007/06/tech-ed-day-5-scalable-aspnet-web.html">Scalable ASP.NET Web Applications</a>, in which a warning was given about using the normal .Net ThreadPool in web apps. A suggestion was made to instead use a custom thread pool so that ASP.NET's worker threads weren't all used up.<br /><br />In that talk it was said there was code for such a class on the <a href="http://www.wintellect.com/webdemos.aspx">Wintellect website</a>, but I remember looking at the time and couldn't find anything.<br /><br />I've since found <a href="http://www.bearcanyon.com/dotnet/">Mike Woodring's .NET Sample Page</a>, on which there is a <a href="http://www.bearcanyon.com/dotnet/#threadpool">custom thread pool</a> inplementation available for download.<br /><br />I've not needed to use it yet, so can't comment on its usage, but I'll give it a go when I need control over the ThreadPool.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-74861771653475280402008-01-30T11:39:00.000+00:002008-01-30T11:40:16.055+00:00Get the current date as a string from a batch fileEver needed to include the current date in something like a filename from a batch file? <a href="http://support.microsoft.com/kb/555314">Check out this MS KB article</a> on how to do it.<br /><br />I've changed the format slightly to include a dash between each part. This is what I used:<br /><br /><span style="font-family: courier new;">SET current.date=%date:~-4,4%-%date:~-7,2%-%date:~0,2%</span>Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-16252887016187181262008-01-25T16:20:00.001+00:002008-01-25T16:24:58.625+00:00Mario, Lego, Plasticine, and Friday afternoon equals...Nice to see <a href="http://www.mindthe.net/devices/">Jonathan</a> and <a href="http://esendexdeveloper.blogspot.com/">Kevin</a> have been hard at work this Friday afternoon... ;)<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://farm3.static.flickr.com/2297/2218252535_05b1c20a5b.jpg?v=0"><img style="cursor: pointer; width: 320px;" src="http://farm3.static.flickr.com/2297/2218252535_05b1c20a5b.jpg?v=0" alt="" border="0" /></a><br /><br /><a href="http://www.flickr.com/photos/jbjon/2218252535/">read more</a> | <a href="http://digg.com/nintendo/Mario_Lego_Plasticine_and_Friday_afternoon_equals">digg story</a>Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com1tag:blogger.com,1999:blog-6691579676571716537.post-70909175393587788742008-01-21T08:58:00.000+00:002008-01-21T08:59:06.406+00:00Truth About Xbox 360 Red Ring of DeathInteresting interview with a "Microsoft insider" covering the <a href="http://blog.seattlepi.nwsource.com/digitaljoystick/archives/129866.asp">Truth About Xbox 360 Red Ring of Death</a>.<br /><br />Not sure how reliable the source is, but it makes interesting reading.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-34994446634838004462008-01-16T21:17:00.000+00:002008-01-18T10:12:03.535+00:00Force a C# Web Service Proxy to use HTTP 1.0<div style="float:right;padding:5px;margin:0px;"><br /><script type="text/javascript">digg_url ='http://devproj20.blogspot.com/2008/01/force-c-web-service-proxy-to-use-http.html';</script><br /><br /><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script><br /></div><br /><a href="#code">(Code at the bottom)</a><br /><br /><a href="https://www.esendex.com/en/Developers/">Esendex customers</a> can submit SMS using <a href="https://www.esendex.com/en/Developers/APIs/SOAP-XML-SMS-API/">.Net Web Services</a>. While the <a href="https://www.esendex.com/en/Developers/SDKs/NET-SMS-SDK/">simple code samples</a> we provide will get most people up and running, the samples aren't always enough when volumes start to increase.<br /><br />The most common error report we receive from these high usage customers usually contains a complaint that our APIs are down, and aren't responding, but this is rarely the case. Our server array offers all our customers the responsiveness and the reliability that they will need, but the error report always seems to look like this is the case.<br /><br />Normally the problem is at the customers side, and more often than not it's due to them consuming our Web Services using HTTP 1.1.<br /><br />A limitation of HTTP 1.1 is that it only support 2 simultaneous connections to another server. This is usually OK, but if a customer has a multi-threaded application then this can quickly become a problem. The problem manifests itself with an error that looks like the server is down.<br /><br />In reality what you'll have is a bunch of threads all waiting for a chance to connect, and when they don't you tend to get timeout errors that make it look like the server didn't respond.<br /><br />To get around this you need to connect using HTTP 1.0, but by default Visual Studio creates a web reference using 1.1. So you need to do some tweaking.<br /><br />Basically we need to override the <a href="http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soaphttpclientprotocol.getwebrequest.aspx">GetWebRequest</a> method on our generated web reference and alter the properties on the <a href="http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest%28VS.80%29.aspx">HttpWebRequest</a> so that we can assign the right version.<br /><br />When you add a Web Reference in Visual Studio you effectively add an auto generated class to your project, which (if you look down the directory tree in Windows Explorer) is saved in a Reference.cs file. This file changes every time you tell Visual Studio to update the web reference.<br /><br />Because of this it isn't always possible to override that particular class. If you working with an API that can change and you want to be able to update it easily, then you'll have to use <a href="http://msdn2.microsoft.com/en-us/library/wa80x488%28VS.80%29.aspx">partial classes</a> in order to override the method. Or you could sub class the proxy and override it in there.<br /><br />Personally I like to move the Reference.cs file into the project as a normal file (renamed of course), and then edit the generated code. I can do this as I know that the API isn't going to change (if we do need to offer new functionality we release new Web Services rather than change existing ones).<br /><br />This allows you to override the method in the normal way, and also allows you to change how the proxy gets the URL to connect to.<br /><br />Whichever way you do it, here's the code you need to add in:<br /><a name="code"></a><pre>protected override WebRequest GetWebRequest(Uri uri)<br />{<br />HttpWebRequest request =<br /> (HttpWebRequest)base.GetWebRequest(uri);<br />request.ProtocolVersion = System.Net.HttpVersion.Version10;<br /><br />return request;<br />}<br /></pre>And, as you've now got access to the HttpWebRequest you can also disable Keep Alives if they're causing you problems as well.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com5tag:blogger.com,1999:blog-6691579676571716537.post-88002181023053297022008-01-13T16:31:00.000+00:002008-01-13T17:16:12.970+00:00confused.com? You will be...My car insurance is due this month, leaving me with that magical four years no claims that most insurance companies seem to love. So I went to confused.com to give it a go.<br /><br />I used my iPod Touch as I didn't want to boot the laptop, and maybe this contributed to the frustrating experience, but if a website can't support Safari then that's hardly my problem really.<br /><br />It didn't start well as the Get Quotes button was floating at the bottom of the page rather than in line with everything else, but it was about to get worse. The site didn't recognise my registration number so I had to manually enter my car details. This is the first site that has failed to find my car from the number plate, and I've used a number of them for looking for insurance and tyres before.<br /><br />Then I was asked for my occupation, and although it didn't recognise Software Developer it did seem to pick up Programmer. Well, it was listed as Computer Programmer in the list so I selected that and tried to continue. That was no good for it though, I had to type in my occupation so that it matched what I selected in the drop down list. Further frustrations...<br /><br />Eventually I get to the last screen on which I'm asked to enter a password so I can retrieve my details later. So I enter a password only to be told it isn't good enough. Passwords have to be between 6 and 8 characters apparently...<br /><br />So I entered in a password that matched this criteria only to be told it still wasn't good enough. I gave up at that point, as a user of web applications I expect better.<br /><br />As a developer of web applications I know the whole experience can be much better. <br /><br />What's the point of heavily advertising your service if you confuse your would be customers before you've convinced them to part with any money?<br /><br />So, after being thoroughly disappointed with that experience I'm just going to stay with my current insurer.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-9690307769510049762008-01-11T12:49:00.000+00:002008-01-11T13:23:43.968+00:00What skills should a graduate have?There's a question <a href="http://ask.slashdot.org/article.pl?sid=08/01/09/1858220">What Skills Should Undergrads Have</a> running on <a href="http://slashdot.org/">slashdot</a> from the aftermath of the whole "<a href="http://developers.slashdot.org/article.pl?sid=08/01/08/0348239&tid=146">Java is damaging students</a>" article. There's a lot of answers already but I think one of the important ones is being able to visualise how software connects to each other.<br /><br />As a graduate programmer it's highly unlikely that you will be given a <a href="http://www.site.uottawa.ca:4321/oose/index.html#greenfielddevelopment">green field development</a> project. It's more likely that you'll be maintaining or enhancing an existing system, so it's important to be able to see in your mind how and where the different components connect.<br /><br />I've tried to answer questions like this before, but it's so difficult as a professional developer needs to have so many skills it's impossible to narrow down even a few as being the most important. But I guess when you're starting out in the business you need to:<br /><ul><li>Realise that you don't know anything</li><li>Be willing to learn<br /></li><li>Not be afraid to ask questions</li><li>Be able to analyse problems and visualise solutions</li></ul>Technical ability is of course important, but you need to interview well and show some potential to get a decent job out of it.<br /><br />A friend of a friend I met in sixth form college once claimed that he didn't need any computing qualifications to get a job, as his proven ability at writing his own programs would set him apart from everyone else. And admittedly he had written a lot of programs.<br /><br />Yet from an employer's point of view all that work he's done hasn't been in a commercial environment where change requests are common, priorities change, your projects are moved to other developers, and you're asked to work on projects of which you have no knowledge.<br /><br />The experience he had of writing programs didn't cover any of that, and being flexible enough to handle those situations is a very desirable attribute to employers.<br /><br />I don't know what he's doing now. Maybe he's carrying on doing what he wants and making a living out of it. But even if that worked for him it's certainly not a path I would recommend for people wishing to get a foothold in the industry.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-28280478656559084412008-01-10T16:44:00.000+00:002008-01-10T17:08:50.467+00:00Needle in a haystackBeen a bit quiet on the blogging front recently. That's mainly because I'm currently running through some tests for the first iteration of an update that will drastically change the architecture of the Esendex Messaging System. I can't go into detail about the change, but my current tests run into a <span style="font-style: italic;">very</span> intermittent failure.<br /><br />At irregular intervals one of the services hangs: just totally stops responding, and because it's multithreaded the log files aren't much help. Actually, its worse than looking for a needle in a haystack, as at least in that case you know what you're looking for.<br /><br />It first presented itself after sending only 100 messages, then after 2,000. An initial investigation didn't shine any light on anything so I sent some more messages. It hasn't failed again yet, and I've currently sent 15,000 through. No code change either, so the error is still in there waiting to be found.<br /><br />Frustrating is not the word.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-73911214948065452752008-01-03T16:33:00.000+00:002008-01-03T17:04:01.719+00:00Esendex Webservice SMS using C++C++ is not my main language, but all <a href="http://www.esendex.com/en/Developers/">Esendex developers</a> are expected to help our customers integrate their systems with ours on top of our usual development work.<br /><br />Admittedly we don't have many people asking for help with C++, but when they do we usually direct them to the <a href="http://www.esendex.com/en/Developers/SDKs/C-SMS-SDK/">C++ SMS SDK</a>. This includes a COM component which developers must install, and this fact does pose some problems for some developers.<br /><br />So, while waiting for a build I found <a href="http://weblogs.asp.net/israelio/archive/2006/06/11/How-to-Consume-WebService-via-unmanaged-C_2B002B00_.aspx">How to Consume [a] WebService via unmanaged C++</a>, which describes how you can get Visual Studio 2005 (and apparently 2003 as well, but I've not checked that), to generate a proxy for you.<br /><br />In Visual Studio 2005:<br /><br /><span style="font-weight: bold;">1. Generate the proxy:</span><br /><ol><li>Right click on the project in the Solution Explorer and click Add Web Reference.</li><li>In the dialog, enter http://www.esendex.com/secure/messenger/soap/SendServiceNoHeader.asmx as the URL, and give it a name<br /></li><li>Click Add Web Reference</li><li>This will generate a file in your project (with the name you gave it)</li></ol><span style="font-weight: bold;">2. Write code to call the proxy:</span><br /><pre><br /> SendServiceNoHeader::CSendServiceNoHeader proxy; <br /> BSTR result = NULL; <br /> HRESULT hr = proxy.SendMessageFull( CComBSTR("username"),<br /> CComBSTR("password"),<br /> CComBSTR("account reference"),<br /> CComBSTR("originator"),<br /> CComBSTR("destination"),<br /> CComBSTR("C++ Hello!"),<br /> CComBSTR("Text"), 0, &result);<br /></pre><span style="font-weight: bold;">3. Notes:</span><br /><ol><li><span style="font-family: courier new;">result</span> will contain the ID of the message you've just sent</li><li><span style="font-family: courier new;">hr</span> can be used to check if the operation was successful</li><li>You may need to include the line <span style="font-family: courier new;">CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);</span> before this code if your application doesn't already have it.<br /></li></ol>Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-14531163194268496672007-12-10T15:52:00.000+00:002007-12-10T16:05:48.646+00:00I'm afraid I'm a car snobMy car needed its second service today, which coincided with a planned shopping trip which i didn't really want to move. So I've got a courtesy car, and although it's almost brand new, clean, quiet and quite nice looking, there's no power there at all. I'm used to 200 horsepower and a turbo, now I've got an entry level 1.4 litre which is too heavy to ever be called nippy.<br /><br />But at least it's only temporary, hopefully I'll get mine back tonight or tomorrow.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com1tag:blogger.com,1999:blog-6691579676571716537.post-39928381667871915262007-12-06T16:59:00.000+00:002007-12-06T17:02:25.740+00:00UltraMonIf you're lucky enough to be using multiple monitors on one PC then check out <a href="http://www.realtimesoft.com/ultramon/overview/">UltraMon</a>.<br /><br />I've been using it for a couple of weeks now, and only just realised I can make Visual Studio span both screens, which means I can dock all the toolbars to one screen, leaving me with a full screen of code :).Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-40623440155334978442007-12-06T14:59:00.000+00:002007-12-06T15:32:24.031+00:00Neat Pattern for Cloning with InheritanceFor once I've come across an <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1911789&SiteID=1">MSDN forum post which exactly solves a problem</a> I had. I'm not having the same problem as the person who asked the question, but the solution given was spot on for me.<br /><br />Suppose you have two classes, SuperClass and SubClass, where SubClass inherits from SuperClass. If I want to create a deep copy of SubClass I should really implement a Copy method in SuperClass, and override that in SubClass.<br /><br />But if I do that I can't really use the Copy method in SuperClass, because I can't cast a SuperClass to a SubClass.<br /><br />The solution (as described in the above post: I can claim zero credit for this neat pattern), is to instead create a CopyFrom method, in which a SuperClass can be populated from another SuperClass. Then in the SuperClass's Copy method I create a new SuperClass, and call the CopyFrom method on it, passing in "this" (or "Me", if in VB.Net).<br /><br />Then SubClass can override CopyFrom and call into the base method, adding any further properties that SubClass has. SubClass then overrides the Copy method, creates a new SubClass, and calls CopyFrom before returning it.<br /><br />This is the code from the post above (credit to "nobugz"):<br /><pre><br />Class A<br /> Private DataA As String = "Data-A"<br /> Public Sub New()<br /> End Sub<br /> Public Overridable Sub CopyFrom(ByVal obj As A)<br /> Me.DataA = obj.DataA<br /> End Sub<br /> Public Overridable Function Clone() As A<br /> Dim NewA As New A<br /> NewA.CopyFrom(Me)<br /> Return NewA<br /> End Function<br />End Class<br /><br />Class B<br /> Inherits A<br /> Private DataB As String = "Data-B"<br /> Public Sub New()<br /> End Sub<br /> Public Overrides Sub CopyFrom(ByVal obj As A)<br /> obj.CopyFrom(Me)<br /> Me.DataB = CType(obj, B).DataB<br /> End Sub<br /> Public Overrides Function Clone() As A<br /> Dim obj As B = New B<br /> obj.CopyFrom(Me)<br /> Return obj<br /> End Function<br />End Class<br /></pre>Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com1tag:blogger.com,1999:blog-6691579676571716537.post-75995935049515576942007-12-05T12:17:00.001+00:002007-12-05T12:24:25.233+00:00Divx XBox 360 Dashboard Update December 2007If you've signed into XBox Live over the past couple of days you'll probably have been prompted to download a console update. I haven't yet found a complete list of everything that's changed, but I can confirm that <span style="font-weight: bold;">the rumoured Divx support has been included</span>. Yes, you can now stream Divx videos from a PC (running Windows Media Player 11) through your XBox so you can watch them on TV.<br /><br />The quality is surprising good from the what I've watched.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-18126899947638071892007-12-04T14:56:00.000+00:002007-12-04T15:05:37.897+00:00Bad Smells in CodeIf you've read anything by <a href="http://en.wikipedia.org/wiki/Kent_Beck">Kent Beck</a> or <a href="http://martinfowler.com/">Martin Fowler</a> you'll probably have come across the concept of <a href="http://sis36.berkeley.edu/projects/streek/agile/bad-smells-in-code.html">Bad Smells</a> in developing computer systems. Not every developer I know has heard of these though, or if they have they're not entirely sure what it means.<br /><br />In general terms it basically means that something just doesn't feel right in the code. But it can take a few years experience in writing code before you get to the point where you start getting this feeling, so I'm glad that a list of the common bad smells are listed for all to see.<br /><br />The list is by no means complete, but please <a href="http://sis36.berkeley.edu/projects/streek/agile/bad-smells-in-code.html">check out the most common bad smells</a>.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-44733631080143551812007-11-28T10:41:00.000+00:002007-11-30T16:11:46.697+00:00DLL DependenciesFound <a href="http://geekswithblogs.net/mwatson/archive/2004/01/29/1610.aspx">this blog entry</a> on <a href="http://geekswithblogs.net/">geekswithblogs.net</a> linking to <a href="http://www.dependencywalker.com/">Dependency Walker</a>. This is an application that shows you the dependancies that a DLL has.<br /><br />I couldn't get to the site though, so I <a href="http://www.majorgeeks.com/Dependency_Walker_d227.html">downloaded the app from majorgeeks.com</a>.<br /><br />There's a comment on that blog saying it doesn't work with .Net assemblies though, but you can just use <a href="http://msdn2.microsoft.com/en-us/library/f7dy01k1%28VS.80%29.aspx">ildasm</a> for that, and look in the manifest.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com0tag:blogger.com,1999:blog-6691579676571716537.post-42523626918824868132007-11-26T22:45:00.000+00:002007-11-26T22:49:16.135+00:00Blackwater (Jeremy Scahill)I'm currently reading <a href="http://www.amazon.co.uk/dp/184668630X?tag=iandyk-21&camp=1406&creative=6394&linkCode=as1&creativeASIN=184668630X&adid=0T3MMKY2HCHQTGQ87RZS&">Blackwater: The Rise of the World's Most Powerful Mercenary Army by Jeremy Scahill</a>. It recounts the history of <a href="http://www.blackwaterusa.com/">Blackwater USA</a> (<a href="http://en.wikipedia.org/wiki/Blackwater_USA">Wiki entry here</a>), the company employing a large proportion of the "security contractors" hired to protect assets in hostile places around the globe, such as in Iraq.<br /><br />The book begins by documenting the bloody ambush of Blackwater contractors in Fallujah in March 2006, and moves on to tell how the U.S. Government is increasingly using companies such as Blackwater to influence foreign policy where it would be politically unwise to use the U.S. Military. Scahill tells how Blackwater has set up bases in Tbilisi, Georgia and Azerbaijan which are now tantamount to having unofficial U.S. bases in the area, but without the political uproar.<br /><br />The book certainly makes interesting reading. In fact, what I find most enlightening is not how powerful and influential companies like Blackwater are, but rather the clear political wrangling that goes off behind closed doors, that common folk like me only get a hint about in the press.<br /><br />Scahill is obviously very passionate about this cause, and he has produced a seemingly well researched piece of writing that forces us to ask questions not just about our role in Iraq, but also asks us to cast an eye over other conflicts and places of political unrest. It is clear from the stories told in this book that our governments aren't giving us a true picture of what is happening in these places. But this is something a cynical, skeptical person such as myself already suspected anyway.<br /><br />However, the book could hardly be called impartial, and as such it loses much of the credibility it should be earning. Scahill's choice of language is constantly laced with emotive terms that will make it easy for any party opposed to his views to dismiss the entire book as left-wing propaganda.<br /><br />In choosing to write in this style Scahill has made a rod for his own back. What should be a chilling, hard hitting exposé on the U.S. Government's recent political choices is in danger of being wholly dismissed when the questions it raises deserve to be answered.<br /><br />If you can look past the occasional emotional phrase, and concentrate on the fully referenced source material, you can see a book which raises as many questions as it answers. Although I doubt answering these questions was ever Scahill's intention, in writing this book he has at least made public what is happening that other media sources aren't giving us a true picture of.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com1tag:blogger.com,1999:blog-6691579676571716537.post-24297826712633922642007-11-26T21:40:00.000+00:002007-11-26T21:53:51.763+00:00What does that error code mean?If you've ever come across an error number in managed code it can be infuriatingly difficult to find out the true root cause of your problem: normally there's a helpful wrapper around the numbers, giving (semi) meaningful names to the errors encountered.<br /><br />But, work with stuff long enough and you'll soon find a huge, dirty-looking (mostly negative) integer staring back at you in your log files or debugger window and you'll wonder "What the **** does that mean?"<br /><br />If you can't find anything on Google for the exact number you've got, paste the number into calc and convert it to hex. You'll usually get a number preceded by a bunch of Fs, which you can ignore. Do another search for this hex number (minus the Fs), and you'll sometimes get something which will point you in the right direction.<br /><br />It was on such a search where I stumbled across <a href="http://www.comp.nus.edu.sg/%7Ewuyongzh/my_doc/ntstatus.txt">this helpful document</a>. This text file contains a heap of hex error codes and their meanings. judging by the <span style="font-style: italic;">ntstatus.txt</span> file name they look to date back to Windows NT days, but they're still helpful now in some cases.<br /><br />I can't say that everything in there is accurate, or that every error code you'll get is listed there.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com1tag:blogger.com,1999:blog-6691579676571716537.post-56572490365045726282007-11-26T16:34:00.000+00:002007-11-26T21:38:14.602+00:00Creating an Interop Assembly for RTC Client API 1.3If you want to use the <a href="http://msdn2.microsoft.com/en-us/library/ms775893.aspx">RTC Client API 1.3</a> in managed code (like C# or VB.Net), you need to create an Interop assembly from the <span style="font-style: italic;">rtccore.idl</span> file that is found in the <span style="font-style: italic;">C:\Program Files\RTC Client API v1.3 SDK\SDK\IDL</span> directory (if you used the default installation path).<br /><br />There are some steps detailing how to create the assembly here: <a href="http://blogs.msdn.com/nnaidu/archive/2006/08/25/720795.aspx">Creating a Interop Assembly for RTC Client API 1.3</a>. However, I found that they were a little out of date and I had to do some reading around before I understood them.<br /><br />To create the assembly:<br /><br />1. Download and install the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en">Microsoft ® Windows Server® 2003 R2 Platform SDK</a>. This SDK works for "the x86, x64 and Itanium-based versions of Windows Server 2003, Windows Server 2003 R2, Windows XP SP2, Windows XP x64 Pro Edition, and Windows 2000".<br /><br />2. Go to the <span style="font-weight: bold;">Visual Studio 2005 Command Prompt</span> from Start Menu -> All Programs -> Microsoft Visual Studio 2005 -> Visual Studio Tools<br /><br />3. In the Command Prompt window, <span style="font-weight: bold;">change directory to where the rtccore.idl file is</span> (C:\Program Files\RTC Client API v1.3 SDK by default).<br /><br />4. In the Command Prompt type: <span style="font-style: italic; font-weight: bold;">midl /I "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include" rtccore.idl</span>. This will create 5 new files in the directory. One of which is rtccore.tlb.<br /><br />5. In the Command Prompt type: <span style="font-style: italic; font-weight: bold;">tlbimp rtccore.tlb /out:Interop.RTCCore.dll /namespace:RTCCore /sysarray</span>. This will create an Interop.RTCCore.dll file in the directory, which you can then reference in your .Net applications.Ian Dykeshttp://www.blogger.com/profile/08235675789374664427noreply@blogger.com2