Permalink
Browse files

Interacting with the application from a plugin

  • Loading branch information...
mikoskinen committed Aug 21, 2010
1 parent cb97576 commit 3dd11e24bdf5fc9f3b9f5cda45768f13b45cd244
Showing with 828 additions and 0 deletions.
  1. BIN plugin-application-interface/lib/StructureMap.dll
  2. +42 −0 plugin-application-interface/src/app-with-plugin-support.sln
  3. +8 −0 plugin-application-interface/src/app-with-plugin-support/IApplicationFeatures.cs
  4. +7 −0 plugin-application-interface/src/app-with-plugin-support/IPlugin.cs
  5. +72 −0 plugin-application-interface/src/app-with-plugin-support/MainApplication.Designer.cs
  6. +48 −0 plugin-application-interface/src/app-with-plugin-support/MainApplication.cs
  7. +120 −0 plugin-application-interface/src/app-with-plugin-support/MainApplication.resx
  8. +16 −0 plugin-application-interface/src/app-with-plugin-support/PluginRegistry.cs
  9. +34 −0 plugin-application-interface/src/app-with-plugin-support/Program.cs
  10. +36 −0 plugin-application-interface/src/app-with-plugin-support/Properties/AssemblyInfo.cs
  11. +63 −0 plugin-application-interface/src/app-with-plugin-support/Properties/Resources.Designer.cs
  12. +117 −0 plugin-application-interface/src/app-with-plugin-support/Properties/Resources.resx
  13. +26 −0 plugin-application-interface/src/app-with-plugin-support/Properties/Settings.Designer.cs
  14. +7 −0 plugin-application-interface/src/app-with-plugin-support/Properties/Settings.settings
  15. +107 −0 plugin-application-interface/src/app-with-plugin-support/app-with-plugin-support.csproj
  16. +3 −0 plugin-application-interface/src/app-with-plugin-support/app.config
  17. +1 −0 plugin-application-interface/src/app-with-plugin-support/pluginarchive/empty.txt
  18. +1 −0 plugin-application-interface/src/app-with-plugin-support/plugins/empty.txt
  19. +20 −0 plugin-application-interface/src/plugin/MyPlugin.cs
  20. +36 −0 plugin-application-interface/src/plugin/Properties/AssemblyInfo.cs
  21. +64 −0 plugin-application-interface/src/plugin/plugin.csproj
Binary file not shown.
@@ -0,0 +1,42 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "app-with-plugin-support", "app-with-plugin-support\app-with-plugin-support.csproj", "{ACC9435F-9B28-4091-BCA5-101A85471BB5}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plugin", "plugin\plugin.csproj", "{D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Debug|x86.ActiveCfg = Debug|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Debug|x86.Build.0 = Debug|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Release|Any CPU.ActiveCfg = Release|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Release|Mixed Platforms.Build.0 = Release|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Release|x86.ActiveCfg = Release|x86
+ {ACC9435F-9B28-4091-BCA5-101A85471BB5}.Release|x86.Build.0 = Release|x86
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {D5E8B273-8CC2-447C-A1D8-94288FEDB4B5}.Release|x86.ActiveCfg = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,8 @@
+namespace app_with_plugin_support
+{
+ public interface IApplicationFeatures
+ {
+ void ShowOnScreen(string message);
+ }
+
+}
@@ -0,0 +1,7 @@
+namespace app_with_plugin_support
+{
+ public interface IPlugin
+ {
+ void Run();
+ }
+}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,48 @@
+using System;
+using System.IO;
+using System.Windows.Forms;
+using StructureMap;
+
+namespace app_with_plugin_support
+{
+ public interface IMainApplication
+ {
+ void Start();
+ }
+
+ public partial class MainApplication : Form, IMainApplication, IApplicationFeatures
+ {
+ private readonly IContainer container;
+
+
+ public MainApplication(IContainer container)
+ {
+ this.container = container;
+ InitializeComponent();
+ }
+
+ public void Start()
+ {
+ this.ShowDialog();
+ }
+
+ public void ShowOnScreen(string message)
+ {
+ this.messageFromPlugin.Text = message;
+ }
+
+ private void RunFeatures_Click(object sender, System.EventArgs e)
+ {
+ var plugins = container.GetAllInstances<IPlugin>();
+ if (plugins == null)
+ return;
+
+ foreach (var plugin in plugins)
+ {
+ plugin.Run();
+ }
+ }
+
+
+ }
+}
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
@@ -0,0 +1,16 @@
+using StructureMap.Configuration.DSL;
+
+namespace app_with_plugin_support
+{
+ public class PluginRegistry : Registry
+ {
+ public PluginRegistry()
+ {
+ Scan( x=>
+ {
+ x.AssembliesFromPath(@".\plugins", null, true);
+ x.AddAllTypesOf<IPlugin>();
+ });
+ }
+ }
+}
@@ -0,0 +1,34 @@
+using System;
+using StructureMap;
+
+namespace app_with_plugin_support
+{
+ static class Program
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+
+ var container = CreateContainer();
+
+ var mainApp = container.GetInstance<IMainApplication>();
+ mainApp.Start();
+
+ }
+
+ private static IContainer CreateContainer()
+ {
+ var container = new Container(x =>
+ {
+ x.AddRegistry<PluginRegistry>();
+ x.For<IMainApplication>().Singleton().Use<MainApplication>();
+ x.Forward<IMainApplication, IApplicationFeatures>();
+ });
+
+ return container;
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("app-with-plugin-support")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("app-with-plugin-support")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("23b9f941-bbec-492c-b03d-48d03dc88a9a")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Oops, something went wrong.

0 comments on commit 3dd11e2

Please sign in to comment.