/// <summary> /// Update the build component 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 lbAvailableComponents_SelectedIndexChanged(object sender, EventArgs e) { string key = (string)lbAvailableComponents.SelectedItem; BuildComponentInfo info = BuildComponentManager.BuildComponents[key]; txtComponentCopyright.Text = info.Copyright; txtComponentVersion.Text = String.Format(CultureInfo.CurrentCulture, "Version {0}", info.Version); txtComponentDescription.Text = info.Description; }
/// <summary> /// Edit the selected build component'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) { BuildComponentConfiguration componentConfig; string newConfig, currentConfig, assembly, key = (string)lbProjectComponents.SelectedItem; BuildComponentInfo info = BuildComponentManager.BuildComponents[key]; componentConfig = currentConfigs[key]; currentConfig = componentConfig.Configuration; // If it doesn't have a configuration method, use the default // configuration editor. if (String.IsNullOrEmpty(info.ConfigureMethod)) { using (ConfigurationEditorDlg dlg = new ConfigurationEditorDlg()) { dlg.Configuration = currentConfig; if (dlg.ShowDialog() == DialogResult.OK) { // Only store it if new or if it changed newConfig = dlg.Configuration; if (currentConfig != newConfig) { componentConfig.Configuration = newConfig; } } } return; } // Don't allow editing if set to "-" if (info.ConfigureMethod == "-") { MessageBox.Show("The selected component contains no " + "editable configuration information", Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { // Change into the component's folder so that it has a // better chance of finding all of its dependencies. assembly = BuildComponentManager.ResolveComponentPath( info.AssemblyPath); Directory.SetCurrentDirectory(Path.GetDirectoryName( Path.GetFullPath(assembly))); // The exception is BuildAssemblerLibrary.dll which is in // the Sandcastle installation folder. We'll have to resolve // that one manually. AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); // Load the type and get a reference to the static // configuration method. Assembly asm = Assembly.LoadFrom(assembly); Type component = asm.GetType(info.TypeName); MethodInfo mi = null; if (component != null) { mi = component.GetMethod(info.ConfigureMethod, BindingFlags.Public | BindingFlags.Static); } if (component != null && mi != null) { // Invoke the method to let it configure the settings newConfig = (string)mi.Invoke(null, new object[] { currentConfig }); // Only store it if new or if it changed if (currentConfig != newConfig) { componentConfig.Configuration = newConfig; } } else { MessageBox.Show(String.Format(CultureInfo.InvariantCulture, "Unable to locate the '{0}' method in component " + "'{1}' in assembly {2}", info.ConfigureMethod, info.TypeName, assembly), Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (IOException ioEx) { System.Diagnostics.Debug.WriteLine(ioEx.ToString()); MessageBox.Show(String.Format(CultureInfo.InvariantCulture, "A file access error occurred trying to configure the " + "component '{0}'. Error: {1}", info.TypeName, ioEx.Message), Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); MessageBox.Show(String.Format(CultureInfo.InvariantCulture, "An error occurred trying to configure the component " + "'{0}'. Error: {1}", info.TypeName, ex.Message), Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve); } }