/// <summary> /// Convert the project /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnConvert_Click(object sender, EventArgs e) { ConvertToMSBuildFormat converter = null; string project, folder; bool isValid = true; epErrors.Clear(); epErrors.SetIconPadding(txtProjectFile, btnSelectProject.Width + 5); epErrors.SetIconPadding(txtNewProjectFolder, btnSelectNewFolder.Width + 5); project = txtProjectFile.Text.Trim(); if (txtNewProjectFolder.Enabled) { folder = txtNewProjectFolder.Text.Trim(); } else { folder = Path.GetDirectoryName(txtNewProjectFolder.Text); } if (project.Length == 0) { epErrors.SetError(txtProjectFile, "A project file must be specified"); isValid = false; } else if (!File.Exists(project)) { epErrors.SetError(txtProjectFile, "The specified project file does not exist"); isValid = false; } if (folder.Length == 0) { epErrors.SetError(txtNewProjectFolder, "An output folder for the converted project must " + "be specified"); isValid = false; } if (isValid) { project = Path.GetFullPath(project); folder = Path.GetFullPath(folder); if (FolderPath.TerminatePath(Path.GetDirectoryName(project)) == FolderPath.TerminatePath(folder)) { epErrors.SetError(txtNewProjectFolder, "The output folder cannot match the folder of the " + "original project"); isValid = false; } } if (!isValid) { return; } try { this.Cursor = Cursors.WaitCursor; switch (cboProjectFormat.SelectedIndex) { case 1: if (currentProject == null) { converter = new ConvertFromNDoc(txtProjectFile.Text, txtNewProjectFolder.Text); } else { converter = new ConvertFromNDoc(txtProjectFile.Text, currentProject); } break; case 2: if (currentProject == null) { converter = new ConvertFromDocProject(txtProjectFile.Text, txtNewProjectFolder.Text); } else { converter = new ConvertFromDocProject(txtProjectFile.Text, currentProject); } break; case 3: if (currentProject == null) { converter = new ConvertFromSandcastleGui(txtProjectFile.Text, txtNewProjectFolder.Text); } else { converter = new ConvertFromSandcastleGui(txtProjectFile.Text, currentProject); } break; case 4: if (currentProject == null) { converter = new ConvertFromMSExampleGui(txtProjectFile.Text, txtNewProjectFolder.Text); } else { converter = new ConvertFromMSExampleGui(txtProjectFile.Text, currentProject); } break; default: if (currentProject == null) { converter = new ConvertFromShfbFile(txtProjectFile.Text, txtNewProjectFolder.Text); } else { converter = new ConvertFromShfbFile(txtProjectFile.Text, currentProject); } break; } newProjectFilename = converter.ConvertProject(); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); BuilderException bex = ex as BuilderException; if (bex != null) { MessageBox.Show("Unable to convert project. Reason: Error " + bex.ErrorCode + ":" + bex.Message, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Unable to convert project. Reason: " + ex.Message, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } finally { this.Cursor = Cursors.Default; if (converter != null) { converter.Dispose(); } } }
//===================================================================== /// <summary> /// Parse project properties from the project extensions section /// </summary> private void ImportProjectExtensionProperties() { XmlNode props = docProject.SelectSingleNode("//prj:Project/prj:ProjectExtensions/" + "prj:VisualStudio/prj:UserProperties", nsm); string value; if (props == null) { return; } if (docProject.SelectSingleNode("//prj:Project/prj:ProjectExtensions/prj:VisualStudio/" + "prj:FlavorProperties", nsm) != null) { project.HelpFileFormat |= HelpFileFormats.Website; } foreach (XmlAttribute attr in props.Attributes) { switch (attr.Name) { case "DocumentationScope": if (String.Compare(attr.Value, "PublicOnly", StringComparison.OrdinalIgnoreCase) != 0) { project.DocumentInternals = project.DocumentPrivates = true; } break; case "ExternalSources": foreach (string source in attr.Value.Split('|')) { value = source.Trim(); if (value.Length != 0) { if (value[value.Length - 1] == '\\') { project.DocumentationSources.Add(base.FullPath(Path.Combine(value, "*.*")), null, null, false); } else { project.DocumentationSources.Add(base.FullPath(value), null, null, false); } } } break; case "Sandcastle_PresentationName": project.PresentationStyle = attr.Value; break; case "Sandcastle_DocumentationSetName": project.HelpTitle = attr.Value; break; case "Sandcastle_UseFriendlyHtmlFileNames": if (String.Compare(attr.Value, "True", StringComparison.OrdinalIgnoreCase) == 0) { project.NamingMethod = NamingMethod.MemberName; } break; case "Sandcastle_ProduceHelp1x": if (String.Compare(attr.Value, "False", StringComparison.OrdinalIgnoreCase) == 0) { if (project.HelpFileFormat == HelpFileFormats.HtmlHelp1) { project.HelpFileFormat = HelpFileFormats.MSHelp2; } else { project.HelpFileFormat &= ~HelpFileFormats.HtmlHelp1; } } break; case "Sandcastle_ProduceHelp2x": if (String.Compare(attr.Value, "True", StringComparison.OrdinalIgnoreCase) == 0) { project.HelpFileFormat |= HelpFileFormats.MSHelp2; } break; case "Sandcastle_GenerateRootApiTopic": if (String.Compare(attr.Value, "True", StringComparison.OrdinalIgnoreCase) == 0) { project.RootNamespaceContainer = true; } break; case "Sandcastle_MissingDependencies": foreach (string file in attr.Value.Split('|')) { value = file.Trim(); if (value.Length == 0) { continue; } if (value[value.Length - 1] != '\\') { project.References.AddReference(Path.GetFileNameWithoutExtension(value), base.FullPath(value)); } else { foreach (string reference in ConvertToMSBuildFormat.ExpandWildcard( Path.Combine(base.FullPath(value), "*.*"), true)) { if (reference.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || reference.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { project.References.AddReference( Path.GetFileNameWithoutExtension(reference), reference); } } } } break; default: // Ignored break; } } }