mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 20:36:33 +01:00
CA-150412: Removed invocation of XenConnections_CollectionChanged with null parameters;
the objective is to mark the events as ready to fire, whcih can be done directly. Also, added null checks where GetCollectionForType is used.
This commit is contained in:
parent
bf08f9d875
commit
082e4693a8
@ -270,23 +270,26 @@ namespace XenAdmin.Network
|
||||
|
||||
public void DeregisterCollectionChanged<T>(CollectionChangeEventHandler h) where T : XenObject<T>
|
||||
{
|
||||
ChangeableDictionary<XenRef<T>, T> d =
|
||||
GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return;
|
||||
|
||||
d.CollectionChanged -= h;
|
||||
}
|
||||
|
||||
public void RegisterCollectionChanged<T>(CollectionChangeEventHandler h) where T : XenObject<T>
|
||||
{
|
||||
ChangeableDictionary<XenRef<T>, T> d =
|
||||
GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return;
|
||||
|
||||
d.CollectionChanged -= h;
|
||||
d.CollectionChanged += h;
|
||||
}
|
||||
|
||||
public void DeregisterBatchCollectionChanged<T>(EventHandler h) where T : XenObject<T>
|
||||
{
|
||||
ChangeableDictionary<XenRef<T>, T> d =
|
||||
GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return;
|
||||
|
||||
@ -295,8 +298,7 @@ namespace XenAdmin.Network
|
||||
|
||||
public void RegisterBatchCollectionChanged<T>(EventHandler h) where T : XenObject<T>
|
||||
{
|
||||
ChangeableDictionary<XenRef<T>, T> d =
|
||||
GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return;
|
||||
|
||||
@ -414,7 +416,9 @@ namespace XenAdmin.Network
|
||||
PropertyInfo p = t.GetProperty("uuid", BindingFlags.Public | BindingFlags.Instance);
|
||||
if (p == null)
|
||||
return null;
|
||||
ChangeableDictionary<XenRef<T>, T> d = (ChangeableDictionary<XenRef<T>, T>)GetCollectionForType(t);
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(t) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return null;
|
||||
lock (d)
|
||||
{
|
||||
foreach (T m in d.Values)
|
||||
@ -438,7 +442,9 @@ namespace XenAdmin.Network
|
||||
return null;
|
||||
string uuid = (string)p.GetValue(needle, null);
|
||||
|
||||
ChangeableDictionary<XenRef<T>, T> d = (ChangeableDictionary<XenRef<T>, T>)GetCollectionForType(t);
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(t) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return null;
|
||||
lock (d)
|
||||
{
|
||||
foreach (KeyValuePair<XenRef<T>, T> kvp in d)
|
||||
@ -467,7 +473,9 @@ namespace XenAdmin.Network
|
||||
if (xenRef == null)
|
||||
return null;
|
||||
|
||||
ChangeableDictionary<XenRef<T>, T> d = (ChangeableDictionary<XenRef<T>, T>)GetCollectionForType(typeof(T));
|
||||
ChangeableDictionary<XenRef<T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary<XenRef<T>, T>;
|
||||
if (d == null)
|
||||
return null;
|
||||
T result;
|
||||
return d.TryGetValue(xenRef, out result) ? result : null;
|
||||
}
|
||||
|
@ -41,14 +41,14 @@ namespace XenAdmin
|
||||
public static event Action OtherConfigChanged;
|
||||
public static event Action TagsChanged;
|
||||
public static event Action GuiConfigChanged;
|
||||
private static bool FireOtherConfigEvent = false;
|
||||
private static bool FireTagsEvent = false;
|
||||
private static bool FireGuiConfigEvent = false;
|
||||
private static bool FireOtherConfigEvent;
|
||||
private static bool FireTagsEvent;
|
||||
private static bool FireGuiConfigEvent;
|
||||
|
||||
static OtherConfigAndTagsWatcher()
|
||||
{
|
||||
ConnectionsManager.XenConnections.CollectionChanged += XenConnections_CollectionChanged;
|
||||
XenConnections_CollectionChanged(null, null);
|
||||
MarkEventsReadyToFire(true);
|
||||
}
|
||||
|
||||
public static void DeregisterEventHandlers()
|
||||
@ -77,7 +77,7 @@ namespace XenAdmin
|
||||
VDICollectionChangedWithInvoke = InvokeHelper.InvokeHandler(CollectionChanged<VDI>);
|
||||
NetworkCollectionChangedWithInvoke = InvokeHelper.InvokeHandler(CollectionChanged<XenAPI.Network>);
|
||||
|
||||
XenConnections_CollectionChanged(null, null);
|
||||
MarkEventsReadyToFire(true);
|
||||
}
|
||||
|
||||
private static CollectionChangeEventHandler PoolCollectionChangedWithInvoke;
|
||||
@ -86,50 +86,44 @@ namespace XenAdmin
|
||||
private static CollectionChangeEventHandler SRCollectionChangedWithInvoke;
|
||||
private static CollectionChangeEventHandler VDICollectionChangedWithInvoke;
|
||||
private static CollectionChangeEventHandler NetworkCollectionChangedWithInvoke;
|
||||
|
||||
|
||||
private static void XenConnections_CollectionChanged(object sender, CollectionChangeEventArgs e)
|
||||
{
|
||||
try
|
||||
if (e == null)
|
||||
return;
|
||||
|
||||
IXenConnection connection = e.Element as IXenConnection;
|
||||
if (connection == null)
|
||||
return;
|
||||
|
||||
if (e.Action == CollectionChangeAction.Add)
|
||||
{
|
||||
IXenConnection connection = (IXenConnection)e.Element;
|
||||
if (connection == null)
|
||||
return;
|
||||
connection.Cache.RegisterCollectionChanged<Pool>(PoolCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<Host>(HostCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<VM>(VMCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<SR>(SRCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<VDI>(VDICollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<XenAPI.Network>(NetworkCollectionChangedWithInvoke);
|
||||
|
||||
if (e.Action == CollectionChangeAction.Add)
|
||||
{
|
||||
connection.Cache.RegisterCollectionChanged<Pool>(PoolCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<Host>(HostCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<VM>(VMCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<SR>(SRCollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<VDI>(VDICollectionChangedWithInvoke);
|
||||
connection.Cache.RegisterCollectionChanged<XenAPI.Network>(NetworkCollectionChangedWithInvoke);
|
||||
|
||||
connection.XenObjectsUpdated -= connection_XenObjectsUpdated;
|
||||
connection.XenObjectsUpdated += connection_XenObjectsUpdated;
|
||||
connection.ConnectionStateChanged -= connection_ConnectionStateChanged;
|
||||
connection.ConnectionStateChanged += connection_ConnectionStateChanged;
|
||||
}
|
||||
else if (e.Action == CollectionChangeAction.Remove)
|
||||
{
|
||||
connection.Cache.DeregisterCollectionChanged<Pool>(PoolCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<Host>(HostCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<VM>(VMCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<SR>(SRCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<VDI>(VDICollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<XenAPI.Network>(NetworkCollectionChangedWithInvoke);
|
||||
|
||||
connection.XenObjectsUpdated -= connection_XenObjectsUpdated;
|
||||
connection.ConnectionStateChanged -= connection_ConnectionStateChanged;
|
||||
}
|
||||
connection.XenObjectsUpdated -= connection_XenObjectsUpdated;
|
||||
connection.XenObjectsUpdated += connection_XenObjectsUpdated;
|
||||
connection.ConnectionStateChanged -= connection_ConnectionStateChanged;
|
||||
connection.ConnectionStateChanged += connection_ConnectionStateChanged;
|
||||
}
|
||||
catch (Exception)
|
||||
else if (e.Action == CollectionChangeAction.Remove)
|
||||
{
|
||||
// Can't do any more about this.
|
||||
connection.Cache.DeregisterCollectionChanged<Pool>(PoolCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<Host>(HostCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<VM>(VMCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<SR>(SRCollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<VDI>(VDICollectionChangedWithInvoke);
|
||||
connection.Cache.DeregisterCollectionChanged<XenAPI.Network>(NetworkCollectionChangedWithInvoke);
|
||||
|
||||
connection.XenObjectsUpdated -= connection_XenObjectsUpdated;
|
||||
connection.ConnectionStateChanged -= connection_ConnectionStateChanged;
|
||||
}
|
||||
|
||||
FireOtherConfigEvent = true;
|
||||
FireTagsEvent = true;
|
||||
FireGuiConfigEvent = true;
|
||||
MarkEventsReadyToFire(true);
|
||||
}
|
||||
|
||||
private static void CollectionChanged<T>(object sender, CollectionChangeEventArgs e) where T : XenObject<T>
|
||||
@ -153,9 +147,7 @@ namespace XenAdmin
|
||||
throw new NotImplementedException("CollectionChangeAction.Refresh is unhandled!");
|
||||
}
|
||||
|
||||
FireOtherConfigEvent = true;
|
||||
FireTagsEvent = true;
|
||||
FireGuiConfigEvent = true;
|
||||
MarkEventsReadyToFire(true);
|
||||
}
|
||||
|
||||
private static void PropertyChanged<T>(object sender1, PropertyChangedEventArgs e) where T : XenObject<T>
|
||||
@ -181,25 +173,28 @@ namespace XenAdmin
|
||||
if (FireGuiConfigEvent)
|
||||
OnGuiConfigChanged();
|
||||
|
||||
FireOtherConfigEvent = false;
|
||||
FireTagsEvent = false;
|
||||
FireGuiConfigEvent = false;
|
||||
MarkEventsReadyToFire(false);
|
||||
}
|
||||
|
||||
private static void connection_ConnectionStateChanged(object sender, EventArgs e)
|
||||
{
|
||||
InvokeHelper.Invoke(delegate()
|
||||
InvokeHelper.Invoke(delegate
|
||||
{
|
||||
OnOtherConfigChanged();
|
||||
OnTagsChanged();
|
||||
OnGuiConfigChanged();
|
||||
|
||||
FireOtherConfigEvent = false;
|
||||
FireTagsEvent = false;
|
||||
FireGuiConfigEvent = false;
|
||||
MarkEventsReadyToFire(false);
|
||||
});
|
||||
}
|
||||
|
||||
private static void MarkEventsReadyToFire(bool fire)
|
||||
{
|
||||
FireOtherConfigEvent = fire;
|
||||
FireTagsEvent = fire;
|
||||
FireGuiConfigEvent = fire;
|
||||
}
|
||||
|
||||
private static void OnOtherConfigChanged()
|
||||
{
|
||||
InvokeHelper.AssertOnEventThread();
|
||||
|
Loading…
Reference in New Issue
Block a user