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
        }
Пример #2
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);
            }
        }
        /// <summary>
        /// The creates the configuration information or settings required by the
        /// target component for the build process.
        /// </summary>
        /// <param name="group">
        /// A build group, <see cref="BuildGroup"/>, representing the documentation
        /// target for configuration.
        /// </param>
        /// <param name="writer">
        /// An <see cref="XmlWriter"/> object used to create one or more new
        /// child nodes at the end of the list of child nodes of the current node.
        /// </param>
        /// <returns>
        /// Returns <see langword="true"/> for a successful configuration;
        /// otherwise, it returns <see langword="false"/>.
        /// </returns>
        /// <remarks>
        /// The <see cref="XmlWriter"/> writer passed to this configuration object
        /// may be passed on to other configuration objects, so do not close or
        /// dispose it.
        /// </remarks>
        public override bool Configure(BuildGroup group, XmlWriter writer)
        {
            BuildExceptions.NotNull(group, "group");
            BuildExceptions.NotNull(writer, "writer");

            if (!this.Enabled || !this.IsInitialized)
            {
                return(false);
            }

            IList <MediaContent> listMedia = group.MediaContents;

            if (listMedia == null || listMedia.Count == 0)
            {
                return(false);
            }

            bool      useInclude = false;
            FormatMhv mhvFormat  =
                _settings.Formats[BuildFormatType.HtmlHelp3] as FormatMhv;

            if (mhvFormat != null && mhvFormat.Enabled)
            {
                useInclude = true;
            }

            writer.WriteStartElement("options");  // start: options
            writer.WriteAttributeString("useInclude", useInclude.ToString());
            writer.WriteEndElement();             // end: options

            // The HtmlHelp3 supports a different media link format...
            BuildFormatType formatType = BuildFormatType.None;

            int contentCount = listMedia.Count;

            for (int i = 0; i < contentCount; i++)
            {
                MediaContent mediaContent = listMedia[i];
                if (mediaContent == null || mediaContent.IsEmpty)
                {
                    continue;
                }
                string mediaDir = Path.GetDirectoryName(mediaContent.ContentFile);
                if (String.IsNullOrEmpty(mediaDir))
                {
                    continue;
                }
                if (!mediaDir.EndsWith("\\"))
                {
                    mediaDir += "\\";
                }
                writer.WriteStartElement("targets");
                writer.WriteAttributeString("input", mediaDir);
                writer.WriteAttributeString("baseOutput", mediaContent.OutputBase);
                writer.WriteAttributeString("outputPath", mediaContent.OutputPath);
                if (formatType == BuildFormatType.HtmlHelp3)
                {
                    writer.WriteAttributeString("link", mediaContent.OutputLink);
                }
                else
                {
                    writer.WriteAttributeString("link", "../" + mediaContent.OutputLink);
                }
                writer.WriteAttributeString("map", mediaContent.ContentFile);
                writer.WriteEndElement();
            }

            return(true);
        }