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;
            }
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        internal static RemoteHostResponse Decode(PSObject data)
        {
            long propertyValue1 = RemotingDecoder.GetPropertyValue <long>(data, "ci");
            RemoteHostMethodId   propertyValue2       = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, "mi");
            RemoteHostMethodInfo remoteHostMethodInfo = RemoteHostMethodInfo.LookUp(propertyValue2);
            object    returnValue = RemoteHostResponse.DecodeReturnValue(data, remoteHostMethodInfo.ReturnType);
            Exception exception   = RemoteHostResponse.DecodeException(data);

            return(new RemoteHostResponse(propertyValue1, propertyValue2, returnValue, exception));
        }
Ejemplo n.º 4
0
        internal PSObject Encode()
        {
            PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject();

            RemoteHostResponse.EncodeAndAddReturnValue(emptyPsObject, this._returnValue);
            RemoteHostResponse.EncodeAndAddException(emptyPsObject, this._exception);
            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ci", (object)this._callId));
            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("mi", (object)this._methodId));
            return(emptyPsObject);
        }
Ejemplo n.º 5
0
 private void ExecuteHostCall(RemoteHostCall hostcall)
 {
     if (hostcall.IsVoidMethod)
     {
         if (hostcall.IsSetShouldExitOrPopRunspace)
         {
             this.shell.ClearRemotePowerShell();
         }
         hostcall.ExecuteVoidMethod(this.hostToUse);
     }
     else
     {
         RemoteHostResponse hostResponse = hostcall.ExecuteNonVoidMethod(this.hostToUse);
         this.dataStructureHandler.SendHostResponseToServer(hostResponse);
     }
 }
        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;
            }
        }
Ejemplo n.º 7
0
 internal void HandleRemoteHostCalls(object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs)
 {
     if (this.HostCallReceived != null)
     {
         this.HostCallReceived.SafeInvoke <RemoteDataEventArgs <RemoteHostCall> >(sender, eventArgs);
     }
     else
     {
         RemoteHostCall data = eventArgs.Data;
         if (data.IsVoidMethod)
         {
             data.ExecuteVoidMethod(base.host);
         }
         else
         {
             RemoteHostResponse hostResponse = data.ExecuteNonVoidMethod(base.host);
             this.dataStructureHandler.SendHostResponseToServer(hostResponse);
         }
     }
 }
 internal void SendHostResponseToServer(RemoteHostResponse hostResponse)
 {
     using (ClientPowerShellDataStructureHandler.tracer.TraceMethod())
         this.transportManager.DataToBeSentCollection.Add <PSObject>(RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.Server, RemotingDataType.RemotePowerShellHostResponseData, this.clientRunspacePoolId, this.clientPowerShellId, hostResponse.Encode()), DataPriorityType.PromptResponse);
 }
Ejemplo n.º 9
0
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            using (ServerRunspacePoolDataStructureHandler.tracer.TraceMethod())
            {
                if (receivedData == null)
                {
                    throw ServerRunspacePoolDataStructureHandler.tracer.NewArgumentNullException(nameof(receivedData));
                }
                switch (receivedData.DataType)
                {
                case RemotingDataType.SetMaxRunspaces:
                    this.SetMaxRunspacesReceived((object)this, new RemoteDataEventArgs <PSObject>((object)receivedData.Data));
                    break;

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

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

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

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

                case RemotingDataType.RemoteRunspaceHostResponseData:
                    this.HostResponseReceived((object)this, new RemoteDataEventArgs <RemoteHostResponse>((object)RemoteHostResponse.Decode(receivedData.Data)));
                    break;
                }
            }
        }
        internal void SendHostResponseToServer(RemoteHostResponse hostResponse)
        {
            RemoteDataObject <PSObject> data = RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Server, RemotingDataType.RemotePowerShellHostResponseData, this.clientRunspacePoolId, this.clientPowerShellId, hostResponse.Encode());

            this.transportManager.DataToBeSentCollection.Add <PSObject>(data, DataPriorityType.PromptResponse);
        }
Ejemplo n.º 11
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;
            }
        }
Ejemplo n.º 12
0
 internal void SendHostResponseToServer(RemoteHostResponse hostResponse)
 {
     using (ClientRunspacePoolDataStructureHandler.tracer.TraceMethod())
         this.SendDataAsync(hostResponse.Encode(), DataPriorityType.PromptResponse);
 }
 internal void SendHostResponseToServer(RemoteHostResponse hostResponse)
 {
     this.SendDataAsync(hostResponse.Encode(), DataPriorityType.PromptResponse);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Start (or Connect) event handler.
 /// <para>There are 2 instances of the process control control.</para>
 /// <para>When context is null, this function handles the Start event for the local TPE.</para>
 /// <para>When context is not null, this function handles the Connect event for a remote TPE.</para>
 /// </summary>
 /// <param name="context">Indicates to handler method whether it is from the local or remote TPE.</param>
 public void Start(object context)
 {
     // Start Event from local TPE
     if (context == null)
     {
         // ensure that this tpe host is unique host session base on engineId
         // When the Overwrite parameter of appSession.Start is false
         // we will receive an error message when there is an existing record.
         // As long as we receive an error message, the session already exists
         // so user will be presented with dialog box.
         // When user confirms, then we call function with Overwrite = true;
         string sessionExists = _appSession.Start(_configSettings, "Application Startup", false, _hostEndpointAddress);
         while (!string.IsNullOrEmpty(sessionExists))
         {
             if (MessageBox.Show(sessionExists + " Press OK to reset; CANCEL to stop."
                                 , "Session Startup Conflict", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
             {
                 return;
             }
             // otherwise reset session record (remove existing)
             else
             {
                 sessionExists = _appSession.Start(_configSettings
                                                   , "Application Startup After Session Conflict Reset"
                                                   , true
                                                   , _hostEndpointAddress); // host address of this local TPE to be used for other applications to connect to.
             }
         }
         // instantiate this application's local TPE
         _localTpe = new TaskProcessing.TaskProcessingEngine(_daMgr
                                                             , _taskAssemblyPath
                                                             , _engineId
                                                             , _configId
                                                             , _appSession.SignonControl
                                                             , _maxTasks
                                                             , _hostEndpointAddress);
         // start the TPE
         _localTpe.Start();
         // display status
         Status();
     }
     else
     {
         // WCF Connect
         pagingTableRemoteHosts.IsEnabled = false;
         EndpointAddress remoteAddress = new EndpointAddress(string.Format("{0}{1}", _hostEndpointAddress
                                                                           , _engineId));
         WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
         _remoteTpe = new RemoteHostClient(binding, remoteAddress);
         RemoteHostResponse response = _remoteTpe.Connect(_engineId);
         if (response.Success)
         {
             RemoteHostResponseString configSettingsResponse = _remoteTpe.ConfigSettings();
             RemoteHostResponseString dynamicSettingsReponse = _remoteTpe.DynamicSettings();
             if (configSettingsResponse.Success && dynamicSettingsReponse.Success)
             {
                 Dictionary <string, string> configSettings = (Dictionary <string, string>)
                                                              Core.Functions.Deserialize <Dictionary <string, string> >
                                                                  (configSettingsResponse.ReturnValue);
                 Dictionary <string, string> dynamicSettings = (Dictionary <string, string>)
                                                               Core.Functions.Deserialize <Dictionary <string, string> >
                                                                   (dynamicSettingsReponse.ReturnValue);
                 DisplayRemoteTpeConfiguration(configSettings, dynamicSettings);
             }
             else
             {
                 remoteTpeStatus.Status = string.Format("{0}{1}{2}", configSettingsResponse.ErrorMsg
                                                        , Environment.NewLine, dynamicSettingsReponse.ErrorMsg);
             }
         }
         else
         {
             HostConnectionAborted(response.ErrorMsg);
         }
     }
 }
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            using (ServerPowerShellDataStructureHandler.tracer.TraceMethod())
            {
                if (receivedData == null)
                {
                    throw ServerPowerShellDataStructureHandler.tracer.NewArgumentNullException(nameof(receivedData));
                }
                switch (receivedData.DataType)
                {
                case RemotingDataType.PowerShellInput:
                    this.InputReceived((object)this, new RemoteDataEventArgs <object>((object)receivedData.Data));
                    break;

                case RemotingDataType.PowerShellInputEnd:
                    this.InputEndReceived((object)this, new EventArgs());
                    break;

                case RemotingDataType.StopPowerShell:
                    this.StopPowerShellReceived((object)this, new EventArgs());
                    break;

                case RemotingDataType.RemotePowerShellHostResponseData:
                    this.HostResponseReceived((object)this, new RemoteDataEventArgs <RemoteHostResponse>((object)RemoteHostResponse.Decode(receivedData.Data)));
                    break;
                }
            }
        }