Exemplo n.º 1
0
        internal override MonadCommand InnerBuildProcedureCore(string commandText, DataRow row)
        {
            MonadCommand monadCommand = new LoggableMonadCommand(commandText);
            UserRange    userRange    = UserRange.AllUsersWithoutMailAttributes;
            string       name         = null;
            string       displayName  = null;
            string       text         = null;
            PSCredential pscredential = null;

            if (!DBNull.Value.Equals(row["UserRange"]))
            {
                userRange = (UserRange)row["UserRange"];
            }
            if (!DBNull.Value.Equals(row["NameForFilter"]))
            {
                name = (string)row["NameForFilter"];
            }
            if (!DBNull.Value.Equals(row["DisplayNameForFilter"]))
            {
                displayName = (string)row["DisplayNameForFilter"];
            }
            if (!DBNull.Value.Equals(row["DomainController"]))
            {
                text = (string)row["DomainController"];
            }
            if (!DBNull.Value.Equals(row["Credential"]))
            {
                pscredential = (PSCredential)row["Credential"];
            }
            string value = UserCommandBuilder.ConstructFilterParameterValue(name, displayName);

            if (!string.IsNullOrEmpty(value))
            {
                monadCommand.Parameters.AddWithValue("Filter", value);
            }
            monadCommand.Parameters.AddWithValue("RecipientTypeDetails", UserCommandBuilder.ConstructRecipientTypeDetailsArray(userRange));
            monadCommand.Parameters.AddWithValue("ResultSize", "Unlimited");
            if (text != null)
            {
                monadCommand.Parameters.AddWithValue("DomainController", text);
            }
            if (pscredential != null)
            {
                monadCommand.Parameters.AddWithValue("Credential", pscredential);
            }
            return(monadCommand);
        }
        internal override MonadCommand InnerBuildProcedureCore(string commandText, DataRow row)
        {
            MonadCommand monadCommand = new LoggableMonadCommand(commandText);
            string       value        = null;

            if (!DBNull.Value.Equals(row["Forest"]))
            {
                value = (string)row["Forest"];
            }
            string value2 = null;

            if (!DBNull.Value.Equals(row["DomainName"]))
            {
                value2 = (string)row["DomainName"];
            }
            PSCredential pscredential = null;

            if (!DBNull.Value.Equals(row["Credential"]))
            {
                pscredential = (PSCredential)row["Credential"];
            }
            bool flag = false;

            if (!DBNull.Value.Equals(row["IsGlobalCatalog"]))
            {
                flag = (bool)row["IsGlobalCatalog"];
            }
            if (flag)
            {
                monadCommand.Parameters.AddSwitch("GlobalCatalog");
            }
            if (!string.IsNullOrEmpty(value))
            {
                monadCommand.Parameters.AddWithValue("Forest", value);
            }
            if (!string.IsNullOrEmpty(value2))
            {
                monadCommand.Parameters.AddWithValue("DomainName", value2);
            }
            if (pscredential != null)
            {
                monadCommand.Parameters.AddWithValue("Credential", pscredential);
            }
            return(monadCommand);
        }
Exemplo n.º 3
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();
            }
        }