private void DownloadPatchFile(XenServerPatchAlert patch) { if (string.IsNullOrEmpty(patch.Patch.PatchUrl)) { Results.Add("Patch conatined no URL: " + patch.Patch.Name); return; } string tempFileName = NewTempPath(); DownloadAndUnzipXenServerPatchAction action = new DownloadAndUnzipXenServerPatchAction(patch.Patch.Name, new Uri(patch.Patch.PatchUrl), tempFileName); try { Status = "Download and unzip patch " + patch.Patch.Name; ConsoleSpinner spinner = new ConsoleSpinner(); action.RunAsync(); while (!action.IsCompleted) { spinner.Turn(action.PercentComplete); } if (!action.Succeeded) { Results.Add("Patch download and unzip unsuccessful: " + action.Exception.Message); } } catch (Exception ex) { Results.Add("Patch download error: " + ex.Message); } }
private void VerifyPatchDetailsMissing(XenServerPatchAlert alert) { if (string.IsNullOrEmpty(alert.Patch.Uuid)) { Results.Add("Missing patch uuid for patch: " + alert.Patch.Name); } if (string.IsNullOrEmpty(alert.Patch.Name)) { Results.Add("Missing patch name for patch with UUID: " + alert.Patch.Uuid); } if (string.IsNullOrEmpty(alert.Patch.PatchUrl)) { Results.Add("Missing patch patch-url for patch with UUID: " + alert.Patch.Uuid); } if (string.IsNullOrEmpty(alert.Patch.Description)) { Results.Add("Missing patch description for patch with UUID: " + alert.Patch.Uuid); } if (string.IsNullOrEmpty(alert.Patch.Url)) { Results.Add("Missing patch webpage url for patch with UUID: " + alert.Patch.Uuid); } if (string.IsNullOrEmpty(alert.Patch.Guidance)) { Results.Add("Missing patch guidance for patch with UUID: " + alert.Patch.Uuid); } if (string.IsNullOrEmpty(alert.Patch.TimeStamp.ToString())) { Results.Add("Missing patch timestamp for patch with UUID: " + alert.Patch.Uuid); } }
private void DownloadAndInstall() { if (dataGridViewUpdates.SelectedRows.Count == 0) { return; } XenServerPatchAlert patchAlert = dataGridViewUpdates.SelectedRows[0].Tag as XenServerPatchAlert; if (patchAlert == null) { return; } string patchUri = patchAlert.Patch.PatchUrl; if (string.IsNullOrEmpty(patchUri)) { return; } Uri address = new Uri(patchUri); string tempFile = Path.GetTempFileName(); var action = new DownloadAndUnzipXenServerPatchAction(patchAlert.Description, address, tempFile); ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Continuous, false) { ShowCancel = true }; dialog.ShowDialog(this); if (action.Succeeded) { var wizard = new PatchingWizard(); wizard.Show(); wizard.NextStep(); wizard.AddFile(action.PatchPath); wizard.NextStep(); if (patchAlert.Hosts.Count > 0) { wizard.SelectServers(patchAlert.Hosts); if (wizard.CurrentStepTabPage.EnableNext()) { wizard.NextStep(); } } else { string disconnectedServerNames = dataGridViewUpdates.SelectedRows[0].Cells[ColumnLocation.Index].Value.ToString(); new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.UPDATES_WIZARD_DISCONNECTED_SERVER, disconnectedServerNames), Messages.UPDATES_WIZARD)).ShowDialog(this); } } }
public void AddAlert(XenServerPatchAlert alert) { PatchingWizard_SelectPatchPage.SelectDownloadAlert(alert); PatchingWizard_SelectPatchPage.SelectedUpdateAlert = alert; PatchingWizard_SelectServers.SelectedUpdateAlert = alert; PatchingWizard_UploadPage.SelectedUpdateAlert = alert; }
public void TestAlertWithHostsAndNoConnection() { XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "1"); XenServerPatchAlert alert = new XenServerPatchAlert(p); alert.IncludeHosts(new List <Host>() { hostA.Object, hostB.Object }); IUnitTestVerifier validator = new VerifyGetters(alert); validator.Verify(new AlertClassUnitTestData { AppliesTo = "HostAName, HostBName", FixLinkText = "Go to Web Page", HelpID = "XenServerPatchAlert", Description = "My description", HelpLinkText = "Help", Title = "New Update Available - name", Priority = "Priority1" }); Assert.IsFalse(alert.CanIgnore); VerifyConnExpectations(Times.Never); VerifyHostsExpectations(Times.Once); }
private void ToolStripMenuItemDownload_Click(object sender, EventArgs e) { DataGridViewRow clickedRow = FindAlertRow(sender as ToolStripMenuItem); if (clickedRow == null) { return; } XenServerPatchAlert patchAlert = (XenServerPatchAlert)clickedRow.Tag; if (patchAlert == null) { return; } string patchUri = patchAlert.Patch.PatchUrl; if (string.IsNullOrEmpty(patchUri)) { return; } Uri address = new Uri(patchUri); string tempFile = Path.GetTempFileName(); var action = new DownloadAndUnzipXenServerPatchAction(patchAlert.Description, address, tempFile); ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Continuous, false) { ShowCancel = true }; dialog.ShowDialog(this); if (action.Succeeded) { var wizard = new PatchingWizard(); wizard.Show(); wizard.NextStep(); wizard.AddFile(action.PatchPath); wizard.NextStep(); var hosts = patchAlert.DistinctHosts; if (hosts.Count > 0) { wizard.SelectServers(hosts); } else { string disconnectedServerNames = clickedRow.Cells[ColumnLocation.Index].Value.ToString(); new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.UPDATES_WIZARD_DISCONNECTED_SERVER, disconnectedServerNames), Messages.UPDATES_WIZARD)).ShowDialog(this); } } }
public void SelectDownloadAlert(XenServerPatchAlert alert) { downloadUpdateRadioButton.Checked = true; foreach (PatchGridViewRow row in dataGridViewPatches.Rows) { if (row.UpdateAlert.Equals(alert)) { row.Selected = true; } } }
public PatchGridViewRow(XenServerPatchAlert alert) { _alert = alert; Cells.AddRange(_nameCell, _descriptionCell, _dateCell, _webPageCell); _nameCell.Value = String.Format(alert.Name); _descriptionCell.Value = String.Format(alert.Description); _dateCell.Value = HelpersGUI.DateTimeToString(alert.Timestamp.ToLocalTime(), Messages.DATEFORMAT_DMY, true); _webPageCell.Value = Messages.PATCHING_WIZARD_WEBPAGE_CELL; }
private void ToolStripMenuItemDownload_Click(object sender, EventArgs e) { DataGridViewRow clickedRow = FindAlertRow(sender as ToolStripMenuItem); if (clickedRow == null) { return; } XenServerPatchAlert patchAlert = (XenServerPatchAlert)clickedRow.Tag; if (patchAlert == null) { return; } string patchUri = patchAlert.Patch.PatchUrl; if (string.IsNullOrEmpty(patchUri)) { return; } Program.Invoke(Program.MainWindow, () => { var wizard = new PatchingWizard(); wizard.Show(); wizard.NextStep(); wizard.AddAlert(patchAlert); wizard.NextStep(); var hosts = patchAlert.DistinctHosts; if (hosts.Count > 0) { wizard.SelectServers(hosts); } else { string disconnectedServerNames = clickedRow.Cells[ColumnLocation.Index].Value.ToString(); using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.UPDATES_WIZARD_DISCONNECTED_SERVER, disconnectedServerNames), Messages.UPDATES_WIZARD))) { dlg.ShowDialog(this); } } }); }
public void PrepareToInstallUpdate(XenServerPatchAlert alert, List <Host> hosts) { if (!IsFirstPage()) { return; } //set the pages before landing on them so they are populated correctly PatchingWizard_SelectPatchPage.UpdateAlertFromWeb = alert; PatchingWizard_SelectPatchPage.UpdateAlertFromWebSelected += page_UpdateAlertFromWebSelected; PatchingWizard_SelectServers.SelectedServers = hosts; NextStep(); //FirstPage -> SelectPatchPage }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) { var fileName = fileNameTextBox.Text; if (downloadUpdateRadioButton.Checked) { SelectedUpdateType = UpdateType.NewRetail; } else { if (isValidFile()) { if (fileName.EndsWith(".xsupdate")) { 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)); } } Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted; base.PageLeave(direction, ref cancel); }
private static XenServerPatchAlert GetServerPatchAlert(List <XenServerPatchAlert> alerts, XenServerPatch patch) { XenServerPatchAlert alert = new XenServerPatchAlert(patch); XenServerPatchAlert existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } return(alert); }
/// <summary> /// Gets an upgrade sequence that contains a version upgrade, optionally followed by the minimal patches for the new version /// </summary> /// <param name="alert">The alert that refers the version-update</param> /// <param name="updateTheNewVersion">Also add the minimum patches for the new version (true) or not (false).</param> public static List <XenServerPatch> GetMinimalPatches(XenServerPatchAlert alert, bool updateTheNewVersion) { Debug.Assert(alert != null); var minimalPatches = new List <XenServerPatch> { alert.Patch }; // if it's a version updgrade the min sequence will be this patch (the upgrade) and the min patches for the new version if (updateTheNewVersion && alert.NewServerVersion != null && alert.NewServerVersion.MinimalPatches != null) { minimalPatches.AddRange(alert.NewServerVersion.MinimalPatches); } return(minimalPatches); }
/// <summary> /// Gets an upgrade sequence that contains a version upgrade, optionally followed by the minimal patches for the new version /// </summary> /// <param name="conn">Connection for the pool</param> /// <param name="alert">The alert that refers the version-update</param> /// <param name="updateTheNewVersion">Also add the minimum patches for the new version (true) or not (false).</param> /// <returns></returns> public static UpgradeSequence GetUpgradeSequence(IXenConnection conn, XenServerPatchAlert alert, bool updateTheNewVersion) { Debug.Assert(conn != null); Debug.Assert(alert != null); var uSeq = new UpgradeSequence(); if (XenServerVersions == null) { return(null); } Host master = Helpers.GetMaster(conn); if (master == null) { return(null); } var version = GetCommonServerVersionOfHostsInAConnection(conn, XenServerVersions); // the pool has to be homogeneous if (version != null) { uSeq.MinimalPatches = new List <XenServerPatch>(); uSeq.MinimalPatches.Add(alert.Patch); // if it's a version updgrade the min sequence will be this patch (the upgrade) and the min patches for the new version if (updateTheNewVersion && alert.NewServerVersion != null && alert.NewServerVersion.MinimalPatches != null) { uSeq.MinimalPatches.AddRange(alert.NewServerVersion.MinimalPatches); } conn.Cache.Hosts.ToList().ForEach(h => uSeq[h] = GetUpgradeSequenceForHost(h, uSeq.MinimalPatches) ); return(uSeq); } return(null); }
/// <summary> /// Gets an upgrade sequence that contains a version upgrade, optionally followed by all the patches for the new version /// </summary> public static List <XenServerPatch> GetAllPatches(XenServerPatchAlert alert, bool updateTheNewVersion) { Debug.Assert(alert != null); var allPatches = new List <XenServerPatch> { alert.Patch }; // if it's a version updgrade the update sequence will be this patch (the upgrade) and the patches for the new version if (updateTheNewVersion && alert.NewServerVersion != null) { var newVersionPatches = GetAllPatches(alert.NewServerVersion); if (newVersionPatches != null) { allPatches.AddRange(newVersionPatches); } } return(allPatches); }
public void TestAlertWithNoConnectionAndNoHosts() { XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", string.Empty, "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "5", "", ""); XenServerPatchAlert alert = new XenServerPatchAlert(p); ClassVerifiers.VerifyGetters(alert, new AlertClassUnitTestData { AppliesTo = string.Empty, FixLinkText = "Go to Web Page", HelpID = "XenServerPatchAlert", Description = "My description", HelpLinkText = "Help", Title = "New Update Available - name", Priority = "Priority5" }); Assert.IsTrue(alert.CanIgnore); VerifyConnExpectations(Times.Never); VerifyHostsExpectations(Times.Never); }
private void UpdateDownloadAndInstallButton(bool canEnable) { if (canEnable && (dataGridViewUpdates.SelectedRows.Count > 0)) { XenServerPatchAlert alert = dataGridViewUpdates.SelectedRows[0].Tag as XenServerPatchAlert; if (alert != null) { if (!alert.CanApply) { ShowInformationHelper = alert.CannotApplyReason; downloadAndInstallButton.Enabled = false; return; } ShowInformationHelper = alert.CannotApplyReason; downloadAndInstallButton.Enabled = !string.IsNullOrEmpty(alert.Patch.PatchUrl); return; } } downloadAndInstallButton.Enabled = false; }
private static List <XenServerPatchAlert> GetServerPatchesAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches, bool checkAlertIsAlreadyDismissed) { List <XenServerPatchAlert> alerts = new List <XenServerPatchAlert>(); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } List <XenServerVersion> serverVersions = xenServerVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(master.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(master) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(master).StartsWith(version.Oem) && Helpers.HostProductVersion(master) == version.Version.ToString())); }); if (serverVersions.Count == 0) { continue; } foreach (XenServerVersion xenServerVersion in serverVersions) { XenServerVersion version = xenServerVersion; List <XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch)); if (patches.Count == 0) { continue; } foreach (XenServerPatch xenServerPatch in patches) { XenServerPatchAlert alert = GetServerPatchAlert(alerts, xenServerPatch); if (checkAlertIsAlreadyDismissed && pool.other_config.ContainsKey(IgnorePatchAction.IgnorePatchKey)) { List <string> ignorelist = new List <string>(pool.other_config[IgnorePatchAction.IgnorePatchKey].Split(',')); if (ignorelist.Contains(xenServerPatch.Uuid)) { // we dont want to show the alert continue; } } XenServerPatch serverPatch = xenServerPatch; List <Host> noPatchHosts = hosts.Where(host => !host.AppliedPatches().Any(patch => patch.uuid == serverPatch.Uuid)).ToList(); if (noPatchHosts.Count == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }
public void TestAlertWithNullPatch() { XenServerPatchAlert alert = new XenServerPatchAlert(null); }
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) { if (!IsInAutomatedUpdatesMode) { if (selectFromDiskRadioButton.Checked && !string.IsNullOrEmpty(fileNameTextBox.Text) && Path.GetExtension(fileNameTextBox.Text).ToLowerInvariant().Equals(".zip")) { //check if we are installing update user sees in textbox if (Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(fileNameTextBox.Text)) { unzippedUpdateFilePath = ExtractUpdate(fileNameTextBox.Text); if (unzippedUpdateFilePath == null) { cancel = true; } unzippedFiles.Add(unzippedUpdateFilePath); } } else { unzippedUpdateFilePath = null; } var fileName = isValidFile(unzippedUpdateFilePath) ? unzippedUpdateFilePath.ToLowerInvariant() : fileNameTextBox.Text.ToLowerInvariant(); SelectedUpdateAlert = downloadUpdateRadioButton.Checked && dataGridViewPatches.SelectedRows.Count > 0 ? ((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert : null; FileFromDiskAlert = selectFromDiskRadioButton.Checked ? GetAlertFromFile(fileName) : null; if (downloadUpdateRadioButton.Checked) { if (SelectedUpdateAlert != null && SelectedUpdateAlert.DistinctHosts != null && SelectedUpdateAlert.DistinctHosts.Any(Helpers.ElyOrGreater)) // this is to check whether the Alert represents an ISO update (Ely or greater) { SelectedUpdateType = UpdateType.ISO; } else //legacy format { SelectedUpdateType = UpdateType.NewRetail; } } else { if (isValidFile(fileName)) { if (fileName.EndsWith("." + Branding.Update)) { SelectedUpdateType = UpdateType.NewRetail; } else if (fileName.EndsWith("." + Branding.UpdateIso)) { SelectedUpdateType = UpdateType.ISO; } else { SelectedUpdateType = UpdateType.Existing; } } } 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 succeed = Updates.CheckForUpdatesSync(this.Parent); cancel = !succeed; } } if (!cancel) //unsubscribe only if we are really leaving this page { Updates.RestoreDismissedUpdatesStarted -= Updates_RestoreDismissedUpdatesStarted; Updates.CheckForUpdatesStarted -= CheckForUpdates_CheckForUpdatesStarted; Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted; } }
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) { if (IsInAutomatedUpdatesMode) { var succeed = Updates.CheckForUpdatesSync(this.Parent); cancel = !succeed; } else if (downloadUpdateRadioButton.Checked) { UpdateAlertFromWeb = dataGridViewPatches.SelectedRows.Count > 0 ? ((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert : null; var distinctHosts = UpdateAlertFromWeb != null ? UpdateAlertFromWeb.DistinctHosts : null; SelectedUpdateType = distinctHosts != null && distinctHosts.Any(Helpers.ElyOrGreater) ? UpdateType.ISO : UpdateType.Legacy; AlertFromFileOnDisk = null; FileFromDiskHasUpdateXml = false; unzippedUpdateFilePath = null; SelectedPatchFilePath = null; PatchFromDisk = new KeyValuePair <XenServerPatch, string>(null, null); } else { UpdateAlertFromWeb = null; SelectedPatchFilePath = null; if (!WizardHelpers.IsValidFile(FilePath, out var pathFailure)) { using (var dlg = new ErrorDialog(pathFailure) { WindowTitle = Messages.UPDATES }) { cancel = true; dlg.ShowDialog(); return; } } SelectedPatchFilePath = FilePath; if (Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip")) { //check if we are installing the update the user sees in the textbox if (unzippedUpdateFilePath == null || !File.Exists(unzippedUpdateFilePath) || Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(FilePath)) { unzippedUpdateFilePath = WizardHelpers.ExtractUpdate(FilePath, this); } if (!WizardHelpers.IsValidFile(unzippedUpdateFilePath, out var zipFailure)) { using (var dlg = new ErrorDialog(zipFailure) { WindowTitle = Messages.UPDATES }) { cancel = true; dlg.ShowDialog(); return; } } if (!UnzippedUpdateFiles.Contains(unzippedUpdateFilePath)) { UnzippedUpdateFiles.Add(unzippedUpdateFilePath); } SelectedPatchFilePath = unzippedUpdateFilePath; } else { unzippedUpdateFilePath = null; } if (SelectedPatchFilePath.EndsWith("." + BrandManager.ExtensionUpdate)) { SelectedUpdateType = UpdateType.Legacy; } else if (SelectedPatchFilePath.EndsWith("." + InvisibleMessages.ISO_UPDATE)) { SelectedUpdateType = UpdateType.ISO; } AlertFromFileOnDisk = GetAlertFromFile(SelectedPatchFilePath, out var hasUpdateXml, out var isUpgradeIso); if (isUpgradeIso) { using (var dlg = new ErrorDialog(Messages.PATCHINGWIZARD_SELECTPATCHPAGE_ERROR_MAINISO)) dlg.ShowDialog(this); cancel = true; return; } FileFromDiskHasUpdateXml = hasUpdateXml; PatchFromDisk = AlertFromFileOnDisk == null ? new KeyValuePair <XenServerPatch, string>(null, null) : new KeyValuePair <XenServerPatch, string>(AlertFromFileOnDisk.Patch, SelectedPatchFilePath); } } if (!cancel) //unsubscribe only if we are really leaving this page { UnRegisterEvents(); } }
public static List <XenServerPatchAlert> NewXenServerPatchAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } var alerts = new List <XenServerPatchAlert>(); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } var serverVersions = xenServerVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(master.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(master) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(master).StartsWith(version.Oem) && Helpers.HostProductVersion(master) == version.Version.ToString())); }); if (serverVersions.Count == 0) { continue; } foreach (XenServerVersion xenServerVersion in serverVersions) { XenServerVersion version = xenServerVersion; List <XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch)); if (patches.Count == 0) { continue; } foreach (XenServerPatch xenServerPatch in patches) { var alert = new XenServerPatchAlert(xenServerPatch); var existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } if (!xenConnection.IsConnected) { continue; } XenServerPatch serverPatch = xenServerPatch; // A patch can be installed on a host if: // 1. it is not already installed and // 2. the host has all the required patches installed and // 3. the host doesn't have any of the conflicting patches installed var noPatchHosts = hosts.Where(host => { var appliedPatches = host.AppliedPatches(); // 1. patch is not already installed if (appliedPatches.Any(patch => patch.uuid == serverPatch.Uuid)) { return(false); } // 2. the host has all the required patches installed if (serverPatch.RequiredPatches != null && serverPatch.RequiredPatches.Count > 0 && !serverPatch.RequiredPatches.All(requiredPatchUuid => appliedPatches.Any(patch => patch.uuid == requiredPatchUuid))) { return(false); } // 3. the host doesn't have any of the conflicting patches installed if (serverPatch.ConflictingPatches != null && serverPatch.ConflictingPatches.Count > 0 && serverPatch.ConflictingPatches.Any(conflictingPatchUuid => appliedPatches.Any(patch => patch.uuid == conflictingPatchUuid))) { return(false); } return(true); }); if (noPatchHosts.Count() == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }
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); }
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) { if (IsInAutomatedUpdatesMode) { var succeed = Updates.CheckForUpdatesSync(this.Parent); cancel = !succeed; } else if (downloadUpdateRadioButton.Checked) { UpdateAlertFromWeb = dataGridViewPatches.SelectedRows.Count > 0 ? ((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert : null; var distinctHosts = UpdateAlertFromWeb != null ? UpdateAlertFromWeb.DistinctHosts : null; SelectedUpdateType = distinctHosts != null && distinctHosts.Any(Helpers.ElyOrGreater) ? UpdateType.ISO : UpdateType.Legacy; AlertFromFileOnDisk = null; FileFromDiskHasUpdateXml = false; unzippedUpdateFilePath = null; SelectedPatchFilePath = null; PatchFromDisk = new KeyValuePair <XenServerPatch, string>(null, null); } else { UpdateAlertFromWeb = null; SelectedPatchFilePath = null; if (!WizardHelpers.IsValidFile(FilePath, out var pathFailure)) { using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details( SystemIcons.Error, pathFailure, Messages.UPDATES))) { cancel = true; dlg.ShowDialog(); return; } } SelectedPatchFilePath = FilePath; if (Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip")) { //check if we are installing the update the user sees in the textbox if (unzippedUpdateFilePath == null || !File.Exists(unzippedUpdateFilePath) || Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(FilePath)) { unzippedUpdateFilePath = WizardHelpers.ExtractUpdate(FilePath, this); } if (!WizardHelpers.IsValidFile(unzippedUpdateFilePath, out var zipFailure)) { using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details( SystemIcons.Error, zipFailure, Messages.UPDATES))) { cancel = true; dlg.ShowDialog(); return; } } if (!unzippedFiles.Contains(unzippedUpdateFilePath)) { unzippedFiles.Add(unzippedUpdateFilePath); } SelectedPatchFilePath = unzippedUpdateFilePath; } else { unzippedUpdateFilePath = null; } if (SelectedPatchFilePath.EndsWith("." + Branding.Update)) { SelectedUpdateType = UpdateType.Legacy; } else if (SelectedPatchFilePath.EndsWith("." + Branding.UpdateIso)) { SelectedUpdateType = UpdateType.ISO; } AlertFromFileOnDisk = GetAlertFromFile(SelectedPatchFilePath, out var hasUpdateXml); FileFromDiskHasUpdateXml = hasUpdateXml; PatchFromDisk = AlertFromFileOnDisk == null ? new KeyValuePair <XenServerPatch, string>(null, null) : new KeyValuePair <XenServerPatch, string>(AlertFromFileOnDisk.Patch, SelectedPatchFilePath); } } if (!cancel) //unsubscribe only if we are really leaving this page { Updates.RestoreDismissedUpdatesStarted -= Updates_RestoreDismissedUpdatesStarted; Updates.CheckForUpdatesStarted -= CheckForUpdates_CheckForUpdatesStarted; Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted; } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel) { if (direction == PageLoadedDirection.Forward) { if (!IsInAutomatedUpdatesMode) { var fileName = fileNameTextBox.Text.ToLowerInvariant(); SelectedUpdateAlert = downloadUpdateRadioButton.Checked ? (XenServerPatchAlert)((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert : null; FileFromDiskAlert = selectFromDiskRadioButton.Checked ? GetAlertFromFileName(fileName) : null; if (downloadUpdateRadioButton.Checked) { if (SelectedUpdateAlert != null && SelectedUpdateAlert.DistinctHosts != null && SelectedUpdateAlert.DistinctHosts.Any(dh => Helpers.ElyOrGreater(dh))) // this is to check whether the Alert represents an ISO update (Ely or greater) { SelectedUpdateType = UpdateType.ISO; } else //legacy format { SelectedUpdateType = UpdateType.NewRetail; } } else { if (isValidFile(fileName)) { if (fileName.EndsWith("." + Branding.Update)) { SelectedUpdateType = UpdateType.NewRetail; } else if (fileName.EndsWith("." + Branding.UpdateIso)) { SelectedUpdateType = UpdateType.ISO; } else { SelectedUpdateType = UpdateType.Existing; } } } 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 succeed = Updates.CheckForUpdatesSync(this.Parent); cancel = !succeed; } } 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); }
public static List <XenServerPatchAlert> NewXenServerPatchAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } var alerts = new List <XenServerPatchAlert>(); var xenServerVersionsAsUpdates = xenServerVersions.Where(v => v.IsVersionAvailableAsAnUpdate); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } var serverVersions = new List <XenServerVersion>(); foreach (Host host in hosts) { var serverVersion = GetServerVersions(host, xenServerVersions); serverVersions.AddRange(serverVersion); } serverVersions = serverVersions.Distinct().ToList(); if (serverVersions.Count == 0) { continue; } foreach (XenServerVersion xenServerVersion in serverVersions) { XenServerVersion version = xenServerVersion; List <XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch)); if (patches.Count == 0) { continue; } foreach (XenServerPatch xenServerPatch in patches) { XenServerVersion newServerVersion = xenServerVersionsAsUpdates.FirstOrDefault(newVersion => newVersion.PatchUuid.Equals(xenServerPatch.Uuid, StringComparison.OrdinalIgnoreCase)); var alert = new XenServerPatchAlert(xenServerPatch, newServerVersion); var existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } if (!xenConnection.IsConnected) { continue; } XenServerPatch serverPatch = xenServerPatch; var noPatchHosts = hosts.Where(host => PatchCanBeInstalledOnHost(serverPatch, host, version)); if (noPatchHosts.Count() == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }