Skip to content

Commit

Permalink
Plugin app
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoskinen committed Aug 20, 2010
1 parent 5792bd4 commit 06ba3e0
Show file tree
Hide file tree
Showing 27 changed files with 1,117 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
obj
bin
_ReSharper.*
*.csproj.user
*.resharper.user
*.ReSharper.user
*.resharper
*.ReSharper
*.suo
*.cache
~$*
Binary file added app-with-plugin-support/lib/StructureMap.dll
Binary file not shown.
66 changes: 66 additions & 0 deletions app-with-plugin-support/src/app-with-plugin-support.sln
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace app_with_plugin_support
{
public interface IPlugin
{
void Run();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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>()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>();
});
}
}
}
Loading

0 comments on commit 06ba3e0

Please sign in to comment.