public void EditGroup(GroupTreeNode group)
        {
            string query = "UPDATE GroupTree SET [Name]=" + qouted(group.Name) + " Description=" + qouted(group.Description) +
                           " WHERE ID=" + group.ID;

            executeNonQuery(query);
        }
        public void EditGroupParent(GroupTreeNode group, int parentID)
        {
            string query = "UPDATE GroupTree ParentID=" + (parentID == -1 ? "NULL" : parentID.ToString()) +
                           " WHERE ID=" + group.ID;

            executeNonQuery(query);
        }
        // for the given item, check its grouping, add it to groups it has newly joined,
        // and record groups it has newly left in the delete-list
        internal void RestoreGrouping(LiveShapingItem lsi, List <AbandonedGroupItem> deleteList)
        {
            GroupTreeNode root = BuildGroupTree(lsi);

            root.ContainsItem = true;
            RestoreGrouping(lsi, root, 0, deleteList);
        }
 public void TestSetup()
 {
     this.sourceFavorite     = this.AddFavorite("SourceFavorite");
     this.sourceFavoriteNode = new FavoriteTreeNode(TestConnectionManager.CreateTestFavoriteIcons(), sourceFavorite, string.Empty);
     this.sourceGroup        = this.AddNewGroup("SourceGroup");
     this.sourceGroupNode    = new GroupTreeNode(sourceGroup);
     this.targetFavorite     = this.AddFavorite("TargetFavorite");
     this.targetGroup        = this.AddNewGroup("TargetGroup");
 }
        public int AddGroupTo(GroupTreeNode group, int gid)
        {
            string query = "INSERT INTO GroupTree ([Name], [Description], ParentID) VALUES (";

            query += qouted(group.Name) + ", " + qouted(group.Description) + ", " + ((gid != -1) ? gid.ToString() : "NULL") + ")";

            executeNonQuery(query);

            int scalar = (int)executeScalar("SELECT MAX(ID) FROM GroupTree");

            return(scalar);
        }
Exemple #6
0
        internal void CreateFavorite(Action<TerminalFormDialogResult> callback,
            string favoriteName = null, GroupTreeNode groupNode = null)
        {
            using (NewTerminalForm createForm = this.CreateFavoriteForm(favoriteName))
            {
                if (groupNode != null)
                    createForm.AssingSelectedGroup(groupNode.Group);

                // TODO add adhoc connection option in case the dialog result is connect only
                this.ShowFavoriteForm(createForm, dr => this.FinishCreateFavorie(dr, createForm, callback));
            }
        }
Exemple #7
0
        private void NewGroupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // backup the selected tree node, because it will be replaced later by focus of NewGroupForm
            GroupTreeNode parentGroupNode = this.favsTree.SelectedGroupNode;
            string        newGroupName    = NewGroupForm.AskFroGroupName(this.persistence);

            if (string.IsNullOrEmpty(newGroupName))
            {
                return;
            }

            IGroup newGroup = this.persistence.Factory.CreateGroup(newGroupName);

            if (parentGroupNode != null)
            {
                newGroup.Parent = parentGroupNode.Group;
            }

            this.persistence.Groups.Add(newGroup);
        }
Exemple #8
0
 private void GroupTreeAddChildren(List <Group> groups, GroupTreeNode node, int index)
 {
     // index 参数减少遍历数,前提是数据库中是严格排序的。
     for (var i = index + 1; i < groups.Count; i++)
     {
         var item = groups[i];
         if (item.ParentId == node.Id)
         {
             if (node.Children == null)
             {
                 node.Children = new List <GroupTreeNode>();
             }
             var child = GroupTreeNodeFromGroup(item);
             // 在父节点的 ParentIdPath 基础上增加 ParentId
             child.ParentIdPath = node.ParentIdPath != null ? new List <Guid>(node.ParentIdPath) : new List <Guid>(1);
             child.ParentIdPath.Add(node.Id);
             node.Children.Add(child);
             GroupTreeAddChildren(groups, child, i);
         }
     }
 }
        /// <summary>
        /// Parses a "group" node, which contains either further groups, or devices
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection to which parsed nodes should be added</param>
        /// <param name="groupXEl">The XElement to parse</param>
        /// <returns>The number of netflow sensors under this group node</returns>
        private int ParseGroupNode(TreeNode parentNode, XElement groupXEl)
        {
            TreeNode groupNode = new GroupTreeNode((string)groupXEl.Attribute("id"), ((string)groupXEl.Element("data").Element("name")).Trim());

            int numChildren = 0;

            foreach (XElement subGroupXEl in groupXEl.Element("nodes").Elements("group"))
            {
                numChildren += this.ParseGroupNode(groupNode, subGroupXEl);
            }

            foreach (XElement deviceXEl in groupXEl.Element("nodes").Elements("device"))
            {
                numChildren += this.ParseDeviceNode(groupNode, deviceXEl);
            }

            if (numChildren > 0)
            {
                parentNode.Nodes.Add(groupNode);
            }

            return(numChildren);
        }
Exemple #10
0
        private void CreateFavoriteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GroupTreeNode groupNode = this.favsTree.SelectedGroupNode;

            this.ConnectionsUiFactory.CreateFavorite(string.Empty, groupNode);
        }
        void RestoreGrouping(LiveShapingItem lsi, GroupTreeNode node, int level, List<AbandonedGroupItem> deleteList)
        {
            if (node.ContainsItem)
            {
                // item belongs to this group - check subgroups
                object name = GetGroupName(lsi.Item, node.Group.GroupBy, level);
                if (name != UseAsItemDirectly)
                {
                    ICollection ic = name as ICollection;
                    ArrayList names = (ic == null) ? null : new ArrayList(ic);

                    // find subgroups whose names still match
                    for (GroupTreeNode child = node.FirstChild; child != null; child = child.Sibling)
                    {
                        if (names == null)
                        {
                            if (Object.Equals(name, child.Group.Name))
                            {
                                child.ContainsItem = true;
                                name = DependencyProperty.UnsetValue;   // name is 'seen'
                                break;
                            }
                        }
                        else
                        {
                            if (names.Contains(child.Group.Name))
                            {
                                child.ContainsItem = true;
                                names.Remove(child.Group.Name);
                            }
                        }
                    }

                    // for names that don't match, add the item to the new subgroup
                    if (names == null)
                    {
                        if (name != DependencyProperty.UnsetValue)
                        {
                            AddToSubgroup(lsi.Item, lsi, node.Group, level, name, false);
                        }
                    }
                    else
                    {
                        foreach (object o in names)
                        {
                            AddToSubgroup(lsi.Item, lsi, node.Group, level, o, false);
                        }
                    }
                }
            }
            else
            {
                // item doesn't belong to this group - if it used to belong directly,
                // mark it for deletion
                if (node.ContainsItemDirectly)
                {
                    deleteList.Add(new AbandonedGroupItem(lsi, node.Group));
                }
            }

            // recursively handle children
            for (GroupTreeNode child = node.FirstChild; child != null; child = child.Sibling)
            {
                RestoreGrouping(lsi, child, level+1, deleteList);
            }
        }
        /// <summary>
        /// Reloads the browse application tree
        /// </summary>
        private void ReloadBrowseTree()
        {
            if (Connection != null)
            {
                var group = GroupApplicationService.GetChildGroups(-1).First();
                var node = new GroupTreeNode(group, GroupApplicationService);
                node.Nodes.Add("Dummy");
                browseApplicationTree.Nodes.Add(node);
                node.Expand();

                browseApplicationTree.Refresh();
            }
        }
        GroupTreeNode BuildGroupTree(LiveShapingItem lsi)
        {
            CollectionViewGroupInternal parentGroup = lsi.ParentGroup;
            GroupTreeNode node;

            if (parentGroup != null)
            {
                // 90% case - item belongs to only one group.   Construct tree
                // the fast way
                node = new GroupTreeNode()
                            { Group = parentGroup, ContainsItemDirectly = true };
                for (;;)
                {
                    CollectionViewGroupInternal group = parentGroup;
                    parentGroup = group.Parent;
                    if (parentGroup == null)
                        break;

                    GroupTreeNode parentNode = new GroupTreeNode()
                            { Group = parentGroup, FirstChild = node };
                    node = parentNode;
                }
                return node;
            }
            else
            {
                // item belongs to multiple groups ("categories").   Construct tree
                // the slow way.
                List<CollectionViewGroupInternal> parentGroups = lsi.ParentGroups;
                List<GroupTreeNode> list = new List<GroupTreeNode>(parentGroups.Count + 1);
                GroupTreeNode root = null;

                // initialize the list with a node for each direct parent group
                foreach (CollectionViewGroupInternal group in parentGroups)
                {
                    node = new GroupTreeNode()
                            { Group = group, ContainsItemDirectly = true };
                    list.Add(node);
                }

                // add each node in the list to the tree
                for (int index = 0;  index < list.Count; ++index)
                {
                    node = list[index];
                    parentGroup = node.Group.Parent;
                    GroupTreeNode parentNode = null;

                    // special case for the root
                    if (parentGroup == null)
                    {
                        root = node;
                        continue;
                    }

                    // search for an existing parent node
                    for (int k=list.Count-1; k>=0; --k)
                    {
                        if (list[k].Group == parentGroup)
                        {
                            parentNode = list[k];
                            break;
                        }
                    }

                    if (parentNode == null)
                    {
                        // no existing parent node - create one now
                        parentNode = new GroupTreeNode()
                                { Group = parentGroup, FirstChild = node };
                        list.Add(parentNode);
                    }
                    else
                    {
                        // add node to existing parent
                        node.Sibling = parentNode.FirstChild;
                        parentNode.FirstChild = node;
                    }
                }

                return root;
            }
        }
        /// <summary>
        /// Event handler fired when the search button is clicked
        /// </summary>
        private void searchButton_Click(object sender, EventArgs e)
        {
            //Provide an indication that something's happening
            searchButton.Text = "Searching...";
            searchButton.Enabled = false;

            //Empty existing search results
            searchApplicationTree.Nodes.Clear();

            try
            {
                var results = GroupApplicationService.Search(searchTextBox.Text);

                if (results.Count() == 0)
                {
                    // If there are no results, clear the image list to ensure
                    // the message gets no  default icon
                    //searchApplicationTree.ImageList.Images.Clear();
                    searchApplicationTree.Nodes.Add("No results");
                }
                else foreach (var app in results)
                    {
                        var group = app as EvolutionGroup;
                        if (group == null)
                        {
                            var appNode = new ApplicationTreeNode(app);
                            searchApplicationTree.Nodes.Add(appNode);
                        }
                        else
                        {
                            var groupNode = new GroupTreeNode(group, GroupApplicationService);
                            searchApplicationTree.Nodes.Add(groupNode);
                            groupNode.LoadAvatar();
                        }
                    }
            }
            catch
            {
                // If there are no results, clear the image list to ensure
                // the message gets no default icon
                searchApplicationTree.ImageList.Images.Clear();
                searchApplicationTree.Nodes.Add("An error occured whilst searching for applications");
            }
            finally
            {
                // Reset the search button
                searchButton.Text = "Search";
                searchButton.Enabled = true;
            }
        }
        //-----------------------------------------------------------//

        public GroupTreeNode GetMeasuresTreeFrom(List <int> statMeasures, GroupTreeNode node)
        {
            if (statMeasures == null)
            {
                statMeasures = GetStatMeasures();
            }
            string query = "SELECT * FROM GroupTree WHERE ParentID" + ((node.ID == -1) ? (" IS NULL") : ("=" + node.ID));

            IDataReader reader = executeSelect(query);

            if (node.SubNodes == null)
            {
                node.SubNodes = new List <GroupTreeNode>();
            }

            if (node.Measures == null)
            {
                node.Measures = new Dictionary <int, string>();
            }

            while (reader.Read())
            {
                int    id          = (int)reader["ID"];
                string name        = reader["Name"] as string;
                string description = reader["Description"] == DBNull.Value ? null : (reader["Description"] as string);

                node.SubNodes.Add(new GroupTreeNode(id, name, description));
            }

            reader.Close();

            query = "SELECT ID, [Name], StartTime, IsMeasured, FullLength FROM Measures WHERE GroupID" + ((node.ID == -1) ? (" IS NULL") : ("=" + node.ID));

            reader = executeSelect(query);
            while (reader.Read())
            {
                int         id         = (int)reader["ID"];
                string      name       = reader["Name"] as string;
                DateTime    dt         = (DateTime)reader["StartTime"];
                bool        IsMeasured = Convert.ToBoolean(reader["IsMeasured"]);
                int         flen       = (int)((double)reader["FullLength"]);
                MeasureData md         = new MeasureData(new Dictionary <Sensor, List <PointD> >(), id, name, dt, "", -1, flen, 1, IsMeasured, null);
                if (statMeasures.Contains(id))
                {
                    md.DispData = new Dictionary <Sensor, Dictionary <double, double> >();
                    md.DispData.Add(sensorList[0], new Dictionary <double, double>());
                }
                node.Measures.Add(id, md.ToString());
            }

            reader.Close();



            for (int i = 0; i < node.SubNodes.Count; i++)
            {
                node.SubNodes[i] = GetMeasuresTreeFrom(statMeasures, node.SubNodes[i]);
            }



            return(node);
        }
        private void AddDeviceTreeForChannel(int channelID, TreeNode parentNode)
        {
            if (!flowChannels.ContainsKey(channelID))
            {
                flowChannels[channelID] = new ChannelDefTreeNode(channelID, "ChannelDef_" + channelID);
            }

            TreeNode currentNode = flowChannels[channelID];

            PRTGTreeNode parNode = parentNode as PRTGTreeNode;
            PRTGTreeNode curNode = currentNode as PRTGTreeNode;

            if (parNode == null || curNode == null)
            {
                return;
            }

            Stack <PRTGTreeNode> nodeList = new Stack <PRTGTreeNode>();

            while (parNode != null)
            {
                PRTGTreeNode newNode = null;
                if (parNode is DeviceTreeNode)
                {
                    newNode = new DeviceTreeNode(parNode.Id, parNode.Text);
                }
                else if (parNode is GroupTreeNode)
                {
                    newNode = new GroupTreeNode(parNode.Id, parNode.Text);
                }
                else if (parNode is ProbeTreeNode)
                {
                    newNode = new ProbeTreeNode(parNode.Id, parNode.Text);
                }
                nodeList.Push(newNode);
                parNode = parNode.Parent as PRTGTreeNode;
            }

            while (nodeList.Count > 0)
            {
                PRTGTreeNode n     = nodeList.Pop();
                bool         found = false;
                PRTGTreeNode t     = null;

                foreach (PRTGTreeNode p in curNode.Nodes)
                {
                    if ((n is DeviceTreeNode && p is DeviceTreeNode && n.Id == p.Id) ||
                        (n is GroupTreeNode && p is GroupTreeNode && n.Id == p.Id) ||
                        (n is ProbeTreeNode && p is ProbeTreeNode && n.Id == p.Id))
                    {
                        found = true;
                        t     = p;
                        break;
                    }
                }

                if (found == true)
                {
                    curNode = t;
                    continue;
                }

                curNode.Nodes.Add(n);
                curNode = n;
            }
        }
        void RestoreGrouping(LiveShapingItem lsi, GroupTreeNode node, int level, List <AbandonedGroupItem> deleteList)
        {
            if (node.ContainsItem)
            {
                // item belongs to this group - check subgroups
                object name = GetGroupName(lsi.Item, node.Group.GroupBy, level);
                if (name != UseAsItemDirectly)
                {
                    ICollection ic    = name as ICollection;
                    ArrayList   names = (ic == null) ? null : new ArrayList(ic);

                    // find subgroups whose names still match
                    for (GroupTreeNode child = node.FirstChild; child != null; child = child.Sibling)
                    {
                        if (names == null)
                        {
                            if (Object.Equals(name, child.Group.Name))
                            {
                                child.ContainsItem = true;
                                name = DependencyProperty.UnsetValue;   // name is 'seen'
                                break;
                            }
                        }
                        else
                        {
                            if (names.Contains(child.Group.Name))
                            {
                                child.ContainsItem = true;
                                names.Remove(child.Group.Name);
                            }
                        }
                    }

                    // for names that don't match, add the item to the new subgroup
                    if (names == null)
                    {
                        if (name != DependencyProperty.UnsetValue)
                        {
                            AddToSubgroup(lsi.Item, lsi, node.Group, level, name, false);
                        }
                    }
                    else
                    {
                        foreach (object o in names)
                        {
                            AddToSubgroup(lsi.Item, lsi, node.Group, level, o, false);
                        }
                    }
                }
            }
            else
            {
                // item doesn't belong to this group - if it used to belong directly,
                // mark it for deletion
                if (node.ContainsItemDirectly)
                {
                    deleteList.Add(new AbandonedGroupItem(lsi, node.Group));
                }
            }

            // recursively handle children
            for (GroupTreeNode child = node.FirstChild; child != null; child = child.Sibling)
            {
                RestoreGrouping(lsi, child, level + 1, deleteList);
            }
        }
            /// <summary>
            /// Loads applications and groups within the current group
            /// as child tree nodes
            /// </summary>
            public void LoadChildren()
            {
                if (hasLoadedChildren)
                    return;

                this.Nodes.Clear();
                var children = GroupApplicationService.GetApplicationsInGroup(Application.Id);
                foreach (var child in children)
                {
                    var group = child as EvolutionGroup;
                    if (group != null)
                    {
                        var groupNode = new GroupTreeNode(group, GroupApplicationService);
                        groupNode.Nodes.Add("Dummy");
                        this.Nodes.Add(groupNode);
                        groupNode.LoadAvatar();
                    }
                    else
                    {
                        var appNode = new ApplicationTreeNode(child);
                        appNode.NodeFont = new Font(SystemFonts.DefaultFont, FontStyle.Regular);
                        this.Nodes.Add(appNode);
                    }
                }

                hasLoadedChildren = true;
            }
        GroupTreeNode BuildGroupTree(LiveShapingItem lsi)
        {
            CollectionViewGroupInternal parentGroup = lsi.ParentGroup;
            GroupTreeNode node;

            if (parentGroup != null)
            {
                // 90% case - item belongs to only one group.   Construct tree
                // the fast way
                node = new GroupTreeNode()
                {
                    Group = parentGroup, ContainsItemDirectly = true
                };
                for (;;)
                {
                    CollectionViewGroupInternal group = parentGroup;
                    parentGroup = group.Parent;
                    if (parentGroup == null)
                    {
                        break;
                    }

                    GroupTreeNode parentNode = new GroupTreeNode()
                    {
                        Group = parentGroup, FirstChild = node
                    };
                    node = parentNode;
                }
                return(node);
            }
            else
            {
                // item belongs to multiple groups ("categories").   Construct tree
                // the slow way.
                List <CollectionViewGroupInternal> parentGroups = lsi.ParentGroups;
                List <GroupTreeNode> list = new List <GroupTreeNode>(parentGroups.Count + 1);
                GroupTreeNode        root = null;

                // initialize the list with a node for each direct parent group
                foreach (CollectionViewGroupInternal group in parentGroups)
                {
                    node = new GroupTreeNode()
                    {
                        Group = group, ContainsItemDirectly = true
                    };
                    list.Add(node);
                }

                // add each node in the list to the tree
                for (int index = 0; index < list.Count; ++index)
                {
                    node        = list[index];
                    parentGroup = node.Group.Parent;
                    GroupTreeNode parentNode = null;

                    // special case for the root
                    if (parentGroup == null)
                    {
                        root = node;
                        continue;
                    }

                    // search for an existing parent node
                    for (int k = list.Count - 1; k >= 0; --k)
                    {
                        if (list[k].Group == parentGroup)
                        {
                            parentNode = list[k];
                            break;
                        }
                    }

                    if (parentNode == null)
                    {
                        // no existing parent node - create one now
                        parentNode = new GroupTreeNode()
                        {
                            Group = parentGroup, FirstChild = node
                        };
                        list.Add(parentNode);
                    }
                    else
                    {
                        // add node to existing parent
                        node.Sibling          = parentNode.FirstChild;
                        parentNode.FirstChild = node;
                    }
                }

                return(root);
            }
        }
 internal void CreateFavorite(string favoriteName = null, GroupTreeNode groupNode = null)
 {
     this.CreateFavorite(dr => { }, favoriteName, groupNode);
 }