Esempio n. 1
0
        /// <summary>
        /// Edit the selected plug-in's project configuration
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnConfigure_Click(object sender, EventArgs e)
        {
            PlugInConfiguration plugInConfig;
            string newConfig, currentConfig,
                   key = (string)lbProjectPlugIns.SelectedItem;

            if (PlugInManager.IsSupported(key))
            {
                PlugInInfo info = PlugInManager.PlugIns[key];

                using (IPlugIn plugIn = info.NewInstance())
                {
                    plugInConfig  = currentConfigs[key];
                    currentConfig = plugInConfig.Configuration;
                    newConfig     = plugIn.ConfigurePlugIn(currentConfigs.ProjectFile,
                                                           currentConfig);
                }

                // Only store it if new or if it changed
                if (currentConfig != newConfig)
                {
                    plugInConfig.Configuration = newConfig;
                }
            }
            else
            {
                MessageBox.Show("The selected plug-in either does not exist " +
                                "or is of a version that is not compatible with this " +
                                "version of the help file builder and cannot be used.",
                                Constants.AppName, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
    private List <PlugInInfo> GetPlugInList()
    {
        // Create a List to hold the info for each plug-in
        List <PlugInInfo> plugInList = new List <PlugInInfo>();
        // Set Plug-In folder path to same directory level as Solution
        string plugInFolderPath = System.IO.Path.Combine(Application.StartupPath, @"..\..\..\Plug-Ins");

        // Test if the Plug-In folder exists
        if (!Directory.Exists(plugInFolderPath))
        {
            // Plug-In Folder is missing, so try to create it
            try
            { Directory.CreateDirectory(plugInFolderPath); }
            catch
            { MessageBox.Show("Failed to create Plug-In folder", "Folder Creation Error:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
        }
        try
        {
            // Create a catalog of plug-ins
            var catalog = new DirectoryCatalog(plugInFolderPath, "*.dll");
            AggregateCatalog plugInCatalog = new AggregateCatalog();
            plugInCatalog.Catalogs.Add(catalog);
            CompositionContainer container = new CompositionContainer(plugInCatalog);

            // This line will fetch the metadata from each plug-in and populate LoadedPlugIns
            container.ComposeParts(this);
            // Save each Plug-Ins metadata
            foreach (var plugin in LoadedPlugIns)
            {
                PlugInInfo info = new PlugInInfo();
                info.PlugInTitle       = plugin.Metadata.PlugInTitle;
                info.PlugInDescription = plugin.Metadata.PlugInDescription;
                info.PlugInVersion     = plugin.Metadata.PlugInVersion;
                info.PlugIn            = plugin.Value;
                plugInList.Add(info);
            }
            int index = 0;
            // Extract icons from each Plug-In DLL and store in Plug-In list
            foreach (var filePath in catalog.LoadedFiles)
            {
                plugInList[index].PlugInIcon = Icon.ExtractAssociatedIcon(filePath);
                index++;
            }
        }
        catch (FileNotFoundException fex)
        {
            Console.WriteLine("File not found exception : " + fex.Message);
        }
        catch (CompositionException cex)
        {
            Console.WriteLine("Composition exception : " + cex.Message);
        }
        catch (DirectoryNotFoundException dex)
        {
            Console.WriteLine("Directory not found exception : " + dex.Message);
        }
        return(plugInList);
    }
Esempio n. 3
0
        /// <summary>
        /// Update the plug-in details when the selected index changes
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void lbAvailablePlugIns_SelectedIndexChanged(object sender,
                                                             EventArgs e)
        {
            string key = (string)lbAvailablePlugIns.SelectedItem;

            PlugInInfo info = PlugInManager.PlugIns[key];

            txtPlugInCopyright.Text = info.Copyright;
            txtPlugInVersion.Text   = String.Format(CultureInfo.CurrentCulture,
                                                    "Version {0}", info.Version);
            txtPlugInDescription.Text = info.Description;
        }
    void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        // Get the Plug-In index number
        int        plugInNum      = listView1.SelectedItems[0].Index;
        PlugInInfo selectedPlugIn = AvailablePlugIns[plugInNum];

        // Call the StartPlugIn method in the selected Plug-In.
        // Lazy Instantiation will fully load the Assembly here
        selectedPlugIn.PlugIn.StartPlugIn(this);
        Console.WriteLine("Plug-In Title:          {0}", selectedPlugIn.PlugInTitle);
        Console.WriteLine("Plug-In Description:    {0}", selectedPlugIn.PlugInDescription);
        Console.WriteLine("Plug-In Version:        {0}", selectedPlugIn.PlugInVersion);
        Console.WriteLine();
    }
Esempio n. 5
0
        /// <summary>
        /// 初始化插件信息
        /// </summary>
        private void InitializePlugIns()
        {
            //读取已安装的插件信息
            List <PlugInInfo> installedPlugIns = plugInAdmin.GetLocalPlugIns();

            Framework.PlugIns.Clear();
            for (int i = 0; i < installedPlugIns.Count; i++)
            {
                PlugInInfo infoTemp = installedPlugIns[i];
                if (infoTemp.PlugInState == PlugInEnableState.Uninstall)
                {
                    plugInAdmin.Uninstall(infoTemp);
                    continue;
                }
                IPlugIn plugIn = PlugInFactory.CreatePlugIn(installedPlugIns[i].PlugInData);
                //Framework.PlugIns.Contains(plugIn,
                Framework.PlugIns.Add(plugIn);
            }
        }