public void buildList() { Program.AssertOnEventThread(); Host selectedhost = null; IXenConnection selectedconnection = null; if (SelectedItem != null) { if (SelectedItem is HostItem) { selectedhost = (SelectedItem as HostItem).TheHost; } else if (SelectedItem is PoolItem) { selectedconnection = (SelectedItem as PoolItem).Connection; } } BeginUpdate(); try { ClearAllNodes(); foreach (IXenConnection xc in ConnectionsManager.XenConnectionsCopy) { if (Helpers.GetPool(xc) != null) { PoolItem item = new PoolItem(xc); if (SupressErrors) { item.Enabled = false; item.Description = ""; } AddNode(item); foreach (Host host in xc.Cache.Hosts) { HostItem item2 = new HostItem(host); if (SupressErrors) { item2.Enabled = host.IsLive(); item2.Description = ""; } AddChildNode(item, item2); host.PropertyChanged -= PropertyChanged; host.PropertyChanged += PropertyChanged; } } else if (xc.IsConnected) { Host host = Helpers.GetMaster(xc); if (host != null) { HostItem item = new HostItem(host); if (SupressErrors) { item.Enabled = host.IsLive(); item.Description = ""; } AddNode(item); host.PropertyChanged -= PropertyChanged; host.PropertyChanged += PropertyChanged; } else { PoolItem item = new PoolItem(xc); if (SupressErrors) { item.Enabled = false; item.Description = ""; } AddNode(item); } } else { PoolItem item = new PoolItem(xc); if (SupressErrors) { item.Enabled = false; item.Description = ""; } AddNode(item); } Pool pool = Helpers.GetPoolOfOne(xc); if (pool != null) { pool.PropertyChanged -= PropertyChanged; pool.PropertyChanged += PropertyChanged; } xc.ConnectionStateChanged -= xc_ConnectionStateChanged; xc.ConnectionStateChanged += xc_ConnectionStateChanged; xc.CachePopulated -= xc_CachePopulated; xc.CachePopulated += xc_CachePopulated; xc.Cache.RegisterCollectionChanged <Host>(CollectionChangedWithInvoke); } } finally { EndUpdate(); if (selectedhost != null) { SelectHost(selectedhost); } else if (selectedconnection != null) { SelectConnection(selectedconnection); } else if (SelectedItemChanged != null) { SelectedItemChanged(null, new SelectedItemEventArgs(false)); } } }
public void buildList() { Program.AssertOnEventThread(); Host selectedhost = null; IXenConnection selectedconnection = null; if (SelectedItem != null) { if (SelectedItem is HostItem) { selectedhost = (SelectedItem as HostItem).TheHost; } else if (SelectedItem is PoolItem) { selectedconnection = (SelectedItem as PoolItem).Connection; } } BeginUpdate(); try { ClearAllNodes(); foreach (IXenConnection xc in ConnectionsManager.XenConnectionsCopy) { if (Helpers.GetPool(xc) != null) { PoolItem item = new PoolItem(xc); if (SupressErrors) { item.Enabled = false; item.Description = ""; } AddNode(item); foreach (Host host in xc.Cache.Hosts) { HostItem item2 = new HostItem(host); if (SupressErrors) { item2.Enabled = host.IsLive; item2.Description = ""; } AddChildNode(item, item2); host.PropertyChanged -= PropertyChanged; host.PropertyChanged += PropertyChanged; } } else if (xc.IsConnected) { Host host = Helpers.GetMaster(xc); if (host != null) { HostItem item = new HostItem(host); if (SupressErrors) { item.Enabled = host.IsLive; item.Description = ""; } AddNode(item); host.PropertyChanged -= PropertyChanged; host.PropertyChanged += PropertyChanged; } else { PoolItem item = new PoolItem(xc); if (SupressErrors) { item.Enabled = false; item.Description = ""; } AddNode(item); } } else { PoolItem item = new PoolItem(xc); if (SupressErrors) { item.Enabled = false; item.Description = ""; } AddNode(item); } Pool pool = Helpers.GetPoolOfOne(xc); if (pool != null) { pool.PropertyChanged -= PropertyChanged; pool.PropertyChanged += PropertyChanged; } xc.ConnectionStateChanged -= xc_ConnectionStateChanged; xc.ConnectionStateChanged += xc_ConnectionStateChanged; xc.CachePopulated -= xc_CachePopulated; xc.CachePopulated += xc_CachePopulated; xc.Cache.RegisterCollectionChanged<Host>(CollectionChangedWithInvoke); } } finally { EndUpdate(); if (selectedhost != null) SelectHost(selectedhost); else if (selectedconnection != null) SelectConnection(selectedconnection); else if (SelectedItemChanged != null) SelectedItemChanged(null, new SelectedItemEventArgs(false)); } }