Beispiel #1
0
 public void SetTocXmlDocument(XmlDocument tocXML)
 {
     foreach (XmlNode childNode in tocXML.ChildNodes)
     {
         if (childNode.Name == "ncx")
         {
             foreach (XmlNode childNode2 in childNode.ChildNodes)
             {
                 if (childNode2.Name == "navMap")
                 {
                     foreach (XmlNode childNode3 in childNode2.ChildNodes)
                     {
                         try
                         {
                             navPoint navPoint = new navPoint();
                             a(childNode3, navPoint);
                             navPoint.IsExpanded = true;
                             TocContent.Add(navPoint);
                         }
                         catch
                         {
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, String.Format(
                                 "The element name '{0}' does not match the expected '{1}'.",
                                 reader.Name, TagName));
                return;
            }

            if (_tocContent == null)
            {
                _tocContent = new TocContent();
            }
            if (reader.IsEmptyElement)
            {
                return;
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, TocContent.TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        _tocContent.ReadXml(reader);
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
 public void SetTocXmlDocument(XmlDocument tocXML)
 {
     foreach (XmlNode childNode in tocXML.ChildNodes)
     {
         if (childNode.Name == "ncx")
         {
             foreach (XmlNode childNode2 in childNode.ChildNodes)
             {
                 if (childNode2.Name == "navMap")
                 {
                     foreach (XmlNode childNode3 in childNode2.ChildNodes)
                     {
                         navPoint navPoint = new navPoint();
                         a(childNode3, navPoint);
                         navPoint.IsExpanded = true;
                         TocContent.Add(navPoint);
                     }
                 }
             }
         }
     }
     tocTreeView.ItemsSource = TocContent;
 }
        public static void Create(BuildDocumenter documenter,
                                  TestOptions options)
        {
            CustomTocType tocType = options.TocType;

            if (tocType == CustomTocType.None)
            {
                return;
            }

            BuildSettings           settings       = documenter.Settings;
            ReferenceEngineSettings engineSettings = settings.EngineSettings[
                BuildEngineType.Reference] as ReferenceEngineSettings;

            IList <BuildGroup> listGroups = documenter.Groups;

            // Create a custom TOC layout for the CHM format only...
            if (tocType != CustomTocType.Default)
            {
                FormatChm chmFormat =
                    settings.Formats[BuildFormatType.HtmlHelp1] as FormatChm;
                if (chmFormat != null && chmFormat.Enabled)
                {
                    TocContent chmTocContent = new TocContent();
                    for (int i = 0; i < listGroups.Count; i++)
                    {
                        TocItem tocItem = new TocItem();
                        tocItem.SourceType      = TocItemSourceType.Group;
                        tocItem.SourceRecursive = true;
                        tocItem.SourceId        = listGroups[i].Id;
                        chmTocContent.Add(tocItem);
                    }

                    chmFormat.TocContent = chmTocContent;
                }
            }

            BuildToc   buildToc   = settings.Toc;
            TocContent tocContent = buildToc.Content;

            switch (tocType)
            {
            case CustomTocType.None:
                break;

            case CustomTocType.Default:
                for (int i = 0; i < listGroups.Count; i++)
                {
                    TocItem tocItem = new TocItem();
                    tocItem.SourceType      = TocItemSourceType.Group;
                    tocItem.SourceRecursive = true;
                    tocItem.SourceId        = listGroups[i].Id;
                    tocContent.Add(tocItem);
                }
                break;

            case CustomTocType.ReferenceRoot:
                // Assumes there are three groups and the third is reference group,
                // and root namespaces container is enabled...
                if (listGroups.Count == 3 &&
                    (engineSettings != null && engineSettings.RootNamespaceContainer))
                {
                    TocItem rootItem = new TocItem();
                    rootItem.SourceType      = TocItemSourceType.NamespaceRoot;
                    rootItem.SourceRecursive = false;
                    rootItem.SourceId        = listGroups[2].Id;
                    tocContent.Add(rootItem);

                    for (int i = 0; i < listGroups.Count - 1; i++)
                    {
                        TocItem tocItem = new TocItem();
                        tocItem.SourceType      = TocItemSourceType.Group;
                        tocItem.SourceRecursive = true;
                        tocItem.SourceId        = listGroups[i].Id;
                        rootItem.Add(tocItem);
                    }

                    TocItem namespaceItem1 = new TocItem();
                    namespaceItem1.SourceType      = TocItemSourceType.Namespace;
                    namespaceItem1.SourceRecursive = true;
                    namespaceItem1.SourceId        = "N:ANamespace";
                    rootItem.Add(namespaceItem1);

                    TocItem namespaceItem2 = new TocItem();
                    namespaceItem2.SourceType      = TocItemSourceType.Namespace;
                    namespaceItem2.SourceRecursive = true;
                    namespaceItem2.SourceId        = "N:TestLibrary";
                    rootItem.Add(namespaceItem2);
                }
                break;

            case CustomTocType.TopicRoot:
                if (settings.BuildConceptual && settings.BuildReferences)
                {
                    TocItem rootTocItem = new TocItem();
                    rootTocItem.SourceType      = TocItemSourceType.Topic;
                    rootTocItem.SourceRecursive = true;
                    rootTocItem.SourceId        = "d36e744f-c053-4e94-9ac9-b1ee054d8de2";
                    tocContent.Add(rootTocItem);
                    for (int i = 0; i < listGroups.Count; i++)
                    {
                        TocItem tocItem = new TocItem();
                        tocItem.SourceType      = TocItemSourceType.Group;
                        tocItem.SourceRecursive = true;
                        tocItem.SourceId        = listGroups[i].Id;
                        rootTocItem.Add(tocItem);
                    }
                }
                break;
            }
        }
Beispiel #5
0
        private bool CustomMergeToc(string mergedToc, TocContent tocContent)
        {
            _tocContext.LoadAll();

            IBuildNamedList <BuildGroupTocInfo> groupTocItems = _tocContext.Items;

            Debug.Assert(groupTocItems != null && groupTocItems.Count != 0);

            int itemCount = tocContent.Count;

            List <BuildTopicTocInfo> listToc = new List <BuildTopicTocInfo>();

            for (int i = 0; i < itemCount; i++)
            {
                TocItem           tocItem    = tocContent[i];
                TocItemSourceType sourceType = tocItem.SourceType;
                if (sourceType == TocItemSourceType.None)
                {
                    continue;
                }

                BuildGroupTocInfo groupToc = null;
                BuildTopicTocInfo tocInfo  = null;
                switch (sourceType)
                {
                case TocItemSourceType.None:
                    break;

                case TocItemSourceType.Group:
                    groupToc = groupTocItems[tocItem.SourceId];
                    Debug.Assert(groupToc != null);
                    break;

                case TocItemSourceType.Namespace:
                    tocInfo = _tocContext[tocItem.SourceId];
                    break;

                case TocItemSourceType.NamespaceRoot:
                    groupToc = groupTocItems[tocItem.SourceId];
                    Debug.Assert(groupToc != null);
                    if (groupToc != null)
                    {
                        if (groupToc.IsRooted)
                        {
                            tocInfo = groupToc[0];
                        }
                        else
                        {
                            throw new BuildException(
                                      "The specified reference group does not have a root container.");
                        }
                        groupToc = null;
                    }
                    break;

                case TocItemSourceType.Topic:
                    tocInfo = _tocContext[tocItem.SourceId];
                    break;
                }

                if (groupToc != null)
                {
                    if (!groupToc.Exclude && groupToc.Count != 0)
                    {
                        listToc.AddRange(groupToc.Items);
                    }
                    continue;
                }

                if (tocInfo == null)
                {
                    if (_logger != null)
                    {
                        _logger.WriteLine(String.Format(
                                              "The TOC topic for the item '{0}' cannot be found.", tocItem.Name),
                                          BuildLoggerLevel.Warn);
                    }

                    continue;
                }

                BuildTopicTocInfo topicToc = null;
                if (tocItem.SourceRecursive)
                {
                    topicToc = tocInfo;
                }
                else
                {
                    topicToc = new BuildTopicTocInfo(tocInfo.Name,
                                                     tocInfo.Source, null);
                    topicToc.Container = tocInfo.Container;
                }

                listToc.Add(topicToc);

                for (int j = 0; j < tocItem.ItemCount; j++)
                {
                    this.CustomMergeToc(topicToc, tocItem[j]);
                }
            }

            if (listToc.Count == 0)
            {
                if (_logger != null)
                {
                    _logger.WriteLine("The custom merging of the table of contents failed.",
                                      BuildLoggerLevel.Error);
                }

                return(false);
            }

            XmlWriter xmlWriter = null;

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

                xmlWriter.WriteStartElement("topics");

                for (int i = 0; i < listToc.Count; i++)
                {
                    listToc[i].WriteXml(xmlWriter);
                }

                xmlWriter.WriteEndElement();

                xmlWriter.Close();
                xmlWriter = null;

                return(true);
            }
            catch (Exception ex)
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Close();
                    xmlWriter = null;
                }

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

                return(false);
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildToc"/> class
 /// with parameters copied from the specified instance of the
 /// <see cref="BuildToc"/> class, a copy constructor.
 /// </summary>
 /// <param name="source">
 /// An instance of the <see cref="BuildToc"/> class from which the
 /// initialization parameters or values will be copied.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If the parameter <paramref name="source"/> is <see langword="null"/>.
 /// </exception>
 public BuildToc(BuildToc source)
     : base(source)
 {
     _tocContent = source._tocContent;
 }
Beispiel #8
0
 /// <overloads>
 /// Initializes a new instance of the <see cref="BuildToc"/> class.
 /// </overloads>
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildToc"/> class
 /// to the default properties or values.
 /// </summary>
 public BuildToc()
 {
     _tocContent = new TocContent();
 }