public void RunPlanAction(PlanAction action, ref DoWorkEventArgs e, bool skip = false) { if (CancellationPending) { e.Cancel = true; return; } // if this action is completed successfully, do not run it again if (DoneActions.Contains(action) && action.Error == null) { return; } // if we retry a failed action, we need to firstly remove it from DoneActions and reset its Error DoneActions.Remove(action); action.Error = null; if (skip) { //skip running it, but still need to report progress, mainly for the progress bar PercentComplete += ProgressIncrement * 100; ReportProgress((int)PercentComplete, action); } else { action.OnProgressChange += action_OnProgressChange; action.Run(); action.OnProgressChange -= action_OnProgressChange; } }
public void RunPlanAction(PlanAction action, ref DoWorkEventArgs e) { if (CancellationPending) { e.Cancel = true; return; } // if this action is completed successfully, do not run it again if (DoneActions.Contains(action) && action.Error == null) { return; } // if we retry a failed action, we need to firstly remove it from DoneActions and reset its Error DoneActions.Remove(action); action.Error = null; if (action == FirstFailedSkippableAction) { FirstFailedSkippableAction = null; action.Skipping = true; } action.OnProgressChange += action_OnProgressChange; action.Run(); action.OnProgressChange -= action_OnProgressChange; }
private static void RunPlanAction(UpdateProgressBackgroundWorker bgw, PlanAction action) { InitializePlanAction(bgw, action); bgw.ReportProgress(0, action); action.Run(); Thread.Sleep(1000); bgw.doneActions.Add(action); bgw.ReportProgress((int)((1.0 / (double)bgw.ActionsCount) * 100), action); }
private void RunPlanAction(UpdateProgressBackgroundWorker bgw, PlanAction action) { action.OnProgressChange += action_OnProgressChange; bgw.ReportProgress(0, action); action.Run(); Thread.Sleep(1000); action.OnProgressChange -= action_OnProgressChange; bgw.ReportProgress(100 / bgw.ActionsCount, action); }
private void BworkerDoWork() { Host currentHost = null; try { foreach (var selectedMaster in _mastersToUpgrade) { if (_cancel) { return; } Pool pool = Helpers.GetPoolOfOne(selectedMaster.Connection); foreach (var host in pool.HostsToUpgrade) { log.InfoFormat("Host '{0}' upgrading from version '{1}'", host.Name, host.LongProductVersion); currentHost = host; bool allactionsDone = true; foreach (var planAction in _planActions[host]) { try { string hostVersion = host.LongProductVersion; ReportRunning(this, new ReportRunningArgs(planAction, host)); planAction.Run(); if (_cancel) { return; } if (planAction is UpgradeHostPlanAction) { Host hostAfterReboot = host.Connection.Resolve(new XenRef <Host>(host.opaque_ref)); if (Helpers.SameServerVersion(hostAfterReboot, hostVersion)) { log.ErrorFormat("Host '{0}' rebooted with the same version '{1}'", hostAfterReboot.Name, hostAfterReboot.LongProductVersion); ReportException.Raise(this, new ReportExceptionArgs( new Exception(Messages.REBOOT_WITH_SAME_VERSION), planAction, host)); allactionsDone = false; if (hostAfterReboot.IsMaster()) { _cancel = true; } } log.InfoFormat("Host '{0}' upgraded with version '{1}'", hostAfterReboot.Name, hostAfterReboot.LongProductVersion); } } catch (Exception e) { ReportException.Raise(this, new ReportExceptionArgs(e, planAction, host)); allactionsDone = false; _cancel = true; } if (_cancel) { return; } } if (allactionsDone) { ReportHostDone.Raise(this, new ReportHostDoneArgs(host)); } } } } catch (Exception excep) { log.Error("Upgrade thread error: ", excep); } finally { //Revert resolved prechecks try { log.Debug("Reverting prechecks"); ReportRunning.Raise(this, () => new ReportRunningArgs(_revertAction, currentHost)); _revertAction.Run(); ReportRevertDone.Raise(this, () => new ReportRevertDoneArgs(_revertAction)); } catch (Exception excep) { log.Error("Exception reverting prechecks", excep); ReportException.Raise(this, () => new ReportExceptionArgs(excep, _revertAction, currentHost)); } Completed.Raise(this); } Completed.Raise(this); }
private void BworkerDoWork() { Host currentHost = null; try { List <Host> hosts = GetAllHosts(_mastersToUpgrade); bool currentMasterFailed = false; string poolHigherProductVersion = string.Empty; for (int i = 0; i < hosts.Count; i++) { if (_cancel) { return; } //Skip hosts already upgraded var host = currentHost = hosts[i]; if (host.IsMaster()) { poolHigherProductVersion = host.LongProductVersion; if (CheckMasterIsUpgraded(hosts, i)) { log.Debug(string.Format("Skipping master '{0}' because it is upgraded", host.Name)); continue; } } else if (host.LongProductVersion == poolHigherProductVersion) { log.Debug(string.Format("Skipping host '{0}' because it is upgraded", host.Name)); continue; } log.Debug(string.Format("Starting to upgrade host '{0}'", host.Name)); //Add subtasks for the current host bool allActionsDone = true; foreach (var planAction in _planActions[host]) { //if the wizard has been cancelled, skip this action, unless it is a BringBabiesBackAction if (_cancel && !(planAction is BringBabiesBackAction)) { continue; } PlanAction action = planAction; ReportRunning.Raise(this, () => new ReportRunningArgs(action, host)); try { if (planAction is UpgradeManualHostPlanAction) { var upgradeAction = (UpgradeManualHostPlanAction)planAction; ManageSemiAutomaticPlanAction.Raise(this, () => new ManageSemiAutomaticPlanActionArgs(upgradeAction)); if (host.IsMaster()) { poolHigherProductVersion = upgradeAction.Host.LongProductVersion; } } else { planAction.Run(); } } catch (Exception excep) { log.Error(string.Format("Exception in host '{0}' while it was upgraded", host.Name), excep); PlanAction action1 = planAction; ReportException.Raise(this, () => new ReportExceptionArgs(excep, action1, host)); if (host.IsMaster()) { currentMasterFailed = true; } allActionsDone = false; break; } } if (allActionsDone) { ReportHostDone.Raise(this, () => new ReportHostDoneArgs(host)); } //Skip slaves if master failed if (currentMasterFailed) { i = SkipSlaves(hosts, i); } } } catch (Exception excep) { log.Error("Upgrade thread error: ", excep); } finally { //Revert resolved prechecks try { log.Debug("Reverting prechecks"); ReportRunning.Raise(this, () => new ReportRunningArgs(_revertAction, currentHost)); _revertAction.Run(); ReportRevertDone.Raise(this, () => new ReportRevertDoneArgs(_revertAction)); } catch (Exception excep) { log.Error("Exception reverting prechecks", excep); ReportException.Raise(this, () => new ReportExceptionArgs(excep, _revertAction, currentHost)); } Completed.Raise(this); } }