Administration Plugin

Description

An administration plugin is able to change the GUI of the administration window e. g. add menu items. Also, it has access to the server control class which provides important events (e. g. when a client connects), methods (e. g. LogInClient, GetAllClients) and properties (e. g. IpAddresses).


Needed libraries


Let's start

Because this is a plugin which will be loaded by the administration, we have to address the .Net Framework 4.5. If you want to open a custom window from the plugin, you should create a WPF User Control Library, but a Class Library also works.



The next thing to do is to add the interface library Orcus.Administration.Plugins.dll and the core library Orcus.Shared.dll to the references. You can do that with a right click on References in the Solution Explorer and then a click on Add Reference.... You can find the libraries in the /libraries folder of your Orcus package. Make sure that you have the newest version. The next thing to do is to create a new class called Plugin (the name doesn't matter, but it makes clear that it's the entry point). REALLY IMPORTANT: the class must be public.

The next step is to implement the interface from the library called IAdministrationPlugin

using System;
using Orcus.Administration.Plugins;

namespace MyAdministrationPlugin
{
    public class Plugin : IAdministrationPlugin
    {
        public void Initialize(IUiModifier uiModifier, IAdministrationControl administrationControl)
        {
            throw new NotImplementedException();
        }
    }
}

As you can see, there is one method which gets called if the user sucessfully connected to a server. Important: this method might get called multiple times so please move basic initialization to the constructor.

Let's add some menu items. We begin to add an item to the top menu:

using System.Windows;
using System.Windows.Controls;
using Orcus.Administration.Plugins;

namespace MyAdministrationPlugin
{
    public class Plugin : IAdministrationPlugin
    {
        public void Initialize(IUiModifier uiModifier, IAdministrationControl administrationControl)
        {
            uiModifier.AddMainMenuItem(new MenuItem {Header = "My Awesome Menu Item"}, MenuEventHandler);
        }

        private void MenuEventHandler(object sender, MenuItemClickedEventArgs menuItemClickedEventArgs)
        {
            MessageBox.Show("Hello");
        }
    }
}


Next, we add a menu item to the context menu of an online client:

using System.Windows;
using System.Windows.Controls;
using Orcus.Administration.Plugins;

namespace MyAdministrationPlugin
{
    public class Plugin : IAdministrationPlugin
    {
        public void Initialize(IUiModifier uiModifier, IAdministrationControl administrationControl)
        {
            uiModifier.AddOnlineClientMenuItem(new MenuItem {Header = "My Item"}, MenuEventHandler);
        }

        private void MenuEventHandler(object sender,
            OnlineClientMenuItemClickedEventArgs onlineClientMenuItemClickedEventArgs)
        {
            MessageBox.Show($"Selected client: {onlineClientMenuItemClickedEventArgs.ClientInformation.UserName}");
        }
    }
}


Last, we add a menu item to the context menu of an offline client:

using System.Windows;
using System.Windows.Controls;
using Orcus.Administration.Plugins;

namespace MyAdministrationPlugin
{
    public class Plugin : IAdministrationPlugin
    {
        public void Initialize(IUiModifier uiModifier, IAdministrationControl administrationControl)
        {
            uiModifier.AddOfflineClientMenuItem(new MenuItem {Header = "Click me"}, MenuEventHandler);
        }

        private void MenuEventHandler(object sender,
            OfflineClientMenuItemClickedEventArgs offlineClientMenuItemClickedEventArgs)
        {
            MessageBox.Show($"Selected client: {offlineClientMenuItemClickedEventArgs.ClientInformation.UserName}");
        }
    }
}


That's not all! The second parameter of our Initialize void gives the plugin access to important features of Orcus to manage the clients. Just take a look at the IAdministrationControl


Sample Projects