예제 #1
0
        private void processNodeList(ContentItem contentItem, TreeNodeCollection tnCollection)
        {
            var xmlDocument = new XmlDocument();
            var nsm = new XmlNamespaceManager(xmlDocument.NameTable);
            nsm.AddNamespace("toc", "urn:mtpg-com:mtps/2004/1/toc");
            nsm.AddNamespace("mtps", "http://msdn2.microsoft.com/mtps");
            nsm.AddNamespace("asp", "http://msdn2.microsoft.com/asp");
            nsm.AddNamespace("mshelp", "http:/msdn.microsoft.com/mshelp");

            if (string.IsNullOrEmpty(contentItem.Toc)) return;

            xmlDocument.LoadXml(contentItem.Toc);

            var nodes = xmlDocument.SelectNodes("/toc:Node/toc:Node", nsm);

            if (nodes == null) return;

            foreach (XmlNode node in nodes)
            {
                var title = GetAttribute(node.Attributes["toc:Title"]);

                var target = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:Target"]));

                var targetLocale = GetAttribute(node.Attributes["toc:TargetLocale"]);
                var targetVersion = GetAttribute(node.Attributes["toc:TargetVersion"]);

                var subTree = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:SubTree"]));
                var subTreeVersion = GetAttribute(node.Attributes["toc:SubTreeVersion"]);
                var subTreeLocale = GetAttribute(node.Attributes["toc:SubTreeLocale"]);
                var isPhantom = GetAttribute(node.Attributes["toc:IsPhantom"]);

                if (isPhantom != "true" &&
                    title != "@PhantomNode" &&
                    title != "@NoTitle" &&
                    string.IsNullOrEmpty(title) != true &&
                    string.IsNullOrEmpty(target) != true)
                {
                    TreeNode treeNode = tnCollection.Add(title);

                    var mtpsNode = new MtpsNode(subTree, subTreeLocale, subTreeVersion,contentItem.ContentId, target, targetLocale, targetVersion, title);

                    treeNode.Tag = mtpsNode;

                    // Mark nodes red that point outside this server
                    if (mtpsNode.External)
                    {
                        treeNode.ForeColor = Color.Red;

                        //treeNode.NodeFont = new System.Drawing.Font(tocControl.Font, System.Drawing.FontStyle.Italic);
                    }

                    if (subTree != null)
                    {
                        // Add a + as the title so any node with subnodes is expandable.
                        // Only load the subnodes when user expands this node.
                        // We rely on Tag == null rather than Text == "+" in case
                        // there really is a node with a title of "+".
                        treeNode.Nodes.Add("+");
                    }
                }
                else
                {
                    if (subTree != null)
                    {
                        // TODO: add a ContentItem constructor that takes a combined
                        // version string: MSDN.10, Office.12, etc.

                        string[] splitVersion = subTreeVersion.Split(new[] {'.'});
                        var childContentItem = new ContentItem(subTree, subTreeLocale,splitVersion[1], splitVersion[0], ApplicationStrings.APPLICATION_NAME);
                        childContentItem.Load(false);

                        processNodeList(childContentItem, tnCollection);
                    }
                }
            }
        }
예제 #2
0
        private void processNodeList(ContentItem contentItem, TreeNodeCollection tnCollection)
        {
            var xmlDocument = new XmlDocument();
            var nsm         = new XmlNamespaceManager(xmlDocument.NameTable);

            nsm.AddNamespace("toc", "urn:mtpg-com:mtps/2004/1/toc");
            nsm.AddNamespace("mtps", "http://msdn2.microsoft.com/mtps");
            nsm.AddNamespace("asp", "http://msdn2.microsoft.com/asp");
            nsm.AddNamespace("mshelp", "http:/msdn.microsoft.com/mshelp");

            if (string.IsNullOrEmpty(contentItem.Toc))
            {
                return;
            }

            xmlDocument.LoadXml(contentItem.Toc);

            var nodes = xmlDocument.SelectNodes("/toc:Node/toc:Node", nsm);

            if (nodes == null)
            {
                return;
            }

            foreach (XmlNode node in nodes)
            {
                var title = GetAttribute(node.Attributes["toc:Title"]);

                var target = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:Target"]));

                var targetLocale  = GetAttribute(node.Attributes["toc:TargetLocale"]);
                var targetVersion = GetAttribute(node.Attributes["toc:TargetVersion"]);

                var subTree        = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:SubTree"]));
                var subTreeVersion = GetAttribute(node.Attributes["toc:SubTreeVersion"]);
                var subTreeLocale  = GetAttribute(node.Attributes["toc:SubTreeLocale"]);
                var isPhantom      = GetAttribute(node.Attributes["toc:IsPhantom"]);

                if (isPhantom != "true" &&
                    title != "@PhantomNode" &&
                    title != "@NoTitle" &&
                    string.IsNullOrEmpty(title) != true &&
                    string.IsNullOrEmpty(target) != true)
                {
                    TreeNode treeNode = tnCollection.Add(title);

                    var mtpsNode = new MtpsNode(subTree, subTreeLocale, subTreeVersion, contentItem.ContentId, target, targetLocale, targetVersion, title);

                    treeNode.Tag = mtpsNode;


                    // Mark nodes red that point outside this server
                    if (mtpsNode.External)
                    {
                        treeNode.ForeColor = Color.Red;

                        //treeNode.NodeFont = new System.Drawing.Font(tocControl.Font, System.Drawing.FontStyle.Italic);
                    }


                    if (subTree != null)
                    {
                        // Add a + as the title so any node with subnodes is expandable.
                        // Only load the subnodes when user expands this node.
                        // We rely on Tag == null rather than Text == "+" in case
                        // there really is a node with a title of "+".
                        treeNode.Nodes.Add("+");
                    }
                }
                else
                {
                    if (subTree != null)
                    {
                        // TODO: add a ContentItem constructor that takes a combined
                        // version string: MSDN.10, Office.12, etc.

                        string[] splitVersion     = subTreeVersion.Split(new[] { '.' });
                        var      childContentItem = new ContentItem(subTree, subTreeLocale, splitVersion[1], splitVersion[0], ApplicationStrings.APPLICATION_NAME);
                        childContentItem.Load(false);

                        processNodeList(childContentItem, tnCollection);
                    }
                }
            }
        }