Tuesday, October 30, 2007

Using Sharepoint activities in a workflow designer

If you're hosting the Windows Workflow designer control in your own application (this shows you how to host the control) and you want to use the Sharepoint activities, these are the files you'll need (these are for Sharepoint Services, I think there are more activities for MOSS 2007).

Microsoft.SharePoint.dll

Microsoft.SharePoint.Security.dll

microsoft.sharepoint.WorkflowActions.dll

microsoft.sharepoint.WorkflowActions.intl.dll

microsoft.SharePoint.workflowactions.intl.resources.dll

I'm not sure of the rules regarding redistribution of these files since I'm only using it for my own personal use. If you're having trouble getting any of these files out of the GAC then read this post which explains how to get them out.

Monday, October 29, 2007

MSDN forums not very useful

How hard can it be to write some code for a web forum? After all it's a problem that has been solved thousands of times before. Well apparently it's too hard for Microsoft. I've been trying to post to their MSDN forums for the last week and whenever I try to create a new thread or reply to a thread I get the following error message.forums

 

 

 

I've tried clearing out all the crud from IE, with no joy. So I'm forced to kick off a Virtual PC session to post, not very handy.

Not only that, when I get an email alert telling me about a reply to my post, the link starts with 'h ttp://forums.micro' so it doesn't fecking work.

A no-op activity

I'm in the process (no pun intended) of converting one business process XML language to XOML via some XSLT. I'm not really sure how some of the source activities will map to Windows Workflow activities so I'd like a no-op activity for the time being, just so I get the correct layout of the process, without having to nail down all the details. The solution is actually very simple, just use the base Activity class whose Execute method does nothing, simply returning ActivityExecutionStatus.Closed. Although it's not available in the Visual Studio toolbox, Visual Studio copes quite happily with a XOML file that contains an Activity activity.

Sunday, October 28, 2007

Web applications aren't the solution to every problem

I've been working on an ASP.NET website for a while now. For the admin side of things, I've added a few pages for updating the database and such like. There have always been problems with updating the data, which is read in from some text files and then dumped in the database. First there were problems with the size of the data in the files, which was solved initially via the maxRequestLength attribute in web.config. Then the file upload to the web server was still taking a long time so I started to require the data to be uploaded via Remote Desktop or FTP. Then I had problems with the SQL update timing out. This was solved by increasing the value of the executionTimeout attribute in web.config. But after a while even this didn't work and the update failed when the request timed out. I could probably increase the timeout some more or I could use some other technique to get it working, but I eventually came to the conclusion that this just isn't what I should be doing. ASP.NET sets these values quite low for a reason, it's just trying to protect itself from poorly written applications. A request to a web server should take as short a time as possible before getting the hell out of there. That's what the web sever is designed to handle.

So I ripped out the code and dumped it in a WinForms application. WinForms has no problems with threads that hang around for a long time so that solved my initial problem. And, even better, I can give feedback to the user very easily, without fiddling round with AJAX. It's also more secure. Remote desktop connections to this server are only accepted from certain IP addresses, whereas anyone might find the admin pages (even though they are password protected).

So to the moral of the story, remember that not every problem is a nail and there are other tools in your toolbox other than the hammer.

Thursday, October 25, 2007

The problem with LINQ

In principle it sounds like a great idea. Rather than having to learn SQL, XPath and whatever other query language you care to mention, just learn LINQ and use it to access any data source you like. That's great and all, if I'm using .NET 3.5 for every single project I work on. And until I am (which I'm guessing will be, er, never), LINQ is actually yet another thing to learn. So now I need to know SQL, XPath and LINQ. Or perhaps not, perhaps best to just forget LINQ and stick to the old stuff, since it works and is available on most platforms. When LINQ is available everywhere, then I'll start to think about learning it. 

Tuesday, October 23, 2007

MySQL error messages = crap

OK, it's an old version of MySQL (4.0.25 to be precise) but the error messages are completely useless. Almost any kind of SQL syntax error shows this helpful message.

#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT PubID FROM Pubs )  LIMIT 0, 30' at line 1

Of course the problem is that MySQL 4 doesn't support subqueries (!), apparently MySQL 5 does and perhaps my ISP will upgrade one day...

Monday, October 22, 2007

SonicWall VPN client for Vista released

My post about the SonicWall Vista client beta is one of the most popular things on here, lord knows why. Anyway, the final version has been released and it is working perfectly for me. I've not had any problems with Vista complaining about two computers with the same IP address being connected to the network. I realise I'm really tempting fate writing that...

Friday, October 19, 2007

Licensing

Somebody emailed me asking what the licensing terms were for some code he'd found. I was surprised somebody would bother asking since I tend to assume any code I find on the web is public domain (although I wouldn't dream of stealing somebody's prose - odd how I think of code differently to the written word). But of course this isn't necessarily the case. In fact I believe if no licensing terms are explicitly stated, the code is by default copyright of the author.

So to clarify the licensing for anything on this site, any code samples are public domain. Do what the hell you want with them. I do however claim the copyright for the English on here, not because I think it's particularly valuable but because I don't want spammers stealing it for their own sites. Not that a little copyright theft is likely to stop them of course, but I don't want to make it perfectly legal for them either.

Whether any of this is legally binding, who knows, but I'm definitely not hiring a lawyer to tell me either way.

Improved Excel-like select all in a DataGrid

My first attempt at this worked mostly but if the user clicked anywhere in the grid that wasn't a cell, the whole grid would be selected, which wasn't what I was after. So here's an improved version which will only select all when the user clicks in the top left cell.

    public void SelectAll()
    {
      BindingManagerBase bm = BindingContext[DataSource];
      for (int i = 0; i < bm.Count; i++)
      {
        Select(i);
      }
    }

    protected override void OnClick (EventArgs e)
    {
      base.OnClick(e);
      Point client = PointToClient(Cursor.Position);
      HitTestInfo hitInfo = HitTest(client);
      if ((hitInfo.Column == -1) && (hitInfo.Row == -1))
      {
        if (client.X < TableStyles[0].GridColumnStyles[0].Width)
          if (client.Y < TableStyles[0].PreferredRowHeight)
            SelectAll();
      }
    }

Friday, October 12, 2007

Radiohead's pay as much you like strategy

I had every intention of buying the new Radiohead album from their website. After all, they've done exactly what I've asked for. It's DRM-free and the price is reasonable (since it's whatever I consider to be reasonable*). But I had some problems. First the site constantly timed out when I tried to connect yesterday (which I guess is a good sign since it suggests they are getting a good number of hits). When I did manage to connect and I registered, I was asked for my mobile number, which was a required field. Er, I don't have a mobile. And if I did, why do I need to give the number to you?

Unsurprisingly, the album is pretty easy to find from illegitimate sources and there are no hoops to jump through to get it from those sources. So if I wasn't fussed about a bit of copyright infringement, that's what I'd probably do.

It's clear the music industry and Radiohead are still missing the point about downloading music. Price isn't the key issue, although it's important (iTunes' pricing is completely screwed, I might as well buy the CD). Downloading has to be as easy, if not easier than the illegal alternatives.

*Since I've been disappointed with every Radiohead album released in the last ten years but have kept buying them in the hope they would repeat the brilliance of 'OK Computer', a reasonable price for me would probably not be very high.

Wednesday, October 10, 2007

Words that annoy me

Spelunking - This word comes from the caving community, the weird guys who like to go down small wet holes at the weekend (fnar, fnar). They may be weird, but their sport is kind of dangerous and possibly exciting. Now the geek community have appropriated the word to describe, er, groping around in new technology or source code. It seems to be a desperate attempt to make IT sound much more interesting than it really is. Look, computing is not cool, get over it.

Grok - What is wrong with 'understand'? It's been in the English language for quite some time and everybody (including normal, non-geek people) knows what it means. Also see above.

Regards - Email and the web have always seemed pretty informal to me. There was a time in about 1990 when I ended emails with some kind of sign off, but now I find my name is plenty to mark the end of a message. So when I see 'regards' (or worse 'kind regards'), I think that the person sending that message has some kind of problem. In fact, I wonder why they are being so formal and wonder if they are implicitly telling me to feck off.

Consumer - Is that all we are good for? Buying more tat to help fuel the economy? I am not a consumer, I am a person. When I think of consumers, I think of Fight Club - "working jobs we hate so we can buy shit we don't need"

Tuesday, October 02, 2007

Excel-like select all in a DataGrid

Clicking on the top-left cell in Excel selects the whole worksheet, which always seemed like a good use of an otherwise useless cell. So I've done the same with the DataGird-derived control I've been using in one of my apps. It's pretty damn simple to implement, but for the lazy amongst you, here's some code.

    public void SelectAll()
    {
      BindingManagerBase bm = BindingContext[DataSource];
      for (int i = 0; i < bm.Count; i++)
      {
        Select(i);
      }
    }

    protected override void OnClick (EventArgs e)
    {
      base.OnClick(e);
      HitTestInfo hitInfo = HitTest(PointToClient(Cursor.Position));
      if ((hitInfo.Column == -1) && (hitInfo.Row == -1))
      {
        SelectAll();
      }
    }

Tuesday, September 25, 2007

A simple 'Check for updates'

My brother asks when I'll post something interesting on here, but it hasn't happened yet so I doubt it will anytime soon... Anyway it seems the most boring posts are the most popular so I'll keep on posting crap.

Back to the point of this post. Lots of applications these days will check for an update when they start or when you press a 'Check for updates' button or menu item. Some really annoying applications have some little helper process that runs continuously and checks on a regular basis then throws up a big dialog telling you that there's an update (that's you Apple).

Not wanting to be left out, I thought I'd do the same. But being incredibly lazy, I couldn't be bothered to implement it completely. So this little bit of code will read a text file stored on the web server and tell the user that an update is available. It won't do anything fancy like download it for them or install it but I might add that at some point. Usage is simple, set the Url property to tell the component where the text file is stored, then call CheckLatestVersion() to show a message saying there is a new version available.

 

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Reflection;
using System.Windows.Forms;

namespace FreeFlowAdministrator
{
    /// <summary>
    /// Component to check for updates for an application.
    /// </summary>
    public class UpdateChecker : System.ComponentModel.Component
    {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public UpdateChecker(System.ComponentModel.IContainer container)
    {
      ///
      /// Required for Windows.Forms Class Composition Designer support
      ///
      container.Add(this);
      InitializeComponent();
    }

    public UpdateChecker()
    {
      ///
      /// Required for Windows.Forms Class Composition Designer support
      ///
      InitializeComponent();
    }

    /// <summary> 
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }


    #region Component Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      components = new System.ComponentModel.Container();
    }
    #endregion

    private string url;
    public string Url
    {
      get
      {
        return url;
      }
      set
      {
        url = value;
      }
    }

    public string GetLatestVersion()
    {
      HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

      // Sends the HttpWebRequest and waits for the response.
      HttpWebResponse myHttpWebResponse = myReq.GetResponse() as HttpWebResponse;
      try
      {
        Stream response = myHttpWebResponse.GetResponseStream();
        StreamReader readStream = new StreamReader(response, System.Text.Encoding.GetEncoding("utf-8"));
        return readStream.ReadToEnd();
      }
      finally
      {
        // Releases the resources of the response.
        myHttpWebResponse.Close();
      }
    }

    public void CheckLatestVersion()
    {
      string latestVersion = GetLatestVersion();
      string currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
      if (latestVersion == currentVersion)
        MessageBox.Show("You are using the latest version");
      else
        MessageBox.Show(string.Format("The latest available version is {0}\nYou are using version {1}", latestVersion, currentVersion));
    }
  }
}

Thursday, September 20, 2007

Getting directions using Google Maps

I'm not sure when this feature was added but Google Maps now lets you drag your route around, if you want to go via a particular place. I'm not sure how useful this will be for me, but it's certainly cool to play with. Saying that I have asked for a web app to create Google Maps routes previously, and this is certainly heading in the right direction. It's possible to embed the map in a web page via an IFrame pretty easily, but I can't add markers and images, so not quite there yet. I was going to embed the route of my bike ride today but of course it doesn't understand about going off road or, erm, going through pedestrianised areas so I didn't have any luck with that.

Another great new feature is the information about bus departures, although weirdly I'm only seeing these in my local area, Kingston. It seems to be getting its information from Transport Direct, a website I've never seen before, but that looks like it goes some way to fulfilling my request for a site with complete knowledge of all the different transport options. It seems to be missing some pricing information but it knows about trains, buses and cars. Depressingly enough, cars are always cheaper than the more environmentally friendly option. Saying that, it claims a 200 mile journey by car is more environmentally friendly than the train, if the car has 4 occupants. But the train will be running anyway and using just the same amount of CO2, so what to do?

Some time ago I complained that Google Maps' directions to Heathrow from my house were completely ludicrous. Well it looks like they've fixed that as well, I'm sure they must have read my post...

Wednesday, September 19, 2007

Buy a people carrier

PeopleCarrier It got us to Spain and back in one piece with not a hiccup, but now it's time to pass our trusty vehicle on to someone else. If you're interested then check it out. All reasonable offers will be considered.

Monday, September 17, 2007

More reliable wireless

When I set up our wireless router, I initially set it up as an unsecured network and restricted access to certain MAC addresses. This worked fine but when we had visitors who wanted to use our wireless connection, it was a bit of a pain to allow access to their laptop. So I changed the router's configuration so it used WPA security and it all seemed to be working fine.

But then a couple of things happened which I didn't realise were related to this seemingly simple change I'd made. First, the wireless connection would stop working every few hours. This affected any computer connected to the network and would typically last a few minutes and then everything would be fine again. This was particularly annoying when I was connected to somebody's VPN and would have to re-establish a connection. The second problem was my Vista PC started to lock up completely. This was less frequent, about once a day.

I put the first problem down to the number of wireless networks in close proximity to our house. I guessed that they were just interfering with each other and causing the connection to drop every so often. Either that or our router was just getting on a bit. Then the other day I thought I'd give Vista's wireless diagnostics a spin and it told me the wireless security key was incorrect. What the...? This kicked my befuddled brain into action and realised these connection problems had started at the same time as the switch to WPA. So I switched back to an insecure network and lo and behold, the wireless connection is working a treat. Not only that but I haven't (fingers crossed) had a Vista freeze since the switch back.

So, if you're having wireless troubles, consider switching to an insecure network. I guess it may well be specific to my router but it may just work. Yeh, hackers can probably read my email, but frankly I hope they have more interesting things to do with their time.

Sunday, September 16, 2007

Are we in a fast moving industry?

It's virtually taken for granted that we work in a fast moving industry and the facts would appear to back up this theory. Just look at the new programming tools coming out of Microsoft (I'm just going to talk about them since I don't really even try and keep up with technology coming out of other companies). In no particular order, some of them are: WPF, WCF, WF, Silverlight, Linq, CardSpace, Virtual Earth, ASP.NET AJAX, Vista...

But hang on a second, who is using this stuff and how much of it will be relevant in five years time? Myself, the only new technology I'm looking at is Windows Workflow, since it may well be useful in my job. The rest may become relevant at some point and if and when it does I'll start looking at it then. And I'm a  geek who likes to fiddle around with new technology. What about the normal people out there who aren't obsessed with software?

Well, it doesn't look so good there either. Take IE7, which has been out for almost a year. Usage stats on the sites I maintain suggest just over 30% of IE users have upgraded to version 7. This is a free bit of software, but still almost 70% of users haven't upgraded. Admittedly some of these will be corporate users who have probably decided not to roll it out yet, but why not? Probably because IE6 is good enough, thank you very much.

And what about Vista? Well I'm seeing just short of 5% of Windows users are on Vista, which makes it somewhat more popular than Server 2003 (and who browses the internet from Server 2003 anyway?) but still less popular than Windows 2000 which, as the name suggests, is about 7 years old.

Here's something else to illustrate my point. I was up the loft the other day and found the notes for a C++ course I went on about 10 years ago. Flicking through them I realised I should probably keep hold of them, since they were still relevant today. Not only were they useful to C++ programming, but also to C#. The basic ideas behind object-oriented programming still apply. And you know what, if I still had the notes for my university C++ course from 17 years ago, they would probably still be relevant as well*

So yes, it's certainly possible to think we work in a fast-moving industry and it's certainly possible to work as if everything is in a constant state of flux. But it's also possible to move into a slower lane and just watch the shenanigans going on from a distance, wait for the dust to settle and learn the stuff that actually becomes important.

 

*You may be wondering why I needed to go on a C++ course when I was working if I'd already been taught it at university. Well I never paid much attention at uni, I was more interested in getting drunk and trying to pull young ladies...

Tuesday, September 11, 2007

Handling 404 errors in PHP

If you're running a PHP site on your own server, you can find out what 404 errors have occurred by viewing the log files. If, like me, you're running your PHP site on a cheap and cheerful host, you're probably not going to have access to the log files. But you can probably still do something to find out about them.

The first thing to do is ensure your users see a useful error message, rather than the default provided by your host, which will probably be some page advertising their services. This can be achieved via the .htaccess file, if your site is running on Apache. IIS has similar features, available through its admin tool (although I can't believe there are many people using PHP on IIS). Add something like the following to the .htaccess file to tell Apache to show your custom error page.

  ErrorDocument 404 /error.php

The next thing to do is to make sure you get notified if somebody ends up on a non-existent page on your site, so just add the following code to error.php somewhere.

  
  $message = "URL: " . $_SERVER["REQUEST_URI"] . "\n" . "Referrer: " . $_SERVER["HTTP_REFERER"] . 
    "\n" . "Browser: " . $_SERVER["HTTP_USER_AGENT"];
  mail("you@wherever.com", "404 error", $message);

And that's that. Well except the referrer doesn't seem to work for me... But it's already been useful, I've found one spurious bit of CSS trying to load an non-existent image, although I've also had quite a few false positives.

Friday, September 07, 2007

Yet more tick mark fun

I've written about this three times now. Read my previous posts here

But it turns out it's not as simple as the browser somebody is using. The other day I noticed that my tick marks weren't displaying on a computer that had IE7 installed. After more fiddling around I realised the fonts installed on that particular PC must be different to the ones installed on other PCs I'd tested and IE7 was unable to find the tick mark. I'm not sure whether IE7 only uses the current font or if it tries other fonts in an attempt to find the correct symbol but in any case it just displayed a square block.

Because of this I'm thinking perhaps the only 100% reliable solution is to either use an image or to display a checkbox in all situations, not just for IE6. In a desperate attempt to avoid either of those solutions, I've started using the 'Arial Unicode MS' font for my document. I guess this is fairly unlikely to work on Macs and Linux boxes, but they aren't particularly high on my list of required supported environments and they will fall back to more conventional fonts anyway, which hopefully work for these computers.

Update: Even the ‘Arial Unicode MS’ font won’t always work, even on Windows. This font is not installed by default on Windows systems, but it does come with Office, which I guess most Windows users will have installed.

Sunday, September 02, 2007

Road trip map

After some fiddling around with Google Maps I've managed to come up with a little map of our journey through France and Spain. It would be way cool if somebody came up with a web app that could be used by normal people to do this kind of thing...