private void warningCaption_Click(object sender, EventArgs e) { this.HideWarningCaption(); if (!this.IsSingleMoreResultsWarning) { UIService.ShowError("", Strings.Warnings, this.workUnitsForWarnings, base.ShellUI); } }
public bool ShowErrors(string errorMessage, string warningMessage, WorkUnitCollection workUnits, IUIService uiService) { Exception error = this.runWorkerCompletedEventArgs.Error; if (error != null) { uiService.ShowError(error); return(true); } IList <WorkUnit> errors = workUnits.FindByErrorOrWarning(); return(UIService.ShowError(errorMessage, warningMessage, errors, uiService)); }
protected override void OnExecute() { string commandDisplayName = this.CommandDisplayName; WorkUnitCollectionEventArgs inputArgs = new WorkUnitCollectionEventArgs(new WorkUnitCollection()); this.OnInputRequested(inputArgs); IUIService uiService = (IUIService)this.GetService(typeof(IUIService)); if (uiService == null) { throw new InvalidOperationException("TaskCommand must be sited and needs to be able to find an IUIService."); } Control controlToRestoreFocus = uiService.GetDialogOwnerWindow() as Control; IRefreshable singleRefreshOnFinish = this.RefreshOnFinish; IRefreshable[] multiRefreshOnFinish = (this.MultiRefreshOnFinish == null) ? null : ((IRefreshable[])this.MultiRefreshOnFinish.Clone()); if (this.ConfirmOperation(inputArgs)) { WorkUnitCollection workUnits = inputArgs.WorkUnits; if (workUnits.Count == 0) { WorkUnit workUnit = new WorkUnit(); workUnit.Text = commandDisplayName; workUnit.Target = null; workUnits.Add(workUnit); } IProgress progress = this.CreateProgress(new LocalizedString(commandDisplayName)); MonadCommand command = new LoggableMonadCommand(); command.CommandText = this.CommandText; foreach (object obj in this.Parameters) { MonadParameter value = (MonadParameter)obj; command.Parameters.Add(value); } command.ProgressReport += delegate(object sender, ProgressReportEventArgs progressReportEventArgs) { progress.ReportProgress(workUnits.ProgressValue, workUnits.MaxProgressValue, progressReportEventArgs.ProgressRecord.StatusDescription); }; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate(object param0, DoWorkEventArgs param1) { MonadConnection connection = new MonadConnection("timeout=30", new WinFormsCommandInteractionHandler(this.TestUIService ?? uiService), ADServerSettingsSingleton.GetInstance().CreateRunspaceServerSettingsObject(), PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo()); command.Connection = connection; using (new OpenConnection(connection)) { command.Execute(workUnits.ToArray()); } }; worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) { command.Connection.Close(); if (runWorkerCompletedEventArgs.Error != null) { progress.ReportProgress(0, 0, ""); uiService.ShowError(runWorkerCompletedEventArgs.Error); } else { int num = workUnits.HasFailures ? 0 : 100; progress.ReportProgress(num, num, ""); List <WorkUnit> list = new List <WorkUnit>(workUnits.FindByErrorOrWarning()); if (workUnits.Cancelled) { WorkUnit workUnit2 = list[list.Count - 1]; for (int i = 0; i < workUnit2.Errors.Count; i++) { if (workUnit2.Errors[i].Exception is PipelineStoppedException) { workUnit2.Errors.Remove(workUnit2.Errors[i]); break; } } if (workUnit2.Errors.Count == 0) { list.Remove(workUnit2); } } if (list.Count > 0) { string errorMessage = null; string warningMessage = null; if (list.Count == 1) { if (this.SingleSelectionError != null) { errorMessage = this.SingleSelectionError(list[0].Text); } else { errorMessage = Strings.SingleSelectionError(commandDisplayName, list[0].Text); } if (this.SingleSelectionWarning != null) { warningMessage = this.SingleSelectionWarning(list[0].Text); } else { warningMessage = Strings.SingleSelectionWarning(commandDisplayName, list[0].Text); } } else if (list.Count > 1) { if (this.MultipleSelectionError != null) { errorMessage = this.MultipleSelectionError(list.Count); } else { errorMessage = Strings.MultipleSelectionError(commandDisplayName, list.Count); } if (this.MultipleSelectionWarning != null) { warningMessage = this.MultipleSelectionWarning(list.Count); } else { warningMessage = Strings.MultipleSelectionWarning(commandDisplayName, list.Count); } } UIService.ShowError(errorMessage, warningMessage, list, uiService); } } this.PerformRefreshOnFinish(workUnits, singleRefreshOnFinish, multiRefreshOnFinish); this.OnCompleted(inputArgs); }; bool flag = workUnits.Count > 1; ProgressDialog pd = null; if (flag) { pd = new ProgressDialog(); pd.OkEnabled = false; pd.Text = Strings.TaskProgressDialogTitle(commandDisplayName); pd.UseMarquee = true; pd.StatusText = workUnits.Description; pd.FormClosing += delegate(object sender, FormClosingEventArgs formClosingEventArgs) { if (worker.IsBusy) { if (pd.CancelEnabled) { pd.CancelEnabled = false; WinformsHelper.InvokeAsync(delegate { command.Cancel(); }, pd); } formClosingEventArgs.Cancel = worker.IsBusy; } }; pd.FormClosed += delegate(object param0, FormClosedEventArgs param1) { if (controlToRestoreFocus != null) { controlToRestoreFocus.Focus(); } }; worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) { pd.UseMarquee = false; pd.Maximum = 100; pd.Value = 100; pd.Close(); }; command.ProgressReport += delegate(object sender, ProgressReportEventArgs progressReportEventArgs) { if ((progressReportEventArgs.ProgressRecord.RecordType == ProgressRecordType.Processing && progressReportEventArgs.ProgressRecord.PercentComplete > 0 && progressReportEventArgs.ProgressRecord.PercentComplete < 100) || workUnits[0].Status == WorkUnitStatus.Completed) { pd.UseMarquee = false; } pd.Maximum = workUnits.MaxProgressValue; pd.Value = workUnits.ProgressValue; pd.StatusText = workUnits.Description; }; pd.ShowModeless(uiService.GetDialogOwnerWindow() as IServiceProvider); uiService = pd.ShellUI; } SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext()); worker.RunWorkerAsync(); base.OnExecute(); } }