Esempio n. 1
0
        protected override void FinishWizard()
        {
            // If the user has chosen a file that already exists, get confirmation
            string path = bugToolPageDestination1.OutputFile;

            if (File.Exists(path))
            {
                DialogResult dialogResult;
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.FILE_X_EXISTS_OVERWRITE, path), Messages.XENCENTER),
                           ThreeButtonDialog.ButtonOK,
                           new ThreeButtonDialog.TBDButton(Messages.CANCEL, DialogResult.Cancel, ThreeButtonDialog.ButtonType.CANCEL, true)))
                {
                    dialogResult = dlg.ShowDialog(this);
                }
                if (dialogResult != DialogResult.OK)
                {
                    FinishCanceled();
                    return;
                }
            }

            // Check we can write to the destination file - otherwise we only find out at the
            // end of the ZipStatusReportAction, and the downloaded server files are lost,
            // and the user will have to run the wizard again.
            try
            {
                using (FileStream temp = File.OpenWrite(path))
                {
                    // Yay, it worked
                }
            }
            catch (Exception exn)
            {
                // Failure
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(
                               SystemIcons.Error,
                               string.Format(Messages.COULD_NOT_WRITE_FILE, path, exn.Message),
                               Messages.XENCENTER)))
                {
                    dlg.ShowDialog(this);
                }
                FinishCanceled();
                return;
            }

            // Proceed to finish the wizard and start the zip action

            // zip up the report files and save them to the chosen file
            Actions.ZipStatusReportAction action =
                new Actions.ZipStatusReportAction(bugToolPageRetrieveData.OutputFolder, bugToolPageDestination1.OutputFile);
            using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
            {
                dialog.ShowCancel = true;
                dialog.ShowDialog();
            }

            if (!action.Succeeded)
            {
                // Close. We can't recover from a partially-completed ZipStatusReportAction.
                base.FinishWizard();
                return;
            }

            // upload the report files
            if (bugToolPageDestination1.Upload)
            {
                var uploadAction = new Actions.UploadServerStatusReportAction(bugToolPageDestination1.OutputFile,
                                                                              bugToolPageDestination1.UploadToken, bugToolPageDestination1.CaseNumber,
                                                                              Registry.HealthCheckUploadDomainName, false);
                using (var dialog = new ActionProgressDialog(uploadAction, ProgressBarStyle.Marquee)
                {
                    ShowCancel = true
                })
                    dialog.ShowDialog();
            }

            // Save away the output path for next time
            XenAdmin.Properties.Settings.Default.ServerStatusPath = bugToolPageDestination1.OutputFile;

            log.Debug("Cleaning up crash dump logs on server");
            var capabilities = bugToolPageSelectCapabilities1.Capabilities;

            foreach (Capability c in capabilities)
            {
                if (c.Key == "host-crashdump-dumps" && c.Checked)
                {
                    var hostList = bugToolPageSelectHosts1.SelectedHosts;
                    if (!hostList.Any(h => h.HasCrashDumps))
                    {
                        break;
                    }

                    DialogResult result;
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(null, Messages.REMOVE_CRASHDUMP_QUESTION, Messages.REMOVE_CRASHDUMP_FILES),
                               ThreeButtonDialog.ButtonYes,
                               ThreeButtonDialog.ButtonNo))
                    {
                        result = dlg.ShowDialog(this);
                    }
                    if (result == DialogResult.Yes)
                    {
                        foreach (Host host in hostList)
                        {
                            if (host != null && host.HasCrashDumps)
                            {
                                new Actions.DestroyHostCrashDumpAction(host).RunAsync();
                            }
                        }
                    }
                    break;
                }
            }
            base.FinishWizard();
        }
Esempio n. 2
0
        protected override void FinishWizard()
        {
            // If the user has chosen a file that already exists, get confirmation
            string path = bugToolPageDestination1.OutputFile;
            if (File.Exists(path))
            {
                if (new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.FILE_X_EXISTS_OVERWRITE, path), Messages.XENCENTER),
                        ThreeButtonDialog.ButtonOK,
                        new ThreeButtonDialog.TBDButton(Messages.CANCEL, DialogResult.Cancel, ThreeButtonDialog.ButtonType.CANCEL, true)).ShowDialog(this) != DialogResult.OK)
                {
                    FinishCanceled();
                    return;
                }
            }

            // Check we can write to the destination file - otherwise we only find out at the
            // end of the ZipStatusReportAction, and the downloaded server files are lost,
            // and the user will have to run the wizard again.
            try
            {
                using (FileStream temp = File.OpenWrite(path))
                {
                    // Yay, it worked
                }
            }
            catch (Exception exn)
            {
                // Failure
                new ThreeButtonDialog(
                   new ThreeButtonDialog.Details(
                       SystemIcons.Error,
                       string.Format(Messages.COULD_NOT_WRITE_FILE, path, exn.Message),
                       Messages.XENCENTER)).ShowDialog(this);
                FinishCanceled();
                return;
            }

            // Proceed to finish the wizard and start the zip action

            // zip up the report files and save them to the chosen file
            Actions.ZipStatusReportAction action =
                new Actions.ZipStatusReportAction(bugToolPageRetrieveData.OutputFolder, bugToolPageDestination1.OutputFile);
            ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks);
            dialog.ShowCancel = true;
            dialog.ShowDialog();

            if (!action.Succeeded)
            {
                // Close. We can't recover from a partially-completed ZipStatusReportAction.
                base.FinishWizard();
                return;
            }

            // upload the report files
            if (bugToolPageDestination1.Upload)
            {
                var uploadAction = new Actions.UploadServerStatusReportAction(bugToolPageDestination1.OutputFile,
                                                                       bugToolPageDestination1.UploadToken,
                                                                       Registry.CallHomeUploadDomainName, false);
                dialog = new ActionProgressDialog(uploadAction, ProgressBarStyle.Blocks) {ShowCancel = true};
                dialog.ShowDialog();
            }

            // Save away the output path for next time
            XenAdmin.Properties.Settings.Default.ServerStatusPath = bugToolPageDestination1.OutputFile;

            log.Debug("Cleaning up crash dump logs on server");
            var capabilities = bugToolPageSelectCapabilities1.Capabilities;
            foreach (Capability c in capabilities)
            {
                if (c.Key == "host-crashdump-dumps" && c.Checked)
                {
                    var hostList = bugToolPageSelectHosts1.SelectedHosts;
                    if (!hostList.Any(h => h.HasCrashDumps))
                        break;

                    DialogResult result = new ThreeButtonDialog(
                                new ThreeButtonDialog.Details(null, Messages.REMOVE_CRASHDUMP_QUESTION, Messages.REMOVE_CRASHDUMP_FILES),
                                ThreeButtonDialog.ButtonYes,
                                ThreeButtonDialog.ButtonNo).ShowDialog(this);

                    if (result == DialogResult.Yes)
                    {
                        foreach (Host host in hostList)
                        {
                            if (host != null && host.HasCrashDumps)
                            {
                                new Actions.DestroyHostCrashDumpAction(host).RunAsync();
                            }
                        }
                    }
                    break;
                }
            }
            base.FinishWizard();
        }