示例#1
0
 public SingleTaskDataHandler(string saveCommandText) : this(saveCommandText, new MonadConnection("timeout=30", new CommandInteractionHandler(), ADServerSettingsSingleton.GetInstance().CreateRunspaceServerSettingsObject(), PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo()))
 {
 }
示例#2
0
 public void ShowError(Exception ex, string message)
 {
     if (ex is ADServerSettingsChangedException || ex.InnerException is ADServerSettingsChangedException)
     {
         ADServerSettingsSingleton.GetInstance().ADServerSettings.SetDefaultSettings();
         this.ShowError(Strings.ADServerSettingsChangedException);
         return;
     }
     if (ex is CmdletInvocationException || DataAccessHelper.IsDataAccessKnownException(ex))
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ExceptionHelper.IsWellknownCommandExecutionException(ex))
     {
         this.ShowError(ex.InnerException.Message);
         return;
     }
     if (ex is VersionMismatchException)
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ex is SupportedVersionListFormatException)
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ex is PooledConnectionOpenTimeoutException)
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ex is PSRemotingTransportException)
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ex is PSRemotingDataStructureException)
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ex is PSInvalidOperationException)
     {
         this.ShowError(ex.Message);
         return;
     }
     if (ex is OperationCanceledException)
     {
         this.ShowError(ex.Message);
         return;
     }
     using (ExceptionDialog exceptionDialog = new ExceptionDialog())
     {
         if (ExceptionHelper.IsWellknownExceptionFromServer(ex.InnerException))
         {
             exceptionDialog.Exception = ex.InnerException;
         }
         else
         {
             exceptionDialog.Exception = ex;
         }
         if (!string.IsNullOrEmpty(message))
         {
             exceptionDialog.Message = string.Format("{0}\r\n\r\n{1}", message, exceptionDialog.Message);
         }
         ((IUIService)this).ShowDialog(exceptionDialog);
     }
 }
示例#3
0
 public override void Open(IUIService service, WorkUnitCollection workUnits, bool enforceViewEntireForest, ResultsLoaderProfile profile)
 {
     this.isResultPane = !enforceViewEntireForest;
     this.workUnits = workUnits;
     this.commandInteractionHandler = ((service != null) ? new WinFormsCommandInteractionHandler(service) : new CommandInteractionHandler());
     RunspaceServerSettingsPresentationObject runspaceServerSettingsPresentationObject = ADServerSettingsSingleton.GetInstance().CreateRunspaceServerSettingsObject();
     if (enforceViewEntireForest && runspaceServerSettingsPresentationObject != null)
     {
         runspaceServerSettingsPresentationObject.ViewEntireForest = true;
     }
     this.connection = new MonadConnection(PSConnectionInfoSingleton.GetInstance().GetConnectionStringForScript(), this.commandInteractionHandler, runspaceServerSettingsPresentationObject, PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo(profile.SerializationLevel));
     this.connection.Open();
 }
示例#4
0
        private void Fill(RefreshRequestEventArgs e)
        {
            ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader>((long)this.GetHashCode(), "-->DataTableLoader.Fill: {0}", this);
            ResultsLoaderProfile profile = e.Argument as ResultsLoaderProfile;

            if (profile != null)
            {
                DataTable dataTable = e.Result as DataTable;
                dataTable.RowChanged += delegate(object sender, DataRowChangeEventArgs eventArgs)
                {
                    if (eventArgs.Action == DataRowAction.Add)
                    {
                        this.FillPrimaryKeysBasedOnLambdaExpression(eventArgs.Row, profile);
                    }
                };
                DataTable dataTable2 = dataTable.Clone();
                dataTable2.RowChanged += delegate(object sender, DataRowChangeEventArgs eventArgs)
                {
                    if (eventArgs.Action == DataRowAction.Add)
                    {
                        this.FillPrimaryKeysBasedOnLambdaExpression(eventArgs.Row, profile);
                    }
                };
                if (!this.EnforeViewEntireForest && !profile.HasPermission())
                {
                    goto IL_26F;
                }
                using (DataAdapterExecutionContext dataAdapterExecutionContext = this.executionContextFactory.CreateExecutionContext())
                {
                    dataAdapterExecutionContext.Open(base.UIService, this.WorkUnits, this.EnforeViewEntireForest, profile);
                    foreach (AbstractDataTableFiller filler in profile.TableFillers)
                    {
                        if (profile.IsRunnable(filler))
                        {
                            if (e.CancellationPending)
                            {
                                break;
                            }
                            profile.BuildCommand(filler);
                            if (profile.FillType == 1 || this.IsPreFillForResolving(filler))
                            {
                                dataAdapterExecutionContext.Execute(filler, dataTable2, profile);
                                this.MergeChanges(dataTable2, dataTable);
                                dataTable2.Clear();
                            }
                            else
                            {
                                dataAdapterExecutionContext.Execute(filler, dataTable, profile);
                            }
                        }
                    }
                    goto IL_26F;
                }
            }
            MonadCommand monadCommand = e.Argument as MonadCommand;

            if (monadCommand != null)
            {
                this.AttachCommandToMonitorWarnings(monadCommand);
                using (MonadConnection monadConnection = new MonadConnection(PSConnectionInfoSingleton.GetInstance().GetConnectionStringForScript(), new CommandInteractionHandler(), ADServerSettingsSingleton.GetInstance().CreateRunspaceServerSettingsObject(), PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo(ExchangeRunspaceConfigurationSettings.SerializationLevel.Full)))
                {
                    monadConnection.Open();
                    monadCommand.Connection = monadConnection;
                    using (MonadDataAdapter monadDataAdapter = new MonadDataAdapter(monadCommand))
                    {
                        DataTable dataTable3 = (DataTable)e.Result;
                        if (dataTable3.Columns.Count != 0)
                        {
                            monadDataAdapter.MissingSchemaAction  = MissingSchemaAction.Ignore;
                            monadDataAdapter.EnforceDataSetSchema = true;
                        }
                        ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader, MonadCommand>((long)this.GetHashCode(), "-->DataTableLoader.Fill: calling dataAdapter.Fill: {0}. Command:{1}", this, monadCommand);
                        monadDataAdapter.Fill(dataTable3);
                        ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader, MonadCommand>((long)this.GetHashCode(), "<--DataTableLoader.Fill: calling dataAdaptr.Fill: {0}. Command:{1}", this, monadCommand);
                    }
                }
                this.DetachCommandFromMonitorWarnings(monadCommand);
            }
IL_26F:
            this.OnFillTable(e);
            ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader>((long)this.GetHashCode(), "<--DataTableLoader.Fill: {0}", this);
        }
        public TableDataHandler(string selectCommandText, string updateCommandText, string insertCommandText, string deleteCommandText)
        {
            this.DataTable   = new DataTable();
            this.dataAdapter = new MonadDataAdapter();
            this.dataAdapter.EnforceDataSetSchema = true;
            MonadConnection connection = new MonadConnection("timeout=30", new CommandInteractionHandler(), ADServerSettingsSingleton.GetInstance().CreateRunspaceServerSettingsObject(), PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo());

            this.dataAdapter.SelectCommand = new LoggableMonadCommand(selectCommandText, connection);
            this.dataAdapter.UpdateCommand = new LoggableMonadCommand(updateCommandText, connection);
            this.dataAdapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
            this.dataAdapter.DeleteCommand = new LoggableMonadCommand(deleteCommandText, connection);
            this.dataAdapter.InsertCommand = new LoggableMonadCommand(insertCommandText, connection);
            this.dataAdapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
            this.synchronizationContext = SynchronizationContext.Current;
        }
 protected virtual MonadConnection CreateMonadConnection(IUIService uiService, CommandInteractionHandler commandInteractionHandler)
 {
     return(new MonadConnection("timeout=30", commandInteractionHandler, ADServerSettingsSingleton.GetInstance().CreateRunspaceServerSettingsObject(), PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo()));
 }
示例#7
0
        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();
            }
        }