Wednesday, April 22, 2009

Adding Street View to web pages

Street View has been available for a while but it didn’t interest me too much until recently when it launched in the UK. Then I noticed it was available as a part of the Google Maps API so I decided I’d add it to the Random Pub Finder. I initially thought it would work like the user interface available on the Google Maps website, but it doesn’t seem such an integrated solution is possible. To be fair, dragging the little man around your map probably isn’t what you’ll want to do generally so this isn’t a big issue, and if you’re clever you could probably implement this kind of solution anyway. I was pleased to find it was very easy to add to the site. First add a div to your page that will contain the Flash control

  <div name="pano" id="pano" style="width: 750px; height: 300px">
    <div id="panoError" style="text-align: center; margin-top: 100px;color: #aaa;">Loading...</div>
  </div>

Then add  a reference to the Google Maps API script.

<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAjtZCgAx5i04BiZDO6HlxhRSDF8NMhBf90dVWYNzYEfop4QQs3RSkYVE7vnmvtIBRRQjoFXq4kz15Mg" type="text/javascript"></script>

Finally add some JavaScript to initialise the control.

    function load()
    {
      var latLong = new GLatLng(51.412640159832, -0.30039334012124);
      var panoramaOptions = { latlng:latLong };
      var myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
      GEvent.addListener(myPano, "error", handlePanoError);
    }

    function handlePanoError(errorCode)
    {
      var error = "An error occurred";
      if (errorCode == 600)
      {
        error = "No street view available";
      }
      else if (errorCode == 603)
      {
        error = "The Flash plugin is not available";
      }

      document.getElementById("panoError").innerText = error;
    }

Actually a lot of this JavaScript isn’t even needed, you can get away with just the first three lines of the load function, but the rest is useful for error handling. Error 600 can happen quite frequently so is best handled in some manner. I’ve not seen error 603 myself but I’ve shown it here because some of the code examples I’ve seen use the constant FLASH_UNAVAILABLE, which doesn’t seem to be defined anywhere, meaning when any error occurs you’ll actually get a script error if you use this constant. I guess there are more errors that can occur but I’ve not come across them yet.

Friday, April 10, 2009

Renaming a user in Metastorm BPM

Rename Metastorm user

People change their names for all sorts of reasons, marriage being the most common, but there are plenty of other reasons, such as a change of religious belief or wanting to get rid of an unfortunate surname. Whatever the reason, the Users and Roles utility that ships with Metastorm BPM doesn’t have any support for changing user names. The FreeFlow Administrator can help out here. Just fire it up, change the user’s name and apply the changes. This will change the user name in all relevant Metastorm tables. However it can’t change every reference to that user. For instance if you’ve stored a user name in a custom variable, that won’t get updated, since there isn’t really any way of knowing that the custom variable value refers to a user.

This can also be achieved programmatically. This may be useful if your corporate standards have changed and you need to change every user’s name in the system. Or you may want to prefix the users’ names with the domain name because you’re moving to SSO. Whatever the reason, here’s some sample code to achieve this.

using System;

using FreeFlow.Administration;

namespace ChangeAllUsers
{
  class Program
  {
    static void Main(string[] args)
    {
      Server server = new Server();
      server.Connect("sa", "a", "Metastorm");
      foreach (User user in server.Users)
      {
        Console.WriteLine("Processing " + user.Name);
        user.Name = "domain\\" + user.Name;
        user.ApplyChanges();
      }
    }
  }
}

Monday, April 06, 2009

Documenting Metastorm procedures

You may be aware of the procedure documenter produced by Process Mapping, the company I work for. If not, have a look. It’s a Designer add-in, which means a menu item is added to the Designer’s Tools menu that kicks off the documenter and generates the HTML documentation. I spent a little time today extracting the HTML generation code from the add-in assembly into a separate assembly. This means that the code can be called from anywhere you like, which leads to the possibility of automating your documentation generation. Combine this with FreeFlow and you can automate the documentation of all your published procedures. The following console application demonstrates how this could be achieved.

using System;
using FreeFlow.Administration;
using ProcessMapping.ProcedureDocumentationGenerator;

namespace DocumentProcedures
{
  class Program
  {
    static void Main(string[] args)
    {
      Server server = new Server();
      server.Connect("sa", "a", "Metastorm");
      foreach (Procedure proc in server.Procedures)
      {
        Console.WriteLine("Processing " + proc.Name);

        string filename = "c:\\temp\\" + proc.Name + ".xep";
        proc.Versions.LatestVersion.SaveToFile(filename);

        string htmlFilename = "c:\\temp\\html\\" + proc.Name + ".html";
        DocumentationGenerator generator = new DocumentationGenerator();
        generator.IncludeMapImages = true;
        generator.Generate(filename, htmlFilename);
      }
    }
  }
}

I believe later versions of SQL Server allow the execution of .NET code from within the database, so I would imagine it is possible to add a trigger to the eProcedure table that kicks off this code whenever a new record is added, so documentation will always be up to date.

Of course the procedure documenter isn’t a silver bullet. To generate useful documentation, some work will be required to ensure the notes in you procedures contain useful information.

Friday, April 03, 2009

Debugging server-side scripts in Metastorm BPM

Script Debugging in Metastorm BPM

Debugging server-side scripts in the Metastorm BPM can be difficult. One thing that can help with debugging JScript/VBscript scripts is the FreeFlow Administrator. When an error occurs in your script, generally you’ll be given a line number where the error occurred. This may not relate to a line number in the Designer because scripts are merged together when they get published to the database. The FreeFlow Administrator provides a simple way to view your scripts and see the line numbers and hence track down bugs more easily.

Unfortunately in the world of JScript.NET, when an error occurs you won’t get a line number telling you where it happened. If you want to learn more about debugging .NET code in Metastorm BPM, I would recommend Process Mapping’s .NET course (generally presented by myself).