예제 #1
0
파일: LinkTree.cs 프로젝트: nandub/DeOps
        private void RefreshOperationTree()
        {
            BeginUpdate();

            // save selected
            LinkNode selected = GetSelected();

            // save visible while unloading
            List <ulong> visible = new List <ulong>();

            foreach (TreeListNode node in Nodes)
            {
                if (node.GetType() == typeof(LinkNode))
                {
                    UnloadNode((LinkNode)node, visible);
                }
            }

            NodeMap.Clear();
            Nodes.Clear();

            // white space
            if (FirstLineBlank)
            {
                Nodes.Add(new LabelNode(""));
            }

            if (!Trust.ProjectRoots.SafeContainsKey(Project))
            {
                EndUpdate();
                return;
            }

            string rootname = Core.User.Settings.Operation;

            if (Project != 0)
            {
                rootname = Trust.GetProjectName(Project);
            }

            // operation
            ProjectNode      = new ProjectNode(rootname, Project);
            ProjectNode.Font = TrustedFont;
            Nodes.Add(ProjectNode);

            // white space
            Nodes.Add(new LabelNode(""));

            // unlinked
            UnlinkedNode      = new ProjectNode("Untrusted", 0);
            UnlinkedNode.Font = UntrustedFont;

            Nodes.Add(UnlinkedNode);


            // if forced, load specific node as root
            if (ForceRootID != 0)
            {
                OpLink root = Trust.GetLink(ForceRootID, Project);

                if (root != null)
                {
                    SetupRoot(root);
                }
            }

            // get roots for specific project
            else
            {
                ThreadedList <OpLink> roots = null;
                if (Trust.ProjectRoots.SafeTryGetValue(Project, out roots))
                {
                    roots.LockReading(delegate()
                    {
                        foreach (OpLink root in roots)
                        {
                            SetupRoot(root);
                        }
                    });
                }
            }

            // show unlinked if there's something to show
            if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count)
            {
                UnlinkedNode.Text = "";
            }
            else
            {
                UnlinkedNode.Text = "Untrusted";
            }

            // restore visible
            foreach (ulong id in visible)
            {
                foreach (TreeListNode node in Nodes)
                {
                    if (node.GetType() == typeof(LinkNode))
                    {
                        List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project);
                        uplinks.Add(id);
                        VisiblePath((LinkNode)node, uplinks);
                    }
                }
            }

            // restore selected
            if (selected != null)
            {
                if (NodeMap.ContainsKey(selected.Link.UserID))
                {
                    Select(NodeMap[selected.Link.UserID]);
                }
            }

            EndUpdate();
        }
예제 #2
0
파일: LinkTree.cs 프로젝트: nandub/DeOps
        private void ArrangeRoots()
        {
            List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(Core.UserID, Project);

            uplinks.Add(Core.UserID);

            OpLink highest = Trust.GetLink(uplinks[uplinks.Count - 1], Project);

            if (highest.LoopRoot != null)
            {
                uplinks.Add(highest.LoopRoot.UserID);
            }

            List <LinkNode> makeUntrusted = new List <LinkNode>();
            List <LinkNode> makeProject   = new List <LinkNode>();

            // look for nodes to switch
            foreach (TreeListNode entry in Nodes)
            {
                LinkNode node = entry as LinkNode;

                if (node == null)
                {
                    continue;
                }


                if (entry == ProjectNode && !uplinks.Contains(node.Link.UserID))
                {
                    makeUntrusted.Add(node);
                }

                else if (entry == UnlinkedNode && uplinks.Contains(node.Link.UserID))
                {
                    makeProject.Add(node);
                }
            }

            // remove, recreate, insert, expand root, expand to self
            foreach (LinkNode delNode in makeUntrusted)
            {
                RemoveNode(delNode);

                if (HideUnlinked)
                {
                    continue;
                }

                LinkNode node = CreateNode(delNode.Link);
                LoadNode(node);
                InsertRootNode(UnlinkedNode, node);
                node.Expand();
            }

            Debug.Assert(makeProject.Count <= 1);

            foreach (LinkNode delNode in makeProject)
            {
                RemoveNode(delNode);
                LinkNode node = CreateNode(delNode.Link);
                LoadNode(node);
                InsertRootNode(ProjectNode, node);

                node.Expand();
                ExpandPath(node, uplinks);
            }
        }
예제 #3
0
파일: LinkTree.cs 프로젝트: nandub/DeOps
 private void RemoveNode(LinkNode node)
 {
     UnloadNode(node, null);           // unload subs
     NodeMap.Remove(node.Link.UserID); // remove from map
     node.Remove();                    // remove from tree
 }
예제 #4
0
파일: LinkTree.cs 프로젝트: nandub/DeOps
        void Trust_Update(ulong key)
        {
            // update
            OpLink link = Trust.GetLink(key, Project);

            if (link == null)
            {
                if (NodeMap.ContainsKey(key))
                {
                    RemoveNode(NodeMap[key]);
                }

                return;
            }

            ProjectNode.Text = Trust.GetProjectName(Project);

            /* taken care of above
             * if (!link.Projects.Contains(Project) && !link.Downlinks.ContainsKey(Project))
             * {
             *  if (NodeMap.ContainsKey(key))
             *      RemoveNode(NodeMap[key]);
             *
             *  return;
             * }*/

            if (ForceRootID != 0)
            {
                // root must be a parent of the updating node
                if (link.UserID != ForceRootID && !Trust.IsUnconfirmedHigher(link.UserID, ForceRootID, Project))
                {
                    return;
                }
            }

            LinkNode node = null;

            if (NodeMap.ContainsKey(key))
            {
                node      = NodeMap[key];
                node.Link = link; // links reset and re-loaded from file
            }

            TreeListNode parent = null;
            OpLink       uplink = GetTreeHigher(link);

            if (uplink == null)
            {
                parent = virtualParent;
            }

            else if (NodeMap.ContainsKey(uplink.UserID))
            {
                parent = NodeMap[uplink.UserID];
            }

            else if (uplink.IsLoopRoot)
            {
                parent = new TreeListNode(); // ensures that tree is refreshed
            }
            // if nodes status unchanged
            if (node != null && parent != null && node.Parent == parent)
            {
                node.UpdateStatus();
                Invalidate();
                return;
            }

            // only if parent is visible
            if (parent != null)
            {
                RefreshOperationTree();
            }
        }
예제 #5
0
파일: LinkTree.cs 프로젝트: nandub/DeOps
        private void UpdateOperation(LinkNode node)
        {
            OpLink link = node.Link;

            TreeListNode parent = null;

            OpLink uplink = GetTreeHigher(link);

            if (uplink == null)
            {
                parent = virtualParent;
            }

            else if (NodeMap.ContainsKey(uplink.UserID))
            {
                parent = NodeMap[uplink.UserID];
            }

            else if (uplink.IsLoopRoot)
            {
                parent = CreateNode(uplink);
                LoadRoot((LinkNode)parent);
            }

            // else branch this link is apart of is not visible in current display


            // self is changing ensure it's visible
            if (node.Link.UserID == Core.UserID)
            {
                if (parent == null)
                {
                    List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(Core.UserID, Project);
                    uplinks.Add(Core.UserID);

                    ExpandPath(node, uplinks);

                    // check nodeMap again now that highers added
                    if (NodeMap.ContainsKey(uplink.UserID))
                    {
                        parent = NodeMap[uplink.UserID];
                    }
                }

                if (parent != null)
                {
                    parent.Expand();
                }
            }


            // remember settings
            bool selected = node.Selected;
            bool expanded = node.IsExpanded;
            bool loadsubs = node.AddSubs;


            // update parent node
            if (node.Parent != parent)
            {
                List <ulong> visible = new List <ulong>();

                // remove previous instance of node
                if (node.Parent != null)
                {
                    if (node.IsVisible())
                    {
                        visible.Add(link.UserID);
                    }

                    LinkNode oldParent = node.Parent as LinkNode;

                    LinkNode unload = (oldParent != null && oldParent.Link.IsLoopRoot) ? oldParent : node;

                    // if old parent is a loop node, the loop is made obsolete by change
                    UnloadNode(unload, visible);
                    unload.Remove();
                }

                if (parent == null)
                {
                    return;
                }

                // if new parent is hidden, dont bother adding till user expands
                LinkNode newParent = parent as LinkNode; // null if virtual parent (root)

                if (newParent != null && newParent.AddSubs == false)
                {
                    return;
                }


                // copy node to start fresh
                LinkNode newNode = CreateNode(node.Link);

                if (newParent != null)
                {
                    GuiUtils.InsertSubNode(newParent, newNode);
                }
                else
                {
                    LoadRoot(newNode);
                }


                ArrangeRoots();

                // arrange nodes can cause newNode to become invalid, retrieve updated copy
                if (!NodeMap.ContainsKey(link.UserID))
                {
                    return;
                }

                newNode = NodeMap[link.UserID];

                if (loadsubs) // if previous node set to add kids
                {
                    LoadNode(newNode);

                    if (expanded) // if previous node set expanded
                    {
                        newNode.Expand();
                    }
                }

                node = newNode;


                // recurse to each previously visible node
                List <LinkNode> roots = new List <LinkNode>();
                foreach (TreeListNode treeNode in Nodes)
                {
                    if (treeNode.GetType() == typeof(LinkNode))
                    {
                        if (((LinkNode)treeNode).Section == ProjectNode)
                        {
                            roots.Add(treeNode as LinkNode);
                        }
                    }
                }

                foreach (ulong id in visible)
                {
                    List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project);

                    foreach (LinkNode root in roots)
                    {
                        VisiblePath(root, uplinks);
                    }
                }

                // show unlinked if there's something to show
                if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count)
                {
                    UnlinkedNode.Text = "";
                }
                else
                {
                    UnlinkedNode.Text = "Untrusted";
                }
            }

            node.UpdateStatus();

            if (selected)
            {
                node.Selected = true;
            }

            Invalidate();
        }
예제 #6
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private void UpdateOperation(LinkNode node)
        {
            OpLink link = node.Link;

            TreeListNode parent = null;

            OpLink uplink = GetTreeHigher(link);

            if (uplink == null)
                parent = virtualParent;

            else if (NodeMap.ContainsKey(uplink.UserID))
                parent = NodeMap[uplink.UserID];

            else if (uplink.IsLoopRoot)
            {
                parent = CreateNode(uplink);
                LoadRoot((LinkNode)parent);
            }

            // else branch this link is apart of is not visible in current display

            // self is changing ensure it's visible
            if (node.Link.UserID == Core.UserID)
            {
                if (parent == null)
                {
                    List<ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(Core.UserID, Project);
                    uplinks.Add(Core.UserID);

                    ExpandPath(node, uplinks);

                    // check nodeMap again now that highers added
                    if (NodeMap.ContainsKey(uplink.UserID))
                        parent = NodeMap[uplink.UserID];
                }

                if (parent != null)
                    parent.Expand();
            }

            // remember settings
            bool selected = node.Selected;
            bool expanded = node.IsExpanded;
            bool loadsubs = node.AddSubs;

            // update parent node
            if (node.Parent != parent)
            {
                List<ulong> visible = new List<ulong>();

                // remove previous instance of node
                if (node.Parent != null)
                {
                    if (node.IsVisible())
                        visible.Add(link.UserID);

                    LinkNode oldParent = node.Parent as LinkNode;

                    LinkNode unload = (oldParent != null && oldParent.Link.IsLoopRoot) ? oldParent : node;

                    // if old parent is a loop node, the loop is made obsolete by change
                    UnloadNode(unload, visible);
                    unload.Remove();
                }

                if (parent == null)
                    return;

                // if new parent is hidden, dont bother adding till user expands
                LinkNode newParent = parent as LinkNode; // null if virtual parent (root)

                if (newParent != null && newParent.AddSubs == false)
                    return;

                // copy node to start fresh
                LinkNode newNode = CreateNode(node.Link);

                if (newParent != null)
                    GuiUtils.InsertSubNode(newParent, newNode);
                else
                    LoadRoot(newNode);

                ArrangeRoots();

                // arrange nodes can cause newNode to become invalid, retrieve updated copy
                if(!NodeMap.ContainsKey(link.UserID))
                    return;

                newNode = NodeMap[link.UserID];

                if (loadsubs) // if previous node set to add kids
                {
                    LoadNode(newNode);

                    if (expanded) // if previous node set expanded
                        newNode.Expand();
                }

                node = newNode;

                // recurse to each previously visible node
                List<LinkNode> roots = new List<LinkNode>();
                foreach (TreeListNode treeNode in Nodes)
                    if (treeNode.GetType() == typeof(LinkNode))
                        if (((LinkNode)treeNode).Section == ProjectNode)
                            roots.Add(treeNode as LinkNode);

                foreach (ulong id in visible)
                {
                    List<ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project);

                    foreach (LinkNode root in roots)
                        VisiblePath(root, uplinks);
                }

                // show unlinked if there's something to show
                if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count)
                    UnlinkedNode.Text = "";
                else
                    UnlinkedNode.Text = "Untrusted";
            }

            node.UpdateStatus();

            if (selected)
                node.Selected = true;

            Invalidate();
        }
예제 #7
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private void VisiblePath(LinkNode node, List<ulong> uplinks)
        {
            bool found = false;

            foreach (LinkNode sub in node.Nodes)
                if (uplinks.Contains(sub.Link.UserID))
                    found = true;

            if (found)
            {
                node.Expand();

                foreach (LinkNode sub in node.Nodes)
                    VisiblePath(sub, uplinks);
            }
        }
예제 #8
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
 private void RemoveNode(LinkNode node)
 {
     UnloadNode(node, null); // unload subs
     NodeMap.Remove(node.Link.UserID); // remove from map
     node.Remove(); // remove from tree
 }
예제 #9
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private void UnloadNode(LinkNode node, List<ulong> visible)
        {
            node.AddSubs = false;

            if (visible != null && node.IsVisible())
                visible.Add(node.Link.UserID);

            if (NodeMap.ContainsKey(node.Link.UserID))
                NodeMap.Remove(node.Link.UserID);

            // for each child, call unload node, then clear
            foreach (LinkNode child in node.Nodes)
                UnloadNode(child, visible);

            // unloads children of node, not the node itself
            node.Nodes.Clear();
            node.Collapse();
        }
예제 #10
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private void LoadRoot(LinkNode node)
        {
            // set up root with hidden subs
            LoadNode(node);

            // if self or uplinks contains root, put in project
            if(node.Link.UserID == Core.UserID ||
                Trust.IsUnconfirmedHigher(node.Link.UserID, Project))
                InsertRootNode(ProjectNode, node);

            // else put in untrusted
            else if (!HideUnlinked)
                InsertRootNode(UnlinkedNode, node);
        }
예제 #11
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private void LoadNode(LinkNode node)
        {
            // check if already loaded
            if (node.AddSubs)
                return;

            node.AddSubs = true;

            // go through downlinks
            foreach (OpLink link in node.Link.Downlinks)
                if (!node.Link.IsLoopedTo(link))
                {
                    if(SearchOnline)
                        Core.Locations.Research(link.UserID);

                    // if doesnt exist search for it
                    if (!link.Trust.Loaded)
                    {
                        Trust.Research(link.UserID, Project, false);
                        continue;
                    }

                    //if(node.Link.IsLoopRoot)
                    //    node.Nodes.Insert(0, CreateNode(link));
                    //else
                    GuiUtils.InsertSubNode(node, CreateNode(link));
                }
        }
예제 #12
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private void ExpandPath(LinkNode node, List<ulong> uplinks)
        {
            if (!uplinks.Contains(node.Link.UserID))
                return;

            // expand triggers even loading nodes two levels down, one level shown, the other hidden
            node.Expand();

            foreach (LinkNode sub in node.Nodes)
                ExpandPath(sub, uplinks);
        }
예제 #13
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        private LinkNode CreateNode(OpLink link)
        {
            LinkNode node = new LinkNode(link, this);

            NodeMap[link.UserID] = node;

            return node;
        }
예제 #14
0
파일: LinkTree.cs 프로젝트: RoelofSol/DeOps
        public void InsertRootNode(ProjectNode start, LinkNode node)
        {
            // inserts item directly under start, not as a child node

            int index = 0;

            TreeListNode root = start.Parent;
            node.Section = start;
            bool ready = false;

            foreach (TreeListNode entry in root.Nodes)
            {
                if (ready)
                    if (start == ProjectNode ||
                        (start == UnlinkedNode && string.Compare(node.Text, entry.Text, true) < 0) ||
                        entry.GetType() == typeof(LabelNode)) // lower bounds
                    {
                        root.Nodes.Insert(index, node);
                        return;
                    }

                if (entry == start)
                    ready = true;

                index++;
            }

            root.Nodes.Insert(index, node);
        }