B2S.Server Sample Plugin
Sample plugin implementation for the B2S.Server
|
Go to: Overview |
Creating your own plugin is a relatively easy process. You only neeed to build a new class library, implement the IDirectPlugin interface(s) and decorate the class with [Export(typeof(IDirectPlugin))] to get rolling.
The following sections are explaing plugin creation in more detail.
This step by step guide will teach you how to implement your own plugin.
Sorry, all screenshots are from a german version of Visual Studio.
Start Visual Studio and create a new class library project. Dont forget to give a nice name to your plugin.
Add references to B2SServerPluginInterface and System.ComponentModel.Composition.
Browse for the B2SServerPluginInterface.dll and click OK.
Add another reference to System.ComponentModel.Composition by selection the .NET tab in the dialog and selecting the mentioned component.
Now it would be a good idea to rename the class (class1.cs) which was during project creation to something meaningfull. If the system asks you to rename all references to the old class name, click yes.
Add using statements for B2SServerPluginInterface and e System.ComponentModel.Composition namespaces to your class.
Add the Export attribute to the top of your class, to allow the export of the class for the use by the MEF framework (that is whats inside the System.ComponentModel.Composition namespace).
Your plugin class should now look like this:
Next you have to implement the necessary interfaces. It is mandatory to implement IDirectPlugin, the other interfaces in the B2SServerPluginInterface namespace are optional.
First tell your plugin class to inherit the IDirectPlugin interface.
If you plan to have a configuration frontend for your plugin or to get updates on important PinMame events, inherit IDirectPluginFrontEnd and/or IDirectPluginPinmame.
Now you have to implement the methods of the inherited plugins. The easiest way to get a rough structure for the plugin member implementation is to click the name of a interface in the class definition with the right mouse button and select "Implement interface" (depending on your version of Visual Studio this function might not be available).
This will result in the following code for the IDirectPlugin interface;
Get a implementation for the other interfaces the same way.
Alternatively you can also implement the interface member by hand.
Now it is your turn to be creative and add some functionality to your plugin.
Remove the throw new NotImplementedException(); statements from the default plugin implementation and add your own code.
See the guidelines section for some general hints how to implement your own fuctionality.
Once you have completed the code for your plugin build the code in Visual Studio. This will result in a dll file having the same name as your plugin project.
Copy this dll to a appropriatley named sub folder of the plugin directory of your B2S.Server installation. If your B2S.Server is located in the Tables directory of Visual Pinball your directory structre might looks as follows:
Alternatively you can also put your plugin into any other directory on your system and add a windows shortcut pointing to this directory to the plugin directory of your B2S.Server installation.
After you have installed your plugin as advised above, it is time for some action.
Start Visual Pinball, load a table which is using the B2S.Server and start the table.
If everything is correct in your plugin implementation, the B2S.Server will load and execute your plugin automatically when the table is started.
Open the config window of the B2S.Server (click the backglass and push s on your keyboard) and click the plugin window button to open up a window showing all loaded plugins. If your plugin implements a frontend you can double click the name of the plugin in the B2S.Server plugin window to open up the frontend of the plugin.