Пример #1
0
        private void ProcessMarker(ConceptualGroupContext conceptualContext,
                                   BuildContext context)
        {
            IList <ConceptualMarkerTopic> markerTopics = conceptualContext.MarkerTopics;

            BuildTocContext tocContext = context.TocContext;

            ConceptualGroupTocInfo groupTocInfo =
                tocContext.Items[conceptualContext.Id] as ConceptualGroupTocInfo;

            if (groupTocInfo == null)
            {
                return;
            }

            for (int i = 0; i < markerTopics.Count; i++)
            {
                ConceptualMarkerTopic markerTopic = markerTopics[i];

                if (conceptualContext.Exclude(markerTopic))
                {
                    this.RemoveMarker(groupTocInfo, markerTopic, context);
                }
                else
                {
                    this.ProcessMarker(groupTocInfo, markerTopic, context);
                }
            }
        }
        private void WriteMshc(XmlWriter writer)
        {
            BuildFormat   format   = this.Format;
            BuildSettings settings = this.Settings;
            BuildContext  context  = this.Context;

            if (format.FormatType != BuildFormatType.HtmlHelp3)
            {
                return;
            }

            BuildTocContext tocContext = context.TocContext;
            string          tocFile    = tocContext.GetValue("$" + format.Name);

            if (!String.IsNullOrEmpty(tocFile) && File.Exists(tocFile))
            {
                tocFile = Path.GetFileName(tocFile);
            }
            else
            {
                tocFile = context["$HelpTocFile"];
            }

            FormatMhv mshcFormat = (FormatMhv)format;

            //<!-- add Microsoft Help System data -->
            //<component type="Microsoft.Ddue.Tools.MSHCComponent" assembly="%DXROOT%\ProductionTools\BuildComponents.dll">
            //  <data self-branded="true" topic-version="100" toc-file=".\toc.xml" toc-parent="" toc-parent-version="100" />
            //</component>
            writer.WriteComment(" Add Microsoft Help System data  ");
            writer.WriteStartElement("component");    // start - component
            writer.WriteAttributeString("type", "Sandcastle.Components.MshcComponent");
            writer.WriteAttributeString("assembly", "$(SandAssistComponent)");

            // For now, lets simply write the default...
            writer.WriteStartElement("data");     // start - data
            writer.WriteAttributeString("self-branded",
                                        mshcFormat.Selfbranded.ToString());
            writer.WriteAttributeString("topic-version",
                                        mshcFormat.TopicVersion.ToString());
            writer.WriteAttributeString("toc-file", @".\" + tocFile);
            writer.WriteAttributeString("toc-parent",
                                        mshcFormat.TocParent.ToString());
            writer.WriteAttributeString("toc-parent-version",
                                        mshcFormat.TocParentVersion.ToString());
            writer.WriteAttributeString("locale",
                                        settings.CultureInfo.Name.ToLower());
            writer.WriteEndElement();             // end - data

            writer.WriteEndElement();             // end - component
        }
Пример #3
0
        protected override bool OnExecute(BuildContext context)
        {
            BuildLogger logger = context.Logger;

            bool buildResult = false;

            try
            {
                buildResult = PreProcess(context, logger);

                if (buildResult)
                {
                    if (_options != null)
                    {
                        _options.TocStyle = _tocStyle;

                        BuildTocContext tocContext = context.TocContext;
                        string          tocFile    = tocContext.GetValue("$" + _format.Name);
                        if (!String.IsNullOrEmpty(tocFile) && File.Exists(tocFile))
                        {
                            _options.TocFile = Path.GetFileName(tocFile);
                        }

                        FormatChmHelper chmHelper = new FormatChmHelper(_options);
                        chmHelper.Run(context);
                    }
                    else
                    {
                        buildResult = base.Run(logger);

                        if (buildResult)
                        {
                            buildResult = PostProcess(context, logger);
                        }
                    }

                    this.OptimizeStyles(context);
                }
            }
            catch (Exception ex)
            {
                buildResult = false;
                if (logger != null)
                {
                    logger.WriteLine(ex, BuildLoggerLevel.Error);
                }
            }

            return(buildResult);
        }
Пример #4
0
        protected override bool OnExecute(BuildContext context)
        {
            if (_options == null || String.IsNullOrEmpty(_helpDir))
            {
                return(false);
            }

            BuildTocContext tocContext = context.TocContext;
            string          tocFile    = tocContext.GetValue("$" + _format.Name);

            if (!String.IsNullOrEmpty(tocFile) && File.Exists(tocFile))
            {
                _options.HelpTocFile = Path.GetFileName(tocFile);
            }
            FormatWebHelper helper = new FormatWebHelper(_options);

            return(helper.Run(context));
        }
Пример #5
0
        private void ProcessMarkers(BuildContext context)
        {
            BuildTocContext tocContext = context.TocContext;

            tocContext.LoadAll();

            IBuildNamedList <BuildGroupContext> groupContexts = context.GroupContexts;

            for (int i = 0; i < groupContexts.Count; i++)
            {
                BuildGroupContext groupContext = groupContexts[i];
                if (groupContext.GroupType == BuildGroupType.Conceptual)
                {
                    ConceptualGroupContext conceptualContext =
                        (ConceptualGroupContext)groupContext;

                    if (conceptualContext.HasMarkers)
                    {
                        this.ProcessMarker(conceptualContext, context);
                    }
                }
            }

            if (_pendindDelete != null && _pendindDelete.Count != 0)
            {
                for (int i = 0; i < _pendindDelete.Count; i++)
                {
                    _pendindDelete[i].RemoveTopic();
                }
            }

            _pendindDelete = null;

            tocContext.SaveAll();

            // Reset the markers state, since it is handled...
            context["$HelpTocMarkers"] = Boolean.FalseString;
        }
Пример #6
0
        private bool ProcessRootToc(BuildContext context,
                                    BuildGroupContext groupContext, string tocFilePath)
        {
            bool buildResult = true;

            string rootTopicId = _group.RootTopicId;

            if (String.IsNullOrEmpty(rootTopicId) ||
                !ConceptualUtils.IsValidId(rootTopicId))
            {
                return(buildResult);
            }

            BuildLogger logger = context.Logger;

            BuildTocContext tocContext = context.TocContext;
            IBuildNamedList <BuildTopicTocInfo> relatedTopics =
                tocContext.RelatedTopics;

            if (relatedTopics == null || relatedTopics.Count == 0 ||
                relatedTopics[rootTopicId] == null)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "The related topic '{0}' for the reference group '{1}' is not defined.",
                                         rootTopicId, _group.Name), BuildLoggerLevel.Warn);
                }

                return(buildResult);
            }

            bool isRooted = Convert.ToBoolean(groupContext["$IsRooted"]);

            string tocFileBackup = Path.ChangeExtension(tocFilePath, ".tocbak");

            File.SetAttributes(tocFilePath, FileAttributes.Normal);
            File.Move(tocFilePath, tocFileBackup);

            XmlWriter writer = null;

            try
            {
                XmlWriterSettings writerSettings = new XmlWriterSettings();
                writerSettings.Indent             = true;
                writerSettings.OmitXmlDeclaration = false;
                writer = XmlWriter.Create(tocFilePath, writerSettings);

                writer.WriteStartElement("topics"); // start: topics
                writer.WriteStartElement("topic");  // start: topic
                writer.WriteAttributeString("id", rootTopicId);
                writer.WriteAttributeString("file", rootTopicId);

                using (XmlReader reader = XmlReader.Create(tocFileBackup))
                {
                    if (reader.IsStartElement("topics"))
                    {
                        while (!reader.EOF)
                        {
                            if (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.Element &&
                                    String.Equals(reader.Name, "topic",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    if (isRooted)
                                    {
                                        isRooted = false;
                                        continue;
                                    }

                                    writer.WriteNode(reader, true);
                                }
                            }
                        }
                    }
                }

                writer.WriteEndElement();           // end: topic
                writer.WriteEndElement();           // end: topics

                writer.Close();
                writer = null;

                return(true);
            }
            catch (Exception ex)
            {
                File.Move(tocFileBackup, tocFilePath);

                if (logger != null)
                {
                    logger.WriteLine(ex);
                }

                buildResult = false;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer = null;
                }
            }

            return(buildResult);
        }
Пример #7
0
        private bool OpenHelpFile(BuildContext context)
        {
            // 1. Start the Microsoft Help Library Agent process...
            StartHelpAgent(context);

            // 2. Wait for the help library service to be available...
            int waitCount = 0;

            while (!ProcessRunner.IsProcessOpen("HelpLibAgent"))
            {
                // We wait for a max of 5 times, should be enough on even slow
                // systems...
                if (waitCount >= 5)
                {
                    break;
                }

                waitCount++;
                Thread.Sleep(100);
            }

            BuildLogger logger = context.Logger;

            if (logger != null)
            {
                logger.WriteLine("Opening: " + _helpPath,
                                 BuildLoggerLevel.Info);
            }

            string helpUrlFormat =
                "ms-xhelp:///?method=page&id={0}&product={1}&productversion={2}&locale={3}";

            string helpUrl = null;
            // 3. The startup help ID will normally be saved in the context, get it...
            string helpStartId = context["$HelpTocRoot"];
            string tempText    = context["$HelpHierarchicalToc"];
            // If there is a custom format TOC, we use its root...
            BuildTocContext tocContext = context.TocContext;
            BuildFormatList formatList = context.Settings.Formats;
            FormatMhv       mhvFormat  = formatList[BuildFormatType.HtmlHelp3]
                                         as FormatMhv;
            string formatTocFile = tocContext.GetValue("$" + mhvFormat.Name);
            string formatTocRoot = tocContext.GetValue("$" + mhvFormat.Name +
                                                       "-HelpTocRoot");

            if (!(String.IsNullOrEmpty(formatTocFile) && File.Exists(formatTocFile)) &&
                !String.IsNullOrEmpty(formatTocRoot))
            {
                helpStartId = formatTocRoot;
            }
            else if (!String.IsNullOrEmpty(tempText) && String.Equals(tempText,
                                                                      Boolean.TrueString, StringComparison.OrdinalIgnoreCase))
            {
                helpStartId = context["$HelpHierarchicalTocRoot"];
            }

            if (String.IsNullOrEmpty(helpStartId))
            {
                helpUrl = String.Format(
                    "ms-xhelp:///?method=page&id=-1&format=html&product={0}&productVersion={1}",
                    _catalogProductId, _catalogVersion);
            }
            else
            {
                helpUrl = String.Format(helpUrlFormat,
                                        helpStartId, _catalogProductId, _catalogVersion, _catalogLocale);
            }

            try
            {
                // 4. Request the Microsoft Help Library Agent to open the page...
                Process startHelp = Process.Start(helpUrl);
                // The return could be null, if no process resource is started
                // (for example, if an existing process is reused as in browsers).
                if (startHelp != null)
                {
                    startHelp.Close();
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.WriteLine(ex, BuildLoggerLevel.Error);
                }

                return(false);
            }
        }
Пример #8
0
        protected override bool OnExecute(BuildContext context)
        {
            string workingDir = this.WorkingDirectory;

            if (String.IsNullOrEmpty(workingDir))
            {
                throw new BuildException("A working directory is required.");
            }

            BuildTocContext tocContext = context.TocContext;
            string          tocFile    = tocContext.GetValue("$" + _buildFormat.Name);

            if (!String.IsNullOrEmpty(tocFile) && File.Exists(tocFile))
            {
                _helpToc = Path.GetFileName(tocFile);
            }

            if (String.IsNullOrEmpty(_helpName) || String.IsNullOrEmpty(_helpToc))
            {
                throw new BuildException("The required property values are set.");
            }

            _logger = context.Logger;
            if (_logger != null)
            {
                _verbosity = _logger.Verbosity;
            }

            bool buildResult = false;

            _settings = context.Settings;
            BuildFormatList formats = _settings.Formats;

            if (formats == null || formats.Count == 0)
            {
                return(buildResult);
            }
            FormatHxs hxsFormat =
                formats[BuildFormatType.HtmlHelp2] as FormatHxs;

            if (hxsFormat == null || hxsFormat.Enabled == false)
            {
                return(buildResult);
            }
            _buildFormat = hxsFormat;
            string helpTitleId = _helpTitleId;

            if (helpTitleId != null)
            {
                helpTitleId = helpTitleId.Trim();
            }
            if (String.IsNullOrEmpty(helpTitleId))
            {
                helpTitleId = _helpName;
            }
            _helpTitleId = helpTitleId;

            // We create a common XML Settings for all the writers...
            _xmlSettings                    = new XmlWriterSettings();
            _xmlSettings.Encoding           = Encoding.UTF8;
            _xmlSettings.Indent             = true;
            _xmlSettings.IndentChars        = "    ";
            _xmlSettings.OmitXmlDeclaration = false;
            _xmlSettings.CloseOutput        = true;

            buildResult = true;
            try
            {
                if (_helpCulture != null)
                {
                    _langId = _helpCulture.LCID;
                }

                // For these properties, we do not mind if set or there is error.
                string tmpText = _buildFormat["IndexAutoInclude"];
                if (String.IsNullOrEmpty(tmpText) == false)
                {
                    try
                    {
                        _indexAutoInclude = Convert.ToBoolean(tmpText);
                    }
                    catch
                    {
                    }
                }
                tmpText = _buildFormat["IndexSort"];
                if (String.IsNullOrEmpty(tmpText) == false)
                {
                    try
                    {
                        _indexSort = Convert.ToBoolean(tmpText);
                    }
                    catch
                    {
                    }
                }
                tmpText = _buildFormat["IndexMerge"];
                if (String.IsNullOrEmpty(tmpText) == false)
                {
                    try
                    {
                        _indexMerge = Convert.ToBoolean(tmpText);
                    }
                    catch
                    {
                    }
                }
                tmpText = _buildFormat["SampleInfo"];
                if (String.IsNullOrEmpty(tmpText) == false)
                {
                    try
                    {
                        _sampleInfo = Convert.ToBoolean(tmpText);
                    }
                    catch
                    {
                    }
                }

                _helpDir = Path.Combine(workingDir, _helpFolder);
                if (Directory.Exists(_helpDir) == false)
                {
                    Directory.CreateDirectory(_helpDir);
                }

                buildResult = CreateContents(context);
                if (buildResult == false)
                {
                    return(buildResult);
                }

                buildResult = CreateProject(context);
                if (buildResult == false)
                {
                    return(buildResult);
                }

                buildResult = CreateToc(context);
                if (buildResult == false)
                {
                    return(buildResult);
                }

                buildResult = CreateIndex(context);
            }
            catch (Exception ex)
            {
                if (_logger != null)
                {
                    _logger.WriteLine(ex, BuildLoggerLevel.Error);
                }

                buildResult = false;
            }

            return(buildResult);
        }
Пример #9
0
        private void ProcessMarker(ConceptualGroupTocInfo groupTocInfo,
                                   ConceptualMarkerTopic markerTopic, BuildContext context)
        {
            BuildTopicTocInfo markerTocInfo =
                groupTocInfo.Find(markerTopic.TopicId, true);

            if (markerTocInfo == null)
            {
                return;
            }

            BuildTocContext tocContext = context.TocContext;

            BuildGroupTocInfo sourceTocInfo = null;

            switch (markerTopic.SourceType)
            {
            case BuildTocInfoType.Topic:
                BuildTopicTocInfo topicTocInfo = tocContext[markerTopic.SourceId];
                if (topicTocInfo == null)
                {
                    BuildTopicTocInfo markerParent = markerTocInfo.Parent;
                    if (markerParent != null)
                    {
                        markerParent.Remove(markerTocInfo);
                    }
                    else
                    {
                        groupTocInfo.Remove(markerTocInfo);
                    }
                }
                else
                {
                    groupTocInfo.Replace(markerTocInfo, topicTocInfo);

                    // Now, exclude the topic from being included in
                    // the final merging operation...
                    sourceTocInfo = tocContext.GroupOf(topicTocInfo.Name);
                    if (sourceTocInfo != null)
                    {
                        if (sourceTocInfo.ItemType == BuildTocInfoType.Conceptual)
                        {
                            if (_pendindDelete == null)
                            {
                                _pendindDelete = new List <PendingDeletePair>();
                            }

                            // For the conceptual group, we make room for
                            // nested markers, and suspend the deletion...
                            _pendindDelete.Add(new PendingDeletePair(
                                                   topicTocInfo, groupTocInfo));
                        }
                        else if (sourceTocInfo.ItemType == BuildTocInfoType.Reference)
                        {
                            sourceTocInfo.Remove(topicTocInfo);
                        }
                    }
                }
                break;

            case BuildTocInfoType.Reference:
            case BuildTocInfoType.Conceptual:
                sourceTocInfo = tocContext.Items[markerTopic.SourceId];
                if (sourceTocInfo == null)
                {
                    //groupTocInfo.Remove(markerTocInfo);
                    BuildTopicTocInfo markerParent = markerTocInfo.Parent;
                    if (markerParent != null)
                    {
                        markerParent.Remove(markerTocInfo);
                    }
                    else
                    {
                        groupTocInfo.Remove(markerTocInfo);
                    }
                }
                else
                {
                    groupTocInfo.Replace(markerTocInfo, sourceTocInfo);

                    // Now, exclude the source group from being included in
                    // the final merging operation...
                    sourceTocInfo.Exclude = true;

                    TocMerge sourceToc = _listTocMerges[markerTopic.SourceId];
                    if (sourceToc != null)
                    {
                        sourceToc.IsIncluded = false;
                    }
                }
                break;
            }
        }
Пример #10
0
        private bool ProcessToc(BuildContext context)
        {
            _logger     = context.Logger;
            _tocContext = context.TocContext;

            bool tocIsCreated = false;

            if (_helpToc != null && !_helpToc.IsEmpty)
            {
                TocContent tocContent = _helpToc.Content;
                if (tocContent.Enabled)
                {
                    tocIsCreated = this.CustomMergeToc(_mergedToc, tocContent);
                }
            }

            IList <BuildFormat> formats = context.Settings.Formats;
            int enabledFormats          = 0;
            int customizedToc           = 0;

            for (int i = 0; i < formats.Count; i++)
            {
                BuildFormat format = formats[i];
                if (format.Enabled)
                {
                    enabledFormats++;

                    TocContent tocContent = format.TocContent;
                    if (tocContent != null && !tocContent.IsEmpty &&
                        tocContent.Enabled)
                    {
                        string mergedToc = this.ExpandPath(format.TocFileName);
                        if (this.CustomMergeToc(mergedToc, tocContent))
                        {
                            string tocKey = "$" + format.Name;
                            _tocContext.SetValue(tocKey, mergedToc);

                            // For a successful merge, get the "root/first" topic...
                            using (XmlReader reader = XmlReader.Create(mergedToc))
                            {
                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element &&
                                        String.Equals(reader.Name, "topic",
                                                      StringComparison.OrdinalIgnoreCase))
                                    {
                                        _tocContext.SetValue(tocKey + "-HelpTocRoot", reader.GetAttribute("file"));
                                        break;
                                    }
                                }
                            }

                            customizedToc++;
                        }
                    }
                }
            }

            // If all the formats have customized TOC, there is no need to
            // proceed further, creating a general merged TOC...
            if (customizedToc != 0 && customizedToc == enabledFormats)
            {
                if (!tocIsCreated)
                {
                    tocIsCreated = true;
                }
            }

            if (tocIsCreated)
            {
                return(tocIsCreated);
            }

            if (_listTocMerges != null && _listTocMerges.Count != 0)
            {
                int itemCount = _listTocMerges.Count;

                // If there is a single TOC, we simply rename it...
                if (itemCount == 1)
                {
                    tocIsCreated = RenameToc(_mergedToc);
                }
                else
                {
                    tocIsCreated = MergeToc(_mergedToc, itemCount);
                }
            }

            return(tocIsCreated);
        }