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

Imports Orcus.Administration.Plugins

Public Class Plugin
    Implements IAdministrationPlugin

    Public Sub Initialize(uiModifier As IUiModifier, administrationControl As IAdministrationControl) Implements IAdministrationPlugin.Initialize
        Throw New NotImplementedException
    End Sub
End Class

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:

Imports Orcus.Administration.Plugins

Public Class Plugin
    Implements IAdministrationPlugin

    Public Sub Initialize(uiModifier As IUiModifier, administrationControl As IAdministrationControl) Implements IAdministrationPlugin.Initialize
        uiModifier.AddMainMenuItem(New MenuItem With {.Header ="My Awesome Menu Item"}, AddressOf MenuEventHandler)
    End Sub

    Private Sub MenuEventHandler(sender As Object, e As MenuItemClickedEventArgs)
        MessageBox.Show("Hello")
    End Sub
End Class


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

Imports Orcus.Administration.Plugins

Public Class Plugin
    Implements IAdministrationPlugin

    Public Sub Initialize(uiModifier As IUiModifier, administrationControl As IAdministrationControl) Implements IAdministrationPlugin.Initialize
        uiModifier.AddOnlineClientMenuItem(new MenuItem With {.Header ="My Item"}, AddressOf MenuEventHandler)
    End Sub

    Private Sub MenuEventHandler(sender As Object, e As OnlineClientMenuItemClickedEventArgs)
        MessageBox.Show(String.Format("Selected client: {0}", e.ClientInformation.UserName))
    End Sub
End Class


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

Imports Orcus.Administration.Plugins

Public Class Plugin
    Implements IAdministrationPlugin

    Public Sub Initialize(uiModifier As IUiModifier, administrationControl As IAdministrationControl) Implements IAdministrationPlugin.Initialize
        uiModifier.AddOfflineClientMenuItem(New MenuItem With {.Header ="Click me"}, AddressOf MenuEventHandler)
    End Sub

    Private Sub MenuEventHandler(sender As Object, e As OfflineClientMenuItemClickedEventArgs)
        MessageBox.Show(String.Format("Selected client: {0}", e.ClientInformation.UserName))
    End Sub
End Class


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


Sample Projects