Thursday, September 27, 2007

Is ploughing like software development?

Jonathan's blogged about a quote from Joe Berkovitz seemingly comparing software development to agriculture: Is ploughing like software development?

While I too wonder at this strange analogy, development is sometimes like running on a ploughed field: requiring lots of energy, getting nowhere fast, and when you look back you've just made one hell of a mess. ;)

Wednesday, September 26, 2007

Visual Studio 2005 Automation Samples

Guess I should have looked at creating a Visual Studio plugin first rather than figuring out how to convert RTF to HTML. I might not need to do that judging by the description of one of the Visual Studio 2005 Automation Samples:

Generate HTML
This sample demonstrates how to take text from the editor window and build a HTML file using this text, including font and color syntax highlighting information.

Haven't downloaded this yet, but I will do. Sounds like the Blogger code upload plugin could be quite easy to implement.

I found this page linked from the Customize and Extend Visual Studio page on MSDN.

UPDATE: Ahh, the Generate HTML sample is actually in C++, not C#. Should still be able to use it as a guide though, just need to figure out what objects to use.

Nottingham isn't that far from New York then

Driving home yesterday was an experience to say the least. Where the ring road around Nottingham meets the A610 was the scene of chaos. So much chaos that I found myself laughing at it so I didn't get annoyed with the stupidity of the people involved.

The A610 heading out of Nottingham was grid-locked completely. So much so that when the traffic lights changed to red there was still traffic on the junction, and that traffic had nowhere to go. It effectively cut off the ring road.

Normally this isn't a problem, but I think there must have been something in the water yesterday. Horns were sounded, tyres screeched, cars swerved into oncoming traffic--I particularly liked the van driver who did a racing start when the ring road's lights went green, even though 10 feet in front of him was a line of traffic that could not go anywhere.

He slammed on the brakes and swerved into another lane, cutting up a car and resulting in more horns being sounded.

I didn't want to add to all of this mayhem, so I turned around and went home another way.

I always find it curious when people get angry over things that no one has any real control over, and which aren't particularly important anyway.

Tuesday, September 25, 2007

RTF to HTML and the GData API

Finally got around to properly extracting the RTF conversion code from AutoFormatter last night. It turned out to be as easy as I thought, after last time's wasted efforts. I've had a look on Robert Verpalen's blog for some contact details, but I can't find any and the AutoFormatter post doesn't seem to allow comments.

I might have to leave a comment on another one of his other posts, but the date on the AutoFormatter post is December 2005, so I don't know if he's maintaining it now. Doesn't seem to be any posts since then about the application anyway.

I think I'll wait until I have something usable first though.

Anyway, with that extracted I downloaded the GData API SDK and tried to connect to my blog. The sample code included is very helpful, but it still took a little time to get my head around. I eventually knocked up some code that would add a new draft to my blog, so I think I have everything I need to make the plugin now.

Now I just need to learn about how to make a decent plugin.

Comics Britannia on BBC4

I watched Comics Britannia on BBC4 last night, an episode that focused on more modern comics, ones which a parent probably wouldn't want a young child to read.

I'm not what you call a comic geek, but I've read a couple of the more "adult" orientated comics (and graphic novels), so I found last night's programme very interesting.

A pleasingly large section of the programme was devoted to Alan Moore. His V For Vendetta, Watchmen and Lost Girls (which is not one I'd recommend for the easily offended) are among my favourite books of all time, so it was interesting listening to the man himself talk about his creations.

I think I got into this series a bit too late, so I'm looking forward for a repeat showing sometime soon.

Friday, September 21, 2007

Trying to Extract Features from AutoFormatter

I took a look at the AutoFormatter code last night, and tried to make a start on extracting the code that does the conversion into a class library.

I can't say it was an easy task though, and at the end of it all I found I'd done it wrong anyway. What I really need is a class that just converts RTF to HTML, but I had extracted the method that creates the div blocks around the code as well. Surrounding the code in this way does make the end result nice and pretty, but for the purposes of a generic conversion library it's not needed.

It was about 11 o'clock last night when I figured this out. It's always a little disheartening when you find you've just spent the last 3 hours doing something that you now need to discard.

Guess that's what happens when you try to modify code without truely understanding it. I can't see any unit tests in the code to give an indication of the intention of some of the code, or to provide a safety net to the quite severe refactoring that I am attempting.

But I think extracting the RTF to HTML code should be easier than what I did last night. There were a number of options I needed to extract into a class and pass into the method last night, but I'm sure I don't need all of this for the straight conversion.

I'll see how it goes.

Thursday, September 20, 2007

Formatting Currency to Pence and Cents

Almost anyone will know how to format a decimal to a currency string. It's nice and easy to make a number like 1.25 format like £1.25, (or $1.25 if you're using a CultureInfo that has a dollar CurrencySymbol in its NumberFormatInfo.

But, say I have the decimal 0.06, and I want this to format to 6p. Or I might have 0.065 which I want to show as 6.5p.

How do I do that?

I understand I may need to multiply this decimal by 100 to get the whole number of pence, but how do I know which symbol to append? Plus, how do I know which end of the string the symbol needs to go?

There is nothing in a NumberFormatInfo that describes these things. The CurrencySymbol gives us our $, £, €, etc, but where's the pence and cents symbols?

Any ideas?

Right now we've got a workaround in place that works, but shouldn't this be a part of the NumberFormatInfo?

I've posted a question on the MSDN Forums about this.

UPDATE: Kevin posted a question on the MSDN Forums for this as well, and got a more satisfactory answer than I did.

Read that post here.

Wednesday, September 19, 2007

RTF to HTML: AutoFormatter 2.0

Visual Studio copies code from the editor in RTF format, so technically all you need to do is convert RTF to HTML in order to upload it to a blog post, which will form part of the plugin, if I ever get around to making it.

Looking around last night I found AutoFormatter 2.0. This is a .Net 2.0 application written in C# that does a neat job of doing exactly what I need. The HTML it produces is in a scrolling DIV, formatted in Visual Studio colours, and looks quite nice.

In fact, as a standalone application this is just what I need to post code samples, but I started down this path to try the GData API with a Visual Studio plugin. I'm hoping to use part of AutoFormatter to do it though.

If I can extract the conversion code from the AutoFormatter app into a standalone assembly, then theoretically I should be able to use it from the plugin. The code is available for download, and I made a start at extracting the required elements last night. If I can get this working then that's a big chunk of the work done I think.

I'll get in touch with AutoFormatter's author if I manage to get the core functionality extracted to a separate assembly. Hope he doesn't mind.

Creating Visual Studio Plugins

This is more of a reminder to myself than anything else: Exploring Extensibility: Your First Visual Studio Add-in.

I found it at about the same time I was looking into the GData API, and I had an idea about creating a plugin to Visual Studio which would allow you to upload a code snippet to a blog post, and have it fully formatted so it was readable.

Still might do it, but I'm not sure how indepth the wizard approach will be. I'll probably end up with a standalone application that you paste code into and then upload it.

What's the carbon footprint of a potato?

BBC News is running an article about the carbon footprint of Walkers Crisps: What's the carbon footprint of a potato?

Seemed like a rather spurious thing to blog about at the time.

Configure an Assembly in .Net 2.0

Found this article for an example on redirecting an assembly's version via the App.config file. In .Net 1.1 it was easy to do this as there was a GUI to let you redirect all version bindings to a different version. You still get this GUI if you have the .Net 2.0 SDK installed, but you don't get it with the .Net 2.0 Redistributable.

This way you only redirect specific applications rather than your entire system.

Monday, September 17, 2007

Using UDP in XNA

I've had an anonymous comment left on a UdpClient post asking if I have used the UdpClient in an XNA game. Well, no I haven't--and to be honest I've not used the class much in anything else either. In fact that previous blog entry was posted after pairing with Nick on a bespoke application for a customer of ours.

But, the question got me thinking about it anyway. The comment says that they have a piece of code using the UdpClient that works in a normal .Net application, but when included in an XNA game, it no longer receives anything.

Now, I can't see why this would be the case if you are compiling to a Windows game. A Windows game is just running on the standard .Net framework, so everything should be OK. However, XBOX 360 games will run on a variation of the .Net Compact Framework, so there is a difference there to be aware of.

So assuming you're making a Windows game, why should the UdpClient now not work? Well to start I made a normal console application with the code snippet posted in the comment, and tried to get that to work. I made a separate console application to use as the sender.

And that's when the problem struck--one which I should have seen at first glance anyway. If you try to have multiple applications on the same computer accessing the same port using UdpClient you will get an exception that says "Only one usage of each socket address (protocol/network address/port) is normally permitted". (Read this article for a bit more information).

The only way we've found to stop this happening is to not use UdpClient at all, but to create Sockets yourself and use those instead.

However, I thought there must be an easier way--someone must have solved this problem before. And it looks like someone has.

I've not had a look at it in much depth, but if you want to send and receive UDP packets in XNA then take a look at the lidgren-library-network, which is on Google Code.

I don't know whether this uses UdpClient under the hood or not, but it has an XNA extension for sending Vectors and Matrices so it must have been used in some XNA games somewhere along the line.

Check it out and see if it helps.

Ajax onreadystatechange Arguments

Having not used Ajax that much I was surprised to see that the function you declare for the onreadystatechange event could not take any arguments. I thought that this was a bit of a limitation as it meant that if you wanted that function to use any external data you had to declare that data globally, which has always been a big no-no in my book.

Global data when it's not needed always leads to a lot of pain in my experience.

But despair not, there is a way to pass arguments in. As Javascript supports anonymous methods you can create a new method inline, and then call another function from there--one that does have the arguments.

Take a look at this article if you're still stuck.

A Day For Winning

I got back from a week's holiday this morning to find that I had not only won Esendex's new strapline competition, but I've also taken the spot prize in the Esendex fantasy football mini league.

Maybe I should go and buy a lottery ticket ;)

Friday, September 07, 2007

How C# 3.0 and LINQ Evolved

Starting Visual Studio today the Start Page's MSDN feed pointed to this article: C# 3.0: The Evolution Of LINQ And Its Impact On The Design Of C#.

It describes the separate language additions that were required to make LINQ work, and is well worth a read in my opinion.

Having been introduced to C# and LINQ at Tech Ed earlier this year I'm itching to try some of it out when I get the chance.

My Internet is back

I've now got a new cable modem, and things are eventually beginning to look up on the internet connectivity front. I'd had that modem since about 2004, and the engineer thought it was time to get a new one.

It's much smaller than the old one. We'll see how it goes on the reliability front.

Tuesday, September 04, 2007

Internet Problems Update

Apparently my internet provider think the connection problems are because my modem is broken, and they are sending an engineer around with a replacement on Thursday afternoon.

We'll see if this fixes the problem.

Essential SQL Server Date, Time and DateTime Functions

Just found this article on Essential SQL Server Date, Time and DateTime Functions. Has some handy functions you can add to get the following:

  • Get just the date part of a DateTime value
  • Get the time part of a DateTime value
  • Create a DateTime value with explicit Day, Month, Year, Hour Minute and Second parts
  • Create just a time value (with the date section set to a 'base' date)

Angry with No Internet

I had a plan to play with the Google Blogger API last night in order to write an application that would allow me to upload code samples to this blog more easily than at present, but as I got home my internet connection was down yet again.

I won't name the company in question, but I connect to the internet at home through a well known supplier here in the UK, but just recently the levels of service I've been receiving have been shocking. I'm having to reboot the cable modem on a daily basis whereas before a few weeks ago I rarely, if ever, had to do this.

And it appeared that last night was going to be the same. Switched on the laptop, watched AVG try (and fail) to update itself, followed by the GMail Notifier's exclamation mark proclaiming it couldn't establish a connection. So off I trudged, yet again, to unplug the cable modem. Wait two minutes. Switch cable modem back on. Off I trudged back to my laptop.

Still no connection.

Sigh. Unplug cable modem again. Wait 10 minutes this time. Switch back on. And nothing.

So I phone their customer services number, only to be told I must pay a 10p connection fee, and then it would be a 25p a minute phone call... How can any company think it's a good idea to charge premium rates for requesting help? This is worse than the company who demand payment to fix bugs in their software! It wouldn't be so bad except this company is notorious for leaving you on hold for at least 20-30 minutes.

Gritting my teeth I resorted to emailing them... but can I find an email address to send to? No. I looked back through the recent bills for one, but there's nothing there.

I pulled out the emergency DKU-2 cable I have and connected my Nokia 6230i to my laptop. Nokia PC Suite allows you to connect to the internet over your mobile phone, so I connected and went to the offending company's website. The only thing I could find was a General Enquiries email form--and I'm pretty sure that won't be monitored out of office hours.

So, no service, no free help on the phone, and seemingly no way of requesting help through email.

I think it's about time I switched suppliers.

Monday, September 03, 2007

Calling all drivers (in the UK at least)

Try out the BBC's Highway Code Quiz.

I'm not going to gloat over my 10 out of 10 score though, the questions didn't seem too difficult.