/// <summary> /// This method is used to initialize the plug-in at the start of the /// build process. /// </summary> /// <param name="buildProcess">A reference to the current build /// process.</param> /// <param name="configuration">The configuration data that the plug-in /// should use to initialize itself.</param> /// <exception cref="BuilderException">This is thrown if the plug-in /// configuration is not valid.</exception> public void Initialize(BuildProcess buildProcess, XPathNavigator configuration) { XPathNavigator root, node; string ripOld; builder = buildProcess; allVersions = new VersionSettingsCollection(); uniqueLabels = new List <string>(); builder.ReportProgress("{0} Version {1}\r\n{2}", this.Name, this.Version, this.Copyright); root = configuration.SelectSingleNode("configuration"); if (root.IsEmptyElement) { throw new BuilderException("VBP0002", "The Version Builder plug-in has not been configured yet"); } // Add an element for the current project. This one won't have // a project to build. currentVersion = new VersionSettings(); allVersions.Add(currentVersion); node = root.SelectSingleNode("currentProject"); if (node != null) { currentVersion.FrameworkLabel = node.GetAttribute("label", String.Empty).Trim(); currentVersion.Version = node.GetAttribute("version", String.Empty).Trim(); ripOld = node.GetAttribute("ripOldApis", String.Empty); // This wasn't in older versions if (!String.IsNullOrEmpty(ripOld)) { ripOldApis = Convert.ToBoolean(ripOld, CultureInfo.InvariantCulture); } } allVersions.FromXml(builder.CurrentProject, root); // An empty label messes up the HTML so use a single space // if it's blank. if (String.IsNullOrEmpty(currentVersion.FrameworkLabel)) { currentVersion.FrameworkLabel = " "; } if (node == null || allVersions.Count == 1) { throw new BuilderException("VBP0003", "A version value and at least one prior version " + "are required for the Version Builder plug-in."); } foreach (VersionSettings vs in allVersions) { if (!uniqueLabels.Contains(vs.FrameworkLabel)) { uniqueLabels.Add(vs.FrameworkLabel); } } uniqueLabels.Sort(); }
/// <summary> /// This method is used to initialize the plug-in at the start of the build process /// </summary> /// <param name="buildProcess">A reference to the current build process</param> /// <param name="configuration">The configuration data that the plug-in should use to initialize itself</param> /// <exception cref="BuilderException">This is thrown if the plug-in configuration is not valid</exception> public void Initialize(BuildProcess buildProcess, XPathNavigator configuration) { XPathNavigator root, node; string ripOld; builder = buildProcess; allVersions = new VersionSettingsCollection(); uniqueLabels = new List <string>(); var metadata = (HelpFileBuilderPlugInExportAttribute)this.GetType().GetCustomAttributes( typeof(HelpFileBuilderPlugInExportAttribute), false).First(); builder.ReportProgress("{0} Version {1}\r\n{2}", metadata.Id, metadata.Version, metadata.Copyright); root = configuration.SelectSingleNode("configuration"); if (root.IsEmptyElement) { throw new BuilderException("VBP0001", "The Version Builder plug-in has not been configured yet"); } // Add an element for the current project. This one won't have a project to build. currentVersion = new VersionSettings(); allVersions.Add(currentVersion); node = root.SelectSingleNode("currentProject"); if (node != null) { currentVersion.FrameworkLabel = node.GetAttribute("label", String.Empty).Trim(); currentVersion.Version = node.GetAttribute("version", String.Empty).Trim(); ripOld = node.GetAttribute("ripOldApis", String.Empty); // This wasn't in older versions if (!String.IsNullOrEmpty(ripOld)) { ripOldApis = Convert.ToBoolean(ripOld, CultureInfo.InvariantCulture); } } allVersions.FromXml(builder.CurrentProject, root); // An empty label messes up the HTML so use a single space if it's blank if (String.IsNullOrEmpty(currentVersion.FrameworkLabel)) { currentVersion.FrameworkLabel = " "; } if (node == null) { throw new BuilderException("VBP0002", "A version value is required for the Version Builder plug-in"); } if (allVersions.Count == 1) { builder.ReportProgress("No other version information was supplied. Only version information " + "for the documented assemblies will be included."); } foreach (VersionSettings vs in allVersions) { if (!uniqueLabels.Contains(vs.FrameworkLabel)) { uniqueLabels.Add(vs.FrameworkLabel); } } uniqueLabels.Sort(); }
/// <summary> /// Validate the configuration and save it /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnOK_Click(object sender, EventArgs e) { Dictionary <int, string> projects = new Dictionary <int, string>(); VersionSettings vs; XmlAttribute attr; XmlNode root, node; string hash; bool isValid = true; txtLabel.Text = txtLabel.Text.Trim(); txtVersion.Text = txtVersion.Text.Trim(); epErrors.Clear(); epErrors.SetIconAlignment(lbVersionInfo, ErrorIconAlignment.BottomRight); if (txtVersion.Text.Length == 0) { epErrors.SetError(txtVersion, "A version for the containing project is required"); isValid = false; } items.Clear(); hash = txtLabel.Text + txtVersion.Text; projects.Add(hash.GetHashCode(), "@CurrentProject"); for (int idx = 0; idx < lbVersionInfo.Items.Count; idx++) { vs = (VersionSettings)lbVersionInfo.Items[idx]; // There can't be duplicate IDs or projects if (projects.ContainsKey(vs.GetHashCode()) || projects.ContainsValue(vs.HelpFileProject)) { epErrors.SetError(lbVersionInfo, "Label + Version values and project filenames must be unique"); isValid = false; break; } if (vs.Version == txtVersion.Text) { epErrors.SetError(lbVersionInfo, "A prior version cannot match the current project's version"); isValid = false; break; } items.Add(vs); projects.Add(vs.GetHashCode(), vs.HelpFileProject); } if (!isValid) { return; } // Store the changes root = config.SelectSingleNode("configuration"); node = root.SelectSingleNode("currentProject"); if (node == null) { node = config.CreateNode(XmlNodeType.Element, "currentProject", null); root.AppendChild(node); attr = config.CreateAttribute("label"); node.Attributes.Append(attr); attr = config.CreateAttribute("version"); node.Attributes.Append(attr); attr = config.CreateAttribute("ripOldApis"); node.Attributes.Append(attr); } else { // This wasn't in older versions so add it if it is missing if (node.Attributes["ripOldApis"] == null) { attr = config.CreateAttribute("ripOldApis"); node.Attributes.Append(attr); } } node.Attributes["label"].Value = txtLabel.Text; node.Attributes["version"].Value = txtVersion.Text; node.Attributes["ripOldApis"].Value = chkRipOldAPIs.Checked.ToString(); items.ToXml(config, root); this.DialogResult = DialogResult.OK; this.Close(); }