コード例 #1
0
ファイル: MainForm.cs プロジェクト: Kybs0/Diversos
 /// <summary>
 /// Save the project file
 /// </summary>
 private void SaveProject()
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         project.SaveProject();
         MainForm.UpdateMruList(project.Filename);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write(ex);
         MessageBox.Show(ex.Message, Constants.AppName,
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
コード例 #2
0
        //=====================================================================

        /// <summary>
        /// This is used to perform the actual conversion
        /// </summary>
        /// <returns>The new project filename on success.  An exception is thrown if the conversion fails.</returns>
        public override string ConvertProject()
        {
            SandcastleProject project = base.Project;
            FileItem          fileItem;
            List <string>     syntaxFilters = new List <string> {
                "C#", "Visual Basic", "Managed C++"
            };
            string option, lastProperty = null, value;
            int    pos;

            try
            {
                project.HelpTitle = project.HtmlHelpName = Path.GetFileNameWithoutExtension(base.OldProjectFile);

                using (StreamReader sr = new StreamReader(base.OldProjectFile))
                    while (!sr.EndOfStream)
                    {
                        option = sr.ReadLine();

                        if (String.IsNullOrEmpty(option))
                        {
                            continue;
                        }

                        pos = option.IndexOf('=');

                        if (pos == -1)
                        {
                            continue;
                        }

                        lastProperty = option.Substring(0, pos).Trim().ToLowerInvariant();

                        value = option.Substring(pos + 1).Trim();

                        switch (lastProperty)
                        {
                        case "copyright":
                            project.CopyrightText = value;
                            break;

                        case "productname":
                            project.HelpTitle = value;
                            break;

                        case "assemblydir":
                            project.DocumentationSources.Add(Path.Combine(value, "*.*"), null, null, false);
                            break;

                        case "docdir":
                            this.ConvertAdditionalContent(value);
                            break;

                        case "logo":
                            fileItem = project.AddFileToProject(value, Path.Combine(base.ProjectFolder,
                                                                                    Path.GetFileName(value)));

                            // The transform arguments category of properties will need to be set to include
                            // the logo in the XSL transformations.  The build action must be content.  It
                            // will also need to be moved to the .\Icons folder in the project.
                            fileItem.BuildAction = BuildAction.Content;
                            break;

                        case "msdnlinks":
                            if (String.Compare(value, "false", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                project.HtmlSdkLinkType         = project.WebsiteSdkLinkType = HtmlSdkLinkType.None;
                                project.MSHelp2SdkLinkType      = MSHelp2SdkLinkType.Index;
                                project.MSHelpViewerSdkLinkType = MSHelpViewerSdkLinkType.Id;
                            }
                            break;

                        case "outputtype":
                            if (value.IndexOf("website", StringComparison.OrdinalIgnoreCase) != -1)
                            {
                                project.HelpFileFormat = HelpFileFormats.HtmlHelp1 | HelpFileFormats.Website;
                            }
                            break;

                        case "friendlyfilenames":
                            if (String.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                project.NamingMethod = NamingMethod.MemberName;
                            }
                            break;

                        case "template":
                            project.PresentationStyle = value;
                            break;

                        case "internals":
                            if (String.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                project.DocumentPrivates = project.DocumentInternals = true;
                            }
                            break;

                        case "cssyntaxdeclaration":
                            if (String.Compare(value, "false", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                syntaxFilters.Remove("C#");
                            }
                            break;

                        case "vbsyntaxdeclaration":
                            if (String.Compare(value, "false", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                syntaxFilters.Remove("Visual Basic");
                            }
                            break;

                        case "cppsyntaxdeclaration":
                            if (String.Compare(value, "false", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                syntaxFilters.Remove("Managed C++");
                            }
                            break;

                        case "javascriptsyntaxdeclaration":
                            if (String.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                syntaxFilters.Add("JavaScript");
                            }
                            break;

                        default:        // Ignored
                            break;
                        }
                    }

                // Set the syntax filters
                project.SyntaxFilters = String.Join(", ", syntaxFilters.ToArray());

                base.CreateFolderItems();
                project.SaveProject(project.Filename);
            }
            catch (Exception ex)
            {
                throw new BuilderException("CVT0005", String.Format(CultureInfo.CurrentCulture,
                                                                    "Error reading project from '{0}' (last property = {1}):\r\n{2}", base.OldProjectFile,
                                                                    lastProperty, ex.Message), ex);
            }

            return(project.Filename);
        }
コード例 #3
0
        //=====================================================================

        /// <summary>
        /// This is used to perform the actual conversion
        /// </summary>
        /// <returns>The new project filename on success.  An exception is
        /// thrown if the conversion fails.</returns>
        public override string ConvertProject()
        {
            XPathDocument     sourceFile;
            XPathNavigator    navNDoc;
            SearchOption      searchOpts;
            SandcastleProject project = base.Project;
            FileItem          fileItem;
            List <string>     syntaxFilters = new List <string> {
                "C#", "Visual Basic", "Managed C++"
            };
            string assemblyName, commentsName, folderName, value, destFile,
                   propName = null;

            string[] list;

            try
            {
                sourceFile = new XPathDocument(base.OldProjectFile);
                navNDoc    = sourceFile.CreateNavigator();

                // Add the assemblies
                foreach (XPathNavigator assembly in navNDoc.Select(
                             "project/assemblies/assembly"))
                {
                    assemblyName = this.FullPath(
                        assembly.GetAttribute("location", String.Empty));
                    commentsName = this.FullPath(
                        assembly.GetAttribute("documentation", String.Empty));

                    if (!String.IsNullOrEmpty(assemblyName))
                    {
                        project.DocumentationSources.Add(assemblyName, null,
                                                         null, false);
                    }

                    if (!String.IsNullOrEmpty(commentsName))
                    {
                        project.DocumentationSources.Add(commentsName, null,
                                                         null, false);
                    }
                }

                // Add reference paths
                foreach (XPathNavigator reference in navNDoc.Select(
                             "project/referencePaths/referencePath"))
                {
                    folderName = this.FullPath(reference.GetAttribute(
                                                   "path", String.Empty));

                    if (folderName.EndsWith("\\**", StringComparison.Ordinal))
                    {
                        searchOpts = SearchOption.AllDirectories;
                        folderName = folderName.Substring(0,
                                                          folderName.Length - 3);
                    }
                    else
                    {
                        searchOpts = SearchOption.TopDirectoryOnly;
                    }

                    foreach (string refFile in Directory.EnumerateFiles(folderName, "*.dll", searchOpts))
                    {
                        Project.References.AddReference(Path.GetFileNameWithoutExtension(refFile), refFile);
                    }
                }

                // Add the namespace summaries
                foreach (XPathNavigator ns in navNDoc.Select(
                             "project/namespaces/namespace"))
                {
                    if (!String.IsNullOrEmpty(ns.InnerXml))
                    {
                        project.NamespaceSummaries.Add(ns.GetAttribute("name", String.Empty), false, true,
                                                       ns.InnerXml);
                    }
                }

                // Add one for the global namespace if it isn't there
                if (project.NamespaceSummaries[String.Empty] == null)
                {
                    project.NamespaceSummaries.Add(String.Empty, false, false, String.Empty);
                }

                project.NamespaceSummaries.Sort();

                // Add options from the MSDN documenters.  This will be a
                // merger of all the documenters present in the file since
                // we can't tell which one is the active one.  The file can
                // be edited by hand to delete unwanted documenters or
                // properties before converting it.
                foreach (XPathNavigator node in navNDoc.Select(
                             "project/documenters/documenter[@name=\"MSDN\" or " +
                             "@name=\"MSDN-CHM\" or @name=\"VS.NET 2003\" or " +
                             "@name=\"MSDN 2003\"]"))
                {
                    foreach (XPathNavigator child in node.Select("*"))
                    {
                        propName = child.GetAttribute("name", String.Empty);

                        switch (propName)
                        {
                        case "AdditionalContentResourceDirectory":
                            this.ConvertAdditionalContent(child.GetAttribute(
                                                              "value", String.Empty));
                            break;

                        case "BinaryTOC":
                            project.BinaryTOC = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "CleanIntermediates":
                            project.CleanIntermediates = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "CopyrightHref":
                            project.CopyrightHref = child.GetAttribute(
                                "value", String.Empty);
                            break;

                        case "CopyrightText":
                            project.CopyrightText = child.GetAttribute(
                                "value", String.Empty);
                            break;

                        case "DocumentAttributes":
                            project.DocumentAttributes = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "DocumentExplicitInterfaceImplementations":
                            project.DocumentExplicitInterfaceImplementations =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "DocumentInheritedMembers":
                            project.DocumentInheritedMembers =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "DocumentInheritedFrameworkMembers":
                            project.DocumentInheritedFrameworkMembers =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "DocumentInternals":
                            project.DocumentInternals = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "DocumentPrivates":
                            project.DocumentPrivates = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "DocumentProtected":
                            project.DocumentProtected = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "DocumentProtectedInternalAsProtected":
                            project.DocumentProtectedInternalAsProtected =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "DocumentSealedProtected":
                            project.DocumentSealedProtected =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "FeedbackEmailAddress":
                            project.FeedbackEMailAddress =
                                child.GetAttribute("value", String.Empty);
                            break;

                        case "HtmlHelpName":
                            project.HtmlHelpName = child.GetAttribute(
                                "value", String.Empty);
                            break;

                        case "IncludeFavorites":
                            project.IncludeFavorites = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "OutputDirectory":
                            folderName = child.GetAttribute("value",
                                                            String.Empty);

                            if (folderName != @".\doc\")
                            {
                                project.OutputPath = new FolderPath(
                                    folderName, project);
                            }
                            break;

                        case "Preliminary":
                            project.Preliminary = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "Title":
                            value = child.GetAttribute("value", String.Empty);

                            if (value != "An NDoc Documented Class Library" &&
                                value != "An NDoc documented library")
                            {
                                project.HelpTitle = value;
                            }
                            break;

                        case "RootPageContainsNamespaces":
                            project.RootNamespaceContainer =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "RootPageFileName":
                            value = this.FullPath(child.GetAttribute(
                                                      "value", String.Empty));
                            destFile = Path.Combine(base.ProjectFolder,
                                                    Path.GetFileName(value));
                            project.AddFileToProject(value, destFile);
                            break;

                        case "RootPageTOCName":
                            project.RootNamespaceTitle = child.GetAttribute(
                                "value", String.Empty);
                            break;

                        case "FilesToInclude":
                            foreach (string filename in child.GetAttribute(
                                         "value", String.Empty).Split(new char[] { '|' }))
                            {
                                value    = this.FullPath(filename.Trim());
                                destFile = Path.Combine(base.ProjectFolder,
                                                        Path.GetFileName(value));
                                project.AddFileToProject(value, destFile);
                            }
                            break;

                        case "AutoDocumentConstructors":
                            project.AutoDocumentConstructors =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "ShowMissingSummaries":
                            project.ShowMissingSummaries =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "ShowMissingRemarks":
                            project.ShowMissingRemarks =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "ShowMissingParams":
                            project.ShowMissingParams =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "ShowMissingReturns":
                            project.ShowMissingReturns =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "ShowMissingValues":
                            project.ShowMissingValues =
                                Convert.ToBoolean(child.GetAttribute(
                                                      "value", String.Empty),
                                                  CultureInfo.InvariantCulture);
                            break;

                        case "ShowVisualBasic":
                            if (child.GetAttribute("value", String.Empty) == "False")
                            {
                                syntaxFilters.Remove("Visual Basic");
                            }
                            break;

                        case "AboutPageIconPage":
                        case "AboutPageInfo":
                        case "EmptyIndexTermPage":
                        case "IntroductionPage":
                        case "NavFailPage":
                            value = this.FullPath(child.GetAttribute(
                                                      "value", String.Empty));
                            destFile = Path.Combine(base.ProjectFolder,
                                                    Path.GetFileName(value));
                            fileItem = project.AddFileToProject(value,
                                                                destFile);
                            fileItem.ExcludeFromToc = true;
                            break;

                        case "CollectionTOCStyle":
                            project.CollectionTocStyle =
                                (CollectionTocStyle)Enum.Parse(
                                    typeof(CollectionTocStyle),
                                    child.GetAttribute("value", String.Empty),
                                    true);
                            break;

                        case "DocSetList":
                            list = child.GetAttribute("value",
                                                      String.Empty).Split(',');

                            foreach (string docSet in list)
                            {
                                project.HelpAttributes.Add("DocSet",
                                                           docSet.Trim());
                            }
                            break;

                        case "IncludeDefaultStopWordList":
                            project.IncludeStopWordList = Convert.ToBoolean(
                                child.GetAttribute("value", String.Empty),
                                CultureInfo.InvariantCulture);
                            break;

                        case "Version":
                            project.HelpFileVersion = child.GetAttribute(
                                "value", String.Empty);
                            break;

                        case "OutputTarget":
                            value = child.GetAttribute("value", String.Empty);

                            if (value == "HtmlHelp")
                            {
                                project.HelpFileFormat = HelpFileFormats.HtmlHelp1;
                            }
                            else
                            if (value == "Web")
                            {
                                project.HelpFileFormat = HelpFileFormats.Website;
                            }
                            else
                            {
                                project.HelpFileFormat = HelpFileFormats.HtmlHelp1 |
                                                         HelpFileFormats.Website;
                            }
                            break;

                        case "SdkDocLanguage":
                            project.Language = new CultureInfo(
                                child.GetAttribute("value", String.Empty));
                            break;

                        case "SdkDocVersion":
                            value = child.GetAttribute("value", String.Empty).Substring(5).Replace('_', '.');
                            project.FrameworkVersion = Utility.ConvertFromOldValue(value);
                            break;

                        case "SdkLinksOnWeb":
                            if (child.GetAttribute("value", String.Empty) == "True")
                            {
                                project.HtmlSdkLinkType         = project.WebsiteSdkLinkType = HtmlSdkLinkType.Msdn;
                                project.MSHelp2SdkLinkType      = MSHelp2SdkLinkType.Msdn;
                                project.MSHelpViewerSdkLinkType = MSHelpViewerSdkLinkType.Msdn;
                            }
                            else
                            {
                                project.HtmlSdkLinkType         = project.WebsiteSdkLinkType = HtmlSdkLinkType.None;
                                project.MSHelp2SdkLinkType      = MSHelp2SdkLinkType.Index;
                                project.MSHelpViewerSdkLinkType = MSHelpViewerSdkLinkType.Id;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }

                // Set the syntax filters
                project.SyntaxFilters = String.Join(", ", syntaxFilters.ToArray());

                base.CreateFolderItems();
                project.SaveProject(project.Filename);
            }
            catch (Exception ex)
            {
                throw new BuilderException("CVT0005", String.Format(
                                               CultureInfo.CurrentCulture, "Error reading project " +
                                               "from '{0}' (last property = {1}):\r\n{2}",
                                               base.OldProjectFile, propName, ex.Message), ex);
            }

            return(project.Filename);
        }
コード例 #4
0
        /// <inheritdoc />
        public int UpgradeProject(string bstrFileName, uint fUpgradeFlag, string bstrCopyLocation,
                                  out string pbstrUpgradedFullyQualifiedFileName, IVsUpgradeLogger pLogger, out int pUpgradeRequired,
                                  out Guid pguidNewProjectFactory)
        {
            uint verdict, moreInfo, ignored;

            string[] files = new string[1] {
                bstrFileName
            };
            string projectName     = Path.GetFileNameWithoutExtension(bstrFileName);
            bool   continueUpgrade = false;

            pbstrUpgradedFullyQualifiedFileName = bstrFileName;

            // Be sure we need an upgrade
            this.UpgradeProject_CheckOnly(bstrFileName, pLogger, out pUpgradeRequired, out pguidNewProjectFactory, out ignored);

            if (pUpgradeRequired == 0)
            {
                return(VSConstants.S_OK);
            }

            // See if the file is editable
            IVsQueryEditQuerySave2 qes = Utility.GetServiceFromPackage <IVsQueryEditQuerySave2, SVsQueryEditQuerySave>(true);

            ErrorHandler.ThrowOnFailure(qes.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_ReportOnly |
                                                           (uint)__VSQueryEditFlags2.QEF_AllowUnopenedProjects, 1, files, null, null, out verdict,
                                                           out moreInfo));

            if (verdict == (uint)tagVSQueryEditResult.QER_EditOK)
            {
                continueUpgrade = true;
            }

            if (verdict == (uint)tagVSQueryEditResult.QER_EditNotOK)
            {
                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, bstrFileName,
                                   "The project file is read-only.  An attempt will be made to check it out if under source control.");

                if ((moreInfo & (uint)tagVSQueryEditResultFlags.QER_ReadOnlyUnderScc) != 0)
                {
                    ErrorHandler.ThrowOnFailure(qes.QueryEditFiles(
                                                    (uint)tagVSQueryEditFlags.QEF_DisallowInMemoryEdits |
                                                    (uint)__VSQueryEditFlags2.QEF_AllowUnopenedProjects |
                                                    (uint)tagVSQueryEditFlags.QEF_ForceEdit_NoPrompting, 1, files, null, null,
                                                    out verdict, out moreInfo));

                    if (verdict == (uint)tagVSQueryEditResult.QER_EditOK)
                    {
                        continueUpgrade = true;
                    }
                }

                if (continueUpgrade)
                {
                    pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, bstrFileName,
                                       "The project file was successfully checked out.");
                }
                else
                {
                    pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, bstrFileName,
                                       "Unable to check project out of source control.  Upgrade failed.");
                    throw new InvalidOperationException("Unable to check out project file for upgrade: " + bstrFileName);
                }
            }

            // If file was modified during the checkout, confirm that it still needs upgrading
            if ((moreInfo & (uint)tagVSQueryEditResultFlags.QER_MaybeChanged) != 0)
            {
                this.UpgradeProject_CheckOnly(bstrFileName, pLogger, out pUpgradeRequired, out pguidNewProjectFactory, out ignored);

                if (pUpgradeRequired == 0)
                {
                    if (pLogger != null)
                    {
                        pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, bstrFileName,
                                           "The project file was checked out and is already up to date.  No upgrade needed.");
                    }

                    return(VSConstants.S_OK);
                }
            }

            if (continueUpgrade)
            {
                // Make a backup?
                if (fUpgradeFlag == PUVFF_SXSBACKUP)
                {
                    File.Copy(bstrFileName, bstrFileName + ".backup", true);
                }

                // The SancastleProject class contains all the code needed to update the project so all we need
                // to do is load a copy and force it to save a new copy.
                using (SandcastleProject p = new SandcastleProject(bstrFileName, true))
                {
                    p.UpgradeProjectProperties();
                    p.SaveProject(bstrFileName);
                }

                pLogger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, bstrFileName,
                                   "The project file was upgraded successfully.");
            }

            return(VSConstants.S_OK);
        }
コード例 #5
0
        //=====================================================================

        /// <summary>
        /// This is used to perform the actual conversion
        /// </summary>
        /// <returns>The new project filename on success.  An exception is thrown if the conversion fails.</returns>
        public override string ConvertProject()
        {
            XPathNavigator navProject;
            Topic          t;
            string         lastProperty = null;

            try
            {
                project           = base.Project;
                project.HelpTitle = project.HtmlHelpName =
                    Path.GetFileNameWithoutExtension(base.OldProjectFile);

                // We'll process it as XML rather than an MSBuild project as it may contain references to target
                // files that don't exist which would prevent it from loading.
                docProject = new XmlDocument();
                docProject.Load(base.OldProjectFile);
                nsm = new XmlNamespaceManager(docProject.NameTable);
                nsm.AddNamespace("prj", docProject.DocumentElement.NamespaceURI);
                navProject = docProject.CreateNavigator();

                lastProperty = "ProjectExtensions/VisualStudio";
                this.ImportProjectExtensionProperties();

                // Parse each build item to look for stuff we need to add to the project
                foreach (XPathNavigator buildItem in navProject.Select("//prj:Project/prj:ItemGroup/*", nsm))
                {
                    lastProperty = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", buildItem.Name,
                                                 buildItem.GetAttribute("Include", String.Empty));

                    switch (buildItem.Name)
                    {
                    case "Content":
                    case "None":
                        this.ImportFile(buildItem);
                        break;

                    case "ProjectReference":
                        project.DocumentationSources.Add(base.FullPath(buildItem.GetAttribute("Include",
                                                                                              String.Empty)), null, null, false);
                        break;

                    default:        // Ignore
                        break;
                    }
                }

                // Add project-level help attributes if any
                if (topicSettings.TryGetValue("*", out t))
                {
                    foreach (MSHelpAttr ha in t.HelpAttributes)
                    {
                        project.HelpAttributes.Add(ha);
                    }
                }

                if (topicLayoutFilename != null)
                {
                    this.CreateContentLayoutFile();
                }
                else
                if (topicSettings.Count != 0)
                {
                    this.CreateDefaultContentLayoutFile();
                }

                base.CreateFolderItems();
                project.SaveProject(project.Filename);
            }
            catch (Exception ex)
            {
                throw new BuilderException("CVT0005", String.Format(CultureInfo.CurrentCulture,
                                                                    "Error reading project from '{0}' (last property = {1}):\r\n{2}", base.OldProjectFile,
                                                                    lastProperty, ex.Message), ex);
            }

            return(project.Filename);
        }
コード例 #6
0
        //=====================================================================
        /// <summary>
        /// This is used to perform the actual conversion
        /// </summary>
        /// <returns>The new project filename on success.  An exception is
        /// thrown if the conversion fails.</returns>
        public override string ConvertProject()
        {
            XPathNavigator navProject;
            Topic t;
            string lastProperty = null;

            try
            {
                project = base.Project;
                project.HelpTitle = project.HtmlHelpName =
                    Path.GetFileNameWithoutExtension(base.OldProjectFile);

                // We'll process it as XML rather than an MSBuild project as
                // it may contain references to target files that don't exist
                // which would prevent it from loading.
                docProject = new XmlDocument();
                docProject.Load(base.OldProjectFile);
                nsm = new XmlNamespaceManager(docProject.NameTable);
                nsm.AddNamespace("prj", docProject.DocumentElement.NamespaceURI);
                navProject = docProject.CreateNavigator();

                lastProperty = "ProjectExtensions/VisualStudio";
                this.ImportProjectExtensionProperties();

                // Parse each build item to look for stuff we need to add
                // to the project.
                foreach(XPathNavigator buildItem in navProject.Select(
                  "//prj:Project/prj:ItemGroup/*", nsm))
                {
                    lastProperty = String.Format(CultureInfo.InvariantCulture,
                        "{0} ({1})", buildItem.Name,
                        buildItem.GetAttribute("Include", String.Empty));

                    switch(buildItem.Name)
                    {
                        case "Content":
                        case "None":
                            this.ImportFile(buildItem);
                            break;

                        case "ProjectReference":
                            project.DocumentationSources.Add(base.FullPath(
                                buildItem.GetAttribute("Include", String.Empty)),
                                null, null, false);
                            break;

                        default:    // Ignore
                            break;
                    }
                }

                // Add project-level help attributes if any
                if(topicSettings.TryGetValue("*", out t))
                    foreach(MSHelpAttr ha in t.HelpAttributes)
                        project.HelpAttributes.Add(ha);

                if(topicLayoutFilename != null)
                    this.CreateContentLayoutFile();
                else
                    if(topicSettings.Count != 0)
                        this.CreateDefaultContentLayoutFile();

                base.CreateFolderItems();
                project.SaveProject(project.Filename);
            }
            catch(Exception ex)
            {
                throw new BuilderException("CVT0005", String.Format(
                    CultureInfo.CurrentCulture, "Error reading project " +
                    "from '{0}' (last property = {1}):\r\n{2}",
                    base.OldProjectFile, lastProperty, ex.Message), ex);
            }

            return project.Filename;
        }
コード例 #7
0
        //=====================================================================

        /// <summary>
        /// This is used to perform the actual conversion
        /// </summary>
        /// <returns>The new project filename on success.  An exception is thrown if the conversion fails.</returns>
        public override string ConvertProject()
        {
            XmlNamespaceManager nsm;
            XmlDocument         sourceFile;
            XPathNavigator      navProject, navProp;
            SandcastleProject   project = base.Project;
            string includePath, lastProperty = null;

            try
            {
                project.HelpTitle = project.HtmlHelpName = Path.GetFileNameWithoutExtension(base.OldProjectFile);

                sourceFile = new XmlDocument();
                sourceFile.Load(base.OldProjectFile);
                nsm = new XmlNamespaceManager(sourceFile.NameTable);
                nsm.AddNamespace("prj", sourceFile.DocumentElement.NamespaceURI);

                navProject = sourceFile.CreateNavigator();

                // Get the name, topic style, and language ID
                lastProperty = "Name";
                navProp      = navProject.SelectSingleNode("//prj:Project/prj:PropertyGroup/prj:Name", nsm);

                if (navProp != null)
                {
                    project.HtmlHelpName = project.HelpTitle = navProp.Value;
                }

                lastProperty = "TopicStyle";
                navProp      = navProject.SelectSingleNode("//prj:Project/prj:PropertyGroup/prj:TopicStyle", nsm);

                if (navProp != null)
                {
                    project.PresentationStyle = navProp.Value;
                }

                lastProperty = "LanguageId";
                navProp      = navProject.SelectSingleNode("//prj:Project/prj:PropertyGroup/prj:LanguageId", nsm);

                if (navProp != null)
                {
                    project.Language = new CultureInfo(Convert.ToInt32(navProp.Value,
                                                                       CultureInfo.InvariantCulture));
                }

                // Add the documentation sources
                lastProperty = "Dlls|Comments";

                foreach (XPathNavigator docSource in navProject.Select("//prj:Project/prj:ItemGroup/prj:Dlls|" +
                                                                       "//prj:Project/prj:ItemGroup/prj:Comments", nsm))
                {
                    includePath = docSource.GetAttribute("Include", String.Empty);

                    if (!String.IsNullOrEmpty(includePath))
                    {
                        project.DocumentationSources.Add(includePath, null, null, false);
                    }
                }

                // Add the dependencies
                lastProperty = "Dependents";

                foreach (XPathNavigator dependency in navProject.Select(
                             "//prj:Project/prj:ItemGroup/prj:Dependents", nsm))
                {
                    includePath = dependency.GetAttribute("Include", String.Empty);

                    if (includePath.IndexOfAny(new char[] { '*', '?' }) == -1)
                    {
                        project.References.AddReference(Path.GetFileNameWithoutExtension(includePath), includePath);
                    }
                    else
                    {
                        foreach (string file in Directory.EnumerateFiles(Path.GetDirectoryName(includePath),
                                                                         Path.GetFileName(includePath)).Where(f =>
                                                                                                              f.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                                                                                                              f.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)))
                        {
                            project.References.AddReference(Path.GetFileNameWithoutExtension(file), file);
                        }
                    }
                }

                project.SaveProject(project.Filename);
            }
            catch (Exception ex)
            {
                throw new BuilderException("CVT0005", String.Format(CultureInfo.CurrentCulture,
                                                                    "Error reading project from '{0}' (last property = {1}):\r\n{2}", base.OldProjectFile,
                                                                    lastProperty, ex.Message), ex);
            }

            return(project.Filename);
        }