Comfort Home Automation/ Security System Forums Home

 Moderated by: juwi_uk, Ingo  
AuthorPost
juwi_uk
Member


Joined: Friday May 25th, 2007
Location: Newbury, United Kingdom
Posts: 1254
Status: 
Offline

  back to top

Here's a sample plugin to show what's involved.

Julian

This Code
(and the window form for About Box):


' ----------------------
' Hello World Plugin
' ----------------------

Imports System.ComponentModel.Composition
Imports ComfortClient.Plugin.Framework
Imports System.Windows.Forms
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Drawing

<PartMetadata("ComfortClientPlugin", "1.0"), Export()> _
Public Class HelloWorld_Plugin
' Plugin Contracts Supported
Implements IClientPluginMain
Implements IClientPluginMainMenu

#Region "Properties"

' Unique Identifier of the Plugin
Private ReadOnly Property GUID() As Guid Implements IClientPluginMain.Guid
Get
Return _GUID
End Get
End Property
Private _GUID As Guid

' Name of the Plugin
Private ReadOnly Property ID() As String Implements IClientPluginMain.ID
Get
Return _ID
End Get
End Property
Private _ID As String

' Plugin Image
Private ReadOnly Property Image() As Image Implements IClientPluginMain.Image
Get
Return _Image
End Get
End Property
Private _Image As Image

' Host Reference
Private Property Host() As IClientPluginHost Implements IClientPluginMain.Host
Set(value As IClientPluginHost)
_Host = value
End Set
Get
Return _Host
End Get
End Property
Private _Host As IClientPluginHost

' About Handler
ReadOnly Property AboutHandler() As System.EventHandler Implements IClientPluginMain.AboutHandler
Get
Return _AboutHandler
End Get
End Property
Private _AboutHandler As System.EventHandler
#End Region

#Region "Methods"

' Plugin Instantiation
Public Sub New()
' Mandatory Plugin Identification; GUID and ID
For Each Attr In Attribute.GetCustomAttributes(Me.GetType.Assembly)
If TypeOf Attr Is GuidAttribute Then
_GUID = New Guid(CType(Attr, GuidAttribute).Value)
ElseIf TypeOf Attr Is AssemblyTitleAttribute Then
_ID = CType(Attr, AssemblyTitleAttribute).Title
End If
Next
_Image = My.Resources.plugin
_AboutHandler = AddressOf About
End Sub

' Before Plugin Initialises
Private Function BeforePluginInitialisation() As ReturnCode _
Implements IClientPluginMain.BeforePluginInitialisation
' Set Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' After Plugin Initialises
Private Function AfterPluginInitialisation() As ReturnCode _
Implements IClientPluginMain.AfterPluginInitialisation
' Set Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' Plugin is disabled by the Client
Private Function PluginIsDisabled() As ReturnCode _
Implements IClientPluginMain.PluginIsDisabled
' Set Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' Plugin is enabled by the Client
Private Function PluginIsEnabled() As ReturnCode _
Implements IClientPluginMain.PluginIsEnabled
' Set Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' Adds thw About Box for the Plugin
Private Function About(ByVal sender As Object, ByVal e As System.EventArgs) _
As ReturnCode Implements IClientPluginMain.About
Dim AboutForm As New About()
Call AboutForm.ShowDialog()
' Set Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' Adds the Plugin About Menu Item to the Main Menu
Private Function SetAboutMenu(ByRef MenuAbout As ToolStripMenuItem) _
As ReturnCode Implements IClientPluginMain.SetAboutMenu

' Mandatory About Box
With MenuAbout
.Name = "About"
.Text = "About"
.Image = My.Resources.About
End With
AddHandler MenuAbout.Click, AddressOf About

' Set Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' Add Other Menu Item(s) to the Main Menu
Private Function SetMainMenu(ByRef PluginMenu As List(Of ToolStripItem)) _
As ReturnCode Implements IClientPluginMainMenu.SetMainMenu
' Setup Menu Item
Dim HelloItem As New ToolStripMenuItem
With HelloItem
.Name = Me.ID & "_Hello_World"
.Text = "Hello World!"
.Image = My.Resources.World
End With

' Add Menu Click Handler
AddHandler HelloItem.Click, AddressOf Hello

' Add to the Menu List
PluginMenu.Add(HelloItem)

' Set Success Returncode
Return New ReturnCode(ReturnCodeType.Internal, ReturnCodeValue.OK)
End Function

' Payload
Private Sub Hello(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("Hello World!")
End Sub

#End Region

End Class


Produces this Plugin....

Attachment: HelloWorld.png (Downloaded 61 times)

Last edited on Saturday May 19th, 2012 07:29 am by juwi_uk

TheMax74
Member


Joined: Monday Jul 16th, 2007
Location: Italy
Posts: 242
Status: 
Offline

  back to top

Good job

juwi_uk
Member


Joined: Friday May 25th, 2007
Location: Newbury, United Kingdom
Posts: 1254
Status: 
Offline

  back to top

You can download this very simple plugin visual studio project source from the link below if you want to play.

http://www.futurehomesoftware.co.uk/development/helloworld_project.zip

It uses a "Test Company" strong name key which is (purposely) not on the whitelist so you'll get a warning message when you start the Client and need to accept to load it.

Remember put the compiled DLL (normally you'll have an installer to create this) in a folder under the plugins folder.

<client root folder>\plugins\Hello World

Regards

Julian


UltraBB 1.172 Copyright © 2007-2014 Data 1 Systems