Example #1
0
		public IEnumerator<DSResource> InvokeAsync(Expression expression, bool noStreamingResponse)
		{
			IEnumerator<DSResource> enumerator;
			using (OperationTracer operationTracer = new OperationTracer("Entering Pipeline.InvokeAsync"))
			{
				MonitorLock monitorLock = new MonitorLock(this);
				MonitorLock monitorLock1 = monitorLock;
				using (monitorLock)
				{
					if (this.Command == null || this.OutputFormat == null)
					{
						throw new DataServiceException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidInvocationData, new object[0]));
					}
					else
					{
						this.ExpirationTime = DateTimeHelper.UtcNow;
						DateTime expirationTime = this.ExpirationTime;
						this.ExpirationTime = expirationTime.AddMilliseconds((double)this.WaitMsec);
						DateTime dateTime = this.ExpirationTime;
						this.ExpirationTime = dateTime.AddSeconds((double)DataServiceController.Current.Configuration.Invocation.Lifetime);
						WindowsImpersonationContext windowsImpersonationContext = this.executionToken.Instance.Impersonate();
						using (windowsImpersonationContext)
						{
							using (OperationTracer operationTracer1 = new OperationTracer("PowerShell.Create"))
							{
								ScriptBlockAst scriptBlockAst = this.ValidateAndBuildPipeline(string.Concat(this.Command, "| ConvertTo-", this.OutputFormat));
								Runspace.DefaultRunspace = this.runspace.Item.Runspace;
								this.powerShell = scriptBlockAst.GetScriptBlock().GetPowerShell(new object[0]);
								this.powerShell.Runspace = this.runspace.Item.Runspace;
								Runspace.DefaultRunspace = null;
							}
							TraceHelper.Current.BeginOperation0("RunspaceContext.Create");
							DefaultRunspaceContext defaultRunspaceContext = DefaultRunspaceContext.Create(this.runspace.Item.Runspace);
							using (defaultRunspaceContext)
							{
								TraceHelper.Current.EndOperation("RunspaceContext.Create");
								TraceHelper.Current.PipelineStart(this.ID, this.Command, this.OutputFormat);
								this.outputObjects.DataAdded += new EventHandler<DataAddedEventArgs>(this.DataAddedEventHandler);
								this.powerShell.BeginInvoke<PSObject, PSObject>(null, this.outputObjects, Utils.GetPSInvocationSettings(), this.TestHookCompletionCallback, null);
								monitorLock1.Exit();
								this.finished.WaitOne(this.WaitMsec);
								this.timer.Start();
								monitorLock1.Enter();
								List<DSResource> dSResources = new List<DSResource>();
								dSResources.Add(this.MakeDsResource());
								TraceHelper.Current.DebugMessage("Exiting Pipeline.InvokeAsync");
								enumerator = dSResources.AsEnumerable<DSResource>().GetEnumerator();
							}
						}
					}
				}
			}
			return enumerator;
		}
Example #2
0
		internal IEnumerator<DSResource> InvokeCmdletAsync(System.Management.Automation.PowerShell powerShell, Expression expression, EventHandler<DataAddedEventArgs> dataAddedEventHandler, AsyncCallback executionCompletionCallback, bool noStreamingResponse)
		{
			Tracer tracer = new Tracer();
			this.dataStore = new AsyncDataStore<DSResource>(expression, noStreamingResponse);
			this.output = new PSDataCollection<PSObject>();
			tracer.CommandInvocationStart(this.cmdletInfo.CmdletName);
			powerShell.Runspace = this.runspace.Item.Runspace;
			powerShell.AddCommand(this.cmdletInfo.CmdletName);
			foreach (string key in this.parameters.Keys)
			{
				if (!this.cmdletInfo.IsSwitch(key))
				{
					powerShell.AddParameter(key, this.parameters[key]);
				}
				else
				{
					powerShell.AddParameter(key);
				}
			}
			this.isExecutionCompleted = false;
			using (OperationTracer operationTracer = new OperationTracer(new Action<string>(TraceHelper.Current.CmdletExecutionStart), new Action<string>(TraceHelper.Current.CmdletExecutionEnd), powerShell.Commands.ToTraceMessage()))
			{
				try
				{
					this.timer.Start();
					powerShell.Invoke<PSObject>(null, this.output, Utils.GetPSInvocationSettings());
				}
				catch (CommandNotFoundException commandNotFoundException1)
				{
					CommandNotFoundException commandNotFoundException = commandNotFoundException1;
					throw new CommandInvocationFailedException(powerShell.Commands.Commands[0].CommandText, commandNotFoundException);
				}
				catch (ParameterBindingException parameterBindingException1)
				{
					ParameterBindingException parameterBindingException = parameterBindingException1;
					throw new CommandInvocationFailedException(powerShell.Commands.Commands[0].CommandText, parameterBindingException);
				}
				catch (CmdletInvocationException cmdletInvocationException1)
				{
					CmdletInvocationException cmdletInvocationException = cmdletInvocationException1;
					throw new CommandInvocationFailedException(powerShell.Commands.Commands[0].CommandText, cmdletInvocationException);
				}
			}
			return new BlockingEnumerator<DSResource>(this.dataStore);
		}
Example #3
0
		internal void DataAddedEventHandler(object obj, DataAddedEventArgs eventArgs)
		{
			int length;
			using (OperationTracer operationTracer = new OperationTracer("Invoke.OutputAddedCallback"))
			{
				lock (this)
				{
					if (obj == this.outputObjects)
					{
						PSObject item = this.outputObjects[eventArgs.Index];
						string str = PipelineInvocation.TranslatePSObjectToString(item, this.OutputFormat);
						int maxResponseChars = DataServiceController.Current.Configuration.Invocation.MaxResponseChars;
						if (this.Output != null)
						{
							length = this.Output.Length;
						}
						else
						{
							length = 0;
						}
						int num = maxResponseChars - length;
						if (num < str.Length)
						{
							if (!this.outputQuotaExceeded)
							{
								this.outputQuotaExceeded = true;
								if (num > 0)
								{
									PipelineInvocation pipelineInvocation = this;
									pipelineInvocation.Output = string.Concat(pipelineInvocation.Output, str.Substring(0, num));
								}
								object[] objArray = new object[1];
								objArray[0] = DataServiceController.Current.Configuration.Invocation.MaxResponseChars;
								string str1 = string.Format(CultureInfo.CurrentCulture, Resources.InvocationOutputQuotaExceeded, objArray);
								ErrorRecord errorRecord = new ErrorRecord(new DataServiceException(0x193, str1), null, ErrorCategory.PermissionDenied, null);
								errorRecord.ErrorDetails = new ErrorDetails(str1);
								this.Errors.Add(errorRecord);
							}
							this.outputObjects.Clear();
						}
						else
						{
							PipelineInvocation pipelineInvocation1 = this;
							pipelineInvocation1.Output = string.Concat(pipelineInvocation1.Output, str);
						}
					}
					else
					{
						return;
					}
				}
			}
		}