Permalink
Browse files

Plugin app

  • Loading branch information...
1 parent 5792bd4 commit 06ba3e0f43a2e84f015306d005058df052afc964 @mikoskinen committed Aug 20, 2010
Showing with 1,117 additions and 0 deletions.
  1. +11 −0 .gitignore
  2. BIN app-with-plugin-support/lib/StructureMap.dll
  3. +66 −0 app-with-plugin-support/src/app-with-plugin-support.sln
  4. +7 −0 app-with-plugin-support/src/app-with-plugin-support/IPlugin.cs
  5. +87 −0 app-with-plugin-support/src/app-with-plugin-support/MainApplication.Designer.cs
  6. +76 −0 app-with-plugin-support/src/app-with-plugin-support/MainApplication.cs
  7. +120 −0 app-with-plugin-support/src/app-with-plugin-support/MainApplication.resx
  8. +16 −0 app-with-plugin-support/src/app-with-plugin-support/PluginRegistry.cs
  9. +34 −0 app-with-plugin-support/src/app-with-plugin-support/Program.cs
  10. +36 −0 app-with-plugin-support/src/app-with-plugin-support/Properties/AssemblyInfo.cs
  11. +63 −0 app-with-plugin-support/src/app-with-plugin-support/Properties/Resources.Designer.cs
  12. +117 −0 app-with-plugin-support/src/app-with-plugin-support/Properties/Resources.resx
  13. +26 −0 app-with-plugin-support/src/app-with-plugin-support/Properties/Settings.Designer.cs
  14. +7 −0 app-with-plugin-support/src/app-with-plugin-support/Properties/Settings.settings
  15. +106 −0 app-with-plugin-support/src/app-with-plugin-support/app-with-plugin-support.csproj
  16. +3 −0 app-with-plugin-support/src/app-with-plugin-support/app.config
  17. +1 −0 app-with-plugin-support/src/app-with-plugin-support/pluginarchive/empty.txt
  18. +1 −0 app-with-plugin-support/src/app-with-plugin-support/plugins/empty.txt
  19. +14 −0 app-with-plugin-support/src/plugin/MyPlugin.cs
  20. +36 −0 app-with-plugin-support/src/plugin/Properties/AssemblyInfo.cs
  21. +64 −0 app-with-plugin-support/src/plugin/plugin.csproj
  22. +13 −0 app-with-plugin-support/src/plugin2/MyPlugin.cs
  23. +36 −0 app-with-plugin-support/src/plugin2/Properties/AssemblyInfo.cs
  24. +64 −0 app-with-plugin-support/src/plugin2/plugin2.csproj
  25. +13 −0 app-with-plugin-support/src/plugin3/MyPlugin.cs
  26. +36 −0 app-with-plugin-support/src/plugin3/Properties/AssemblyInfo.cs
  27. +64 −0 app-with-plugin-support/src/plugin3/plugin3.csproj
View
@@ -0,0 +1,11 @@
+obj
+bin
+_ReSharper.*
+*.csproj.user
+*.resharper.user
+*.ReSharper.user
+*.resharper
+*.ReSharper
+*.suo
+*.cache
+~$*
Binary file not shown.
@@ -0,0 +1,66 @@
+
+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
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plugin2", "plugin2\plugin2.csproj", "{2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plugin3", "plugin3\plugin3.csproj", "{26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}"
+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
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {2F4257A4-5FEE-46E6-9A44-5BDA4DD5C1C0}.Release|x86.ActiveCfg = Release|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {26F8F1E3-FFFD-4C51-B5D6-918E17437DA8}.Release|x86.ActiveCfg = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -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,76 @@
+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
+ {
+ private readonly IContainer container;
+
+
+ public MainApplication(IContainer container)
+ {
+ this.container = container;
+ InitializeComponent();
+ }
+
+ public void Start()
+ {
+ this.ShowDialog();
+ }
+
+ 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();
+ }
+ }
+
+ private void UpdateFeatures_Click(object sender, System.EventArgs e)
+ {
+ var appPath = Application.StartupPath;
+
+ var sourcePath = Path.Combine(appPath, @"pluginarchive\plugin.dll");
+ var destinationPath = Path.Combine(appPath, @"plugins\plugin.dll");
+
+ File.Copy(sourcePath, destinationPath, true);
+
+ ReloadPlugins();
+
+ }
+
+ private void AddFeatures_Click(object sender, System.EventArgs e)
+ {
+
+ var appPath = Application.StartupPath;
+
+ var sourcePath = Path.Combine(appPath, @"pluginarchive\plugin3.dll");
+ var destinationPath = Path.Combine(appPath, @"plugins\plugin2.dll");
+
+ File.Copy(sourcePath, destinationPath, true);
+
+ ReloadPlugins();
+
+ }
+
+ private void ReloadPlugins()
+ {
+ container.EjectAllInstancesOf<IPlugin>();
+
+ container.Configure(x =>
+ x.AddRegistry<PluginRegistry>()
+ );
+ }
+ }
+}
@@ -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.AssembliesFromPathDynamically(@".\plugins");
+ x.AddAllTypesOf<IPlugin>();
+ });
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 06ba3e0

Please sign in to comment.