示例#1
0
        private void buildList()
        {
            Program.AssertOnEventThread();

            if (inupdate)
            {
                return;
            }

            inupdate = true;
            HostListTreeView.BeginUpdate();

            try
            {
                // Save old checked states to preserve across update
                var oldCheckStates = new Dictionary <string, CheckState>();
                foreach (HostCustomTreeNode node in HostListTreeView.Items)
                {
                    if (node.HostOrPoolUuid != null)
                    {
                        oldCheckStates.Add(node.HostOrPoolUuid, node.State);
                    }
                }

                HostListTreeView.ClearAllNodes();
                DeregisterEvents();

                foreach (IXenConnection connection in ConnectionsManager.XenConnectionsCopy)
                {
                    connection.ConnectionStateChanged += connection_ConnectionStateChanged;
                    connection.Cache.RegisterCollectionChanged <Host>(Host_CollectionChangedWithInvoke);
                    connection.CachePopulated += connection_CachePopulated;

                    if (!connection.IsConnected)
                    {
                        continue;  // don't show disconnected connections CA-60514
                    }
                    HostCustomTreeNode node = new HostCustomTreeNode(true)
                    {
                        Text        = Helpers.GetName(connection),
                        Tag         = connection,
                        Enabled     = true,
                        Description = "",
                        State       = CheckState.Unchecked,
                        Image       = Images.GetImage16For(connection)
                    };

                    HostListTreeView.AddNode(node);

                    // Save uuid of pool to this node
                    Pool pool = Helpers.GetPoolOfOne(connection);
                    if (pool == null)
                    {
                        continue;
                    }

                    pool.PropertyChanged += pool_PropertyChanged;

                    node.HostOrPoolUuid = pool.uuid;
                    node.State          = (oldCheckStates.ContainsKey(node.HostOrPoolUuid) && node.Enabled) ?
                                          oldCheckStates[node.HostOrPoolUuid] :
                                          CheckState.Unchecked;

                    if (Helpers.GetPool(connection) != null)
                    {
                        node.Image = Images.GetImage16For(pool);

                        foreach (Host host in connection.Cache.Hosts)
                        {
                            bool isHostLive = host.IsLive();
                            HostCustomTreeNode childnode = new HostCustomTreeNode(true)
                            {
                                Text           = Helpers.GetName(host),
                                Tag            = host,
                                HostOrPoolUuid = host.uuid,
                                Enabled        = isHostLive,
                                Description    = isHostLive ? "" : Messages.HOST_NOT_LIVE,
                                Image          = Images.GetImage16For(host)
                            };

                            childnode.State = (oldCheckStates.ContainsKey(childnode.HostOrPoolUuid) && childnode.Enabled) ?
                                              oldCheckStates[childnode.HostOrPoolUuid] :
                                              CheckState.Unchecked;

                            HostListTreeView.AddChildNode(node, childnode);

                            RegisterHostEvents(host);
                        }
                    }
                    else
                    {
                        Host master = Helpers.GetMaster(connection);
                        if (master != null)
                        {
                            bool isMasterLive = master.IsLive();
                            node.Enabled     = isMasterLive;
                            node.Description = isMasterLive ? "" : Messages.HOST_NOT_LIVE;
                            node.Image       = Images.GetImage16For(master);

                            RegisterHostEvents(master);
                        }
                    }
                }
            }
            finally
            {
                inupdate = false;
                HostListTreeView.EndUpdate();
                EnableDisableButtons();
            }
        }
示例#2
0
        private void buildList()
        {
            Program.AssertOnEventThread();

            if (inupdate)
                return;
            
            inupdate = true;
            HostListTreeView.BeginUpdate();
           
            try
            {
                // Save old checked states to preserve across update
                var oldCheckStates = new Dictionary<string, CheckState>();
                foreach (HostCustomTreeNode node in HostListTreeView.Items)
                {
                    if (node.HostOrPoolUuid != null)
                        oldCheckStates.Add(node.HostOrPoolUuid, node.State);
                }

                HostListTreeView.ClearAllNodes();
                DeregisterEvents();

                foreach (IXenConnection connection in ConnectionsManager.XenConnectionsCopy)
                {
                    connection.ConnectionStateChanged += connection_ConnectionStateChanged;
                    connection.Cache.RegisterCollectionChanged<Host>(Host_CollectionChangedWithInvoke);
                    connection.CachePopulated += connection_CachePopulated;

                    if (!connection.IsConnected)
                        continue;  // don't show disconnected connections CA-60514

                    HostCustomTreeNode node = new HostCustomTreeNode(true)
                                                  {
                                                      Text = Helpers.GetName(connection),
                                                      Tag = connection,
                                                      Enabled = true,
                                                      Description = "",
                                                      State = CheckState.Unchecked,
                                                      Image = Images.GetImage16For(connection)
                                                  };

                    HostListTreeView.AddNode(node);

                    // Save uuid of pool to this node
                    Pool pool = Helpers.GetPoolOfOne(connection);
                    if (pool == null)
                        continue;

                    pool.PropertyChanged += pool_PropertyChanged;
                    
                    node.HostOrPoolUuid = pool.uuid;
                    node.State = (oldCheckStates.ContainsKey(node.HostOrPoolUuid) && node.Enabled) ?
                        oldCheckStates[node.HostOrPoolUuid] :
                        CheckState.Unchecked;
                  
                    if (Helpers.GetPool(connection) != null)
                    {
                        node.Image = Images.GetImage16For(pool);

                        foreach (Host host in connection.Cache.Hosts)
                        {
                            HostCustomTreeNode childnode = new HostCustomTreeNode(true)
                                                               {
                                                                   Text = Helpers.GetName(host),
                                                                   Tag = host,
                                                                   HostOrPoolUuid = host.uuid,
                                                                   Enabled = host.IsLive,
                                                                   Description = host.IsLive ? "" : Messages.HOST_NOT_LIVE,
                                                                   Image = Images.GetImage16For(host)
                                                               };

                            childnode.State = (oldCheckStates.ContainsKey(childnode.HostOrPoolUuid) && childnode.Enabled) ?
                                oldCheckStates[childnode.HostOrPoolUuid] :
                                CheckState.Unchecked;

                            HostListTreeView.AddChildNode(node, childnode);
  
                            RegisterHostEvents(host);
                        }
                    }
                    else
                    {
                        Host master = Helpers.GetMaster(connection);
                        if (master != null)
                        {
                            node.Enabled = master.IsLive;
                            node.Description = master.IsLive ? "" : Messages.HOST_NOT_LIVE;
                            node.Image = Images.GetImage16For(master);

                            RegisterHostEvents(master);
                        }
                    }
                }
            }
            finally
            {
                inupdate = false;
                HostListTreeView.EndUpdate();
                EnableDisableButtons();
            }
        }