Developing a C# Plugin for The Intel® vPro™ Platform Solution Manager

If you’re not familiar with PSM I’d recommend having a look to the introduction presented by Gael in this post: http://intel.ly/MW65v6, there you’ll get a fairly good understanding on what the tool is and how to use it. By the time you finish reading the previous reference you’ll notice that the preconfigured plugins perform tasks such as Alarm Clock, Asset Inventory, Event Log, IDE-Redirection, KVM Remote Control, Power Management and Serial Over Lan, however other functionalities like Agent Monitoring aren’t present.

For those scenarios the plug-in development is the alternative to follow. In order to develop a plugin you should go through the following 5 steps:

  1. Download and decompress the latest version of The PSM here: http://intel.ly/1fk6AFr (released on: 01/20/2014).
  2. Create a WPF UserControl project in Visual Studio. PSM needs references to the following DLL’s:  System.Xaml, PresentationCore.dll, PresentationFramework.dll and WindowsBase.dll. Then add a reference to the object model defined by PSM in the library SolutionManagerAPI.dll and to the visual aspects included in SolutionManagerWPF.dll.
  3. Add a class which derives the SolutionManagerPlugin and implement its abstract members. You’ll end up with something similar to the following class:
    public class AgentMonitor_Impl : SolutionManagerPlugin
    {
        ctrlAgentMonitor ctrl = null;

        public override void ExecuteNoUI() { }

        public AgentMonitor_Impl()
        {
            _properties.Icon = Plugin_AgentMonitor.Resource1.AgentIcon;
            _properties.Name = "Agent Monitor";
            _properties.Category = Categories.MISC | Categories.AMT;
        }

        public override bool RequiresAMT
        {
            get
            {
                return true;
            }
        }        

        public override System.Windows.Controls.UserControl PluginWPFControl
        {
            get
            {
                lock (this)
                {
                    if (ctrl == null)
                    {
                        ctrl = new ctrlAgentMonitor(this);
                    }
                }
                return ctrl;
            }
        }

        public override SolutionManagerPlugin CreateInstance()
        {
            return new AgentMonitor_Impl();
        }
    }

The previous code sets the plugin properties in the constructor (e.g.: icon, name and category) and exposes its visual elements in the PlugWPFControl property, which implements the singleton design pattern. This property should return your own UI control, so you can use anything inheriting from UserControl, however the PSM includes a ctrlWPFBase class which gives you a good starting point to define your own control.

  1. Add a WPF user control to the project and change its base class from UserControl to ctrlWPFBase in the code behind and XAML files. This class is defined as follows:
    public partial class ctrlAgentMonitor : ctrlWPFBase
    {

        public ctrlAgentMonitor(SolutionManagerPlugin plugin)
            : base(plugin)
        {
            InitializeComponent();
            _plugin = plugin;
        }

        private bool _isLoaded = false;
        private void ctrlWPFBase_Loaded(object sender, RoutedEventArgs e)
        {
            if (!_isLoaded)
            {
                //One time stuff here
                ListWatchdogs();
            }
            _isLoaded = true;
        }

        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            ListWatchdogs();
        }

        /// <summary>
        /// Function to load a list of watch dogs
        /// </summary>
        private void ListWatchdogs()
        {
            IWSManClient wsmanClient = new DotNetWSManClient(_plugin.System.Fqdn, "admin", _plugin.System.Password,
                                                             _plugin.System.UseTls, false, null, null);
            WatchdogWrapper client = new WatchdogWrapper();
            var list = client.List(wsmanClient, null);            
            if (list != null)
            {
                lstAgents.DataContext = list;
            }

            
        }        
    }

For simplicity some functions were omitted. The most important functions are the injection of the plug in object via constructor arguments and the call to your custom code in the Loaded event. The plugin object is quite useful because gives you access to several properties/functions which abstract AMT functionalities/use cases. In this example the plugin object is used to get the machine’s FQDN, the password and other settings required to establish a second connection with the device to get the list of the watchdogs created in that machine.

By setting the DataContext object the data source object (a List<> in our case) is enumerated to match the property names of the objects contained in the collection with binding paths as described in the following XAML fragment:

                    <GridView >
                        <GridViewColumn x:Name="Id"   Header= " Id" DisplayMemberBinding="{Binding Path=Id}" />
                        <GridViewColumn x:Name="Name"  Header=" Name"  DisplayMemberBinding="{Binding Path=Name}" />
                        <GridViewColumn x:Name="State"  Header=" State"  DisplayMemberBinding="{Binding Path=State}" />
                    </GridView>
  1. Once the code is done (and tested), copy the obtained DLL after compiling the WPF UserControl project onto The PSM’s plugin folder (usually: C:\Program Files\Intel Corporation\Intel(R) vPro(tm) Platform Solution Manager\Bin). Then run The PSM and test the new Agent Monitor plugin by selecting the “A” icon as described in the following image. Note that agent’s watchdogs are loaded in the collapsible sidebar.

PSM plugin

General tips for building a custom Plugin:

  • Use the .Net Framework version 3.5 because is the version used by The PSM.
  • If planning to copy/paste a existing WPF user control to build yours make sure to change the XAML Build action to Page in the properties Windows to regenerate the InitializeComponent method (more information here: http://bit.ly/1cN7oWM).

 

Thinks I enjoyed/liked building a plugin for PSM:

  • It’s simple. It’s not overcomplicated with plugin frameworks.
  • The plugin object injected in the constructor provides access to virtually all AMT functionalities.
  • The PSM’s UI. Also it feels fast and nicely asynchronous in ALL its operations.

 

Things I think can be that improved:

  • The Real VNC plugin does not time out, it just keeps trying to connect “forever”.
  • It’s not evident that the machine list is not saved automatically. It should be the default setting. Also the Settings > Options menu is not easy to reach.
  • The PSM is highly modularized, and that’s a good thing. However the required DLLs can increase quickly.  For this simple plugin the following DLLs were required: DotNetWSManClient.dll, CIMFramework.dll, CIMFrameworkUntyped.dll, DotNetWSManClient.dll, IWSManClient.dll and HLAPI.dll. It would be great if all those DLLs would be provided as s single distributable DLL. This can be done using a tool like ilmerge (more information here: http://wp.me/p17pRQ-gm).
  • The plugin object is quite handy, however for this plugin I actually could not find the object/function which provides that data, I thought was the following (but it wasn’t):

List<Agent> recordlist = _plugin.System.Password.AmtSystemInstance.AgentPresence.Remote.GetAllAgents();

The plugin object seems a bit like an ADO.Net DataSet object because is massive, it includes several properties which in turns include several properties and so on, like a Russian doll.

 

The code used for creating the plugin and to access the watchdog list via WS-Man are attached.

 

Javier Andrés Cáceres Alvis

Intel Black Belt Software Developer

Microsoft Most Valuable Professional – MVP

Для получения подробной информации о возможностях оптимизации компилятора обратитесь к нашему Уведомлению об оптимизации.
Теги: