protected virtual void OnCompleted(WorkUnitCollectionEventArgs e) { if (this.Completed != null) { this.Completed(this, e); } }
protected virtual void OnInputRequested(WorkUnitCollectionEventArgs e) { if (this.InputRequested != null) { this.InputRequested(this, e); } }
protected virtual bool ConfirmOperation(WorkUnitCollectionEventArgs inputArgs) { IUIService iuiservice = (IUIService)this.GetService(typeof(IUIService)); string text = null; if (inputArgs.WorkUnits.Count == 1 && this.SingleSelectionConfirmation != null) { text = this.SingleSelectionConfirmation(inputArgs.WorkUnits[0].Text); } if (inputArgs.WorkUnits.Count > 1 && this.MultipleSelectionConfirmation != null) { text = this.MultipleSelectionConfirmation(inputArgs.WorkUnits.Count); } return(string.IsNullOrEmpty(text) || DialogResult.No != iuiservice.ShowMessage(text, this.CommandDisplayName, MessageBoxButtons.YesNo)); }
protected sealed override void OnInputRequested(WorkUnitCollectionEventArgs e) { e.WorkUnits.AddRange(this.OnRequestInputs()); if (this.DataListViewResultPane != null && this.Setting.IsSelectionCommand) { if (this.Setting.UseSingleRowRefresh && this.DataListViewResultPane.HasSelection) { base.RefreshOnFinish = this.DataListViewResultPane.GetSelectionRefreshObjects(); base.MultiRefreshOnFinish = null; return; } if (this.Setting.UseFullRefresh) { base.RefreshOnFinish = this.DataListViewResultPane.RefreshableDataSource; base.MultiRefreshOnFinish = null; } } }
protected sealed override void OnCompleted(WorkUnitCollectionEventArgs e) { if (this.DataListViewResultPane != null && this.Setting.IsSelectionCommand && this.Setting.Operation == CommandOperation.Delete) { ISupportFastRefresh supportFastRefresh = this.DataListViewResultPane.RefreshableDataSource as ISupportFastRefresh; if (supportFastRefresh != null && base.RefreshOnFinish == null && base.MultiRefreshOnFinish == null) { foreach (WorkUnit workUnit in e.WorkUnits) { if (workUnit.Status == WorkUnitStatus.Completed) { supportFastRefresh.Remove(workUnit.Target); } } } if (this.rowIdToSelectAfterDelete != null && !e.WorkUnits.HasFailures) { this.DataListViewResultPane.ListControl.SelectItemBySpecifiedIdentity(this.rowIdToSelectAfterDelete, false); } this.rowIdToSelectAfterDelete = null; } this.OnCompleted(e.WorkUnits.ToArray()); base.OnCompleted(e); }
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(); } }