private OutOfProcessMediator() { Console.SetIn(TextReader.Null); this.originalStdOut = new OutOfProcessTextWriter(Console.Out); Console.SetOut(TextWriter.Null); this.originalStdErr = new OutOfProcessTextWriter(Console.Error); Console.SetError(TextWriter.Null); this.callbacks = new OutOfProcessUtils.DataProcessingDelegates(); this.callbacks.DataPacketReceived = (OutOfProcessUtils.DataPacketReceived) Delegate.Combine(this.callbacks.DataPacketReceived, new OutOfProcessUtils.DataPacketReceived(this.OnDataPacketReceived)); this.callbacks.DataAckPacketReceived = (OutOfProcessUtils.DataAckPacketReceived) Delegate.Combine(this.callbacks.DataAckPacketReceived, new OutOfProcessUtils.DataAckPacketReceived(this.OnDataAckPacketReceived)); this.callbacks.CommandCreationPacketReceived = (OutOfProcessUtils.CommandCreationPacketReceived) Delegate.Combine(this.callbacks.CommandCreationPacketReceived, new OutOfProcessUtils.CommandCreationPacketReceived(this.OnCommandCreationPacketReceived)); this.callbacks.CommandCreationAckReceived = (OutOfProcessUtils.CommandCreationAckReceived) Delegate.Combine(this.callbacks.CommandCreationAckReceived, new OutOfProcessUtils.CommandCreationAckReceived(this.OnCommandCreationAckReceived)); this.callbacks.ClosePacketReceived = (OutOfProcessUtils.ClosePacketReceived) Delegate.Combine(this.callbacks.ClosePacketReceived, new OutOfProcessUtils.ClosePacketReceived(this.OnClosePacketReceived)); this.callbacks.CloseAckPacketReceived = (OutOfProcessUtils.CloseAckPacketReceived) Delegate.Combine(this.callbacks.CloseAckPacketReceived, new OutOfProcessUtils.CloseAckPacketReceived(this.OnCloseAckPacketReceived)); this.callbacks.SignalPacketReceived = (OutOfProcessUtils.SignalPacketReceived) Delegate.Combine(this.callbacks.SignalPacketReceived, new OutOfProcessUtils.SignalPacketReceived(this.OnSignalPacketReceived)); this.callbacks.SignalAckPacketReceived = (OutOfProcessUtils.SignalAckPacketReceived) Delegate.Combine(this.callbacks.SignalAckPacketReceived, new OutOfProcessUtils.SignalAckPacketReceived(this.OnSignalAckPacketReceived)); this.allcmdsClosedEvent = new ManualResetEvent(true); }
internal OutOfProcessClientSessionTransportManager(Guid runspaceId, NewProcessConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper) : base(runspaceId, cryptoHelper) { this._processCreated = true; this.onDataAvailableToSendCallback = new System.Management.Automation.Remoting.PrioritySendDataCollection.OnDataAvailableCallback(this.OnDataAvailableCallback); this.cmdTransportManagers = new Dictionary<Guid, OutOfProcessClientCommandTransportManager>(); this.connectionInfo = connectionInfo; this.dataProcessingCallbacks = new OutOfProcessUtils.DataProcessingDelegates(); this.dataProcessingCallbacks.DataPacketReceived = (OutOfProcessUtils.DataPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.DataPacketReceived, new OutOfProcessUtils.DataPacketReceived(this.OnDataPacketReceived)); this.dataProcessingCallbacks.DataAckPacketReceived = (OutOfProcessUtils.DataAckPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.DataAckPacketReceived, new OutOfProcessUtils.DataAckPacketReceived(this.OnDataAckPacketReceived)); this.dataProcessingCallbacks.CommandCreationPacketReceived = (OutOfProcessUtils.CommandCreationPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.CommandCreationPacketReceived, new OutOfProcessUtils.CommandCreationPacketReceived(this.OnCommandCreationPacketReceived)); this.dataProcessingCallbacks.CommandCreationAckReceived = (OutOfProcessUtils.CommandCreationAckReceived) Delegate.Combine(this.dataProcessingCallbacks.CommandCreationAckReceived, new OutOfProcessUtils.CommandCreationAckReceived(this.OnCommandCreationAckReceived)); this.dataProcessingCallbacks.SignalPacketReceived = (OutOfProcessUtils.SignalPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.SignalPacketReceived, new OutOfProcessUtils.SignalPacketReceived(this.OnSignalPacketReceived)); this.dataProcessingCallbacks.SignalAckPacketReceived = (OutOfProcessUtils.SignalAckPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.SignalAckPacketReceived, new OutOfProcessUtils.SignalAckPacketReceived(this.OnSiganlAckPacketReceived)); this.dataProcessingCallbacks.ClosePacketReceived = (OutOfProcessUtils.ClosePacketReceived) Delegate.Combine(this.dataProcessingCallbacks.ClosePacketReceived, new OutOfProcessUtils.ClosePacketReceived(this.OnClosePacketReceived)); this.dataProcessingCallbacks.CloseAckPacketReceived = (OutOfProcessUtils.CloseAckPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.CloseAckPacketReceived, new OutOfProcessUtils.CloseAckPacketReceived(this.OnCloseAckReceived)); base.dataToBeSent.Fragmentor = base.Fragmentor; base.ReceivedDataCollection.MaximumReceivedDataSize = null; base.ReceivedDataCollection.MaximumReceivedObjectSize = 0xa00000; this.closeTimeOutTimer = new Timer(60000.0); this.closeTimeOutTimer.Elapsed += new ElapsedEventHandler(this.OnCloseTimeOutTimerElapsed); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
private static void ProcessElement( XmlReader xmlReader, OutOfProcessUtils.DataProcessingDelegates callbacks) { switch (xmlReader.LocalName) { case "Data": string stream = xmlReader.AttributeCount == 2 ? xmlReader.GetAttribute("Stream") : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForDataElement, new object[3] { (object)"Stream", (object)"PSGuid", (object)"Data" }); Guid psGuid1 = new Guid(xmlReader.GetAttribute("PSGuid")); if (!xmlReader.Read()) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCInsufficientDataforElement, new object[1] { (object)"Data" }); } byte[] rawData = xmlReader.NodeType == XmlNodeType.Text ? Convert.FromBase64String(xmlReader.Value) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCOnlyTextExpectedInDataElement, new object[3] { (object)xmlReader.NodeType, (object)"Data", (object)XmlNodeType.Text }); callbacks.DataPacketReceived(rawData, stream, psGuid1); break; case "DataAck": Guid psGuid2 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"DataAck" }); callbacks.DataAckPacketReceived(psGuid2); break; case "Command": Guid psGuid3 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"Command" }); callbacks.CommandCreationPacketReceived(psGuid3); break; case "CommandAck": Guid psGuid4 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"CommandAck" }); callbacks.CommandCreationAckReceived(psGuid4); break; case "Close": Guid psGuid5 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"Close" }); callbacks.ClosePacketReceived(psGuid5); break; case "CloseAck": Guid psGuid6 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"CloseAck" }); callbacks.CloseAckPacketReceived(psGuid6); break; case "Signal": Guid psGuid7 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"Signal" }); callbacks.SignalPacketReceived(psGuid7); break; case "SignalAck": Guid psGuid8 = xmlReader.AttributeCount == 1 ? new Guid(xmlReader.GetAttribute("PSGuid")) : throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, new object[2] { (object)"PSGuid", (object)"SignalAck" }); callbacks.SignalAckPacketReceived(psGuid8); break; default: throw new PSRemotingTransportException(PSRemotingErrorId.IPCUnknownElementReceived, new object[1] { (object)xmlReader.LocalName }); } }