/// <summary> /// If AutomaticCheck is enabled it checks for updates regardless the /// value of the parameter force. If AutomaticCheck is disabled it only /// checks if force is true. /// </summary> public static void CheckForUpdates(bool force) { if (Helpers.CommonCriteriaCertificationRelease) { return; } if (Properties.Settings.Default.AllowXenCenterUpdates || Properties.Settings.Default.AllowXenServerUpdates || Properties.Settings.Default.AllowPatchesUpdates || force) { DownloadUpdatesXmlAction action = new DownloadUpdatesXmlAction( Properties.Settings.Default.AllowXenCenterUpdates || force, Properties.Settings.Default.AllowXenServerUpdates || force, Properties.Settings.Default.AllowPatchesUpdates || force); { action.Completed += actionCompleted; } if (CheckForUpdatesStarted != null) { CheckForUpdatesStarted(); } action.RunAsync(); } }
private static void RunCheckForUpdates(Action <ActionBase> completedEvent) { DownloadUpdatesXmlAction action = new DownloadUpdatesXmlAction(); action.Completed += completedEvent; action.RunAsync(); }
private void actionCompleted(ActionBase sender) { Program.AssertOffEventThread(); DownloadUpdatesXmlAction action = sender as DownloadUpdatesXmlAction; bool succeeded = false; string errorMessage = string.Empty; if (action != null) { succeeded = action.Succeeded; if (succeeded) { XenCenterVersions = action.XenCenterVersions; XenServerVersions = action.XenServerVersions; XenServerPatches = action.XenServerPatches; } else { XenCenterVersions.Clear(); XenServerVersions.Clear(); XenServerPatches.Clear(); if (action.Exception != null) { if (action.Exception is System.Net.Sockets.SocketException) { errorMessage = Messages.AVAILABLE_UPDATES_NETWORK_ERROR; } else { // Clean up and remove excess newlines, carriage returns, trailing nonsense string errorText = action.Exception.Message.Trim(); errorText = System.Text.RegularExpressions.Regex.Replace(errorText, @"\r\n+", ""); errorMessage = string.Format(Messages.AVAILABLE_UPDATES_ERROR, errorText); } } if (string.IsNullOrEmpty(errorMessage)) { errorMessage = Messages.AVAILABLE_UPDATES_INTERNAL_ERROR; } } } if (CheckForUpdatesCompleted != null) { CheckForUpdatesCompleted(this, new CheckForUpdatesCompletedEventArgs(succeeded, errorMessage)); } }
private static void action_Completed(ActionBase sender) { DownloadUpdatesXmlAction action = (DownloadUpdatesXmlAction)sender; if (!action.Succeeded) { return; } XenCenterVersions = action.XenCenterVersions; XenServerVersions = action.XenServerVersions; XenServerPatches = action.XenServerPatches; CheckXenCenterVersion(); CheckServerPatches(); CheckServerVersion(); }
/// <summary> /// It does exactly what CheckForUpdates(true) does, but this is sync and shows an ActionProgressDialog while running /// </summary> /// <returns>true if the action has succeeded</returns> public static bool CheckForUpdatesSync(Control parentForProgressDialog) { if (Helpers.CommonCriteriaCertificationRelease) { return(false); } DownloadUpdatesXmlAction action = new DownloadUpdatesXmlAction(true, true, true, Updates.CheckForUpdatesUrl); action.Completed += actionCompleted; if (CheckForUpdatesStarted != null) { CheckForUpdatesStarted(); } using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee)) dialog.ShowDialog(parentForProgressDialog); return(action.Succeeded); }
private static void actionCompleted(ActionBase sender) { Program.AssertOffEventThread(); DownloadUpdatesXmlAction action = sender as DownloadUpdatesXmlAction; if (action == null) { return; } bool succeeded = action.Succeeded; string errorMessage = string.Empty; lock (updateAlertsLock) updateAlerts.Clear(); if (succeeded) { lock (downloadedUpdatesLock) { var xcvs = action.XenCenterVersions.Where(v => !XenCenterVersions.Contains(v)); XenCenterVersions.AddRange(xcvs); var versForAutoCheck = action.XenServerVersionsForAutoCheck.Where(v => !XenServerVersionsForAutoCheck.Contains(v)); XenServerVersionsForAutoCheck.AddRange(versForAutoCheck); var vers = action.XenServerVersions.Where(v => !XenServerVersions.Contains(v)); XenServerVersions.AddRange(vers); var patches = action.XenServerPatches.Where(p => !XenServerPatches.Contains(p)); XenServerPatches.AddRange(patches); } var xenCenterAlert = NewXenCenterUpdateAlert(XenCenterVersions, Program.Version); if (xenCenterAlert != null && !xenCenterAlert.IsDismissed()) { updateAlerts.Add(xenCenterAlert); } var xenServerUpdateAlert = NewXenServerVersionAlert(XenServerVersionsForAutoCheck); if (xenServerUpdateAlert != null && !xenServerUpdateAlert.CanIgnore) { updateAlerts.Add(xenServerUpdateAlert); } var xenServerPatchAlerts = NewXenServerPatchAlerts(XenServerVersions, XenServerPatches); if (xenServerPatchAlerts != null) { updateAlerts.AddRange(xenServerPatchAlerts.Where(alert => !alert.CanIgnore)); } } else { if (action.Exception != null) { if (action.Exception is System.Net.Sockets.SocketException) { errorMessage = Messages.AVAILABLE_UPDATES_NETWORK_ERROR; } else { // Clean up and remove excess newlines, carriage returns, trailing nonsense string errorText = action.Exception.Message.Trim(); errorText = System.Text.RegularExpressions.Regex.Replace(errorText, @"\r\n+", ""); errorMessage = string.Format(Messages.AVAILABLE_UPDATES_ERROR, errorText); } } if (string.IsNullOrEmpty(errorMessage)) { errorMessage = Messages.AVAILABLE_UPDATES_INTERNAL_ERROR; } } if (CheckForUpdatesCompleted != null) { CheckForUpdatesCompleted(succeeded, errorMessage); } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) { if (!IsInAutomaticMode) { var fileName = fileNameTextBox.Text; if (downloadUpdateRadioButton.Checked) { SelectedUpdateType = UpdateType.NewRetail; } else { if (isValidFile()) { if (fileName.EndsWith(UpdateExtension)) { SelectedUpdateType = UpdateType.NewRetail; } else if (fileName.EndsWith(".iso")) { SelectedUpdateType = UpdateType.NewSuppPack; } else { SelectedUpdateType = UpdateType.Existing; } } } SelectedUpdateAlert = downloadUpdateRadioButton.Checked ? (XenServerPatchAlert)((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert : null; FileFromDiskAlert = selectFromDiskRadioButton.Checked ? GetAlertFromFileName(fileName) : null; if (SelectedExistingPatch != null && !SelectedExistingPatch.Connection.IsConnected) { cancel = true; PageLeaveCancelled(string.Format(Messages.UPDATES_WIZARD_CANNOT_DOWNLOAD_PATCH, SelectedExistingPatch.Connection.Name)); } else if (!string.IsNullOrEmpty(SelectedNewPatch) && !File.Exists(SelectedNewPatch)) { cancel = true; PageLeaveCancelled(string.Format(Messages.UPDATES_WIZARD_FILE_NOT_FOUND, SelectedNewPatch)); } } else //In Automatic Mode { var downloadUpdatesAction = new DownloadUpdatesXmlAction(false, true, true, Updates.CheckForUpdatesUrl); using (var dialog = new ActionProgressDialog(downloadUpdatesAction, ProgressBarStyle.Marquee)) dialog.ShowDialog(this.Parent); //Will block until dialog closes, action completed if (!downloadUpdatesAction.Succeeded) { cancel = true; } AutoDownloadedXenServerVersions = downloadUpdatesAction.XenServerVersions; } } if (!cancel) //unsubscribe only if we are really leaving this page { Updates.RestoreDismissedUpdatesStarted -= Updates_RestoreDismissedUpdatesStarted; Updates.CheckForUpdatesStarted -= CheckForUpdates_CheckForUpdatesStarted; Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted; } base.PageLeave(direction, ref cancel); }