Ejemplo n.º 1
0
 // Parse the metadata from the given element?
 private void ParseMetaCategories(DitaElement parentElement)
 {
     try
     {
         List <DitaElement> categoriesData = parentElement?.FindChildren("category");
         if (categoriesData != null)
         {
             foreach (DitaElement categoryData in categoriesData)
             {
                 foreach (DitaElement data in categoryData.Children)
                 {
                     if (data?.Attributes.ContainsKey("name") ?? false)
                     {
                         if (BookMeta.ContainsKey(data?.Attributes["name"]))
                         {
                             Trace.TraceWarning($"BookMeta already contains a value for {data?.Attributes["name"]}");
                         }
                         else
                         {
                             BookMeta.Add(data?.Attributes["name"], data?.Attributes["value"]);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Trace.TraceError(ex);
     }
 }
Ejemplo n.º 2
0
        // Build the internal structure based on a map
        private void ParseMap()
        {
            try
            {
                // Read the title
                BookTitle.Add("mainbooktitle", RootMap.Title);

                // Read the metadata
                ParseMapMeta();

                if (!BookMeta.ContainsKey("document title"))
                {
                    BookMeta.Add("document title", RootMap.Title);
                }

                // Add the chapters
                Chapters.AddRange(ParseChaptersFromFile(RootMap));

                // Removes any blank topics and replaces them with links to their first populate child
                RemoveBlankPages();
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex);
            }
        }
Ejemplo n.º 3
0
        // Parse the version of the document
        private void ParseBookMapVersion(DitaElement bookMetaElement)
        {
            // Try checking the publisher information section
            DitaElement publisherInformationElement = bookMetaElement?.FindOnlyChild("publisherinformation");
            DitaElement publishedElement            = publisherInformationElement?.FindChildren("published")?.Last();
            DitaElement revisionIdElement           = publishedElement?.FindOnlyChild("revisionid");
            string      version = revisionIdElement?.ToString();

            // Try checking the prodinfo section
            if (string.IsNullOrWhiteSpace(version) || version == "ProductVersionNumber")
            {
                DitaElement prodinfoElement = bookMetaElement?.FindOnlyChild("prodinfo");
                DitaElement vrmlistElement  = prodinfoElement?.FindOnlyChild("vrmlist");
                DitaElement vrmElement      = vrmlistElement?.FindChildren("vrm")?[0];
                version = vrmElement?.Attributes?["version"];
            }

            if (!string.IsNullOrWhiteSpace(version))
            {
                BookMeta.Add("version", version);
            }
        }
Ejemplo n.º 4
0
        // Parse the date of the document
        private void ParseBookMapReleaseDate(DitaElement bookMetaElement)
        {
            DitaElement publisherInformationElement = bookMetaElement?.FindOnlyChild("publisherinformation");
            DitaElement publishedElement            = publisherInformationElement?.FindChildren("published")?.Last();
            DitaElement completedElement            = publishedElement?.FindOnlyChild("completed");
            string      year  = completedElement?.FindOnlyChild("year")?.ToString();
            string      month = completedElement?.FindOnlyChild("month")?.ToString();
            string      day   = completedElement?.FindOnlyChild("day")?.ToString();

            if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month) && !string.IsNullOrWhiteSpace(day))
            {
                try
                {
                    // Is this a valid date?
                    DateTime publishDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));
                    BookMeta.Add("published date", $"{publishDate.Day}/{publishDate.Month}/{publishDate.Year} 00:00:00");
                }
                catch
                {
                    //
                }
            }
        }