Пример #1
0
 internal void EnqueueAndStartProcessingThread(RemoteDataObject<PSObject> remoteObject, TransportErrorOccuredEventArgs transportErrorArgs, object privateData)
 {
     if (!this.isClosed)
     {
         lock (this.callbackNotificationQueue)
         {
             if (((remoteObject != null) || (transportErrorArgs != null)) || (privateData != null))
             {
                 CallbackNotificationInformation item = new CallbackNotificationInformation {
                     remoteObject = remoteObject,
                     transportError = transportErrorArgs,
                     privateData = privateData
                 };
                 if ((remoteObject != null) && (((remoteObject.DataType == RemotingDataType.PublicKey) || (remoteObject.DataType == RemotingDataType.EncryptedSessionKey)) || (remoteObject.DataType == RemotingDataType.PublicKeyRequest)))
                 {
                     base.CryptoHelper.Session.BaseSessionDataStructureHandler.RaiseKeyExchangeMessageReceived(remoteObject);
                 }
                 else
                 {
                     this.callbackNotificationQueue.Enqueue(item);
                 }
             }
             if ((!this.isServicingCallbacks && !this.suspendQueueServicing) && (this.callbackNotificationQueue.Count > 0))
             {
                 this.isServicingCallbacks = true;
                 ThreadPool.QueueUserWorkItem(new WaitCallback(this.ServicePendingCallbacks));
             }
         }
     }
 }
        internal void ProcessReceivedData(RemoteDataObject<PSObject> receivedData)
        {
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }
            switch (receivedData.DataType)
            {
                case RemotingDataType.PowerShellInput:
                    this.InputReceived.SafeInvoke<RemoteDataEventArgs<object>>(this, new RemoteDataEventArgs<object>(receivedData.Data));
                    return;

                case RemotingDataType.PowerShellInputEnd:
                    this.InputEndReceived.SafeInvoke(this, EventArgs.Empty);
                    return;

                case RemotingDataType.StopPowerShell:
                    this.StopPowerShellReceived.SafeInvoke(this, EventArgs.Empty);
                    return;

                case RemotingDataType.RemotePowerShellHostResponseData:
                {
                    RemoteHostResponse data = RemoteHostResponse.Decode(receivedData.Data);
                    this.transportManager.ReportExecutionStatusAsRunning();
                    this.HostResponseReceived.SafeInvoke<RemoteDataEventArgs<RemoteHostResponse>>(this, new RemoteDataEventArgs<RemoteHostResponse>(data));
                    return;
                }
            }
        }
Пример #3
0
 internal RemoteDataEventArgs(RemoteDataObject <PSObject> receivedData)
 {
     if (receivedData == null)
     {
         throw PSTraceSource.NewArgumentNullException("receivedData");
     }
     this._rcvdData = receivedData;
 }
 internal void DispatchMessageToPowerShell(RemoteDataObject<PSObject> rcvdData)
 {
     ServerPowerShellDataStructureHandler associatedPowerShellDataStructureHandler = this.GetAssociatedPowerShellDataStructureHandler(rcvdData.PowerShellId);
     if (associatedPowerShellDataStructureHandler != null)
     {
         associatedPowerShellDataStructureHandler.ProcessReceivedData(rcvdData);
     }
 }
Пример #5
0
        internal static RemoteDataObject GenerateSetMinRunspaces(Guid clientRunspacePoolId, int minRunspaces, long callId)
        {
            PSObject data = CreateEmptyPSObject();

            data.Properties.Add(new PSNoteProperty("MinRunspaces", minRunspaces));
            data.Properties.Add(new PSNoteProperty("ci", callId));
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Server, RemotingDataType.SetMinRunspaces, clientRunspacePoolId, Guid.Empty, data));
        }
Пример #6
0
        internal static RemoteDataObject GenerateRunspacePoolOperationResponse(Guid clientRunspacePoolId, object response, long callId)
        {
            PSObject data = CreateEmptyPSObject();

            data.Properties.Add(new PSNoteProperty("SetMinMaxRunspacesResponse", response));
            data.Properties.Add(new PSNoteProperty("ci", callId));
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Client, RemotingDataType.RunspacePoolOperationResponse, clientRunspacePoolId, Guid.Empty, data));
        }
Пример #7
0
 internal static RemoteDataObject GeneratePowerShellOutput(
     PSObject data,
     Guid clientPowerShellId,
     Guid clientRunspacePoolId)
 {
     using (RemotingEncoder._trace.TraceMethod())
         return(RemoteDataObject.CreateFrom(RemotingDestination.Client, RemotingDataType.PowerShellOutput, clientRunspacePoolId, clientPowerShellId, (object)data));
 }
Пример #8
0
        internal static RemoteDataObject GenerateRunspacePoolInitData(Guid runspacePoolId, int minRunspaces, int maxRunspaces)
        {
            PSObject data = CreateEmptyPSObject();

            data.Properties.Add(new PSNoteProperty("MinRunspaces", minRunspaces));
            data.Properties.Add(new PSNoteProperty("MaxRunspaces", maxRunspaces));
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Client, RemotingDataType.RunspacePoolInitData, runspacePoolId, Guid.Empty, data));
        }
Пример #9
0
 internal override void SendDataToClient <T> (RemoteDataObject <T> data, bool flush, bool reportPending)
 {
     base.SendDataToClient(data, flush, reportPending);
     if (data.DataType == RemotingDataType.RemoteHostCallUsingPowerShellHost)
     {
         _writer.CompleteFeedback();
     }
 }
Пример #10
0
 internal static RemoteDataObject GeneratePowerShellInformational(ProgressRecord progressRecord, Guid clientRunspacePoolId, Guid clientPowerShellId)
 {
     if (progressRecord == null)
     {
         throw PSTraceSource.NewArgumentNullException("progressRecord");
     }
     return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Client, RemotingDataType.PowerShellProgress, clientRunspacePoolId, clientPowerShellId, progressRecord.ToPSObjectForRemoting()));
 }
Пример #11
0
 internal RemoteDataEventArgs(RemoteDataObject<PSObject> receivedData)
 {
     if (receivedData == null)
     {
         throw PSTraceSource.NewArgumentNullException("receivedData");
     }
     this._rcvdData = receivedData;
 }
Пример #12
0
 internal static RemoteDataObject GeneratePowerShellInformational(
     object data,
     Guid clientRunspacePoolId,
     Guid clientPowerShellId,
     RemotingDataType dataType)
 {
     using (RemotingEncoder._trace.TraceMethod())
         return(RemoteDataObject.CreateFrom(RemotingDestination.Client, dataType, clientRunspacePoolId, clientPowerShellId, (object)PSObject.AsPSObject(data)));
 }
Пример #13
0
        internal static RemoteDataObject GenerateClientSessionCapability(
            RemoteSessionCapability capability,
            Guid runspacePoolId)
        {
            PSObject sessionCapability = RemotingEncoder.GenerateSessionCapability(capability);

            sessionCapability.Properties.Add((PSPropertyInfo) new PSNoteProperty("TimeZone", (object)RemoteSessionCapability.GetCurrentTimeZoneInByteFormat()));
            return(RemoteDataObject.CreateFrom(capability.RemotingDestination, RemotingDataType.SessionCapability, runspacePoolId, Guid.Empty, (object)sessionCapability));
        }
        internal void DispatchMessageToPowerShell(RemoteDataObject <PSObject> rcvdData)
        {
            ClientPowerShellDataStructureHandler associatedPowerShellDataStructureHandler = this.GetAssociatedPowerShellDataStructureHandler(rcvdData.PowerShellId);

            if (associatedPowerShellDataStructureHandler != null)
            {
                associatedPowerShellDataStructureHandler.ProcessReceivedData(rcvdData);
            }
        }
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            if (receivedData.RunspacePoolId != this.clientRunspacePoolId)
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceIdsDoNotMatch, new object[] { receivedData.RunspacePoolId, this.clientRunspacePoolId });
            }
            switch (receivedData.DataType)
            {
            case RemotingDataType.RunspacePoolOperationResponse:
                this.SetMaxMinRunspacesResponseRecieved.SafeInvoke <RemoteDataEventArgs <PSObject> >(this, new RemoteDataEventArgs <PSObject>(receivedData.Data));
                return;

            case RemotingDataType.RunspacePoolStateInfo:
            {
                RunspacePoolStateInfo runspacePoolStateInfo = RemotingDecoder.GetRunspacePoolStateInfo(receivedData.Data);
                this.StateInfoReceived.SafeInvoke <RemoteDataEventArgs <RunspacePoolStateInfo> >(this, new RemoteDataEventArgs <RunspacePoolStateInfo>(runspacePoolStateInfo));
                this.NotifyAssociatedPowerShells(runspacePoolStateInfo);
                return;
            }

            case RemotingDataType.CreatePowerShell:
            case RemotingDataType.AvailableRunspaces:
            case RemotingDataType.GetCommandMetadata:
                break;

            case RemotingDataType.PSEventArgs:
            {
                PSEventArgs pSEventArgs = RemotingDecoder.GetPSEventArgs(receivedData.Data);
                this.PSEventArgsReceived.SafeInvoke <RemoteDataEventArgs <PSEventArgs> >(this, new RemoteDataEventArgs <PSEventArgs>(pSEventArgs));
                break;
            }

            case RemotingDataType.ApplicationPrivateData:
            {
                PSPrimitiveDictionary applicationPrivateData = RemotingDecoder.GetApplicationPrivateData(receivedData.Data);
                this.ApplicationPrivateDataReceived.SafeInvoke <RemoteDataEventArgs <PSPrimitiveDictionary> >(this, new RemoteDataEventArgs <PSPrimitiveDictionary>(applicationPrivateData));
                return;
            }

            case RemotingDataType.RunspacePoolInitData:
            {
                RunspacePoolInitInfo runspacePoolInitInfo = RemotingDecoder.GetRunspacePoolInitInfo(receivedData.Data);
                this.RSPoolInitInfoReceived.SafeInvoke <RemoteDataEventArgs <RunspacePoolInitInfo> >(this, new RemoteDataEventArgs <RunspacePoolInitInfo>(runspacePoolInitInfo));
                return;
            }

            case RemotingDataType.RemoteHostCallUsingRunspaceHost:
            {
                RemoteHostCall data = RemoteHostCall.Decode(receivedData.Data);
                this.RemoteHostCallReceived.SafeInvoke <RemoteDataEventArgs <RemoteHostCall> >(this, new RemoteDataEventArgs <RemoteHostCall>(data));
                return;
            }

            default:
                return;
            }
        }
Пример #16
0
        internal static RemoteDataObject GenerateGetAvailableRunspaces(
            Guid clientRunspacePoolId,
            long callId)
        {
            PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();

            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ci", (object)callId));
            return(RemoteDataObject.CreateFrom(RemotingDestination.Server, RemotingDataType.AvailableRunspaces, clientRunspacePoolId, Guid.Empty, (object)emptyPsObject));
        }
Пример #17
0
        internal static RemoteDataObject GenerateEncryptedSessionKeyResponse(
            Guid runspacePoolId,
            string encryptedSessionKey)
        {
            PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();

            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("EncryptedSessionKey", (object)encryptedSessionKey));
            return(RemoteDataObject.CreateFrom(RemotingDestination.Client, RemotingDataType.EncryptedSessionKey, runspacePoolId, Guid.Empty, (object)emptyPsObject));
        }
Пример #18
0
        /// <summary>
        /// Process the data received from the powershell on
        /// the client.
        /// </summary>
        /// <param name="receivedData">Data received.</param>
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }

            Dbg.Assert(receivedData.TargetInterface == RemotingTargetInterface.PowerShell,
                       "RemotingTargetInterface must be PowerShell");

            switch (receivedData.DataType)
            {
            case RemotingDataType.StopPowerShell:
            {
                Dbg.Assert(StopPowerShellReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");
                StopPowerShellReceived.SafeInvoke(this, EventArgs.Empty);
            }

            break;

            case RemotingDataType.PowerShellInput:
            {
                Dbg.Assert(InputReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");
                InputReceived.SafeInvoke(this, new RemoteDataEventArgs <object>(receivedData.Data));
            }

            break;

            case RemotingDataType.PowerShellInputEnd:
            {
                Dbg.Assert(InputEndReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");
                InputEndReceived.SafeInvoke(this, EventArgs.Empty);
            }

            break;

            case RemotingDataType.RemotePowerShellHostResponseData:
            {
                Dbg.Assert(HostResponseReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");

                RemoteHostResponse remoteHostResponse = RemoteHostResponse.Decode(receivedData.Data);

                // part of host message robustness algo. Now the host response is back, report to transport that
                // execution status is back to running
                _transportManager.ReportExecutionStatusAsRunning();

                HostResponseReceived.SafeInvoke(this, new RemoteDataEventArgs <RemoteHostResponse>(remoteHostResponse));
            }

            break;
            }
        }
Пример #19
0
        internal static RemoteDataObject GenerateMyPublicKey(
            Guid runspacePoolId,
            string publicKey,
            RemotingDestination destination)
        {
            PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();

            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("PublicKey", (object)publicKey));
            return(RemoteDataObject.CreateFrom(destination, RemotingDataType.PublicKey, runspacePoolId, Guid.Empty, (object)emptyPsObject));
        }
Пример #20
0
 internal static RemoteDataObject GenerateApplicationPrivateData(
     Guid clientRunspacePoolId,
     PSPrimitiveDictionary applicationPrivateData)
 {
     using (RemotingEncoder._trace.TraceMethod())
     {
         PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();
         emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ApplicationPrivateData", (object)applicationPrivateData));
         return(RemoteDataObject.CreateFrom(RemotingDestination.Client, RemotingDataType.ApplicationPrivateData, clientRunspacePoolId, Guid.Empty, (object)emptyPsObject));
     }
 }
Пример #21
0
        internal RemoteDataEventArgs(RemoteDataObject <PSObject> receivedData)
        {
            Dbg.Assert(receivedData != null, "caller should validate the parameter");

            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }

            ReceivedData = receivedData;
        }
Пример #22
0
        internal RemoteDataEventArgs(RemoteDataObject<PSObject> receivedData)
        {
            Dbg.Assert(receivedData != null, "caller should validate the parameter");

            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }

            ReceivedData = receivedData;
        }
Пример #23
0
        /// <summary>
        /// Dispatch the message to the associated powershell data structure handler.
        /// </summary>
        /// <param name="rcvdData">Message to dispatch.</param>
        internal void DispatchMessageToPowerShell(RemoteDataObject <PSObject> rcvdData)
        {
            ServerPowerShellDataStructureHandler dsHandler =
                GetAssociatedPowerShellDataStructureHandler(rcvdData.PowerShellId);

            // if data structure handler is not found, then association has already been
            // removed, discard message
            if (dsHandler != null)
            {
                dsHandler.ProcessReceivedData(rcvdData);
            }
        }
Пример #24
0
        internal static RemoteDataObject GenerateCreateRunspacePool(Guid clientRunspacePoolId, int minRunspaces, int maxRunspaces, RemoteRunspacePoolInternal runspacePool, PSHost host, PSPrimitiveDictionary applicationArguments)
        {
            PSObject data = CreateEmptyPSObject();

            data.Properties.Add(new PSNoteProperty("MinRunspaces", minRunspaces));
            data.Properties.Add(new PSNoteProperty("MaxRunspaces", maxRunspaces));
            data.Properties.Add(new PSNoteProperty("PSThreadOptions", runspacePool.ThreadOptions));
            data.Properties.Add(new PSNoteProperty("ApartmentState", runspacePool.ApartmentState));
            data.Properties.Add(new PSNoteProperty("ApplicationArguments", applicationArguments));
            data.Properties.Add(CreateHostInfoProperty(new HostInfo(host)));
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Server, RemotingDataType.CreateRunspacePool, clientRunspacePoolId, Guid.Empty, data));
        }
        internal void SendApplicationPrivateDataToClient(PSPrimitiveDictionary applicationPrivateData, RemoteSessionCapability serverCapability)
        {
            PSPrimitiveDictionary dictionary  = PSPrimitiveDictionary.CloneAndAddPSVersionTable(applicationPrivateData);
            PSPrimitiveDictionary dictionary2 = (PSPrimitiveDictionary)dictionary["PSVersionTable"];

            dictionary2["PSRemotingProtocolVersion"] = serverCapability.ProtocolVersion;
            dictionary2["SerializationVersion"]      = serverCapability.SerializationVersion;
            dictionary2["PSVersion"] = serverCapability.PSVersion;
            RemoteDataObject data = RemotingEncoder.GenerateApplicationPrivateData(this.clientRunspacePoolId, dictionary);

            this.SendDataAsync(data);
        }
Пример #26
0
 internal static RemoteDataObject GenerateRunspacePoolOperationResponse(
     Guid clientRunspacePoolId,
     object response,
     long callId)
 {
     using (RemotingEncoder._trace.TraceMethod())
     {
         PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();
         emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("SetMinMaxRunspacesResponse", response));
         emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ci", (object)callId));
         return(RemoteDataObject.CreateFrom(RemotingDestination.Client, RemotingDataType.RunspacePoolOperationResponse, clientRunspacePoolId, Guid.Empty, (object)emptyPsObject));
     }
 }
Пример #27
0
 internal static RemoteDataObject GenerateSetMinRunspaces(
     Guid clientRunspacePoolId,
     int minRunspaces,
     long callId)
 {
     using (RemotingEncoder._trace.TraceMethod())
     {
         PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();
         emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("MinRunspaces", (object)minRunspaces));
         emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ci", (object)callId));
         return(RemoteDataObject.CreateFrom(RemotingDestination.Server, RemotingDataType.SetMinRunspaces, clientRunspacePoolId, Guid.Empty, (object)emptyPsObject));
     }
 }
Пример #28
0
 internal static RemoteDataObject GeneratePowerShellInformational(
     ProgressRecord progressRecord,
     Guid clientRunspacePoolId,
     Guid clientPowerShellId)
 {
     using (RemotingEncoder._trace.TraceMethod())
     {
         if (progressRecord == null)
         {
             throw RemotingEncoder._trace.NewArgumentNullException(nameof(progressRecord));
         }
         return(RemoteDataObject.CreateFrom(RemotingDestination.Client, RemotingDataType.PowerShellProgress, clientRunspacePoolId, clientPowerShellId, (object)progressRecord.ToPSObjectForRemoting()));
     }
 }
 internal virtual void SendDataToClient <T>(RemoteDataObject <T> data, bool flush, bool reportPending = false)
 {
     lock (this.syncObject)
     {
         RemoteDataObject obj2 = RemoteDataObject.CreateFrom(data.Destination, data.DataType, data.RunspacePoolId, data.PowerShellId, data.Data);
         if (this.isSerializing)
         {
             if (this.dataToBeSentQueue == null)
             {
                 this.dataToBeSentQueue = new Queue <Tuple <RemoteDataObject, bool, bool> >();
             }
             this.dataToBeSentQueue.Enqueue(new Tuple <RemoteDataObject, bool, bool>(obj2, flush, reportPending));
         }
         else
         {
             this.isSerializing = true;
             try
             {
                 do
                 {
                     using (SerializedDataStream stream = new SerializedDataStream(base.Fragmentor.FragmentSize, this.onDataAvailable))
                     {
                         this.shouldFlushData       = flush;
                         this.reportAsPending       = reportPending;
                         this.runpacePoolInstanceId = obj2.RunspacePoolId;
                         this.powerShellInstanceId  = obj2.PowerShellId;
                         this.dataType        = obj2.DataType;
                         this.targetInterface = obj2.TargetInterface;
                         base.Fragmentor.Fragment <object>(obj2, stream);
                     }
                     if ((this.dataToBeSentQueue != null) && (this.dataToBeSentQueue.Count > 0))
                     {
                         Tuple <RemoteDataObject, bool, bool> tuple = this.dataToBeSentQueue.Dequeue();
                         obj2          = tuple.Item1;
                         flush         = tuple.Item2;
                         reportPending = tuple.Item3;
                     }
                     else
                     {
                         obj2 = null;
                     }
                 }while (obj2 != null);
             }
             finally
             {
                 this.isSerializing = false;
             }
         }
     }
 }
Пример #30
0
        internal static RemoteDataObject GeneratePSEventArgs(Guid clientRunspacePoolId, PSEventArgs e)
        {
            PSObject data = CreateEmptyPSObject();

            data.Properties.Add(new PSNoteProperty("PSEventArgs.EventIdentifier", e.EventIdentifier));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.SourceIdentifier", e.SourceIdentifier));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.TimeGenerated", e.TimeGenerated));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.Sender", e.Sender));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.SourceArgs", e.SourceArgs));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.MessageData", e.MessageData));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.ComputerName", e.ComputerName));
            data.Properties.Add(new PSNoteProperty("PSEventArgs.RunspaceId", e.RunspaceId));
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Client, RemotingDataType.PSEventArgs, clientRunspacePoolId, Guid.Empty, data));
        }
Пример #31
0
        internal static RemoteDataObject GenerateRunspacePoolStateInfo(Guid clientRunspacePoolId, RunspacePoolStateInfo stateInfo)
        {
            PSObject       data   = CreateEmptyPSObject();
            PSNoteProperty member = new PSNoteProperty("RunspaceState", (int)stateInfo.State);

            data.Properties.Add(member);
            if (stateInfo.Reason != null)
            {
                string         errorId   = "RemoteRunspaceStateInfoReason";
                PSNoteProperty property2 = GetExceptionProperty(stateInfo.Reason, errorId, ErrorCategory.NotSpecified);
                data.Properties.Add(property2);
            }
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Client, RemotingDataType.RunspacePoolStateInfo, clientRunspacePoolId, Guid.Empty, data));
        }
Пример #32
0
 internal void SendDataToClient <T>(RemoteDataObject <T> data, bool flush)
 {
     using (SerializedDataStream dataToBeSent = new SerializedDataStream(this.Fragmentor.FragmentSize, this.onDataAvailable))
     {
         lock (this.syncObject)
         {
             this.shouldFlushData       = flush;
             this.runpacePoolInstanceId = data.RunspacePoolId;
             this.powerShellInstanceId  = data.PowerShellId;
             this.dataType        = data.DataType;
             this.targetInterface = data.TargetInterface;
             this.Fragmentor.Fragment <T>(data, dataToBeSent);
         }
     }
 }
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            using (ClientPowerShellDataStructureHandler.tracer.TraceMethod())
            {
                if (receivedData.PowerShellId != this.clientPowerShellId)
                {
                    throw new PSRemotingDataStructureException(PSRemotingErrorId.PipelineIdsDoNotMatch, new object[2]
                    {
                        (object)receivedData.PowerShellId,
                        (object)this.clientPowerShellId
                    });
                }
                switch (receivedData.DataType)
                {
                case RemotingDataType.PowerShellOutput:
                    this.OutputReceived((object)this, new RemoteDataEventArgs <object>(RemotingDecoder.GetPowerShellOutput((object)receivedData.Data)));
                    break;

                case RemotingDataType.PowerShellErrorRecord:
                    this.ErrorReceived((object)this, new RemoteDataEventArgs <ErrorRecord>((object)RemotingDecoder.GetPowerShellError((object)receivedData.Data)));
                    break;

                case RemotingDataType.PowerShellStateInfo:
                    this.InvocationStateInfoReceived((object)this, new RemoteDataEventArgs <PSInvocationStateInfo>((object)RemotingDecoder.GetPowerShellStateInfo((object)receivedData.Data)));
                    break;

                case RemotingDataType.PowerShellDebug:
                    this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellDebug((object)receivedData.Data), RemotingDataType.PowerShellDebug)));
                    break;

                case RemotingDataType.PowerShellVerbose:
                    this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellVerbose((object)receivedData.Data), RemotingDataType.PowerShellVerbose)));
                    break;

                case RemotingDataType.PowerShellWarning:
                    this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellWarning((object)receivedData.Data), RemotingDataType.PowerShellWarning)));
                    break;

                case RemotingDataType.PowerShellProgress:
                    this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellProgress((object)receivedData.Data), RemotingDataType.PowerShellProgress)));
                    break;

                case RemotingDataType.RemoteHostCallUsingPowerShellHost:
                    this.HostCallReceived((object)this, new RemoteDataEventArgs <RemoteHostCall>((object)RemoteHostCall.Decode(receivedData.Data)));
                    break;
                }
            }
        }
 private void HandleCreateAndInvokePowerShell(
     object sender,
     RemoteDataEventArgs <RemoteDataObject <PSObject> > eventArgs)
 {
     using (ServerRunspacePoolDriver.tracer.TraceEventHandlers())
     {
         RemoteDataObject <PSObject> data        = eventArgs.Data;
         HostInfo            hostInfo            = RemotingDecoder.GetHostInfo(data.Data);
         ApartmentState      apartmentState      = RemotingDecoder.GetApartmentState((object)data.Data);
         RemoteStreamOptions remoteStreamOptions = RemotingDecoder.GetRemoteStreamOptions((object)data.Data);
         PowerShell          powerShell          = RemotingDecoder.GetPowerShell((object)data.Data);
         bool noInput      = RemotingDecoder.GetNoInput((object)data.Data);
         bool addToHistory = RemotingDecoder.GetAddToHistory((object)data.Data);
         new ServerPowerShellDriver(powerShell, (PowerShell)null, noInput, data.PowerShellId, data.RunspacePoolId, this, apartmentState, hostInfo, remoteStreamOptions, addToHistory, (Runspace)null).Start();
     }
 }
Пример #35
0
        internal static RemoteDataObject GenerateGetCommandMetadata(
            ClientRemotePowerShell shell)
        {
            Command command1 = (Command)null;

            foreach (Command command2 in (Collection <Command>)shell.PowerShell.Commands.Commands)
            {
                if (command2.CommandText.Equals("Get-Command", StringComparison.OrdinalIgnoreCase))
                {
                    command1 = command2;
                    break;
                }
            }
            string[]     strArray1    = (string[])null;
            CommandTypes commandTypes = CommandTypes.Alias | CommandTypes.Function | CommandTypes.Filter | CommandTypes.Cmdlet;

            string[] strArray2 = (string[])null;
            object[] objArray  = (object[])null;
            foreach (CommandParameter parameter in (Collection <CommandParameter>)command1.Parameters)
            {
                if (parameter.Name.Equals("Name", StringComparison.OrdinalIgnoreCase))
                {
                    strArray1 = (string[])LanguagePrimitives.ConvertTo(parameter.Value, typeof(string[]), (IFormatProvider)CultureInfo.InvariantCulture);
                }
                else if (parameter.Name.Equals("CommandType", StringComparison.OrdinalIgnoreCase))
                {
                    commandTypes = (CommandTypes)LanguagePrimitives.ConvertTo(parameter.Value, typeof(CommandTypes), (IFormatProvider)CultureInfo.InvariantCulture);
                }
                else if (parameter.Name.Equals("Module", StringComparison.OrdinalIgnoreCase))
                {
                    strArray2 = (string[])LanguagePrimitives.ConvertTo(parameter.Value, typeof(string[]), (IFormatProvider)CultureInfo.InvariantCulture);
                }
                else if (parameter.Name.Equals("ArgumentList", StringComparison.OrdinalIgnoreCase))
                {
                    objArray = (object[])LanguagePrimitives.ConvertTo(parameter.Value, typeof(object[]), (IFormatProvider)CultureInfo.InvariantCulture);
                }
            }
            Guid     instanceId    = (shell.PowerShell.GetRunspaceConnection() as RunspacePool).InstanceId;
            PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();

            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("Name", (object)strArray1));
            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("CommandType", (object)commandTypes));
            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("Namespace", (object)strArray2));
            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ArgumentList", (object)objArray));
            return(RemoteDataObject.CreateFrom(RemotingDestination.Server, RemotingDataType.GetCommandMetadata, instanceId, shell.InstanceId, (object)emptyPsObject));
        }
Пример #36
0
        internal void OnDataAvailableCallback (RemoteDataObject<PSObject> remoteObject)
		{
			PSEtwLog.LogAnalyticInformational (PSEventId.TransportReceivedObject, PSOpcode.Open, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] {
				remoteObject.RunspacePoolId.ToString (),
				remoteObject.PowerShellId.ToString (),
				(int)remoteObject.Destination,
				(int)remoteObject.DataType,
				(int)remoteObject.TargetInterface
			});
			this.PowerShellGuidObserver.SafeInvoke (remoteObject.PowerShellId, EventArgs.Empty);
			RemoteDataEventArgs eventArgs = new RemoteDataEventArgs (remoteObject);
			if (remoteObject.DataType == RemotingDataType.RunspacePoolStateInfo) {
				System.Diagnostics.Debug.WriteLine ("RunspacePool State Opened Received");
				Thread.Sleep (800); //HACK: Delay reception in local mode... TODO: Find why!!! cannot have a Wait somewhere
				_slowed = true;
			}
            this.DataReceived.SafeInvoke<RemoteDataEventArgs>(this, eventArgs);
        }
Пример #37
0
        /// <summary>
        /// Process the data received from the runspace pool on 
        /// the server
        /// </summary>
        /// <param name="receivedData">data received</param>
        internal void ProcessReceivedData(RemoteDataObject<PSObject> receivedData)
        {
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }

            Dbg.Assert(receivedData.TargetInterface == RemotingTargetInterface.RunspacePool,
                "RemotingTargetInterface must be Runspace");

            switch (receivedData.DataType)
            {
                case RemotingDataType.CreatePowerShell:
                    {
                        Dbg.Assert(CreateAndInvokePowerShell != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events");

                        CreateAndInvokePowerShell.SafeInvoke(this, new RemoteDataEventArgs<RemoteDataObject<PSObject>>(receivedData));
                    }
                    break;

                case RemotingDataType.GetCommandMetadata:
                    {
                        Dbg.Assert(GetCommandMetadata != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events");

                        GetCommandMetadata.SafeInvoke(this, new RemoteDataEventArgs<RemoteDataObject<PSObject>>(receivedData));
                    }
                    break;

                case RemotingDataType.RemoteRunspaceHostResponseData:
                    {
                        Dbg.Assert(HostResponseReceived != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events");

                        RemoteHostResponse remoteHostResponse = RemoteHostResponse.Decode(receivedData.Data);

                        //part of host message robustness algo. Now the host response is back, report to transport that
                        // execution status is back to running
                        _transportManager.ReportExecutionStatusAsRunning();

                        HostResponseReceived.SafeInvoke(this, new RemoteDataEventArgs<RemoteHostResponse>(remoteHostResponse));
                    }
                    break;

                case RemotingDataType.SetMaxRunspaces:
                    {
                        Dbg.Assert(SetMaxRunspacesReceived != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events");

                        SetMaxRunspacesReceived.SafeInvoke(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    }
                    break;

                case RemotingDataType.SetMinRunspaces:
                    {
                        Dbg.Assert(SetMinRunspacesReceived != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events");

                        SetMinRunspacesReceived.SafeInvoke(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    }
                    break;

                case RemotingDataType.AvailableRunspaces:
                    {
                        Dbg.Assert(GetAvailableRunspacesReceived != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events");

                        GetAvailableRunspacesReceived.SafeInvoke(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    }
                    break;

                case RemotingDataType.ResetRunspaceState:
                    {
                        Dbg.Assert(ResetRunspaceState != null,
                            "The ServerRunspacePoolDriver should subscribe to all data structure handler events.");

                        ResetRunspaceState.SafeInvoke(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    }
                    break;
            } // switch...
        }
        internal void ProcessReceivedData(RemoteDataObject<PSObject> receivedData)
        {
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }
            switch (receivedData.DataType)
            {
                case RemotingDataType.SetMaxRunspaces:
                    this.SetMaxRunspacesReceived.SafeInvoke<RemoteDataEventArgs<PSObject>>(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    return;

                case RemotingDataType.SetMinRunspaces:
                    this.SetMinRunspacesReceived.SafeInvoke<RemoteDataEventArgs<PSObject>>(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    return;

                case RemotingDataType.RunspacePoolOperationResponse:
                case RemotingDataType.RunspacePoolStateInfo:
                case RemotingDataType.PSEventArgs:
                case RemotingDataType.ApplicationPrivateData:
                    break;

                case RemotingDataType.CreatePowerShell:
                    this.CreateAndInvokePowerShell.SafeInvoke<RemoteDataEventArgs<RemoteDataObject<PSObject>>>(this, new RemoteDataEventArgs<RemoteDataObject<PSObject>>(receivedData));
                    return;

                case RemotingDataType.AvailableRunspaces:
                    this.GetAvailableRunspacesReceived.SafeInvoke<RemoteDataEventArgs<PSObject>>(this, new RemoteDataEventArgs<PSObject>(receivedData.Data));
                    break;

                case RemotingDataType.GetCommandMetadata:
                    this.GetCommandMetadata.SafeInvoke<RemoteDataEventArgs<RemoteDataObject<PSObject>>>(this, new RemoteDataEventArgs<RemoteDataObject<PSObject>>(receivedData));
                    return;

                case RemotingDataType.RemoteRunspaceHostResponseData:
                {
                    RemoteHostResponse data = RemoteHostResponse.Decode(receivedData.Data);
                    this.transportManager.ReportExecutionStatusAsRunning();
                    this.HostResponseReceived.SafeInvoke<RemoteDataEventArgs<RemoteHostResponse>>(this, new RemoteDataEventArgs<RemoteHostResponse>(data));
                    return;
                }
                default:
                    return;
            }
        }
        internal void ProcessNonSessionMessages(RemoteDataObject<PSObject> rcvdData)
        {
            Guid runspacePoolId;
            if (rcvdData == null)
            {
                throw PSTraceSource.NewArgumentNullException("rcvdData");
            }
            switch (rcvdData.TargetInterface)
            {
                case RemotingTargetInterface.Session:
                    break;

                case RemotingTargetInterface.RunspacePool:
                {
                    runspacePoolId = rcvdData.RunspacePoolId;
                    RemoteRunspacePoolInternal runspacePool = this._session.GetRunspacePool(runspacePoolId);
                    if (runspacePool == null)
                    {
                        _trace.WriteLine("Client received data for Runspace (id: {0}), \r\n                            but the Runspace cannot be found", new object[] { runspacePoolId });
                        return;
                    }
                    runspacePool.DataStructureHandler.ProcessReceivedData(rcvdData);
                    return;
                }
                case RemotingTargetInterface.PowerShell:
                    runspacePoolId = rcvdData.RunspacePoolId;
                    this._session.GetRunspacePool(runspacePoolId).DataStructureHandler.DispatchMessageToPowerShell(rcvdData);
                    break;

                default:
                    return;
            }
        }
 internal override void RaiseKeyExchangeMessageReceived(RemoteDataObject<PSObject> receivedData)
 {
     this.ProcessSessionMessages(new RemoteDataEventArgs(receivedData));
 }
Пример #41
0
 /// <summary>
 /// Send the data specified as a RemoteDataObject asynchronously
 /// to the runspace pool on the remote session
 /// </summary>
 /// <param name="data">data to send</param>
 /// <remarks>This overload takes a RemoteDataObject and should
 /// be the one thats used to send data from within this
 /// data structure handler class</remarks>
 private void SendDataAsync(RemoteDataObject data)
 {
     Dbg.Assert(null != data, "Cannot send null object.");
     _transportManager.SendDataToClient(data, true);
 }
Пример #42
0
        /// <summary>
        /// dispatch the message to the associated powershell data structure handler
        /// </summary>
        /// <param name="rcvdData">message to dispatch</param>
        internal void DispatchMessageToPowerShell(RemoteDataObject<PSObject> rcvdData)
        {
            ServerPowerShellDataStructureHandler dsHandler =
                GetAssociatedPowerShellDataStructureHandler(rcvdData.PowerShellId);

            // if data structure handler is not found, then association has already been
            // removed, discard message
            if (dsHandler != null)
            {
                dsHandler.ProcessReceivedData(rcvdData);
            }
        }
Пример #43
0
 /// <summary>
 /// Send the data specified as a RemoteDataObject asynchronously
 /// to the runspace pool on the remote session
 /// </summary>
 /// <param name="data">data to send</param>
 /// <remarks>This overload takes a RemoteDataObject and should
 /// be the one thats used to send data from within this
 /// data structure handler class</remarks>
 private void SendDataAsync(RemoteDataObject data)
 {
     Dbg.Assert(null != data, "Cannot send null object.");
     // this is from a command execution..let transport manager collect
     // as much data as possible and send bigger buffer to client.
     _transportManager.SendDataToClient(data, false);
 }
Пример #44
0
        /// <summary>
        /// Process the data received from the powershell on 
        /// the client
        /// </summary>
        /// <param name="receivedData">data received</param>
        internal void ProcessReceivedData(RemoteDataObject<PSObject> receivedData)
        {
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }

            Dbg.Assert(receivedData.TargetInterface == RemotingTargetInterface.PowerShell,
                "RemotingTargetInterface must be PowerShell");

            switch (receivedData.DataType)
            {
                case RemotingDataType.StopPowerShell:
                    {
                        Dbg.Assert(StopPowerShellReceived != null,
                            "ServerPowerShellDriver should subscribe to all data structure handler events");
                        StopPowerShellReceived.SafeInvoke(this, EventArgs.Empty);
                    }
                    break;

                case RemotingDataType.PowerShellInput:
                    {
                        Dbg.Assert(InputReceived != null,
                            "ServerPowerShellDriver should subscribe to all data structure handler events");
                        InputReceived.SafeInvoke(this, new RemoteDataEventArgs<object>(receivedData.Data));
                    }
                    break;

                case RemotingDataType.PowerShellInputEnd:
                    {
                        Dbg.Assert(InputEndReceived != null,
                            "ServerPowerShellDriver should subscribe to all data structure handler events");
                        InputEndReceived.SafeInvoke(this, EventArgs.Empty);
                    }
                    break;

                case RemotingDataType.RemotePowerShellHostResponseData:
                    {
                        Dbg.Assert(HostResponseReceived != null,
                            "ServerPowerShellDriver should subscribe to all data strucutre handler events");

                        RemoteHostResponse remoteHostResponse = RemoteHostResponse.Decode(receivedData.Data);

                        //part of host message robustness algo. Now the host response is back, report to transport that
                        // execution status is back to running
                        _transportManager.ReportExecutionStatusAsRunning();

                        HostResponseReceived.SafeInvoke(this, new RemoteDataEventArgs<RemoteHostResponse>(remoteHostResponse));
                    }
                    break;
            } // switch ...
        }
        internal void ProcessReceivedData(RemoteDataObject<PSObject> receivedData)
        {
            if (receivedData.PowerShellId != this.clientPowerShellId)
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.PipelineIdsDoNotMatch, new object[] { receivedData.PowerShellId, this.clientPowerShellId });
            }
            switch (receivedData.DataType)
            {
                case RemotingDataType.PowerShellOutput:
                {
                    object powerShellOutput = RemotingDecoder.GetPowerShellOutput(receivedData.Data);
                    this.OutputReceived.SafeInvoke<RemoteDataEventArgs<object>>(this, new RemoteDataEventArgs<object>(powerShellOutput));
                    return;
                }
                case RemotingDataType.PowerShellErrorRecord:
                {
                    ErrorRecord powerShellError = RemotingDecoder.GetPowerShellError(receivedData.Data);
                    this.ErrorReceived.SafeInvoke<RemoteDataEventArgs<ErrorRecord>>(this, new RemoteDataEventArgs<ErrorRecord>(powerShellError));
                    return;
                }
                case RemotingDataType.PowerShellStateInfo:
                {
                    PSInvocationStateInfo powerShellStateInfo = RemotingDecoder.GetPowerShellStateInfo(receivedData.Data);
                    this.InvocationStateInfoReceived.SafeInvoke<RemoteDataEventArgs<PSInvocationStateInfo>>(this, new RemoteDataEventArgs<PSInvocationStateInfo>(powerShellStateInfo));
                    return;
                }
                case RemotingDataType.PowerShellDebug:
                {
                    DebugRecord powerShellDebug = RemotingDecoder.GetPowerShellDebug(receivedData.Data);
                    this.InformationalMessageReceived.SafeInvoke<RemoteDataEventArgs<InformationalMessage>>(this, new RemoteDataEventArgs<InformationalMessage>(new InformationalMessage(powerShellDebug, RemotingDataType.PowerShellDebug)));
                    return;
                }
                case RemotingDataType.PowerShellVerbose:
                {
                    VerboseRecord powerShellVerbose = RemotingDecoder.GetPowerShellVerbose(receivedData.Data);
                    this.InformationalMessageReceived.SafeInvoke<RemoteDataEventArgs<InformationalMessage>>(this, new RemoteDataEventArgs<InformationalMessage>(new InformationalMessage(powerShellVerbose, RemotingDataType.PowerShellVerbose)));
                    return;
                }
                case RemotingDataType.PowerShellWarning:
                {
                    WarningRecord powerShellWarning = RemotingDecoder.GetPowerShellWarning(receivedData.Data);
                    this.InformationalMessageReceived.SafeInvoke<RemoteDataEventArgs<InformationalMessage>>(this, new RemoteDataEventArgs<InformationalMessage>(new InformationalMessage(powerShellWarning, RemotingDataType.PowerShellWarning)));
                    return;
                }
                case ((RemotingDataType) 0x4100a):
                case ((RemotingDataType) 0x4100b):
                case ((RemotingDataType) 0x4100c):
                case ((RemotingDataType) 0x4100d):
                case ((RemotingDataType) 0x4100e):
                case ((RemotingDataType) 0x4100f):
                    break;

                case RemotingDataType.PowerShellProgress:
                {
                    ProgressRecord powerShellProgress = RemotingDecoder.GetPowerShellProgress(receivedData.Data);
                    this.InformationalMessageReceived.SafeInvoke<RemoteDataEventArgs<InformationalMessage>>(this, new RemoteDataEventArgs<InformationalMessage>(new InformationalMessage(powerShellProgress, RemotingDataType.PowerShellProgress)));
                    return;
                }
                case RemotingDataType.RemoteHostCallUsingPowerShellHost:
                {
                    RemoteHostCall data = RemoteHostCall.Decode(receivedData.Data);
                    this.HostCallReceived.SafeInvoke<RemoteDataEventArgs<RemoteHostCall>>(this, new RemoteDataEventArgs<RemoteHostCall>(data));
                    break;
                }
                default:
                    return;
            }
        }
 private void SendDataAsync(RemoteDataObject data)
 {
     RemoteDataObject<object> obj2 = data;
     this.transportManager.DataToBeSentCollection.Add<object>(obj2);
 }
 /// <summary>
 /// Raise the public key received event
 /// </summary>
 /// <param name="receivedData">received data</param>
 /// <remarks>This method is a hook to be called 
 /// from the transport manager</remarks>
 internal override void RaiseKeyExchangeMessageReceived(RemoteDataObject<PSObject> receivedData)
 {
     RaiseDataReceivedEvent(new RemoteDataEventArgs(receivedData));
 }
 private void SendDataAsync(RemoteDataObject data)
 {
     this.transportManager.SendDataToClient(data, true, false);
 }
Пример #49
0
 internal abstract void RaiseKeyExchangeMessageReceived(RemoteDataObject<PSObject> receivedData);
Пример #50
0
 private void OnDataAvailableHandler(RemoteDataObject<PSObject> remoteObject)
 {
     this.EnqueueAndStartProcessingThread(remoteObject, null, null);
 }
        /// <summary>
        /// This processes the object received from transport which are 
        /// not targeted for session
        /// </summary>
        /// <param name="rcvdData">
        /// received data.
        /// </param>
        internal void ProcessNonSessionMessages(RemoteDataObject<PSObject> rcvdData)
        {
            // TODO: Consider changing to Dbg.Assert()
            if (rcvdData == null)
            {
                throw PSTraceSource.NewArgumentNullException("rcvdData");
            }

            RemotingTargetInterface targetInterface = rcvdData.TargetInterface;

            Guid clientRunspacePoolId;
            RemoteRunspacePoolInternal runspacePool;

            switch (targetInterface)
            {
                case RemotingTargetInterface.Session:

                    Dbg.Assert(false,
                        "The session remote data is handled my session data structure handler, not here");
                    break;

                case RemotingTargetInterface.RunspacePool:
                    clientRunspacePoolId = rcvdData.RunspacePoolId;
                    runspacePool = _session.GetRunspacePool(clientRunspacePoolId);

                    if (runspacePool != null)
                    {
                        // GETBACK
                        runspacePool.DataStructureHandler.ProcessReceivedData(rcvdData);
                    }
                    else
                    {
                        // The runspace pool may have been removed on the client side,
                        // so, we should just ignore the message.
                        s_trace.WriteLine(@"Client received data for Runspace (id: {0}), 
                            but the Runspace cannot be found", clientRunspacePoolId);
                    }

                    break;

                case RemotingTargetInterface.PowerShell:
                    clientRunspacePoolId = rcvdData.RunspacePoolId;
                    runspacePool = _session.GetRunspacePool(clientRunspacePoolId);

                    // GETBACK
                    runspacePool.DataStructureHandler.DispatchMessageToPowerShell(rcvdData);
                    break;

                default:

                    break;
            }
        }