예제 #1
0
        internal PowerShellResults <JsonDictionary <object> > GetProgress(string progressId, bool async)
        {
            string text = this.workflow ?? "GetProgress";

            if (!string.IsNullOrEmpty(this.schema) && this.IsWorkflowDefined(text))
            {
                return(this.ExecuteProgressWorkflow(text, progressId));
            }
            if (async)
            {
                DDIHelper.ProgressIdForGetListAsync = progressId;
                DDIParameters               ddiparameters     = new DDIParameters();
                AsyncGetListContext         registeredContext = AsyncServiceManager.GetRegisteredContext(progressId);
                Dictionary <string, object> dictionary;
                if (registeredContext != null && registeredContext.Parameters != null && registeredContext.Parameters.Parameters != null)
                {
                    dictionary = registeredContext.Parameters.Parameters.RawDictionary;
                }
                else
                {
                    dictionary = new Dictionary <string, object>();
                }
                if (registeredContext != null && !string.IsNullOrEmpty(registeredContext.WorkflowOutput))
                {
                    dictionary["workflowOutput"] = registeredContext.WorkflowOutput;
                }
                dictionary["ProgressId"] = progressId;
                ddiparameters.Parameters = new JsonDictionary <object>(dictionary);
                return(this.GetListCommon(ddiparameters, null, true));
            }
            return(AsyncServiceManager.GetProgress(progressId));
        }
예제 #2
0
        public sealed override bool IsRunnable(DataRow input, DataTable dataTable, DataObjectStore store)
        {
            if (AsyncServiceManager.IsCurrentWorkCancelled())
            {
                return(false);
            }
            List <Parameter> parametersToInvoke = this.GetParametersToInvoke(input, dataTable, store);
            bool             flag = this.IsToExecuteCmdlet(input, dataTable, store, parametersToInvoke);

            if (!flag)
            {
                return(false);
            }
            List <string> parameters = (from x in parametersToInvoke
                                        select x.Name).ToList <string>();
            string cmdletRbacString = this.GetCmdletRbacString(store, parameters);
            bool   flag2            = base.RbacChecker.IsInRole(cmdletRbacString);

            DDIHelper.Trace("Checking RBAC: {0} : {1}", new object[]
            {
                cmdletRbacString,
                flag2
            });
            if (!flag2)
            {
                throw new CmdletAccessDeniedException(Strings.AccessDeniedMessage);
            }
            return(true);
        }
예제 #3
0
        public PowerShellResults <JsonDictionary <object> > Execute()
        {
            PowerShellResults <JsonDictionary <object> > result;

            using (EcpPerformanceData.DDIServiceExecution.StartRequestTimer())
            {
                switch (this.ExecutingWorkflow.AsyncMode)
                {
                case AsyncMode.AsynchronousOnly:
                    this.ExecutingWorkflow.AsyncRunning = true;
                    break;

                case AsyncMode.SynchronousAndAsynchronous:
                    this.ExecutingWorkflow.AsyncRunning = (base.DataObjectStore.AsyncType == ListAsyncType.GetListAsync || base.DataObjectStore.AsyncType == ListAsyncType.GetListPreLoad);
                    break;
                }
                if (!this.ExecutingWorkflow.AsyncRunning || DDIHelper.ForGetListProgress)
                {
                    result = this.ExecuteCore(this.ExecutingWorkflow);
                }
                else
                {
                    if (!typeof(ProgressCalculatorBase).IsAssignableFrom(this.ExecutingWorkflow.ProgressCalculator))
                    {
                        throw new ArgumentException("A valid ProgressCalculator type must be specified for async running workflow.");
                    }
                    Func <PowerShellResults> callback = delegate()
                    {
                        IList <string>      outputVariables     = this.GetOutputVariables(this.OutputVariableWorkflow);
                        AsyncGetListContext asyncGetListContext = new AsyncGetListContext
                        {
                            WorkflowOutput           = string.Join(",", outputVariables ?? ((IList <string>)Array <string> .Empty)),
                            UnicodeOutputColumnNames = this.GetUnicodeVariablesFrom(outputVariables),
                            Parameters = this.parameters
                        };
                        AsyncServiceManager.RegisterWorkflow(this.ExecutingWorkflow, asyncGetListContext);
                        return(this.ExecuteCore(this.ExecutingWorkflow));
                    };
                    AsyncTaskType taskType = AsyncTaskType.Default;
                    string        text     = this.ExecutingWorkflow.Name;
                    if (base.DataObjectStore.AsyncType == ListAsyncType.GetListAsync)
                    {
                        taskType = AsyncTaskType.AsyncGetList;
                    }
                    else if (base.DataObjectStore.AsyncType == ListAsyncType.GetListPreLoad)
                    {
                        taskType = AsyncTaskType.AsyncGetListPreLoad;
                        text    += "_PreLoad";
                    }
                    PowerShellResults powerShellResults = AsyncServiceManager.InvokeAsync(callback, null, this.UniqueLogonUserIdentity, taskType, text);
                    result = new PowerShellResults <JsonDictionary <object> >
                    {
                        ProgressId   = powerShellResults.ProgressId,
                        ErrorRecords = powerShellResults.ErrorRecords
                    };
                }
            }
            return(result);
        }
예제 #4
0
        internal PowerShellResults Cancel(string progressId)
        {
            string text = this.workflow ?? "Cancel";

            if (!string.IsNullOrEmpty(this.schema) && this.IsWorkflowDefined(text))
            {
                return(this.ExecuteProgressWorkflow(text, progressId));
            }
            return(AsyncServiceManager.Cancel(progressId));
        }
예제 #5
0
        public override RunResult Run(DataRow input, DataTable dataTable, DataObjectStore store, Type codeBehind, Workflow.UpdateTableDelegate updateTableDelegate)
        {
            DDIHelper.Trace(TraceType.InfoTrace, "Executing :" + base.GetType().Name);
            DDIHelper.Trace <IPSCommandWrapper>(TraceType.InfoTrace, base.Command);
            RunResult runResult = new RunResult();
            PowerShellResults <PSObject> powerShellResults;

            if (!DDIHelper.ForGetListProgress)
            {
                base.ExecuteCmdlet(null, runResult, out powerShellResults, store.AsyncType == ListAsyncType.GetListAsync || store.AsyncType == ListAsyncType.GetListPreLoad);
            }
            else if (store.AsyncType == ListAsyncType.GetListEndLoad)
            {
                powerShellResults = AsyncServiceManager.GetPreLoadResult(DDIHelper.ProgressIdForGetListAsync);
            }
            else
            {
                string progressIdForGetListAsync = DDIHelper.ProgressIdForGetListAsync;
                powerShellResults = AsyncServiceManager.GetCurrentResult(progressIdForGetListAsync);
            }
            base.StatusReport    = powerShellResults;
            runResult.ErrorOccur = !base.StatusReport.Succeeded;
            if (!runResult.ErrorOccur)
            {
                if (powerShellResults.Output != null && powerShellResults.Output.Length > 0)
                {
                    Type      type         = null;
                    Hashtable propertyHash = new Hashtable();
                    Hashtable hashtable    = new Hashtable();
                    dataTable.BeginLoadData();
                    foreach (PSObject psobject in powerShellResults.Output)
                    {
                        if (type == null)
                        {
                            type = psobject.BaseObject.GetType();
                            type.GetProperties().Perform(delegate(PropertyInfo c)
                            {
                                propertyHash[c.Name] = c;
                            });
                        }
                        DataRow dataRow = dataTable.NewRow();
                        dataTable.Rows.Add(dataRow);
                        dataRow.BeginEdit();
                        foreach (object obj in dataTable.Columns)
                        {
                            DataColumn dataColumn = (DataColumn)obj;
                            Variable   variable   = dataColumn.ExtendedProperties["Variable"] as Variable;
                            if (variable != null)
                            {
                                if (variable.PersistWholeObject)
                                {
                                    dataRow[dataColumn.ColumnName] = psobject.BaseObject;
                                }
                                else if (!hashtable.ContainsKey(dataColumn.ColumnName))
                                {
                                    PropertyInfo propertyInfo = propertyHash[variable.MappingProperty] as PropertyInfo;
                                    if (propertyInfo != null)
                                    {
                                        dataRow[dataColumn.ColumnName] = propertyInfo.GetValue(psobject.BaseObject, null);
                                    }
                                    else
                                    {
                                        hashtable.Add(dataColumn.ColumnName, null);
                                    }
                                }
                            }
                        }
                        Collection <Set> defaultValues = this.DefaultValues;
                        NewDefaultObject.SetDefaultValues(input, dataRow, dataTable, defaultValues);
                        dataRow.EndEdit();
                    }
                    dataTable.EndLoadData();
                }
            }
            else if (this.isResultSizeAutoApplied)
            {
                Microsoft.Exchange.Management.ControlPanel.ErrorRecord errorRecord = base.StatusReport.ErrorRecords.FirstOrDefault((Microsoft.Exchange.Management.ControlPanel.ErrorRecord x) => x.Exception is ParameterBindingException && (x.Exception as ParameterBindingException).ParameterName == "ResultSize");
                if (errorRecord != null)
                {
                    if (base.StatusReport.ErrorRecords.Length > 1)
                    {
                        base.StatusReport.ErrorRecords = base.StatusReport.ErrorRecords.Except(new Microsoft.Exchange.Management.ControlPanel.ErrorRecord[]
                        {
                            errorRecord
                        }).ToArray <Microsoft.Exchange.Management.ControlPanel.ErrorRecord>();
                    }
                    else
                    {
                        base.StatusReport.ErrorRecords = new Microsoft.Exchange.Management.ControlPanel.ErrorRecord[]
                        {
                            new Microsoft.Exchange.Management.ControlPanel.ErrorRecord(new Exception(Strings.UnsupportedAutoApplyParamMsgText))
                        };
                    }
                    lock (GetListCmdlet.unsupportedCmdletsLock)
                    {
                        string commandText = base.GetCommandText(store);
                        if (!GetListCmdlet.unsupportedCmdlets.Contains(commandText))
                        {
                            GetListCmdlet.unsupportedCmdlets.Add(commandText);
                        }
                    }
                }
            }
            return(runResult);
        }
예제 #6
0
        protected override PowerShellResults <JsonDictionary <object> > ExecuteCore(Workflow workflow)
        {
            DataRow row = base.Table.NewRow();

            base.Table.Rows.Add(row);
            base.Row.ItemArray = base.Input.ItemArray;
            PowerShellResults <JsonDictionary <object> > powerShellResults = new PowerShellResults <JsonDictionary <object> >();

            powerShellResults.MergeErrors(workflow.Run(base.Input, base.Table, base.DataObjectStore, base.ProfileBuilder.Class, new Workflow.UpdateTableDelegate(this.UpdateTable)));
            if (powerShellResults.ErrorRecords.Length == 0)
            {
                if (workflow.AsyncRunning && AsyncServiceManager.IsCurrentWorkCancelled())
                {
                    goto IL_451;
                }
                using (EcpPerformanceData.DDITypeConversion.StartRequestTimer())
                {
                    IList <string>          outputVariables = base.GetOutputVariables(base.OutputVariableWorkflow);
                    Func <DataColumn, bool> predicate;
                    if (this.IsGetObjectForNew)
                    {
                        predicate = ((DataColumn c) => outputVariables.Contains(c.ColumnName, StringComparer.OrdinalIgnoreCase) && this.Row[c.ColumnName] != DBNull.Value);
                    }
                    else
                    {
                        predicate = ((DataColumn c) => outputVariables.Contains(c.ColumnName, StringComparer.OrdinalIgnoreCase) || (Variable.MandatoryVariablesForGetObject.Contains(c.ColumnName) && this.ExecutingWorkflow is GetObjectWorkflow));
                    }
                    IEnumerable <DataColumn>    columns = (outputVariables == null) ? base.Table.Columns.Cast <DataColumn>() : base.Table.Columns.Cast <DataColumn>().Where(predicate);
                    Dictionary <string, object> dictionary;
                    base.ExtractDataRow(base.Table.Rows[0], columns, out dictionary);
                    if (base.ExecutingWorkflow is GetObjectWorkflow)
                    {
                        foreach (string name in this.GetOutputRelatedDataObjects(columns))
                        {
                            IVersionable versionable = base.DataObjectStore.GetDataObject(name) as IVersionable;
                            if (versionable != null && versionable.ExchangeVersion != null)
                            {
                                bool flag = versionable.ExchangeVersion.IsOlderThan(base.DataObjectStore.GetDataObjectDeclaration(name).MinSupportedVersion);
                                if (versionable.IsReadOnly || flag)
                                {
                                    base.Table.Rows[0]["IsReadOnly"] = true;
                                    if (dictionary.ContainsKey("IsReadOnly"))
                                    {
                                        dictionary["IsReadOnly"] = true;
                                    }
                                    string text = flag ? Strings.ObjectTooOld : Strings.VersionMismatchWarning(versionable.ExchangeVersion.ExchangeBuild);
                                    powerShellResults.Warnings = ((powerShellResults.Warnings == null) ? new string[]
                                    {
                                        text
                                    } : powerShellResults.Warnings.Concat(new string[]
                                    {
                                        text
                                    }).ToArray <string>());
                                    break;
                                }
                            }
                        }
                    }
                    Dictionary <string, ValidatorInfo[]> dictionary2;
                    IList <string> source;
                    IList <string> source2;
                    workflow.LoadMetaData(base.Input, base.Table, base.DataObjectStore, outputVariables, out dictionary2, out source, out source2, base.ProfileBuilder);
                    powerShellResults.Validators         = dictionary2;
                    powerShellResults.ReadOnlyProperties = source.ToArray <string>();
                    powerShellResults.NoAccessProperties = source2.ToArray <string>();
                    powerShellResults.Output             = new JsonDictionary <object>[]
                    {
                        dictionary
                    };
                    goto IL_451;
                }
            }
            ShouldContinueException ex = powerShellResults.ErrorRecords[0].Exception as ShouldContinueException;

            if (ex != null)
            {
                ShouldContinueContext shouldContinueContext = (HttpContext.Current.Items["ShouldContinueContext"] as ShouldContinueContext) ?? new ShouldContinueContext();
                if (!shouldContinueContext.CmdletsPrompted.Contains(ex.Details.CurrentCmdlet))
                {
                    shouldContinueContext.CmdletsPrompted.Add(ex.Details.CurrentCmdlet);
                }
                powerShellResults.ErrorRecords[0].Context = shouldContinueContext;
            }
            if (!workflow.OutputOnError.IsNullOrEmpty())
            {
                IEnumerable <DataColumn> columns2 = from DataColumn c in base.Table.Columns
                                                    where workflow.OutputOnError.Contains(c.ColumnName)
                                                    select c;
                Dictionary <string, object> dictionary3;
                base.ExtractDataRow(base.Table.Rows[0], columns2, out dictionary3);
                if (powerShellResults.ErrorRecords[0].Context == null)
                {
                    powerShellResults.ErrorRecords[0].Context = new ErrorRecordContext();
                }
                powerShellResults.ErrorRecords[0].Context.LastOuput = dictionary3;
            }
IL_451:
            DDIHelper.Trace(TraceType.InfoTrace, "Result: ");
            DDIHelper.Trace <PowerShellResults <JsonDictionary <object> > >(TraceType.InfoTrace, powerShellResults);
            return(powerShellResults);
        }
예제 #7
0
 public virtual bool IsRunnable(DataRow input, DataTable dataTable, DataObjectStore store)
 {
     return(!AsyncServiceManager.IsCurrentWorkCancelled() && this.HasPermission(input, dataTable, store, null));
 }