Visual Rx – Part 6
this post is part of the Visual Rx series and it will focus on Visual Rx Viewer Side Extensibility.
this post is dealing with advance topic, you may want to read other post on this series before reading this one.
this post refer to version 126.96.36.1992.60 or higher (the extensibility model was simplify at this version).
Visual Rx support extension via plug-ins bundle contract.
a plug-ins bundle contains:
- General information about the package (like title and description),
- Publisher information (like name, email and web address)
- Implementation for different plug-ins capabilities.
plug-ins capabilities can be one or more implementation for the following aspects:
a complete Tab (actually the Grid Tab is a plug-in that you can remove).
It can modify a marble diagram icon.
and even change the representation of single item:
it can also control the entire view of a marble diagram (this way you can control the entire diagram view).
you can see the code of this extension in the source code under the StockExchangeGraphPlugin project.
the last extensibility point is a non visual extensibility.
it can intercept an item and do what ever you want to do with it data (for example send an email or write to a file).
How to get started?
first you have to set a plug-in bundle.
as I said earlier a bundle encapsulate the information about the plug-in and the publisher with a set of plug-in’s capabilities.
it is done by inheritance of the PluginBundleBase class which is implementing the IPluginBundle interface (if you want you can inherit the interface directly).
the following is the IPluginBundle definition:
as you can see it start with information about the plug-in and the publisher and followed by a set of properties which return interfaces.
those interfaces represent different capabilities.
let start with the most general interface which is helping the plug-in environment rather then actually having a real plug-in functionality.
Load Resources Plugin
the LoadResourcesPlugin property return the ILoadResourcesPlugin interface. this is how you can add resources which can be latter used by other plug-ins implementation (it is very common that your plug-in representation will need resources which is not available within Visual Rx core).
for example you can load WPF ResourceDictionary which will contain anything needed by your plug-in (images, styles, templates, ext.).
as you can see Visual Rx does have some helper method like UIPluginHelper.GetAssemblyName() which can make this task even easier.
Marble Item Plugin
the must useful capability may be the ability to change the item representation based on it’s data.
this capability achieved by implementation of the MarbleItemPlugin property which return the IMarbleItemPlugin interface.
the interface is fairly simple and it look as follow:
it gets an item and a FrameworkElement and return a DataTemplate.
you should return null if you don’t want to change the default template for the current item.
the following snippet was taken from the System.Reactive.Contrib.Monitoring.SamplePlugin which is part of the source code that available for download at codeplex.
the above implementation is replacing the template for items within marble diagrams that start with "sec" and ignoring items that doesn’t divide by 10.
the result will be the fire icon representation for those items:
Line Header Image Plugin
sometime all you want to do is to change the marble diagram icon.
in this case you should use the LineHeaderImagePlugin property which return the ILineHeaderImagePlugin interface.
the text parameter is the name of the marble diagram.
it can be use as follow (taken from the System.Reactive.Contrib.Monitoring.SamplePlugin):
the above snippet is changing the icons of the stress and sec marble diagrams into a preloaded resource (see LoadResourcesPlugin) and ignore any other diagrams.
the result will be shown as follow:
as you can see the sec icons become a clock, stress become runner while the error icon remain the default one.
I will leave the rest of the plug-in capabilities to a latter post and switch into the plug-in deployment.
the plug-in are exposed though MEF (when you implement IPluginBundle or inherit PluginBundleBase your code is automatically exported).
the Visual Rx setting let you set the plug-ins discovery and activation.
the following diagram is showing the setting dialog:
the plug-in setting is divided into 2 sections:
- discovery section where you can set plug-in folders (both relative and absolute path are supported).
- plug-in activation section where you can enable or disable plug-ins.
the setting dialog will have a plug-in upload and download from a central plug-in repository.
each plug-in will also be able to add a custom setting.
Visual Rx was built for extensibility.
you can use built-in, your own or 3rd party plug-ins which may enhance your monitoring efficiency.
the sample code is part of the source code of Visual Rx.
you can use the sample as a starting point but remember that it is only a sample code, some of the sample has a memory leak and other issues.
you should test the code as you would test your own code.