Ejemplo n.º 1
0
        /// <summary>
        /// This is used to convert the entry to a string and append it to the specified string builder
        /// </summary>
        /// <param name="sb">The string builder to which the entry is appended</param>
        internal void ConvertToString(StringBuilder sb)
        {
            string url, orderAttr, titleAttr;

            if (String.IsNullOrEmpty(this.DestinationFile))
            {
                url       = WebUtility.HtmlEncode(this.Id);
                titleAttr = String.Format(CultureInfo.InvariantCulture, " title=\"{0}\"",
                                          WebUtility.HtmlEncode(this.Title));
            }
            else
            {
                url       = WebUtility.HtmlEncode(Path.GetFileNameWithoutExtension(this.DestinationFile));
                titleAttr = String.Empty;
            }

            if (this.SortOrder != -1)
            {
                orderAttr = String.Format(CultureInfo.InvariantCulture, " sortOrder=\"{0}\"", this.SortOrder);
            }
            else
            {
                orderAttr = String.Empty;
            }

            if (children.Count == 0)
            {
                sb.AppendFormat("<topic id=\"{0}\" file=\"{0}\"{1}{2} />\r\n", url, orderAttr, titleAttr);
            }
            else
            {
                sb.AppendFormat("<topic id=\"{0}\" file=\"{0}\"{1}{2}>\r\n", url, orderAttr, titleAttr);

                children.ConvertToString(sb);
                sb.Append("</topic>\r\n");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is used to convert the collection to a string and append it
        /// to the specified string builder.
        /// </summary>
        /// <param name="format">The help file format to use</param>
        /// <param name="sb">The string builder to which the information is
        /// appended.</param>
        internal void ConvertToString(HelpFileFormats format, StringBuilder sb)
        {
            string guid, url, orderAttr, titleAttr;

            switch (format)
            {
            case HelpFileFormats.HtmlHelp1:
                if (children.Count == 0)
                {
                    sb.AppendFormat("<LI><OBJECT type=\"text/sitemap\">\r\n" +
                                    "<param name=\"Name\" value=\"{0}\">\r\n" +
                                    "<param name=\"Local\" value=\"{1}\">\r\n" +
                                    "</OBJECT></LI>\r\n", WebUtility.HtmlEncode(this.Title),
                                    WebUtility.HtmlEncode(this.DestinationFile));
                }
                else
                {
                    if (String.IsNullOrEmpty(this.DestinationFile))
                    {
                        sb.AppendFormat("<LI><OBJECT type=\"text/sitemap\">\r\n" +
                                        "<param name=\"Name\" value=\"{0}\">\r\n" +
                                        "</OBJECT></LI>\r\n",
                                        WebUtility.HtmlEncode(this.Title));
                    }
                    else
                    {
                        sb.AppendFormat("<LI><OBJECT type=\"text/sitemap\">\r\n" +
                                        "<param name=\"Name\" value=\"{0}\">\r\n" +
                                        "<param name=\"Local\" value=\"{1}\">\r\n" +
                                        "</OBJECT></LI>\r\n",
                                        WebUtility.HtmlEncode(this.Title),
                                        WebUtility.HtmlEncode(this.DestinationFile));
                    }

                    sb.Append("<UL>\r\n");
                    children.ConvertToString(format, sb);
                    sb.Append("</UL>\r\n");
                }
                break;

            case HelpFileFormats.MSHelp2:
            case HelpFileFormats.Website:
            case HelpFileFormats.OpenXml:
                if (!String.IsNullOrEmpty(this.DestinationFile) && format == HelpFileFormats.Website)
                {
                    url = this.DestinationFile.Replace('\\', '/');
                }
                else
                {
                    url = this.DestinationFile;
                }

                if (children.Count == 0)
                {
                    sb.AppendFormat("<HelpTOCNode Url=\"{0}\" Title=\"{1}\" />\r\n",
                                    WebUtility.HtmlEncode(url), WebUtility.HtmlEncode(this.Title));
                }
                else
                {
                    // Use a GUID to uniquely identify the entries with
                    // children.  This allows the ASP.NET web page to find
                    // them to load the child nodes dynamically.
                    guid = Guid.NewGuid().ToString();

                    // If there is no file for the root node, define the title
                    // property instead.
                    if (String.IsNullOrEmpty(url))
                    {
                        sb.AppendFormat("<HelpTOCNode Id=\"{0}\" Title=\"{1}\">\r\n",
                                        guid, WebUtility.HtmlEncode(this.Title));
                    }
                    else
                    {
                        sb.AppendFormat("<HelpTOCNode Id=\"{0}\" Url=\"{1}\" Title=\"{2}\">\r\n",
                                        guid, url, WebUtility.HtmlEncode(this.Title));
                    }

                    children.ConvertToString(format, sb);
                    sb.Append("</HelpTOCNode>\r\n");
                }
                break;

            case HelpFileFormats.MSHelpViewer:
                if (String.IsNullOrEmpty(this.DestinationFile))
                {
                    url       = WebUtility.HtmlEncode(this.Id);
                    titleAttr = String.Format(CultureInfo.InvariantCulture, " title=\"{0}\"",
                                              WebUtility.HtmlEncode(this.Title));
                }
                else
                {
                    url       = WebUtility.HtmlEncode(Path.GetFileNameWithoutExtension(this.DestinationFile));
                    titleAttr = String.Empty;
                }

                if (this.SortOrder != -1)
                {
                    orderAttr = String.Format(CultureInfo.InvariantCulture, " sortOrder=\"{0}\"", this.SortOrder);
                }
                else
                {
                    orderAttr = String.Empty;
                }

                if (children.Count == 0)
                {
                    sb.AppendFormat("<topic id=\"{0}\" file=\"{0}\"{1}{2} />\r\n", url, orderAttr, titleAttr);
                }
                else
                {
                    sb.AppendFormat("<topic id=\"{0}\" file=\"{0}\"{1}{2}>\r\n", url, orderAttr, titleAttr);

                    children.ConvertToString(format, sb);
                    sb.Append("</topic>\r\n");
                }
                break;

            default:
                throw new InvalidOperationException("Unknown TOC help format: " + format.ToString());
            }
        }