Click here to Skip to main content
13,738,608 members
Click here to Skip to main content

Tagged as

Stats

36.1K views
1.3K downloads
40 bookmarked
Posted 13 Nov 2011
Licenced CPOL

Self Contained Assembly

, 13 Nov 2011
Shows how deployment of dynamically loaded assembly can be simplified by reducing the assembly to single self contained file.
Demo
AbstractPanelFactory.dll
AssemblyLoader.dll
DemoClientApp.exe
PlugIns
GradientPanelFactory.dll
SelfContainedAssembly
AbstractPanelFactory
bin
Release
AbstractPanelFactory.dll
AbstractPanelFactory.pdb
Properties
AssemblyLoader
bin
Release
AssemblyLoader.dll
AssemblyLoader.pdb
Properties
DemoClientApp
bin
Release
AbstractPanelFactory.dll
AbstractPanelFactory.pdb
AssemblyLoader.dll
AssemblyLoader.pdb
DemoClientApp.exe
DemoClientApp.pdb
DemoClientApp.vshost.exe
PlugIns
Properties
GradientPanelFactory
bin
Release
GradientPanelFactory.dll
GradientPanelFactory.pdb
DependancyAssemblies.zip
Owf.Controls.A1Panel.dll
Properties
SelfContainedAssembly.suo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using AssemblyLoader;
using PanelFactory;

namespace DemoClientApp
{
    public partial class MainForm : Form
    {
        AbstractPanelFactory factory = null;
        Panel panel;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            var binDebug = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var panelFactoryPluginFile = SearchPanelFactoryPlugin(binDebug);

            if (panelFactoryPluginFile == string.Empty)
            {
                MessageBox.Show("No Plugin Found.");
            }

            Loader.ResolveAssembly = true;

            var pluginAssembly = Loader.LoadAssembly(panelFactoryPluginFile);

            foreach (var type in pluginAssembly.GetTypes())
            {
                if (type.IsAbstract == false)
                {
                    if (type.IsClass)
                    {
                        if (type.BaseType == typeof(AbstractPanelFactory))
                        {
                            factory = pluginAssembly.CreateInstance(type.FullName) as AbstractPanelFactory;
                        }
                    }
                }
            }
        }

        private string SearchPanelFactoryPlugin(string pluginFolder)
        {
            pluginFolder = pluginFolder + "\\PlugIns";
            var dllFiles = Directory.GetFiles(pluginFolder, "*.dll");

            foreach (var dll in dllFiles)
            {
                if (Path.GetFileName(dll) != "AbstractPanelFactory.dll")
                    if (dll.EndsWith("PanelFactory.dll"))
                    {
                        return dll;
                    }
            }

            return string.Empty;
        }

        private void btnGetPanel_Click(object sender, EventArgs e)
        {
            if (factory == null)
            {
                MessageBox.Show(" Unable to find plugin.");
            }

            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Color selectedColor = colorDialog1.Color;
                this.Controls.Remove(panel);
                panel = factory.GetPanel(selectedColor);

                panel.Dock = DockStyle.Fill;
                this.Controls.Add(panel);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Prafulla Hunde
Software Developer Honeywell Automation India Ltd.
India India
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 13 Nov 2011
Article Copyright 2011 by Prafulla Hunde
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid