CA-152052: Fix the issue where the License Manager showed the wrong state when assigning/releasing license from pool

The problem was that the License Manager was listening to PropertyChanged events on the master only, not on slaves.
When the master's properties change (e.g. edition) we update the row in the license manager; but in some cases a slave (or more) hasn't been updated yet (as it may be updated in another event.from) and we think that the pool is partially updated.
Our solution is to listen to Host BatchCollectionChanged event, which is triggered once per cache update for the host collection (it any property changed for any of the hosts).
The sleep in the ApplyLicenseEditionAction is not needed anymore, nor is the extra call to update the cell after the action is completed, because the cell is getting updated correctly on the BatchCollectionChanged event.

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2014-11-24 16:57:42 +00:00
parent 68de517731
commit 65b4ef1f37
3 changed files with 12 additions and 10 deletions

View File

@ -88,19 +88,24 @@ namespace XenAdmin.Controls.CheckableDataGridView
}
cRow.CellDataUpdated += cRow_CellDataUpdated;
IXenObject xenObject = GetXenObject(cRow);
xenObject.PropertyChanged += XenObject_PropertyChanged;
if (xenObject != null && xenObject.Connection != null)
xenObject.Connection.Cache.RegisterBatchCollectionChanged<Host>(HostBatchCollectionChanged);
View.DrawRow(cRow);
}
rows.ForEach(r=>r.BeginCellUpdate());
}
void XenObject_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
void HostBatchCollectionChanged(object sender, EventArgs e)
{
IXenObject xo = sender as IXenObject;
if(xo==null) return;
ChangeableDictionary<XenRef<Host>, Host> d = sender as ChangeableDictionary<XenRef<Host>, Host>;
if (d == null) return;
RedrawRow(storedRows.FirstOrDefault(r => GetXenObject(r) == xo));
foreach (var host in d.Values.Where(host => host.IsMaster()))
{
RedrawRow(storedRows.FirstOrDefault(r => GetXenObject(r) == host));
}
}
private void cRow_CellDataUpdated(object sender, EventArgs e)
@ -387,8 +392,8 @@ namespace XenAdmin.Controls.CheckableDataGridView
{
row.CellDataUpdated -= cRow_CellDataUpdated;
IXenObject xenObject = GetXenObject(row);
if(xenObject != null)
xenObject.PropertyChanged -= XenObject_PropertyChanged;
if (xenObject != null && xenObject.Connection != null)
xenObject.Connection.Cache.DeregisterBatchCollectionChanged<Host>(HostBatchCollectionChanged);
}
if(disposing)

View File

@ -198,7 +198,6 @@ namespace XenAdmin.Dialogs
new OpenLicenseFileDialog(View.Parent, RowsToHosts(validRows)[0], Messages.INSTALL_LICENSE_KEY, false).ShowDialogAndRunAction();
}
licenseRows.ForEach(r => r.BeginCellUpdate());
SummariseDisconnectedRows(rowsChecked);
ResetButtonEnablement();
}

View File

@ -202,8 +202,6 @@ namespace XenAdmin.Actions
else
{
Pool.apply_edition(xo.Connection.Session, pool.opaque_ref, Host.GetEditionText(_edition));
//TODO: Look into why this is required. Event.Next returning late? XAPI returning before updated?
Thread.Sleep(200);
}