Click here to Skip to main content
12,400,556 members (59,490 online)
Click here to Skip to main content

Stats

44.7K views
1.4K downloads
108 bookmarked
Posted

Plug-in Framework

, 14 Sep 2010 CPOL
Basic framework for building desktop plug-in applications.
PluginFramework
Demo
bin
Debug
Plugins
Release
Plugins
Forms
Properties
DemoFormPlugin
Properties
DemoUserControlPlugin
Properties
MBG.Extensions
Collections
Controls
Core
Data
Math
Properties
Xml
MBG.IO
Properties
PluginFramework.Attributes
Properties
PluginFramework.Controls
Properties
Resources
Icons
SettingsIcon.ico
TreeIcon.ico
Images
SettingsImage.png
TreeImage.png
PluginFramework.Interface
Properties
PluginFramework.Utilities
Properties
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using MBG.Extensions.Core;
using Demo.Properties;
using PluginFramework.Utilities;

namespace Demo.Forms
{
    public partial class AvailablePluginsForm : Form
    {
        private IDictionary<string, string> availablePlugins;
        public IDictionary<string, string> SelectedPlugins { get; private set; }

        public AvailablePluginsForm()
        {
            InitializeComponent();
        }
        private void AvailablePluginsForm_Load(object sender, EventArgs e)
        {
            availablePlugins = PluginHelper.FindPlugins();
            clbAvailablePlugins.Items.AddRange(availablePlugins.Keys.ToArray());

            SelectedPlugins = (from p in AppContext.ConfigurationFile.Startup.Plugins
                               select p).ToDictionary(key => key.Title, value => value.AssemblyPath);

            for (int i = 0; i < clbAvailablePlugins.Items.Count; i++)
            {
                if (clbAvailablePlugins.Items[i].ToString().In(SelectedPlugins.Keys))
                {
                    clbAvailablePlugins.SetItemChecked(i, true);
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            SelectedPlugins = (from p in availablePlugins
                               where p.Key.In(clbAvailablePlugins.CheckedItems)
                               select p).ToDictionary(key => key.Key, value => value.Value);

            if (SelectedPlugins != null && SelectedPlugins.Count > 0)
            {
                AppContext.ConfigurationFile.Startup.Plugins.Clear();
                foreach (KeyValuePair<string, string> kv in SelectedPlugins)
                {
                    if (!AppContext.ConfigurationFile.Startup.Plugins.Contains(kv.Key))
                    {
                        StartupPlugin plugin = new StartupPlugin();
                        plugin.Title = kv.Key;
                        plugin.AssemblyPath = kv.Value;
                        AppContext.ConfigurationFile.Startup.Plugins.Add(plugin);
                    }
                }
            }

            AppContext.ConfigurationFile.Save(Settings.Default.PluginConfigFile);
        }
    }
}

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

vnmatt
Software Developer (Senior) Freelancer
Vietnam Vietnam
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 14 Sep 2010
Article Copyright 2010 by vnmatt
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid