HOW TO: First plugin in vb.net (1 Viewer)

celesta

Portal Member
February 7, 2011
46
2
Sorry I don't speak good english and I see how MP2 plugin work from few hours. So I think all I say isn't true but It can help some beginners.


First of all:
-----------------------------------------------------------------------------------------
- install vb.net 2010 Express
- go to this website and click "Download" https://github.com/MediaPortal/MediaPortal-2
- Extract to a folder and launch .\Build\MSBUILD_Build_Report_Release_Client.bat
- Your portable installation of MP2 is on .\Bin\MP2-Client\bin\x86\Release
- To work, you must install "dokan library" Dokan » Download
(I can't install dokan because of antivirus problem, so I just copy the file dokan.dll in .\Bin\MP2-Client\bin\x86\Release to launch MP2-Client.exe ; not sure that all work but it launch)


File structure of a basic plugin:
-----------------------------------------------------------------------------------------
- All plugin are in .\Bin\MP2-Client\bin\x86\Release\Plugins folder, so create a folder named "plugintest"
- plugintest must have these structure:

plugintest\plugintest.dll <-- this is the dll of the vb.net class you create
plugintest\plugin.xml <-- this is a plugin description file with reference to other files and the class
plugintest\Language\strings_en.xml <-- this is a language file, you can use in other files and in the class references to the language file to do multilingual plugin (not used in this how to)
plugintest\Skin\default\screens\plugintest.xaml <-- the graphic interface of the plugin writing in mpf (look like wpf application)
plugintest\Skin\default\workflow\plugintest-actions.xml <-- create link from a screen to another one (used here to say when i'm at home menu, display my plugin button and when user this on this do the state mentionned in the plugintest-states.xml
plugintest\Skin\default\workflow\plugintest-states.xml <-- associate id with a graphic interface


The file plugintest\plugin.xml
-----------------------------------------------------------------------------------------
<Plugin
Name="My Plugin test" <-- A name for the plugin
Author="My name" <-- A name for the author
PluginId="FFFFFFFF-FFFF-FFFF-FFFF-000000000000" <-- A unique GUID to identify the plugin (use a GUID generator to have one)
DescriptorVersion="1.0"
PluginVersion="0.1"> <-- A version of your plugin

<Runtime>
<Assembly FileName="plugintest.dll"/> <-- a reference of the plugin dll
</Runtime>

<Register Location="/Models">
<Model Id="FFFFFFFF-FFFF-FFFF-FFFF-111111111111" ClassName="MediaPortal.plugin.plugintest.Plugin"/> <-- A unique GUID to identify the class (use a GUID generator to have one) and the name of the class you create in vb.net with it's namespace
</Register>

<Register Location="/Resources/Skin">
<Resource Id="test_Skin" Directory="Skin" Type="Skin"/> <-- a reference of the Skin folder (id can be what you want)
</Register>

<Register Location="/Resources/Language">
<Resource Id="test_Language" Directory="Language" Type="Language"/> <-- a reference of the Language folder (id can be what you want)
</Register>
</Plugin>


The file plugintest\Language\strings_en.xml
-----------------------------------------------------------------------------------------
Not used yet; this is the helloworld example:

<?xml version="1.0" encoding="utf-8" ?>
<Language>
<Section Name="Plugintest">
<String Name="MenuEntry" Text="Hello world"/>
<String Name="StateDisplayLabel" Text="Hello world state"/>
<String Name="ButtonText" Text="Press me"/>
<String Name="HelloWorldText" Text="Hello World!"/>
<String Name="ButtonTextCommandExecuted" Text="Congrats, you just triggered a Command!"/>
</Section>
</Language>


The file plugintest\Skin\default\screens\plugintest.xaml
-----------------------------------------------------------------------------------------
Just a xaml graphic interface like this:


<Screen xmlns="www.team-mediaportal.com/2008/mpf/directx" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel>

<Label Content="This is the sample screen of the HelloWorld plugin" FontSize="40" DockPanel.Dock="Top" HorizontalAlignment="Center"/>
<StackPanel DockPanel.Dock="Center" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Press me" Style="{ThemeResource ButtonWideStyle}" Margin="10"
HorizontalAlignment="Right" VerticalAlignment="Center"
Command="{Command ChangeHelloWorldString}"/>
<Label Content="{Binding HelloString}" Margin="10"
HorizontalAlignment="Left" VerticalAlignment="Center"/>
</StackPanel>

</DockPanel>
</Screen>


The file plugintest\Skin\default\workflow\plugintest-actions.xml
-----------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<Workflow DescriptorVersion="1.0">
<MenuActions>
<PushNavigationTransition Id="FFFFFFFF-FFFF-FFFF-FFFF-222222222222" <-- A unique GUID to identify the transition (use a GUID generator to have one)
Name="Home->plugintest" <-- just a name to identify in the log file
DisplayCategory="z-plugintest" <-- just a name to identify in the log file
SortOrder="a" <-- used for sorting
SourceState="7F702D9C-F2DD-42da-9ED8-0BA92F07787F" <-- This is the unique ID of the home of MP2
TargetState="FFFFFFFF-FFFF-FFFF-FFFF-333333333333" <-- A unique GUID to identifie the state section in the plugintest-states.xml file (use a GUID generator to have one)
DisplayTitle="SMC VIDEO"/> <-- the displayed name in the home menu
</MenuActions>
</Workflow>


The file plugintest\Skin\default\workflow\plugintest-states.xml
-----------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Workflow DescriptorVersion="1.0">
<States>
<WorkflowState Id="B150B150-B150-B150-B150-333333333333" <-- The unique GUID used in plugintest-actions.xml to identifie that to do with the action
Name="plugintest" MainScreen="plugintest" <-- this is the reference of the file plugintest.xaml (without the .xaml)
DisplayLabel="plugintest"/> <-- I don't know maybe the name of the screen ?
</States>
</Workflow>


The file plugintest\plugintest.dll
-----------------------------------------------------------------------------------------

To have this file:
- create a new VB.NET Class
- Add reference with the files MediaPortal.Core.dll and MediaPortal.UI.dll
- In advanced compiler option, choose .NET FRAMEWORK 3.5
- Copy this in the code:

Imports MediaPortal.Core.General
Imports MediaPortal.UI.Presentation.Models
Imports MediaPortal.UI.Presentation.Workflow

Namespace MediaPortal.plugin.plugintest
Public Class Plugin
Implements IWorkflowModel

Function CanEnterState(ByVal oldContext As NavigationContext, ByVal newContext As NavigationContext) As Boolean Implements IWorkflowModel.CanEnterState
Return True
End Function

Public Sub ChangeModelContext(ByVal oldContext As NavigationContext, ByVal newContext As NavigationContext, ByVal push As Boolean) Implements IWorkflowModel.ChangeModelContext

End Sub

Public Sub Deactivate(ByVal oldContext As NavigationContext, ByVal newContext As NavigationContext) Implements IWorkflowModel.Deactivate

End Sub

Public Sub EnterModelContext(ByVal oldContext As NavigationContext, ByVal newContext As NavigationContext) Implements IWorkflowModel.EnterModelContext

End Sub

Public Sub ExitModelContext(ByVal oldContext As NavigationContext, ByVal newContext As NavigationContext) Implements IWorkflowModel.ExitModelContext

End Sub

Public ReadOnly Property ModelId As System.Guid Implements IWorkflowModel.ModelId
Get
Return New Guid("B150B150-B150-B150-B150-000000000000")
End Get
End Property

Public Sub Reactivate(ByVal oldContext As NavigationContext, ByVal newContext As NavigationContext) Implements IWorkflowModel.Reactivate

End Sub

Public Sub UpdateMenuActions(ByVal context As NavigationContext, ByVal actions As System.Collections.Generic.IDictionary(Of System.Guid, WorkflowAction)) Implements IWorkflowModel.UpdateMenuActions

End Sub

Public Function UpdateScreen(ByVal context As NavigationContext, ByRef screen As String) As ScreenUpdateMode Implements IWorkflowModel.UpdateScreen
Return ScreenUpdateMode.AutoWorkflowManager
End Function

End Class
End Namespace

- Compile and you will have the dll
 

Albert

MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    45
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: HOW TO: First plugin in vb.net

    Hi celesta,
    thanks for your explanation! It could make some things clearer for some people, but basically, the code is already present in the Resources/Examples/HelloWorldExamplePlugin. I think I'll add some more comments in the example plugin to clarify some of the entries.

    In your posting, there are some errors:
    • In MP2, we don't use WPF. We use MPF, which is very similar to WPF but in some points it is adapted to MP2.
    • The workflow files for the states and for the actions should have the extension .xml, not .xaml. XAML files are files containing visual code to be interpreted by the MPF engine.
    • In MP2, what you see in the UI is called a "screen", not "page". You code screens in XAML/MPF, screens are shown to the user and typically associated to a workflow state as visual representation of that internal state.
    • IDs: Please generate these IDs, don't fill them by hand with arbitrary characters! There are many GUID generators in the internet, for example this one.

    I'll check if it makes sense to put your example VB file into the example plugin.
     

    celesta

    Portal Member
    February 7, 2011
    46
    2
    thank a lot albert for correction (first post edited; but I have keep my hand ID for understanding 0000,1111,222,...)

    To understand plugin, I have read the helloworld example, but few hours are necessary to know functioning.

    I'm not sure what vb code is necessary because vb.net -> C# translation is easy (but I prefer coding in vb.net for me the code is more easy to read and write)

    Next step is to create a interface for movies screen in mpf. I didn't find any doc for mpf so I read skin code.
     

    Users who are viewing this thread

    Top Bottom