The Preview Handlers have been introduced with Microsoft Windows Vista and with Microsoft Office 2007.
However, if you try to preview an attached PDI in Microsoft Outlook, you will see something similar to that:
When getting Windows 7 on my Notebook recently, Steve gave me a head's up to try and write a preview handler for PDI's.
A good start are this article of Stephen Toub, Managed Preview Handlers for Vista and Office in Daniel Moth's blog, More Preview Handlers from the same Blog and especially the screencast by Daniel Moth on channel9.
So what do you need (beside taking a look at the above resources)?
- Microsoft Windows Vista or Microsoft Windows 7
- Microsoft Visual Studio 2008
- The Managed Preview Handler Framework from here.
- OSIsoft PI ProcessBook 3.x or newer
- Microsoft Outlook 2007
And here is my Hello PI preview handler ;-)
- Download the msdn magazine preview handler framework from the first link.
- To build MsdnMagPreviewHandlers.dll, you might have as well to install the Microsoft Visual J# Redistributable Package
- As in Daniel Moth's example, create a new class library.
- Reference the MsdnMagPreviewHandlers.dll.
- Add a reference to System.Windows.Forms.
- Sign the assembly with a strong name key file.
- To render a PDI file we will need an ActiveX control. Hence we are here in .NET we need to create a managed wrapper for the PI ProcessBook Display Control. So we are going to create that wrapper with AxImp.exe:
- We will have to add a reference to our AxPBDCtrl.dll.
- The code for the preview handler is below:
- After building the dll, we have to move it to the Global Assembly Cache (GAC) and register it:
[PreviewHandler("OSIsoft vCampus Preview handler",
publicsealedclassOSIsoftvCampusPDIPreviewHandler : FileBasedPreviewHandler
publicoverridevoid Load(FileInfo file)
AxHost _pbDisplay = new AxPBDCtrl.AxPbd();
IntPtr forceCreation = _pbDisplay.Handle;
_pbDisplay.Dock = DockStyle.Fill;
AxPBDCtrl.AxPbd _AxPbd = (AxPBDCtrl.AxPbd)_pbDisplay;
_AxPbd.DisplayURL = file.ToString();
GACUTIL.EXE -i MsdnMagPreviewHandlers.dll
GACUTIL.EXE -i OSIsoftvCampusPreviewHandler.dll
GACUTIL.EXE -i AxPBDCtrl.dll
GACUTIL.EXE -i PBDCtrl.dll
REGASM.EXE /codebase MsdnMagPreviewHandlers.dll
REGASM.EXE /codebase OSIsoftvCampusPreviewHandler.dll
REGASM.EXE /codebase AxPBDCtrl.dll
REGASM.EXE /codebase PBDCtrl.dll
The result is a PI ProcessBook Display preview handler that allows you to preview a PDI in Outlook
or Windows Explorer
- In this example we are using PI ProcessBook. However, all of this is possible with PI ActiveView as well (Note that PI ActiveView is not part of the OSIsoft vCampus PI Products Kit).
PI ActiveView provides a means to view and interact with PI ProcessBook displays outside of PI ProcessBook. By embedding the PI ActiveView ActiveX control in other applications, such as Internet Explorer, and installing the local executable, users can view PI ProcessBook PDI display files without modification.
- This PreviewHandler uses the PI ProcessBook Display control to preview a PDI. Therefore it has the same requirements as PI ProcessBook: you need to have a PI SDK connection to the PI Server and the necessary access rights to view the data.
- The two batch files to register and unregister as well as the source code above can be downloaded here.
Call for Help
The community is explicitly invited to improve/extend my code. As an example - a known limitation is that the preview handler does not scale the display according to the visible area in the preview.