public override RunResult Run(DataRow input, DataTable dataTable, DataObjectStore store, Type codeBehind, Workflow.UpdateTableDelegate updateTableDelegate) { RunResult runResult = new RunResult(); IPSCommandWrapper ipscommandWrapper = base.PowershellFactory.CreatePSCommand(); Activity activity = null; foreach (Activity activity2 in base.Body) { ((CmdletActivity)activity2).BuildCommand(input, dataTable, store, codeBehind); ipscommandWrapper.AddCommand(((CmdletActivity)activity2).Command.Commands[0]); activity = activity2; } if (activity != null) { base.CurrentExecutingActivity = activity; ((CmdletActivity)activity).Command = ipscommandWrapper; RunResult runResult2 = activity.Run(input, dataTable, store, codeBehind, updateTableDelegate); runResult.DataObjectes.AddRange(runResult2.DataObjectes); this.statusReport = this.statusReport.Concat(activity.GetStatusReport(input, dataTable, store)).ToArray <PowerShellResults>(); base.CurrentExecutingActivity = null; if (runResult2.ErrorOccur && base.ErrorBehavior == ErrorBehavior.Stop && activity.ErrorBehavior == ErrorBehavior.Stop) { runResult.ErrorOccur = true; return(runResult); } } return(runResult); }
internal void BuildCommand(DataRow input, DataTable dataTable, DataObjectStore store, Type codeBehind) { this.Command = base.PowershellFactory.CreatePSCommand().AddCommand(this.GetCommandText(store)); foreach (Parameter parameter in this.GetEffectiveParameters(input, dataTable, store)) { if (parameter.IsRunnable(input, dataTable)) { switch (parameter.Type) { case ParameterType.Switch: this.Command.AddParameter(parameter.Name); break; case ParameterType.Mandatory: case ParameterType.RunOnModified: { object value = Parameter.ConvertToParameterValue(input, dataTable, parameter, store); this.Command.AddParameter(parameter.Name, value); break; } default: throw new NotSupportedException(); } } } }
public IList GetData(IEntity entity, Expression expression) { IPSCommandWrapper ipscommandWrapper = DependencyFactory.CreatePSCommandWrapper(); ipscommandWrapper.AddCommand(entity.TaskInvocationInfo.CmdletName); if (entity.TaskInvocationInfo.Parameters != null) { foreach (KeyValuePair <string, string> keyValuePair in entity.TaskInvocationInfo.Parameters) { ipscommandWrapper.AddParameter(keyValuePair.Key, keyValuePair.Value); } } if (!this.principal.IsInRole(string.Format("{0}\\{1}?{2}", entity.TaskInvocationInfo.SnapinName, entity.TaskInvocationInfo.CmdletName, "Expression"))) { throw new InvalidOperationException(string.Format("Expression parameter is not avaible for the cmdlet {0}\\{1}. Add an entry in Microsoft.Exchange.Configuration.Authorization.ClientRoleEntries.TenantReportingRequiredParameters for your cmdlet.", entity.TaskInvocationInfo.SnapinName, entity.TaskInvocationInfo.CmdletName)); } ipscommandWrapper.AddParameter("Expression", expression); IList data = null; using (new AverageTimePerfCounter(RwsPerfCounters.AverageReportCmdletResponseTime, RwsPerfCounters.AverageReportCmdletResponseTimeBase, true)) { PowerShellResults result = ipscommandWrapper.Invoke(ReportingDataSource.RunspaceMediator); if (result.Succeeded) { ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.CreateGenericTypeListForResults, delegate { data = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { entity.ClrType }), new object[] { result.Output.Count }); }); foreach (PSObject psobject in result.Output) { data.Add(psobject.BaseObject); } ReportingDataSource.reportRowCounter.AddSample((long)data.Count); } else { ReportingWebServiceEventLogConstants.Tuple_InvokeCmdletFailed.LogEvent(new object[] { EventLogExtension.GetUserNameToLog(), ipscommandWrapper.Commands[0].CommandText, result.Errors[0].Exception }); RwsPerfCounters.ReportCmdletErrors.Increment(); this.ThrowError(result.Errors[0]); } } return(data); }