/// <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); } }
/// <summary> /// Add the selected plug-in to the project with a default /// configuration. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnAddPlugIn_Click(object sender, EventArgs e) { string key = (string)lbAvailablePlugIns.SelectedItem; int idx = lbProjectPlugIns.FindStringExact(key); // Currently, no duplicates are allowed if (idx != -1) { lbProjectPlugIns.SelectedIndex = idx; return; } if (PlugInManager.IsSupported(key)) { idx = lbProjectPlugIns.Items.Add(key); if (idx != -1) { currentConfigs.Add(key, true, null); lbProjectPlugIns.SelectedIndex = idx; lbProjectPlugIns.SetItemChecked(idx, true); btnConfigure.Enabled = btnDelete.Enabled = true; currentConfigs.OnDictionaryChanged(new ListChangedEventArgs( ListChangedType.ItemAdded, -1)); } } else { MessageBox.Show("The selected plug-in's version is not " + "compatible with this version of the help file builder " + "and cannot be used.", Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Load and initialize the plug-ins used by this project /// </summary> /// <exception cref="BuilderException">This is thrown if a requested /// plug-in is not found or has a version that is not supported by /// this version of the help file builder.</exception> private void LoadPlugIns() { PlugInConfiguration plugInConfig; IPlugIn plugIn; XmlDocument config; StringBuilder sb = new StringBuilder(256); this.ReportProgress("Loading and initializing plug-ins..."); loadedPlugIns = new Dictionary <string, IPlugIn>(); // Note that a list of failures is accumulate as we may need to // run the Completion Notification plug-in to report the failures // when done. foreach (string key in project.PlugInConfigurations.Keys) { plugInConfig = project.PlugInConfigurations[key]; if (!plugInConfig.Enabled) { this.ReportProgress("{0} plug-in is disabled and will " + "not be loaded", key); continue; } plugIn = null; try { if (!PlugInManager.IsSupported(key)) { sb.AppendFormat("Error: Unable to locate plug-in '{0}' " + "or it is of a version that is not supported by " + "this version of the help file builder\r\n", key); continue; } plugIn = PlugInManager.PlugIns[key].NewInstance(); // For partial builds, only plug-ins that run in partial // builds are loaded. if (!this.IsPartialBuild || plugIn.RunsInPartialBuild) { config = new XmlDocument(); config.LoadXml(plugInConfig.Configuration); plugIn.Initialize(this, config.CreateNavigator()); loadedPlugIns.Add(key, plugIn); } else { plugIn.Dispose(); } } catch (ReflectionTypeLoadException rex) { sb.AppendFormat("Unable to load plug-in assembly for {0}:\r\n", key); if (rex.Types.Length != 0) { sb.AppendFormat(" Assembly: {0}\r\n", rex.Types[0].Module.FullyQualifiedName); } foreach (Exception ex in rex.LoaderExceptions) { sb.AppendFormat(" {0}\r\n", ex.Message); } } catch (Exception ex) { BuilderException bex = ex as BuilderException; if (bex != null) { sb.AppendFormat("{0}: {1}\r\n", bex.ErrorCode, bex.Message); } else { sb.AppendFormat("{0}: Unexpected error: {1}\r\n", (plugIn != null) ? plugIn.Name : key, ex.ToString()); } } } if (sb.Length != 0) { sb.Insert(0, "Plug-in loading errors:\r\n"); throw new BuilderException("BE0028", sb.ToString()); } }