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;
            }
        }
示例#2
0
        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();
            }
        }