예제 #1
0
 /// <summary>
 /// Compares two index items. Used in sorting
 /// </summary>
 /// <param name="obj">Second class.</param>
 /// <returns>Comparing result.</returns>
 public int CompareTo(object obj)
 {
     if (obj is IndexInfo)
     {
         IndexInfo info2 = (IndexInfo)obj;
         if (this.Key != info2.Key)
         {
             return(this.Key.CompareTo(info2.Key));
         }
         return(this.SubKey.CompareTo(info2.SubKey));
     }
     return(0);
 }
예제 #2
0
        /// <summary>
        /// Prepare index info array list.
        /// </summary>
        private void PrepareIndexInfoList()
        {
            // Define item names
            for (int index = 0; index < this.contentIndexList.Count; index++)
            {
                IndexInfo indexInfo = (IndexInfo)this.contentIndexList[index];

                // Only for items with sub-key
                if (indexInfo.SubKey.Length > 0)
                {
                    indexInfo.Name = "   " + indexInfo.SubKey;

                    IndexInfo mainKeyInfo = new IndexInfo();
                    mainKeyInfo.Key = indexInfo.Key;
                    this.contentIndexList.Insert(index, mainKeyInfo);
                    ++index;
                }
            }

            // Remove duplicated items
            for (int index1 = 0; index1 < this.contentIndexList.Count; index1++)
            {
                IndexInfo indexInfo1 = (IndexInfo)this.contentIndexList[index1];
                for (int index2 = index1 + 1; index2 < this.contentIndexList.Count; index2++)
                {
                    IndexInfo indexInfo2 = (IndexInfo)this.contentIndexList[index2];

                    // Remove completly identical items
                    if (indexInfo1.Key == indexInfo2.Key &&
                        indexInfo1.SubKey == indexInfo2.SubKey)
                    {
                        if (indexInfo1.Path == indexInfo2.Path ||
                            indexInfo2.Path.Length == 0)
                        {
                            this.contentIndexList.RemoveAt(index2);
                            --index2;
                        }
                        else if (indexInfo1.Path.Length == 0)
                        {
                            this.contentIndexList.RemoveAt(index1);
                            --index1;
                            --index2;
                        }
                    }
                }
            }

            // Sort items in the list using Key + SubKey
            this.contentIndexList.Sort();
        }
예제 #3
0
        /// <summary>
        /// Creates a Content index based off of a TOC template and the data in the
        /// DynSampleConfig XML document
        /// </summary>
        private void CreateContentIndex(String rootDirectory)
        {
            // check to see if the DynIndex.HTM file exists
            if (File.Exists(rootDirectory + "\\DynIndex.htm"))
            {
                return;
            }

            // load index keywords from "DynSampleConfig.xml" file
            XmlNode rootNode = samplesXMLDoc["SampleList"];
            XmlNode node     = rootNode.FirstChild;

            while (node != null)
            {
                // Process sample config nodes with non-empty content
                if (node.Name == "SampleConfig" &&
                    node["Content"] != null)
                {
                    // get sample content URL

                    /*
                     * string	sampleHref = "content.aspx?Content=" +
                     *      node.Attributes["Path"].Value + "\\" +
                     *      node["Content"].InnerText;
                     */
                    String sampleHref = "content.aspx?Sample=" +
                                        node.Attributes["ID"].Value;


                    // get keywords node
                    if (node["Keywords"] != null)
                    {
                        XmlNode nodeKeyword = node["Keywords"].FirstChild;
                        while (nodeKeyword != null)
                        {
                            // create new index info object
                            IndexInfo indexInfo = new IndexInfo();
                            indexInfo.Href = sampleHref;
                            indexInfo.Path = RemoveUpDir(node.Attributes["Path"].Value + "\\" + node["Content"].InnerText);
                            indexInfo.Key  = nodeKeyword.InnerText.Trim();

                            // Check if string has a sub index separated with comma
                            int commaIndex = indexInfo.Key.IndexOf(',');
                            if (commaIndex > 0)
                            {
                                indexInfo.SubKey = indexInfo.Key.Substring(commaIndex + 1).Trim();
                                indexInfo.Key    = indexInfo.Key.Substring(0, commaIndex).Trim();
                            }

                            // insert index information into the list
                            this.contentIndexList.Add(indexInfo);

                            // get next node
                            nodeKeyword = nodeKeyword.NextSibling;
                        }
                    }
                }
                node = node.NextSibling;
            }

            // sort and remove duplicate index items
            PrepareIndexInfoList();

            // create ContentIndex.HTM file

            // TODO: Here is the htm file must be generated based on the infomation
            // in the contentIndexList. List contains IndexInfo objects in the same
            // order they should appear in the index. Use ToString() method of the
            // IndexInfo class to get the name of the index item.

            //save the toc string
            StreamWriter sw     = File.CreateText(rootDirectory + "\\DynIndex.htm");
            String       output =
                "<html><head><title>TOC</title></head>" +
                "<link type=\"text/css\" rel=\"stylesheet\" href=\"anseStyles.css\">" +
                "<body leftmargin=\"10px\" topMargin=\"5px\">" +
                "<table class=\"IndexItem\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";

            sw.WriteLine(output);

            for (int index = 0; index < this.contentIndexList.Count; index++)
            {
                IndexInfo indexInfo = (IndexInfo)this.contentIndexList[index];

                String display = indexInfo.Key;
                if (indexInfo.Name != null && indexInfo.Name.Length > 0)
                {
                    display = indexInfo.Name;
                }
                bool indent = false;
                if (display[0] == ' ')
                {
                    indent = true;
                }
                display = display.Trim();

                output = "<tr><td class=\"IndexItem\">&nbsp;";
                if (indent)
                {
                    output += "&nbsp;&nbsp;&nbsp;&nbsp;";
                }
                if (indexInfo.Href != null && indexInfo.Href.Length > 0)
                {
                    output += "<a style=\"color:#000000\" class=\"IndexItem\" target=\"Content\" href=\"" + indexInfo.Href + "\">" +
                              display +
                              "</a><br>";
                }
                else
                {
                    output += display +
                              "<br>";
                }

                output += "</td></tr></body></html>";
                sw.WriteLine(output);
            }

            output = "</table>";
            sw.WriteLine(output);

            sw.Close();
        }