public async Task ContextPassesToDifferentStagesReverse() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var key = "xxx"; var actual = "zzz"; var expected = actual + actual; pipeline.Add(async(ctx, next, cancel) => { await next(); if (ctx.Enviorment.ContainsKey(key)) { actual = ctx.Enviorment[key] as string; } }); pipeline.Add(async(ctx, next, cancel) => { await next(); ctx.Enviorment[key] = expected; }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsTrue(result); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); Assert.AreEqual(expected, actual); }
public async Task ExceptionInDoublePipePreTrigger() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var pre = false; pipeline.Add(async(ctx, next, cancel) => { pre = true; await next(); }); pipeline.Add((ctx, next, cancel) => { throw new DivideByZeroException(); }); try { await pipeline.BeginProcessingMessageAsync(message, token.Token); } catch { Assert.IsTrue(pre); throw; } }
public async Task BeginProcessingMessageAsyncDoubleDoNotProcess() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var entered = false; var pre = false; var post = false; pipeline.Add(async(ctx, next, cancel) => { pre = true; await next(); post = true; }); pipeline.Add(async(ctx, next, cancel) => { entered = true; await Task.Delay(0); }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsFalse(result); Assert.IsTrue(entered); Assert.IsTrue(pre); Assert.IsTrue(post); }
private PipelineProcessor BuildRedirectionPipeline( string path, ExecutionContext context) { CommandProcessorBase command = context.CreateCommand("out-file"); command.AddParameter("-encoding", (object)"unicode"); if (this.Appending) { command.AddParameter("-append", (object)true); } command.AddParameter("-filepath", (object)path); PipelineProcessor pipelineProcessor = new PipelineProcessor(); pipelineProcessor.Add(command); try { pipelineProcessor.StartStepping(true); } catch (RuntimeException ex) { if (ex.ErrorRecord.Exception is ArgumentException) { throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), this._token, "RedirectionFailed", ex.ErrorRecord.Exception, (object)path, (object)ex.ErrorRecord.Exception.Message); } ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this._token, context)); throw ex; } return(pipelineProcessor); }
public async Task RawMessageAvailable() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); BrokeredMessage pre = null; BrokeredMessage post = null; pipeline.Add(async(ctx, next, cancel) => { pre = ctx.Message; await next(); post = ctx.Message; }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsTrue(result); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); Assert.AreSame(message, pre); Assert.AreSame(message, post); }
private static void AddNoopCommandProcessor(PipelineProcessor pipelineProcessor, System.Management.Automation.ExecutionContext context) { CmdletInfo commandInfo = new CmdletInfo("Out-Null", typeof(OutNullCommand)); CommandProcessorBase commandProcessor = context.CommandDiscovery.LookupCommandProcessor(commandInfo, context.EngineSessionState.CurrentScope.ScopeOrigin, false, null); pipelineProcessor.Add(commandProcessor); }
internal CommandProcessorBase AddToPipeline( PipelineProcessor pipeline, ExecutionContext context) { if (pipeline == null) { throw ParseTreeNode.tracer.NewArgumentNullException(nameof(pipeline)); } int index; CommandProcessorBase commandProcessor = this.CreateCommandProcessor(out index, context); foreach (CommandParameterInternal parametersAndArgument in (IEnumerable <CommandParameterInternal>) this.BindParametersAndArguments(index, context)) { commandProcessor.AddParameter(parametersAndArgument); } string helpTarget; HelpCategory helpCategory; if (commandProcessor.IsHelpRequested(out helpTarget, out helpCategory)) { commandProcessor = CommandProcessorBase.CreateGetHelpCommandProcessor(context, helpTarget, helpCategory); commandProcessor.Command.MyInvocation.ScriptToken = (Token)this._elements[0]; } pipeline.Add(commandProcessor); this.BindRedirectionPipes(commandProcessor, pipeline, context); return(commandProcessor); }
public void AddNullFunction2() { var pipeline = new PipelineProcessor(new OnMessageOptions()); Func <IPipelineContext, Func <Task>, CancellationToken, Task> stage = null; pipeline.Add(stage); }
public void AddNullFunction1() { var pipeline = new PipelineProcessor(new OnMessageOptions()); Type stage = null; pipeline.Add(stage); }
public void AddNotMessageProcessor() { var pipeline = new PipelineProcessor(new OnMessageOptions()); Type stage = typeof(string); pipeline.Add(stage); }
public async Task ResultAvailableAfterTrigger() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var pre = false; var post = false; pipeline.Add(async(ctx, next, cancel) => { pre = ctx.Result == null; await next(); post = ctx.Result != null; }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsTrue(result); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); Assert.IsTrue(pre); Assert.IsTrue(post); }
private void ConvertToString() { PipelineProcessor pipelineProcessor = new PipelineProcessor(); pipelineProcessor.Add(this.command.Context.CreateCommand("out-string")); this.inputList = new ArrayList((ICollection)pipelineProcessor.Execute((Array)this.inputList.ToArray())); }
private void ConvertToString() { PipelineProcessor processor = new PipelineProcessor(); processor.Add(this.command.Context.CreateCommand("out-string", false)); object[] c = (object[])processor.Execute(this.inputList.ToArray()); this.inputList = new ArrayList(c); }
public ServiceBusPipelineProcessor(OnMessageOptions messageOptions, List <object> stages) : base(messageOptions) { if (stages == null) { throw new ArgumentNullException(nameof(stages)); } _processor = new PipelineProcessor(messageOptions); foreach (var stage in stages) { if (stage is Type) { _processor.Add(stage as Type); } else { _processor.Add(stage as Func <IPipelineContext, Func <Task>, CancellationToken, Task>); } } }
public async Task ExceptionInDoublePipePostTrigger2() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var pre1 = false; var pre2 = false; var post = false; var result = false; pipeline.Add(async(ctx, next, cancel) => { pre1 = true; await next(); throw new DivideByZeroException(); }); pipeline.Add(async(ctx, next, cancel) => { pre2 = true; await next(); post = true; }); try { result = await pipeline.BeginProcessingMessageAsync(message, token.Token); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); } catch { Assert.IsTrue(pre1); Assert.IsTrue(pre2); Assert.IsTrue(post); Assert.IsTrue(result); throw; } }
public async Task ExceptionInPipePreTrigger() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); pipeline.Add((ctx, next, cancel) => { throw new DivideByZeroException(); }); await pipeline.BeginProcessingMessageAsync(message, token.Token); }
private void DelayedInternalInitialize() { _pp = new PipelineProcessor(); CmdletInfo cmdletInfo = new CmdletInfo(_commandName, _commandType, null, null, _context); CommandProcessor cp = new CommandProcessor(cmdletInfo, _context); foreach (CommandParameterInternal par in _commandParameterList) { cp.AddParameter(par); } _pp.Add(cp); }
private PipelineProcessor CreatePipelineProcessor() { CommandCollection commands = this.Commands; if (commands == null || commands.Count == 0) { throw LocalPipeline._trace.NewInvalidOperationException("Runspace", "NoCommandInPipeline"); } PipelineProcessor pipelineProcessor = new PipelineProcessor(); pipelineProcessor.TopLevel = true; bool flag = false; try { foreach (Command command in (Collection <Command>)commands) { CommandProcessorBase commandProcessor = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, this.AddToHistory); commandProcessor.RedirectShellErrorOutputPipe = this.RedirectShellErrorOutputPipe; pipelineProcessor.Add(commandProcessor); } return(pipelineProcessor); } catch (RuntimeException ex) { flag = true; throw; } catch (Exception ex) { flag = true; CommandProcessorBase.CheckForSevereException(ex); throw new RuntimeException(ResourceManagerCache.GetResourceString("Pipeline", "CannotCreatePipeline"), ex); } finally { if (flag) { pipelineProcessor.Dispose(); } } }
/// <summary> /// Gets the PSTraceSource instances that match the names specified. /// </summary> protected override void BeginProcessing() { Collection <PSTraceSource> preconfiguredSources = null; _matchingSources = ConfigureTraceSource(base.NameInternal, false, out preconfiguredSources); TurnOnTracing(_matchingSources, false); TurnOnTracing(preconfiguredSources, true); // Now that tracing has been configured, move all the sources into a // single collection foreach (PSTraceSource preconfiguredSource in preconfiguredSources) { _matchingSources.Add(preconfiguredSource); } if (ParameterSetName == "commandSet") { // Create the CommandProcessor and add it to a pipeline CommandProcessorBase commandProcessor = this.Context.CommandDiscovery.LookupCommandProcessor(Command, CommandOrigin.Runspace, false); // Add the parameters that were specified ParameterBinderController.AddArgumentsToCommandProcessor(commandProcessor, ArgumentList); _pipeline = new PipelineProcessor(); _pipeline.Add(commandProcessor); // Hook up the success and error pipelines to this cmdlet's WriteObject and // WriteError methods _pipeline.ExternalErrorOutput = new TracePipelineWriter(this, true, _matchingSources); _pipeline.ExternalSuccessOutput = new TracePipelineWriter(this, false, _matchingSources); } ResetTracing(_matchingSources); }
public async Task ContextsDontMixMessages2() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var id1 = Guid.NewGuid().ToString(); var id2 = Guid.NewGuid().ToString(); var message1 = new BrokeredMessage() { MessageId = id1 }; var message2 = new BrokeredMessage() { MessageId = id2 }; var token1 = new CancellationTokenSource(); var token2 = new CancellationTokenSource(); var funcresult = new FunctionResult(true); pipeline.Add(async(ctx, next, cancel) => { ctx.Enviorment["id"] = ctx.Message.MessageId; await next(); ctx.Message.MessageId = ctx.Enviorment["id"] as string; }); var result1 = await pipeline.BeginProcessingMessageAsync(message1, token1.Token); var result2 = await pipeline.BeginProcessingMessageAsync(message2, token1.Token); await pipeline.CompleteProcessingMessageAsync(message2, funcresult, token2.Token); await pipeline.CompleteProcessingMessageAsync(message1, funcresult, token1.Token); Assert.IsTrue(result1); Assert.IsTrue(result2); Assert.AreEqual(id1, message1.MessageId); Assert.AreEqual(id2, message2.MessageId); }
private PipelineProcessor CreatePipelineProcessor() { PipelineProcessor processor2; CommandCollection commands = base.Commands; if ((commands == null) || (commands.Count == 0)) { throw PSTraceSource.NewInvalidOperationException("RunspaceStrings", "NoCommandInPipeline", new object[0]); } PipelineProcessor processor = new PipelineProcessor { TopLevel = true }; bool flag = false; try { foreach (Command command in commands) { CommandProcessorBase base2; if (command.CommandInfo == null) { base2 = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, base.AddToHistory, this.IsNested ? CommandOrigin.Internal : CommandOrigin.Runspace); } else { CmdletInfo commandInfo = (CmdletInfo)command.CommandInfo; base2 = new CommandProcessor(commandInfo, this.LocalRunspace.ExecutionContext); PSSQMAPI.IncrementData(commandInfo.CommandType); base2.Command.CommandOriginInternal = CommandOrigin.Internal; base2.Command.MyInvocation.InvocationName = commandInfo.Name; if (command.Parameters != null) { foreach (CommandParameter parameter in command.Parameters) { CommandParameterInternal internal2 = CommandParameter.ToCommandParameterInternal(parameter, false); base2.AddParameter(internal2); } } } base2.RedirectShellErrorOutputPipe = base.RedirectShellErrorOutputPipe; processor.Add(base2); } processor2 = processor; } catch (RuntimeException) { flag = true; throw; } catch (Exception exception) { flag = true; CommandProcessorBase.CheckForSevereException(exception); throw new RuntimeException(PipelineStrings.CannotCreatePipeline, exception); } finally { if (flag) { base.SetHadErrors(true); processor.Dispose(); } } return(processor2); }
private static CommandProcessorBase AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, System.Management.Automation.ExecutionContext context) { object parameterText; IScriptExtent parameterExtent; CommandProcessorBase base2; InternalCommand command; string str3; HelpCategory category; CommandAst ast = commandBaseAst as CommandAst; TokenKind kind = (ast != null) ? ast.InvocationOperator : TokenKind.Unknown; bool dotSource = kind == TokenKind.Dot; SessionStateInternal sessionState = null; int index = 0; PSModuleInfo info = PSObject.Base(commandElements[0].ArgumentValue) as PSModuleInfo; if (info != null) { if ((info.ModuleType == ModuleType.Binary) && (info.SessionState == null)) { throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "CantInvokeInBinaryModule", ParserStrings.CantInvokeInBinaryModule, new object[] { info.Name }); } if (info.SessionState == null) { throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "CantInvokeInNonImportedModule", ParserStrings.CantInvokeInNonImportedModule, new object[] { info.Name }); } sessionState = info.SessionState.Internal; index++; } CommandParameterInternal internal3 = commandElements[index]; if (internal3.ParameterNameSpecified) { parameterText = internal3.ParameterText; parameterExtent = internal3.ParameterExtent; if (!internal3.ArgumentSpecified) { } } else { parameterText = PSObject.Base(internal3.ArgumentValue); parameterExtent = internal3.ArgumentExtent; } string str = dotSource ? "." : ((kind == TokenKind.Ampersand) ? "&" : null); ScriptBlock scriptblock = parameterText as ScriptBlock; if (scriptblock != null) { base2 = CommandDiscovery.CreateCommandProcessorForScript(scriptblock, context, !dotSource, sessionState); } else { CommandInfo commandInfo = parameterText as CommandInfo; if (commandInfo != null) { base2 = context.CommandDiscovery.LookupCommandProcessor(commandInfo, context.EngineSessionState.CurrentScope.ScopeOrigin, new bool?(!dotSource), sessionState); } else { string str2 = (parameterText as string) ?? PSObject.ToStringParser(context, parameterText); str = str ?? str2; if (string.IsNullOrEmpty(str2)) { throw InterpreterError.NewInterpreterException(parameterText, typeof(RuntimeException), parameterExtent, "BadExpression", ParserStrings.BadExpression, new object[] { dotSource ? "." : "&" }); } try { if (sessionState != null) { SessionStateInternal engineSessionState = context.EngineSessionState; try { context.EngineSessionState = sessionState; base2 = context.CreateCommand(str2, dotSource); goto Label_025D; } finally { context.EngineSessionState = engineSessionState; } } base2 = context.CreateCommand(str2, dotSource); } catch (RuntimeException exception) { if (exception.ErrorRecord.InvocationInfo == null) { InvocationInfo invocationInfo = new InvocationInfo(null, parameterExtent, context) { InvocationName = str }; exception.ErrorRecord.SetInvocationInfo(invocationInfo); } throw; } } } Label_025D: command = base2.Command; base2.UseLocalScope = !dotSource && ((command is ScriptCommand) || (command is PSScriptCmdlet)); bool flag2 = base2 is NativeCommandProcessor; for (int i = index + 1; i < commandElements.Length; i++) { CommandParameterInternal parameter = commandElements[i]; if ((!parameter.ParameterNameSpecified || !parameter.ParameterName.Equals("-", StringComparison.OrdinalIgnoreCase)) || flag2) { if (parameter.ArgumentSplatted) { foreach (CommandParameterInternal internal6 in Splat(parameter.ArgumentValue, parameter.ArgumentExtent)) { base2.AddParameter(internal6); } } else { base2.AddParameter(parameter); } } } if (base2.IsHelpRequested(out str3, out category)) { base2 = CommandProcessorBase.CreateGetHelpCommandProcessor(context, str3, category); } base2.Command.InvocationExtent = commandBaseAst.Extent; base2.Command.MyInvocation.ScriptPosition = commandBaseAst.Extent; base2.Command.MyInvocation.InvocationName = str; pipe.Add(base2); bool flag3 = false; bool flag4 = false; bool flag5 = false; bool flag6 = false; if (redirections != null) { foreach (CommandRedirection redirection in redirections) { redirection.Bind(pipe, base2, context); switch (redirection.FromStream) { case RedirectionStream.All: flag3 = true; flag4 = true; flag5 = true; flag6 = true; break; case RedirectionStream.Error: flag3 = true; break; case RedirectionStream.Warning: flag4 = true; break; case RedirectionStream.Verbose: flag5 = true; break; case RedirectionStream.Debug: flag6 = true; break; } } } if (!flag3) { if (context.ShellFunctionErrorOutputPipe != null) { base2.CommandRuntime.ErrorOutputPipe = context.ShellFunctionErrorOutputPipe; } else { base2.CommandRuntime.ErrorOutputPipe.ExternalWriter = context.ExternalErrorOutput; } } if (!flag4 && (context.ExpressionWarningOutputPipe != null)) { base2.CommandRuntime.WarningOutputPipe = context.ExpressionWarningOutputPipe; flag4 = true; } if (!flag5 && (context.ExpressionVerboseOutputPipe != null)) { base2.CommandRuntime.VerboseOutputPipe = context.ExpressionVerboseOutputPipe; flag5 = true; } if (!flag6 && (context.ExpressionDebugOutputPipe != null)) { base2.CommandRuntime.DebugOutputPipe = context.ExpressionDebugOutputPipe; flag6 = true; } if ((context.CurrentCommandProcessor != null) && (context.CurrentCommandProcessor.CommandRuntime != null)) { if (!flag4 && (context.CurrentCommandProcessor.CommandRuntime.WarningOutputPipe != null)) { base2.CommandRuntime.WarningOutputPipe = context.CurrentCommandProcessor.CommandRuntime.WarningOutputPipe; } if (!flag5 && (context.CurrentCommandProcessor.CommandRuntime.VerboseOutputPipe != null)) { base2.CommandRuntime.VerboseOutputPipe = context.CurrentCommandProcessor.CommandRuntime.VerboseOutputPipe; } if (!flag6 && (context.CurrentCommandProcessor.CommandRuntime.DebugOutputPipe != null)) { base2.CommandRuntime.DebugOutputPipe = context.CurrentCommandProcessor.CommandRuntime.DebugOutputPipe; } } return(base2); }