Tidy up event registration and deregistration on the MainWindow.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2020-07-26 14:05:58 +01:00
parent 56fdf0402e
commit f05b512ca4
3 changed files with 36 additions and 23 deletions

View File

@ -15,24 +15,17 @@ namespace XenAdmin
{
Program.Exiting = true;
XenAdmin.Core.Clip.UnregisterClipboardViewer();
pluginManager.PluginsChanged -= pluginManager_PluginsChanged;
pluginManager.Dispose();
UnRegisterEvents();
OtherConfigAndTagsWatcher.DeregisterEventHandlers();
ConnectionsManager.History.CollectionChanged -= History_CollectionChanged;
XenAdmin.Alerts.Alert.DeregisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged);
XenAdmin.Core.Updates.DeregisterCollectionChanged(Updates_CollectionChanged);
ConnectionsManager.XenConnections.CollectionChanged -= XenConnection_CollectionChanged;
Properties.Settings.Default.SettingChanging -= new System.Configuration.SettingChangingEventHandler(Default_SettingChanging);
SearchPage.SearchChanged -= SearchPanel_SearchChanged;
if (disposing && (components != null))
if (disposing)
{
components.Dispose();
if (components != null)
components.Dispose();
log.Debug("MainWindow disoposing license timer");
pluginManager.Dispose();
log.Debug("MainWindow disposing of license timer");
if (licenseTimer != null)
licenseTimer.Dispose();
}

View File

@ -213,7 +213,8 @@ namespace XenAdmin
SRCollectionChangedWithInvoke = Program.ProgramInvokeHandler(CollectionChanged<SR>);
FolderCollectionChangedWithInvoke = Program.ProgramInvokeHandler(CollectionChanged<Folder>);
TaskCollectionChangedWithInvoke = Program.ProgramInvokeHandler(MeddlingActionManager.TaskCollectionChanged);
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
RegisterEvents();
CommandLineArgType = argType;
CommandLineParam = args;
@ -224,16 +225,10 @@ namespace XenAdmin
contextMenuBuilder = new ContextMenuBuilder(pluginManager, this);
((WinformsXenAdminConfigProvider) XenAdminConfigManager.Provider).PluginManager = pluginManager;
eventsPage.GoToXenObjectRequested += eventsPage_GoToXenObjectRequested;
SearchPage.SearchChanged += SearchPanel_SearchChanged;
Alert.RegisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged);
Updates.RegisterCollectionChanged(Updates_CollectionChanged);
FormFontFixer.Fix(this);
Folders.InitFolders();
DockerContainers.InitDockerContainers();
OtherConfigAndTagsWatcher.InitEventHandlers();
// Fix colour of text on gradient panels
TitleLabel.ForeColor = Program.TitleBarForeColor;
@ -243,7 +238,6 @@ namespace XenAdmin
SelectionManager.BindTo(MainMenuBar.Items, this);
SelectionManager.BindTo(ToolStrip.Items, this);
Properties.Settings.Default.SettingChanging += Default_SettingChanging;
licenseTimer = new LicenseTimer(licenseManagerLauncher);
GeneralPage.LicenseLauncher = licenseManagerLauncher;
@ -254,6 +248,32 @@ namespace XenAdmin
statusLabelAlerts.Visible = statusLabelUpdates.Visible = statusLabelErrors.Visible = false;
}
private void RegisterEvents()
{
//ClipboardViewer is registered in OnHandleCreated
OtherConfigAndTagsWatcher.RegisterEventHandlers();
Alert.RegisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged);
Updates.RegisterCollectionChanged(Updates_CollectionChanged);
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
//ConnectionsManager.XenConnections.CollectionChanged is registered in OnShown
Properties.Settings.Default.SettingChanging += Default_SettingChanging;
eventsPage.GoToXenObjectRequested += eventsPage_GoToXenObjectRequested;
SearchPage.SearchChanged += SearchPanel_SearchChanged;
}
private void UnRegisterEvents()
{
Clip.UnregisterClipboardViewer();
OtherConfigAndTagsWatcher.DeregisterEventHandlers();
Alert.DeregisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged);
Updates.DeregisterCollectionChanged(Updates_CollectionChanged);
ConnectionsManager.History.CollectionChanged -= History_CollectionChanged;
ConnectionsManager.XenConnections.CollectionChanged -= XenConnection_CollectionChanged;
Properties.Settings.Default.SettingChanging -= Default_SettingChanging;
eventsPage.GoToXenObjectRequested -= eventsPage_GoToXenObjectRequested;
SearchPage.SearchChanged -= SearchPanel_SearchChanged;
}
private void Default_SettingChanging(object sender, SettingChangingEventArgs e)
{
if (e == null)

View File

@ -69,7 +69,7 @@ namespace XenAdmin
}
}
public static void InitEventHandlers()
public static void RegisterEventHandlers()
{
PoolCollectionChangedWithInvoke = InvokeHelper.InvokeHandler(CollectionChanged<Pool>);
VMCollectionChangedWithInvoke = InvokeHelper.InvokeHandler(CollectionChanged<VM>);