Add ILOG Diagrammer for .NET previews to Windows Vista Explorer

One of the most unknown new Windows Vista features is the new Windows Explorer Preview Pane that displays a preview of the selected file. Why it is unknown ? Because Microsoft has made the choice to hide it by default, which does not help to make it popular… To enable it, open a Windows Explorer and select Organize > Layout > Preview Pane. 

In the following article, I will explain how to extend the Vista Explorer to add support for ILOG Diagrammer for .NET (with the .ivn extension) files preview. The following picture shows the extension is action :

ILOG Diagrammer for .NET Preview Handler

As you have probably guessed, the purpose of the Preview Pane is to display a preview of the selected file so that it is not required to open the associated application for viewing it. This mechanism is also used by Outlook to display a preview of files attached to a mail. While XP already provided something similar for images or video files, the Vista Preview Pane goes further by allowing to “interact” with the preview (for example you can switch the tabs of an Excel document). By default, the list of the supported file formats is limited to the images, audio and video files, and Office documents if you have Outlook installed. Not so bad, but what about other propriatory file formats ?

The good news is the Vista Shell supports a plug-in-like API that allows to add your own viewer to the Preview Pane. You may think this is not quite new compares to Windows XP that already supports custom extensions in its thumbnail view. Actually, there is a big difference for us .NET managed developpers : the Vista Shell Preview Pane API has been designed so that it is possible to write Preview Pane extensions in managed code. I do not wish to extend on this as it could be the purpose of its own article, but in brief, while it was technically possible to write an XP Shell extension in managed code, the Microsoft guys themselves highly recommend not to do it. One of the reasons behind is the XP Explorer loads all its extensions in the same process, and because there is only one CLR per process, you may have some conflicts between extensions that target a different CLR.  To solve this issue, the Vista Shell Preview Pane extension architecture has been designed on a one-process-per-extension basis which makes writing managed code extensions possible (see this post or this MSDN article which I talk about just below).

In the Vista API, Preview Pane extensions are called Preview Handlers, and is heavily based on COM. Fortunately for us, a Managed Preview Handler Framework has been published in the MSDN magazine January 2007 issue by Stephen Toub that makes developping Preview Handler much easier. You can find the article here, and while you are there, get the code as you will need it too to build (and run) the extension.

What this framework does is that it wraps all the COM API into a nice and extensible .NET managed API to develop custom preview handlers. It is so well designed that in our case, it requires to implement only two classes : the control (i.e. the preview handler control) embedded into the Preview Pane that displays the ILOG Diagrammer for .NET files, and the handler control factory (invoked to create the handler control).

The code is quite straightforward and is shown below : to display ivn files (the ILOG Diagrammer for .NET files), an ILOG.Diagrammer.Windows.Forms.DiagramView is used as the preview handler control, with all interactions disabled (so that you cannot interact on the graphic objects, for example changing the value of a gauge) :

using System.Windows.Forms;using System.Runtime.InteropServices;using ILOG.Diagrammer.Windows.Forms;   

using ILOG.Diagrammer;   

using System.IO;   

namespace ILOG.Samples {   

  [MsdnMag.PreviewHandler("ILOG Diagrammer.NET Preview Handler", ".ivn", "{F060452D-41EF-4c1c-BFFF-861869261A1D}")]   

  [ProgId("ILOG.Samples.IvnPreviewHandler")]   

  [Guid("D34FE641-53E5-4f8e-991F-B686C5532421")]   

  [ClassInterface(ClassInterfaceType.None)]   

  [ComVisible(true)]   

  public sealed class IvnPreviewHandler : MsdnMag.FileBasedPreviewHandler {   

    protected override MsdnMag.PreviewHandlerControl CreatePreviewHandlerControl() {   

      return new IvnPreviewHandlerControl();   

    }   

  }   

  public sealed class IvnPreviewHandlerControl : MsdnMag.FileBasedPreviewHandlerControl {   

    public override void Load(System.IO.FileInfo file) {   

      DiagramView view = new DiagramView();   

      using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read)) {   

        view.Content = GraphicContainer.FromXmlStream(stream) as GraphicContainer;   

      }   

      view.Dock = DockStyle.Fill;   

      view.DispatchEventsToObjects = false;   

      base.Controls.Add(view);   

    }   

  }   

}

You can download the IvnPreviewHandler Visual Studio 2008 Solution here so that you can easily build the extension.

Installation

To install the Diagrammer extension, you must first install the MSDN Preview Handler Managed Framework on the target machine.

Then, copy the IvnPreviewHandler dll on the target machine along with the install.bat file that is provided in the Solution root directory.  Open a command prompt as administrator, go to the directory containing the files you copied, and run install.bat to properly register the ILOG Diagrammer for .NET Preview Handler in the Vista Explorer.

You are now able to view your ivn files from the Vista Explorer Preview Pane and Outlook !

Patrick Ruzand

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

Leave a Reply