/// <summary>
    /// Reloads the data.
    /// </summary>
    /// <returns>If reloading failed returns false, else returns true</returns>
    public bool ReloadData()
    {
        try
        {
            MapProvider.ReloadData();

            // Expand current node parent
            if ((ExpandNodeID <= 0) && (SelectedNode != null))
            {
                ExpandNodeID = SelectedNode.NodeParentID;
            }

            // If expand node set, set the node to expand
            if (ExpandNodeID > 0)
            {
                // Get node list to expand
                expandNodes.Clear();

                TreeNode node = TreeProvider.SelectSingleNode(ExpandNodeID, TreeProvider.ALL_CULTURES);
                if (node != null)
                {
                    TreeSiteMapNode targetNode = MapProvider.GetNodeByAliasPath(node.NodeAliasPath);
                    if (targetNode != null)
                    {
                        int targetNodeId = (int)targetNode.NodeData["NodeID"];
                        expandNodes.Add(targetNodeId);
                        while (targetNode.ParentNode != null)
                        {
                            int targetParentNodeId = (int)((TreeSiteMapNode)targetNode.ParentNode).NodeData["NodeID"];
                            expandNodes.Add(targetParentNodeId);
                            targetNode = (TreeSiteMapNode)targetNode.ParentNode;
                        }
                    }
                }
            }

            treeElem.Nodes.Clear();

            // Add root node
            treeElem.Nodes.Add(CreateNode(RootNode, 0, false));

            // Raise root node created event
            RaiseRootNodeCreated();

            return(true);
        }
        catch (Exception ex)
        {
            lblError.Text = GetString("ContentTree.FailedLoad");

            EventLogProvider.LogException("ContentTree", "LOAD", ex, SiteContext.CurrentSiteID);

            return(false);
        }
    }
Пример #2
0
    public void ReloadData()
    {
        try
        {
            MapProvider.ReloadData();

            // Expand current node parent
            if ((ExpandNodeID <= 0) && (NodeID > 0))
            {
                if (SelectedNode != null)
                {
                    ExpandNodeID = SelectedNode.NodeParentID;
                }
            }

            // If expand node set, set the node to expand
            if (ExpandNodeID > 0)
            {
                // Get node list to expand
                expandNodes.Clear();

                TreeNode node = TreeProvider.SelectSingleNode(ExpandNodeID, TreeProvider.ALL_CULTURES);
                if (node != null)
                {
                    TreeSiteMapNode targetNode = MapProvider.GetNodeByAliasPath(node.NodeAliasPath);
                    if (targetNode != null)
                    {
                        int targetNodeId = (int)targetNode.NodeData["NodeID"];
                        expandNodes.Add(targetNodeId);
                        while (targetNode.ParentNode != null)
                        {
                            int targetParentNodeId = (int)((TreeSiteMapNode)targetNode.ParentNode).NodeData["NodeID"];
                            expandNodes.Add(targetParentNodeId);
                            targetNode = (TreeSiteMapNode)targetNode.ParentNode;
                        }
                    }
                }
            }

            treeElem.Nodes.Clear();

            // Add root node
            treeElem.Nodes.Add(CreateNode((TreeSiteMapNode)MapProvider.RootNode, 0, false));
        }
        catch (Exception ex)
        {
            lblError.Text    = GetString("ContentTree.FailedLoad") + ": " + ex.Message;
            lblError.ToolTip = EventLogProvider.GetExceptionLogMessage(ex);
        }
    }
    /// <summary>
    /// Ensures the given node within the tree.
    /// </summary>
    /// <param name="node">Node to ensure</param>
    /// <param name="nodeId">Ensure by NodeID</param>
    protected void EnsureNode(TreeNode node, int nodeId)
    {
        if (node == null)
        {
            // If not already exists, do not add
            if (allNodes[nodeId] != null)
            {
                return;
            }
            else
            {
                // Get the node
                node = TreeProvider.SelectSingleNode(nodeId, TreeProvider.ALL_CULTURES, true);

                if (!SelectPublishedData)
                {
                    node = DocumentHelper.GetDocument(node, TreeProvider);
                }
            }
        }
        else
        {
            nodeId = node.NodeID;
        }

        if (node != null)
        {
            // Get the correct parent node
            System.Web.UI.WebControls.TreeNode parentNode = (System.Web.UI.WebControls.TreeNode)allNodes[node.NodeParentID];
            if (parentNode != null)
            {
                // Expand the parent
                parentNode.Expanded = true;

                // If still not present, add the node
                if (allNodes[nodeId] == null)
                {
                    TreeSiteMapNode sourceNode = new TreeSiteMapNode(MapProvider, nodeId.ToString());
                    sourceNode.TreeNode = node;

                    System.Web.UI.WebControls.TreeNode newNode = CreateNode(sourceNode, 0, true);

                    // If MaxTreeNodes threshold reached, sourceNode must be placed before "Click here..." node
                    if (parentNode.ChildNodes.Count >= MaxTreeNodes)
                    {
                        parentNode.ChildNodes.AddAt(parentNode.ChildNodes.Count - 1, newNode);
                    }
                    else
                    {
                        parentNode.ChildNodes.Add(newNode);
                    }
                }
            }
            else
            {
                // Get the correct node and add it to list of processed nodes
                TreeSiteMapNode targetNode = MapProvider.GetNodeByAliasPath(node.NodeAliasPath);

                if (targetNode != null)
                {
                    List <int> procNodes = new List <int>();
                    procNodes.Add((int)targetNode.NodeData["NodeID"]);

                    if (targetNode.ParentNode != null)
                    {
                        // Repeat until existing parent node in allNodes is found
                        do
                        {
                            int targetParentNodeId = (int)((TreeSiteMapNode)targetNode.ParentNode).NodeData["NodeID"];
                            procNodes.Add(targetParentNodeId);
                            targetNode = (TreeSiteMapNode)targetNode.ParentNode;
                        } while ((targetNode.ParentNode != null) && (allNodes[(int)(((TreeSiteMapNode)(targetNode.ParentNode)).NodeData["NodeID"])] == null));
                    }

                    // Process nodes in reverse order
                    procNodes.Reverse();
                    if (!procNodes.Any(p => (p <= 0)))
                    {
                        foreach (int nodeID in procNodes)
                        {
                            EnsureNode(null, nodeID);
                        }
                    }
                }
            }
        }
    }