Пример #1
0
        public void Refresh()
        {
            bool changed = false;

            using (Helpers.Timer("refreshing smart group {0}", base.Text))
            {
                ServerTree.Instance.Operation(OperationBehavior.SuspendSort | OperationBehavior.SuspendUpdate | OperationBehavior.SuspendGroupChanged, delegate
                {
                    HashSet <SmartServerRef> set = new HashSet <SmartServerRef>();
                    base.Nodes.ForEach(delegate(TreeNode s)
                    {
                        set.Add(s as SmartServerRef);
                    });
                    this.GetParentNodes().VisitNodes(delegate(RdcTreeNode node)
                    {
                        if (node is VirtualGroup)
                        {
                            return(NodeVisitorResult.NoRecurse);
                        }
                        Server server = node as Server;
                        if (server != null)
                        {
                            SmartServerRef item = UpdateForServer(server, ref changed);
                            set.Remove(item);
                        }
                        return(NodeVisitorResult.Continue);
                    });
                    if (set.Count > 0)
                    {
                        changed = true;
                        set.ForEach(delegate(SmartServerRef s)
                        {
                            ServerTree.Instance.RemoveNode(s);
                        });
                    }
                });
            }
            if (changed)
            {
                ServerTree.Instance.SortGroup(this);
                ServerTree.Instance.OnGroupChanged(this, ChangeType.InvalidateUI);
            }
        }
Пример #2
0
        private SmartServerRef UpdateForServer(Server server, ref bool changed)
        {
            SmartServerRef smartServerRef = server.FindServerRef <SmartServerRef>(this);
            bool           flag           = RuleGroup != null && RuleGroup.Evaluate(server);

            if (smartServerRef != null != flag)
            {
                changed = true;
                if (flag)
                {
                    smartServerRef = new SmartServerRef(server);
                    ServerTree.Instance.AddNode(smartServerRef, this);
                }
                else
                {
                    ServerTree.Instance.RemoveNode(smartServerRef);
                }
            }
            return(smartServerRef);
        }