private void AddToPipe(object obj) { if (PipelineProcessor != null) { // Put the pipeline on the notification stack for stop. _context.PushPipelineProcessor(PipelineProcessor); PipelineProcessor.Step(obj); _context.PopPipelineProcessor(false); } else if (_resultCollection != null) { _resultCollection.Add(obj != null ? PSObject.AsPSObject(obj) : null); } else if (_resultList != null) { _resultList.Add(obj); } else if (_externalWriter != null) { _externalWriter.Write(obj); } else if (ObjectQueue != null) { ObjectQueue.Enqueue(obj); // This is the "streamlet" recursive call if (_downstreamCmdlet != null && ObjectQueue.Count > OutBufferCount) { _downstreamCmdlet.DoExecute(); } } }
private void WriteErrorCreateRemoteRunspaceFailed(Exception e, Uri uri) { PipelineWriter objectWriter = this.stream.ObjectWriter; ErrorRecord errorRecord = new ErrorRecord(e, "CreateRemoteRunspaceFailed", ErrorCategory.InvalidArgument, uri); Action <Cmdlet> action = cmdlet => cmdlet.WriteError(errorRecord); objectWriter.Write(action); }
private List <RemoteRunspace> CreateRunspacesWhenRunspaceParameterSpecified() { List <RemoteRunspace> list = new List <RemoteRunspace>(); base.ValidateRemoteRunspacesSpecified(); int rsIndex = 0; foreach (PSSession session in this.remoteRunspaceInfos) { if ((session == null) || (session.Runspace == null)) { base.ThrowTerminatingError(new ErrorRecord(new ArgumentNullException("PSSession"), "PSSessionArgumentNull", ErrorCategory.InvalidArgument, null)); } else { try { int num2; RemoteRunspace runspace = (RemoteRunspace)session.Runspace; WSManConnectionInfo connectionInfo = runspace.ConnectionInfo as WSManConnectionInfo; WSManConnectionInfo info2 = null; if (connectionInfo != null) { info2 = connectionInfo.Copy(); info2.EnableNetworkAccess = info2.EnableNetworkAccess || (this.EnableNetworkAccess != false); } else { Uri uri = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <Uri>(runspace.ConnectionInfo, "ConnectionUri", null); string shellUri = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(runspace.ConnectionInfo, "ShellUri", string.Empty); info2 = new WSManConnectionInfo(uri, shellUri, runspace.ConnectionInfo.Credential); base.UpdateConnectionInfo(info2); info2.EnableNetworkAccess = (bool)this.EnableNetworkAccess; } RemoteRunspacePoolInternal remoteRunspacePoolInternal = runspace.RunspacePool.RemoteRunspacePoolInternal; TypeTable typeTable = null; if (((remoteRunspacePoolInternal != null) && (remoteRunspacePoolInternal.DataStructureHandler != null)) && (remoteRunspacePoolInternal.DataStructureHandler.TransportManager != null)) { typeTable = remoteRunspacePoolInternal.DataStructureHandler.TransportManager.Fragmentor.TypeTable; } string runspaceName = this.GetRunspaceName(rsIndex, out num2); RemoteRunspace item = new RemoteRunspace(typeTable, info2, base.Host, this.SessionOption.ApplicationArguments, runspaceName, num2); list.Add(item); } catch (UriFormatException exception) { PipelineWriter objectWriter = this.stream.ObjectWriter; ErrorRecord errorRecord = new ErrorRecord(exception, "CreateRemoteRunspaceFailed", ErrorCategory.InvalidArgument, session); Action <Cmdlet> action = delegate(Cmdlet cmdlet) { cmdlet.WriteError(errorRecord); }; objectWriter.Write(action); } } rsIndex++; } return(list); }
public override void Read(PipelineWriter output) { using (SimpleBinaryStream stream = new SimpleBinaryStream(dataSource)) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { output.Write(ReadPixel(stream)); } } } }
private List <RemoteRunspace> CreateRunspacesWhenComputerNameParameterSpecified() { string[] strArray; List <RemoteRunspace> list = new List <RemoteRunspace>(); base.ResolveComputerNames(this.ComputerName, out strArray); base.ValidateComputerName(strArray); for (int i = 0; i < strArray.Length; i++) { try { int num2; WSManConnectionInfo connectionInfo = null; connectionInfo = new WSManConnectionInfo(); string str = this.UseSSL.IsPresent ? "https" : "http"; connectionInfo.ComputerName = strArray[i]; connectionInfo.Port = this.Port; connectionInfo.AppName = this.ApplicationName; connectionInfo.ShellUri = this.ConfigurationName; connectionInfo.Scheme = str; if (this.CertificateThumbprint != null) { connectionInfo.CertificateThumbprint = this.CertificateThumbprint; } else { connectionInfo.Credential = this.Credential; } connectionInfo.AuthenticationMechanism = this.Authentication; base.UpdateConnectionInfo(connectionInfo); connectionInfo.EnableNetworkAccess = (bool)this.EnableNetworkAccess; string runspaceName = this.GetRunspaceName(i, out num2); RemoteRunspace item = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(), connectionInfo, base.Host, this.SessionOption.ApplicationArguments, runspaceName, num2); list.Add(item); } catch (UriFormatException exception) { PipelineWriter objectWriter = this.stream.ObjectWriter; ErrorRecord errorRecord = new ErrorRecord(exception, "CreateRemoteRunspaceFailed", ErrorCategory.InvalidArgument, strArray[i]); Action <Cmdlet> action = delegate(Cmdlet cmdlet) { cmdlet.WriteError(errorRecord); }; objectWriter.Write(action); } } return(list); }
private void HandleRunspaceStateChanged(object sender, OperationStateEventArgs stateEventArgs) { ErrorRecord errorRecord; PSRemotingTransportException exception2; string str; if (sender == null) { throw PSTraceSource.NewArgumentNullException("sender"); } if (stateEventArgs == null) { throw PSTraceSource.NewArgumentNullException("stateEventArgs"); } RunspaceStateEventArgs baseEvent = stateEventArgs.BaseEvent as RunspaceStateEventArgs; RunspaceState state = baseEvent.RunspaceStateInfo.State; OpenRunspaceOperation operation = sender as OpenRunspaceOperation; RemoteRunspace operatedRunspace = operation.OperatedRunspace; if (operatedRunspace != null) { operatedRunspace.URIRedirectionReported -= new EventHandler <RemoteDataEventArgs <Uri> >(this.HandleURIDirectionReported); } PipelineWriter objectWriter = this.stream.ObjectWriter; Exception reason = baseEvent.RunspaceStateInfo.Reason; switch (state) { case RunspaceState.Opened: { PSSession remoteRunspaceInfo = new PSSession(operatedRunspace); base.RunspaceRepository.Add(remoteRunspaceInfo); Action <Cmdlet> action = cmdlet => cmdlet.WriteObject(remoteRunspaceInfo); if (objectWriter.IsOpen) { objectWriter.Write(action); } return; } case RunspaceState.Closed: { Uri uri = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <Uri>(operatedRunspace.ConnectionInfo, "ConnectionUri", null); string message = base.GetMessage(RemotingErrorIdStrings.RemoteRunspaceClosed, new object[] { (uri != null) ? uri.AbsoluteUri : string.Empty }); Action <Cmdlet> action3 = cmdlet => cmdlet.WriteVerbose(message); if (objectWriter.IsOpen) { objectWriter.Write(action3); } if (reason != null) { ErrorRecord errorRecord2 = new ErrorRecord(reason, "PSSessionStateClosed", ErrorCategory.OpenError, operatedRunspace); Action <Cmdlet> action4 = cmdlet => cmdlet.WriteError(errorRecord2); if (objectWriter.IsOpen) { objectWriter.Write(action4); } } return; } case RunspaceState.Closing: return; case RunspaceState.Broken: exception2 = reason as PSRemotingTransportException; str = null; if (exception2 != null) { OpenRunspaceOperation operation2 = sender as OpenRunspaceOperation; if (operation2 != null) { string computerName = operation2.OperatedRunspace.ConnectionInfo.ComputerName; if (exception2.ErrorCode != -2144108135) { str = "[" + computerName + "] "; if (!string.IsNullOrEmpty(exception2.Message)) { str = str + exception2.Message; } else if (!string.IsNullOrEmpty(exception2.TransportMessage)) { str = str + exception2.TransportMessage; } break; } string str3 = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.URIRedirectionReported, new object[] { exception2.Message, "MaximumConnectionRedirectionCount", "PSSessionOption", "AllowRedirection" }); str = "[" + computerName + "] " + str3; } } break; default: return; } PSRemotingDataStructureException exception3 = reason as PSRemotingDataStructureException; if (exception3 != null) { OpenRunspaceOperation operation3 = sender as OpenRunspaceOperation; if (operation3 != null) { string str4 = operation3.OperatedRunspace.ConnectionInfo.ComputerName; str = "[" + str4 + "] " + exception3.Message; } } if (reason == null) { reason = new RuntimeException(base.GetMessage(RemotingErrorIdStrings.RemoteRunspaceOpenUnknownState, new object[] { state })); } string fQEIDFromTransportError = WSManTransportManagerUtils.GetFQEIDFromTransportError((exception2 != null) ? exception2.ErrorCode : 0, this._defaultFQEID); errorRecord = new ErrorRecord(reason, operatedRunspace, fQEIDFromTransportError, ErrorCategory.OpenError, null, null, null, null, null, str, null); Action <Cmdlet> action2 = cmdlet => cmdlet.WriteError(errorRecord); if (objectWriter.IsOpen) { objectWriter.Write(action2); } this.toDispose.Add(operatedRunspace); }
public override void Read(PipelineWriter output) { int blockWidth = Math.Max((width + 3) / 4, 1); int blockHeight = Math.Max((height + 3) / 4, 1); PixelColor[,] cache0 = new PixelColor[4, blockWidth * 4]; PixelColor[,] cache1 = new PixelColor[4, blockWidth * 4]; bool isPingPong = false; #if !NET40 System.Threading.Tasks.Task task = null; #endif using (SimpleBinaryStream stream = new SimpleBinaryStream(dataSource)) { for (int y = 0; y < blockHeight; y++) { if (isPingPong) { for (int x = 0; x < blockWidth; x++) ReadBlock(stream, ref cache1, x); } else { for (int x = 0; x < blockWidth; x++) ReadBlock(stream, ref cache0, x); } #if !NET40 if (task != null) task.Wait(); #endif bool pingPoing = isPingPong; int baseY = y; #if !NET40 task = System.Threading.Tasks.Task.Run((() => { #endif for (int y2 = 0; y2 < 4; y2++) { int currentY = baseY * 4 + y2; if (currentY < height) { if (pingPoing) { for (int x = 0; x < width; x++) output.Write(cache1[y2, x]); } else { for (int x = 0; x < width; x++) output.Write(cache0[y2, x]); } } } #if !NET40 })); #endif isPingPong = !isPingPong; } #if !NET40 task.Wait(); #endif } }