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
        }
Beispiel #2
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);
        }
        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));
        }
Beispiel #4
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);
            }
        }
        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);
        }