Wikipedia:AutoWikiBrowser/Plugins

AWB is able to load and use fully customised plugins. These plugins can process article text and extend the user interface, and are in the form of libraries (.dll files) which can be made in any .NET language such as C# or Visual Basic .NET. When AWB loads it automatically checks to see if there are any plugins in the folder it was executed from. Any plugins found are loaded and initialised without further intervention by the user.

List of plugins

 * CFD
 * Kingbotk's Plugin

C#

 * 1) Firstly create a class library project in Visual Studio.
 * 2) Now add a reference to the WikiFunctions.dll file that comes with AWB (right click the project in the "solution explorer" => click "add reference" => click the "browse" tab => locate the WikiFunctions.dll file). Also add a reference to System.Windows.Forms under the ".NET" tab.
 * 3) Add   and   to the code.
 * 4) Implement the interface   in the WikiFunctions namespace so your code looks like this:

using System; using System.Collections.Generic; using System.Text; using WikiFunctions; using System.Windows.Forms;

namespace ExamplePlugin {   public class ExamplePlugin : WikiFunctions.Plugin.IAWBPlugin {   } }


 * 5. In Visual Studio, hold the mouse over IAWBPlugin, right click, and select one of the 2 options under "Implement interface". This will build the required members for you. If you're using a text editor, you'll have to implement the members manually; if you're using another IDE, well, you should know what to do :)
 * 6. When AWB finds your plugin, it will create an instance of it, and call Initialise. Your plugin will receive an IAutoWikiBrowser object using which you can interract with the application.
 * 7. Add all processing code to the  method. The method receives a ProcessArticleEventArgs object, which contains all the info you need about the article and some writable members. Return the modified text as the exit value of ProcessArticle.
 * 8. Compile the library.
 * 9. Put the new .dll file in the AWB directory and load it up. There is now a new main menu option listing the plugins and an option to enable/disable the use the available plugins. ??? is there ??? I thought plugins had to enable/disable themselves?

More complex example
The AWB project at Sourceforge includes a CFD plugin which you can use to familiarise yourself with the techniques.

Visual Basic

 * 1. Firstly create a class library project in Visual Studio.
 * 2. Double click on "My Project" in the solution explorer, select references, and add a reference as per step 2 above. You'll also need to add a reference to System.Windows.Forms.
 * 3. Import the AWB namespaces in the same tab

Imports System.Collections.Generic Imports System.Text Imports WikiFunctions Imports System.Windows.Forms


 * 4. Create a new class and type "Implements IAWBPlugin". Press Enter and Visual Studio will auto-generate the code required to implement the interface. The code will look something like this (AWB version 4, pre-release):

Public Class Plugin1 Implements WikiFunctions.Plugin.IAWBPlugin

Public Sub Initialise(ByVal MainForm As WikiFunctions.Plugin.IAutoWikiBrowser) _ Implements WikiFunctions.Plugin.IAWBPlugin.Initialise

End Sub

Public Sub LoadSettings(ByVal Prefs As Object) Implements WikiFunctions.Plugin.IAWBPlugin.LoadSettings

End Sub

Public ReadOnly Property Name As String Implements WikiFunctions.Plugin.IAWBPlugin.Name Get

End Get End Property

Public Sub Nudge(ByRef Cancel As Boolean) Implements WikiFunctions.Plugin.IAWBPlugin.Nudge

End Sub

Public Sub Nudged(ByVal Nudges As Integer) Implements WikiFunctions.Plugin.IAWBPlugin.Nudged

End Sub

Public Function ProcessArticle(ByVal sender As WikiFunctions.Plugin.IAutoWikiBrowser, _   ByVal eventargs As WikiFunctions.Plugin.ProcessArticleEventArgs) As String _ Implements WikiFunctions.Plugin.IAWBPlugin.ProcessArticle

End Function

Public Sub Reset Implements WikiFunctions.Plugin.IAWBPlugin.Reset

End Sub

Public Function SaveSettings As Object Implements WikiFunctions.Plugin.IAWBPlugin.SaveSettings

End Function End Class
 * 5. Follow steps 6-9 above.

Advanced example
The AWB Sourceforge project includes a working VB.net plugin called WPAssessmentsCatCreator. You may study the source code of that library to familiarise yourself with the object model.

Settings
When AWB loads and saves settings, it calls each loaded plugin. Plugins are not obliged to do anything, but users of complex plugins will surely appreciate being able to save their preferences.

Plugin authors have at least 4 ways of saving their settings, by returning an array of:
 * 1) Simple, serializable types such as Strings.
 * 2) AWBSettings.PrefsKeyPair objects
 * 3) Custom public classes with each field marked as Serializable
 * 4) An XML block converted to a String. (This is what the Kingbotk plugin uses).

Uses

 * Advanced regular expressions and text handling
 * Conditionally prepend or append templates or edit existing instances in the same AWB run
 * Access certain AWB controls
 * Many other uses... please add any you think of