Exemplo n.º 1
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 = PresentationStyleTypeConverter.FirstMatching(
                        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.GetFiles(
                                     Path.GetDirectoryName(includePath),
                                     Path.GetFileName(includePath)))
                        {
                            if (file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                                file.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);
        }
Exemplo n.º 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> {
                "CSharp", "VisualBasic", "CPlusPlus"
            };
            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().ToLower(
                            CultureInfo.InvariantCulture);
                        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)));

                            // Since the logo is copied by the
                            // Post-Transform component, set the build
                            // action to None so that it isn't added
                            // to the help file as content.
                            fileItem.BuildAction = BuildAction.None;
                            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 = HelpFileFormat.HtmlHelp1 |
                                                         HelpFileFormat.Website;
                            }
                            break;

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

                        case "template":
                            project.PresentationStyle =
                                PresentationStyleTypeConverter.FirstMatching(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("CSharp");
                            }
                            break;

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

                        case "cppsyntaxdeclaration":
                            if (String.Compare(value, "false",
                                               StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                syntaxFilters.Remove("CPlusPlus");
                            }
                            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);
        }
Exemplo n.º 3
0
        //=====================================================================

        /// <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 |= HelpFileFormat.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":
                    if (attr.Value.IndexOf("prototype", StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        value = "prototype";
                    }
                    else
                    if (attr.Value.IndexOf("hana", StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        value = "hana";
                    }
                    else
                    {
                        value = "vs2005";
                    }

                    project.PresentationStyle =
                        PresentationStyleTypeConverter.FirstMatching(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 == HelpFileFormat.HtmlHelp1)
                        {
                            project.HelpFileFormat = HelpFileFormat.MSHelp2;
                        }
                        else
                        {
                            project.HelpFileFormat &= ~HelpFileFormat.HtmlHelp1;
                        }
                    }
                    break;

                case "Sandcastle_ProduceHelp2x":
                    if (String.Compare(attr.Value, "True",
                                       StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        project.HelpFileFormat |= HelpFileFormat.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;
                }
            }
        }