IN THIS SECTION


ExampleExample

Let's start by writing a plugin which shows you the current date and time from the plugin host. Launch Visual Studio then create a new C# or VB project using the "Class Library" template with the name "SimplePlugin".

Example

From solution explorer rename "Class1.cs" to "SimplePlugin.cs" and open it. Now we need to add a project reference to our PCMonitorClient.dll file which is located in the directory of Pulseway.

Example

Now we can start writing our plugin. Let's open "SimplePlugin.cs" (if it's not already opened) and add under the last using statement:

using MM.Monitor.Client;

Also we need to tell Visual Studio that we are implementing Pulseway's API's interface by adding “ : ClientPlugin” right after the class definition, like this:

public class SimplePlugin : ClientPlugin

At this moment we start writing the code that will identify our plugin. After the class opening bracket you need to add a new line in order to write code inside the class and add the following code that will be used by Pulseway Manager to show it's user the name and description of the plugin.

public override string GetPluginName()
{
    return "Simple Plugin";
}
public override string GetPluginDescription()
{
    return "This plugin shows the current date and time.";
}

The text between the brackets can be changed to match your plugin name and description. Now only one thing remains to be implemented, the part where we tell our Mobile Pulseway what to show to clients. We do this by adding the following code under the other two (Order doesn't matter).

public override Groups GetAdditionalComputerDetails()
{
        Groups container = new Groups();
        Group mainGroup = new Group("Simple Plugin");
        SimpleItem date = new SimpleItem("Current Date: ", System.DateTime.Now.Date.ToShortDateString());
        SimpleItem time = new SimpleItem("Current Time: ", System.DateTime.Now.TimeOfDay.ToString());
        NumberInputItem numericInput = new NumberInputItem("numeric", "Invocation Count", invocationCount.ToString());
        mainGroup.Items.Add(date);
        mainGroup.Items.Add(time);
        mainGroup.Items.Add(numericInput);
        container.Add(mainGroup);
        return container;
}

Don't worry, it's actually not as complicated as it seems. As you can see from the method (function) declaration we have to return a Groups type back to Pulseway which is actually a container of containers. A "Groups" type can have many "Group" containers which can have many "SimpleItem" / "CommandItem" / "PageItem".

using System;
using MM.Monitor.Client;
namespace SimplePlugin
{
    public class SimplePlugin : ClientPlugin
    {
        ///<summary>
        /// Defines the plugin name.
        ///</summary>
        ///<returns>Plugin name</returns>
        public override string GetPluginName()
        {
            return "Simple Plugin";
        }
        /// <summary>
        /// A short description which will be displayed when the plugin is installed.
        /// </summary>
        /// <returns>Plugin description</returns>
        public override string GetPluginDescription()
        {
            return "This plugin shows the current date and time.";
        }
        /// <summary>
        /// Occurs whenever a Pulseway loads the computer details page.
        /// </summary>
        /// <returns>A group of items which contain the current date and time.</returns>
        public override Groups GetAdditionalComputerDetails()
        {
            Groups container = new Groups(); // Group of "Group" types.
            Group mainGroup = new Group("Simple Plugin"); // Group of "SimpleItem" / "CommandItem" / "PageItem" with the title Simple Plugin.
            SimpleItem date = new SimpleItem("Current Date: ", System.DateTime.Now.Date.ToShortDateString()); // Simple Item with "Current Date: " title and current date as subtitle.
            SimpleItem time = new SimpleItem("Current Time: ", System.DateTime.Now.TimeOfDay.ToString()); // Simple Item with "Current Time: " title and current time as subtitle.
            NumberInputItem numericInput = new NumberInputItem("numeric", "Invocation Count", invocationCount.ToString());
            mainGroup.Items.Add(date); // Adding the date SimpleItem to our Group container.
            mainGroup.Items.Add(time); // Adding the time SimpleItem to our Group container.
            mainGroup.Items.Add(numericInput); // Adding the NumericInputItem to our Group container.
            container.Add(mainGroup); // Adding the mainGroup Group to Groups container.
            return container; // Returning our Groups container to Pulseway.
        }
        private int invocationCount = 1; // An integer variable that will be used with our numeric input
        public override void NumericInputValueChanged(string inputId, int inputValue) // Occurs whenever you submit a new value from the mobile client.
        {
            invocationCount = inputValue;
        }
    }
}

ⓘ All the text after double ("//") or triple slashes ("///") is completely optional and its reason is for code comments. Now go ahead and press the "F6" button on your keyboard and Visual Studio will build your plugin into a dll file. Now browse to your project's folder, go inside the "bin" folder, then inside "Debug" you will find "SimplePlugin.dll". This file represents the plugin you just made and you need to install it into Pulseway for it to work.