private void HandleGetCommandMetadata( object sender, RemoteDataEventArgs <RemoteDataObject <PSObject> > eventArgs) { using (ServerRunspacePoolDriver.tracer.TraceEventHandlers()) { RemoteDataObject <PSObject> data = eventArgs.Data; PowerShell discoveryPipeline1 = RemotingDecoder.GetCommandDiscoveryPipeline((object)data.Data); discoveryPipeline1.AddParameter("ErrorAction", (object)"SilentlyContinue").AddCommand("Measure-Object").AddCommand("Select-Object").AddParameter("Property", (object)"Count"); PowerShell discoveryPipeline2 = RemotingDecoder.GetCommandDiscoveryPipeline((object)data.Data); discoveryPipeline2.AddCommand("Select-Object").AddParameter("Property", (object)new string[7] { "Name", "Namespace", "HelpUri", "CommandType", "ResolvedCommandName", "OutputType", "Parameters" }); new ServerPowerShellDriver(discoveryPipeline1, discoveryPipeline2, true, data.PowerShellId, data.RunspacePoolId, this, ApartmentState.Unknown, new HostInfo((PSHost)null) { UseRunspaceHost = true }, (RemoteStreamOptions)0, false, (Runspace)null).Start(); } }
private void HandleGetAvailalbeRunspacesReceived(object sender, RemoteDataEventArgs <PSObject> eventArgs) { long callId = (long)((PSNoteProperty)eventArgs.Data.Properties["ci"]).Value; int availableRunspaces = this.localRunspacePool.GetAvailableRunspaces(); this.dsHandler.SendResponseToClient(callId, availableRunspaces); }
private void HandleInputReceived(object sender, RemoteDataEventArgs <object> eventArgs) { if (this.input != null) { this.input.Add(eventArgs.Data); } }
private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs <RemoteDataObject <PSObject> > eventArgs) { RemoteDataObject <PSObject> data = eventArgs.Data; HostInfo hostInfo = RemotingDecoder.GetHostInfo(data.Data); ApartmentState apartmentState = RemotingDecoder.GetApartmentState(data.Data); RemoteStreamOptions remoteStreamOptions = RemotingDecoder.GetRemoteStreamOptions(data.Data); PowerShell powerShell = RemotingDecoder.GetPowerShell(data.Data); bool noInput = RemotingDecoder.GetNoInput(data.Data); bool addToHistory = RemotingDecoder.GetAddToHistory(data.Data); bool isNested = false; if (this.serverCapability.ProtocolVersion >= RemotingConstants.ProtocolVersionWin8RTM) { isNested = RemotingDecoder.GetIsNested(data.Data); } if (isNested) { if (this.dsHandler.GetAssociatedPowerShellDataStructureHandler(powerShell.InstanceId) != null) { throw new InvalidOperationException("NestedPipeline is not supported in this release."); } powerShell.SetIsNested(false); if ((this.localRunspacePool.GetMaxRunspaces() == 1) && (this.dsHandler.GetPowerShellDataStructureHandler() != null)) { new ServerSteppablePipelineDriver(powerShell, noInput, data.PowerShellId, data.RunspacePoolId, this, apartmentState, hostInfo, remoteStreamOptions, addToHistory, this.rsToUseForSteppablePipeline, this.eventSubscriber, this.inputCollection).Start(); return; } } ServerPowerShellDriver driver2 = new ServerPowerShellDriver(powerShell, null, noInput, data.PowerShellId, data.RunspacePoolId, this, apartmentState, hostInfo, remoteStreamOptions, addToHistory, null); this.inputCollection = driver2.InputCollection; driver2.Start(); }
private void HandleSetMinRunspacesReceived( object sender, RemoteDataEventArgs <PSObject> eventArgs) { PSObject data = eventArgs.Data; int minRunspaces = (int)data.Properties["MinRunspaces"].Value; this.dsHandler.SendResponseToClient((long)data.Properties["ci"].Value, (object)this.localRunspacePool.SetMinRunspaces(minRunspaces)); }
private void HandleSetMinRunspacesReceived(object sender, RemoteDataEventArgs <PSObject> eventArgs) { PSObject data = eventArgs.Data; int minRunspaces = (int)((PSNoteProperty)data.Properties["MinRunspaces"]).Value; long callId = (long)((PSNoteProperty)data.Properties["ci"]).Value; bool response = this.localRunspacePool.SetMinRunspaces(minRunspaces); this.dsHandler.SendResponseToClient(callId, response); }
/// <summary> /// Add input to the local powershell's input collection /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void HandleInputReceived(object sender, RemoteDataEventArgs <object> eventArgs) { // This can be called in pushed runspace scenarios for error reporting (pipeline stopped). // Ignore for noInput. if (!_noInput && (InputCollection != null)) { InputCollection.Add(eventArgs.Data); } }
private void HandleURIDirectionReported(object sender, RemoteDataEventArgs <Uri> eventArgs) { WSManConnectionInfo info = this._connectionInfo as WSManConnectionInfo; if (info != null) { info.ConnectionUri = eventArgs.Data; this.URIRedirectionReported.SafeInvoke <RemoteDataEventArgs <Uri> >(this, eventArgs); } }
internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg) { if (dataArg == null) { throw PSTraceSource.NewArgumentNullException("dataArg"); } RemoteDataObject<PSObject> receivedData = dataArg.ReceivedData; RemotingTargetInterface targetInterface = receivedData.TargetInterface; RemotingDataType dataType = receivedData.DataType; switch (dataType) { case RemotingDataType.SessionCapability: { RemoteSessionCapability remoteSessionCapability = null; try { remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data); } catch (PSRemotingDataStructureException exception2) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); } RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) { RemoteSessionCapability = remoteSessionCapability }; this._stateMachine.RaiseEvent(fsmEventArg); if (this.NegotiationReceived != null) { RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability) { RemoteData = receivedData }; this.NegotiationReceived.SafeInvoke<RemoteSessionNegotiationEventArgs>(this, eventArgs); } return; } case RemotingDataType.CloseSession: { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession); RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this._stateMachine.RaiseEvent(args); return; } case RemotingDataType.CreateRunspacePool: this.CreateRunspacePoolReceived.SafeInvoke<RemoteDataEventArgs>(this, dataArg); return; case RemotingDataType.PublicKey: { string publicKey = RemotingDecoder.GetPublicKey(receivedData.Data); this.PublicKeyReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(publicKey)); return; } } throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType }); }
private void HandleInputReceived(object sender, RemoteDataEventArgs <object> eventArgs) { using (ServerPowerShellDriver.tracer.TraceEventHandlers()) { if (this.input == null) { return; } this.input.Add(eventArgs.Data); } }
/// <summary> /// Handle host call received /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing the host call to invoke</param> private void HandleHostCallReceived(object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs) { ClientMethodExecutor.Dispatch( _powershell.RemotePowerShell.DataStructureHandler.TransportManager, ((RemoteRunspace)_runspace).RunspacePool.RemoteRunspacePoolInternal.Host, _errorStream, MethodExecutorStream, IsMethodExecutorStreamEnabled, ((RemoteRunspace)_runspace).RunspacePool.RemoteRunspacePoolInternal, _powershell.InstanceId, eventArgs.Data); }
private void HandleInputReceived(object sender, RemoteDataEventArgs <object> eventArgs) { if (this.input != null) { lock (this.syncObject) { this.input.Add(eventArgs.Data); } this.CheckAndPulseForProcessing(false); if (this.powershellInput != null) { this.powershellInput.Pulse(); } } }
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(); } }
/// <summary> /// Add input to the local powershell's input collection /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void HandleInputReceived(object sender, RemoteDataEventArgs <object> eventArgs) { Dbg.Assert(!NoInput, "Input data should not be received for powershells created with no input"); if (Input != null) { lock (SyncObject) { Input.Add(eventArgs.Data); } CheckAndPulseForProcessing(false); if (_powershellInput != null) { _powershellInput.Pulse(); } } }
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); }
private void HandleGetCommandMetadata(object sender, RemoteDataEventArgs <RemoteDataObject <PSObject> > eventArgs) { RemoteDataObject <PSObject> data = eventArgs.Data; PowerShell commandDiscoveryPipeline = RemotingDecoder.GetCommandDiscoveryPipeline(data.Data); if (this.DoesInitialSessionStateIncludeGetCommandWithListImportedSwitch()) { commandDiscoveryPipeline.AddParameter("ListImported", true); } commandDiscoveryPipeline.AddParameter("ErrorAction", "SilentlyContinue").AddCommand("Measure-Object").AddCommand("Select-Object").AddParameter("Property", "Count"); PowerShell extraPowerShell = RemotingDecoder.GetCommandDiscoveryPipeline(data.Data); if (this.DoesInitialSessionStateIncludeGetCommandWithListImportedSwitch()) { extraPowerShell.AddParameter("ListImported", true); } extraPowerShell.AddCommand("Select-Object").AddParameter("Property", new string[] { "Name", "Namespace", "HelpUri", "CommandType", "ResolvedCommandName", "OutputType", "Parameters" }); HostInfo hostInfo = new HostInfo(null) { UseRunspaceHost = true }; new ServerPowerShellDriver(commandDiscoveryPipeline, extraPowerShell, true, data.PowerShellId, data.RunspacePoolId, this, ApartmentState.Unknown, hostInfo, 0, false, null).Start(); }
private void HandleHostCallReceived(object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs) { ClientMethodExecutor.Dispatch(this._runspacePool.RemoteRunspacePoolInternal.DataStructureHandler.TransportManager, this._runspacePool.RemoteRunspacePoolInternal.Host, null, null, false, this._runspacePool.RemoteRunspacePoolInternal, Guid.Empty, eventArgs.Data); }
private void ProcessSessionMessages(RemoteDataEventArgs arg) { if ((arg == null) || (arg.ReceivedData == null)) { throw PSTraceSource.NewArgumentNullException("arg"); } RemoteDataObject<PSObject> receivedData = arg.ReceivedData; RemotingTargetInterface targetInterface = receivedData.TargetInterface; RemotingDataType dataType = receivedData.DataType; switch (dataType) { case RemotingDataType.SessionCapability: { RemoteSessionCapability remoteSessionCapability = null; try { remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data); } catch (PSRemotingDataStructureException exception2) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion }); } RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) { RemoteSessionCapability = remoteSessionCapability }; this._stateMachine.RaiseEvent(args2, false); RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability); this.NegotiationReceived.SafeInvoke<RemoteSessionNegotiationEventArgs>(this, eventArgs); return; } case RemotingDataType.CloseSession: { PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession); RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason); this._stateMachine.RaiseEvent(args, false); return; } case RemotingDataType.EncryptedSessionKey: { string encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(receivedData.Data); this.EncryptedSessionKeyReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(encryptedSessionKey)); return; } case RemotingDataType.PublicKeyRequest: this.PublicKeyRequestReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(string.Empty)); return; } throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType }); }
/// <summary> /// When the client remote session reports a URI redirection, this method will report the /// message to the user as a Warning using Host method calls. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void HandleURIDirectionReported(object sender, RemoteDataEventArgs<Uri> eventArgs) { string message = StringUtil.Format(RemotingErrorIdStrings.URIRedirectWarningToHost, eventArgs.Data.OriginalString); Action<Cmdlet> warningWriter = delegate (Cmdlet cmdlet) { cmdlet.WriteWarning(message); }; _stream.Write(warningWriter); }
internal void HandleStateInfoReceived(object sender, RemoteDataEventArgs<RunspacePoolStateInfo> eventArgs) { RunspacePoolStateInfo data = eventArgs.Data; bool flag = false; if (data.State == RunspacePoolState.Opened) { lock (base.syncObject) { if (base.stateInfo.State == RunspacePoolState.Opening) { this.SetRunspacePoolState(data); flag = true; } } if (flag) { base.RaiseStateChangeEvent(base.stateInfo); this.SetOpenAsCompleted(); } } else if ((data.State == RunspacePoolState.Closed) || (data.State == RunspacePoolState.Broken)) { bool flag3 = false; lock (base.syncObject) { if ((base.stateInfo.State == RunspacePoolState.Closed) || (base.stateInfo.State == RunspacePoolState.Broken)) { return; } if (((base.stateInfo.State == RunspacePoolState.Opening) || (base.stateInfo.State == RunspacePoolState.Opened)) || (base.stateInfo.State == RunspacePoolState.Closing)) { flag3 = true; this.SetRunspacePoolState(data); } } if (flag3 && (this.closeAsyncResult == null)) { this.dataStructureHandler.CloseRunspacePoolAsync(); } } }
private void HandleSessionRCDisconnecting(object sender, RemoteDataEventArgs<Exception> e) { lock (base.syncObject) { this.SetRunspacePoolState(new RunspacePoolStateInfo(RunspacePoolState.Disconnecting, e.Data)); } base.RaiseStateChangeEvent(base.stateInfo); }
private void HandleSessionClosed(object sender, RemoteDataEventArgs<Exception> eventArgs) { RunspacePoolState state; RunspacePoolStateInfo info; if (eventArgs.Data != null) { this.closingReason = eventArgs.Data; } lock (base.syncObject) { state = base.stateInfo.State; switch (state) { case RunspacePoolState.Opening: case RunspacePoolState.Opened: case RunspacePoolState.Disconnecting: case RunspacePoolState.Disconnected: case RunspacePoolState.Connecting: this.SetRunspacePoolState(new RunspacePoolStateInfo(RunspacePoolState.Broken, this.closingReason)); break; case RunspacePoolState.Closing: this.SetRunspacePoolState(new RunspacePoolStateInfo(RunspacePoolState.Closed, this.closingReason)); break; } info = new RunspacePoolStateInfo(base.stateInfo.State, base.stateInfo.Reason); } try { base.RaiseStateChangeEvent(info); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); } switch (state) { case RunspacePoolState.Disconnecting: case RunspacePoolState.Disconnected: this.SetDisconnectAsCompleted(); break; default: if (state == RunspacePoolState.Connecting) { this.SetReconnectAsCompleted(); } break; } this.SetCloseAsCompleted(); }
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); } } }
/// <summary> /// Handle the invocation of command discovery pipeline /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void HandleGetCommandMetadata(object sender, RemoteDataEventArgs<RemoteDataObject<PSObject>> eventArgs) { RemoteDataObject<PSObject> data = eventArgs.Data; PowerShell countingPipeline = RemotingDecoder.GetCommandDiscoveryPipeline(data.Data); if (this.DoesInitialSessionStateIncludeGetCommandWithListImportedSwitch()) { countingPipeline.AddParameter("ListImported", true); } countingPipeline .AddParameter("ErrorAction", "SilentlyContinue") .AddCommand("Measure-Object") .AddCommand("Select-Object") .AddParameter("Property", "Count"); PowerShell mainPipeline = RemotingDecoder.GetCommandDiscoveryPipeline(data.Data); if (this.DoesInitialSessionStateIncludeGetCommandWithListImportedSwitch()) { mainPipeline.AddParameter("ListImported", true); } mainPipeline .AddCommand("Select-Object") .AddParameter("Property", new string[] { "Name", "Namespace", "HelpUri", "CommandType", "ResolvedCommandName", "OutputType", "Parameters" }); HostInfo useRunspaceHost = new HostInfo(null); useRunspaceHost.UseRunspaceHost = true; if (_remoteHost.IsRunspacePushed) { // If we have a pushed runspace then execute there. StartPowerShellCommandOnPushedRunspace( countingPipeline, mainPipeline, data.PowerShellId, data.RunspacePoolId, useRunspaceHost, 0, true, false); } else { // Run on usual driver. ServerPowerShellDriver driver = new ServerPowerShellDriver( countingPipeline, mainPipeline, true /* no input */, data.PowerShellId, data.RunspacePoolId, this, #if !CORECLR // No ApartmentState In CoreCLR ApartmentState.Unknown, #endif useRunspaceHost, 0 /* stream options */, false /* addToHistory */, null /* use default rsPool runspace */); driver.Start(); } }
private void HandlePublicKeyRequestReceived(object sender, RemoteDataEventArgs<string> eventArgs) { var state = base.SessionDataStructureHandler.StateMachine.State; if (state == RemoteSessionState.Established) { RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyRequested); base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false); this.StartKeyExchange(); } }
private void HandleEncryptedSessionKeyReceived(object sender, RemoteDataEventArgs<string> eventArgs) { if (base.SessionDataStructureHandler.StateMachine.State == RemoteSessionState.EstablishedAndKeySent) { string data = eventArgs.Data; bool flag = this._cryptoHelper.ImportEncryptedSessionKey(data); RemoteSessionStateMachineEventArgs arg = null; if (!flag) { arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceiveFailed); base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false); } this.CompleteKeyExchange(); arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceived); base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false); } }
internal void HandleHostResponseReceived(object sender, RemoteDataEventArgs<RemoteHostResponse> eventArgs) { this.remoteHost.ServerMethodExecutor.HandleRemoteHostResponseFromClient(eventArgs.Data); }
private void HandleInputReceived(object sender, RemoteDataEventArgs<object> eventArgs) { if (this.input != null) { lock (this.syncObject) { this.input.Add(eventArgs.Data); } this.CheckAndPulseForProcessing(false); if (this.powershellInput != null) { this.powershellInput.Pulse(); } } }
private void HandleGetAvailalbeRunspacesReceived( object sender, RemoteDataEventArgs <PSObject> eventArgs) { this.dsHandler.SendResponseToClient((long)eventArgs.Data.Properties["ci"].Value, (object)this.localRunspacePool.GetAvailableRunspaces()); }
/// <summary> /// Add input to the local powershell's input collection /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void HandleInputReceived(object sender, RemoteDataEventArgs<object> eventArgs) { Dbg.Assert(!NoInput, "Input data should not be received for powershells created with no input"); if (Input != null) { lock (SyncObject) { Input.Add(eventArgs.Data); } CheckAndPulseForProcessing(false); if (_powershellInput != null) { _powershellInput.Pulse(); } } }
private void HandlePSEventArgsReceived(object sender, RemoteDataEventArgs<PSEventArgs> e) { this.OnForwardEvent(e.Data); }
private void HandleHostCall(object sender, RemoteDataEventArgs<RemoteHostCall> eventArgs) { ClientRemotePowerShell.ExitHandler(sender, eventArgs); }
private void HandleResponseReceived(object sender, RemoteDataEventArgs<PSObject> eventArgs) { PSObject data = eventArgs.Data; object propertyValue = RemotingDecoder.GetPropertyValue<object>(data, "SetMinMaxRunspacesResponse"); long callId = RemotingDecoder.GetPropertyValue<long>(data, "ci"); this.dispatchTable.SetResponse(callId, propertyValue); }
/// <summary> /// Gets the available runspaces from the server and sends it across /// to the client /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">contains information on the callid</param> private void HandleGetAvailableRunspacesReceived(object sender, RemoteDataEventArgs<PSObject> eventArgs) { PSObject data = eventArgs.Data; long callId = (long)((PSNoteProperty)data.Properties[RemoteDataNameStrings.CallId]).Value; int availableRunspaces = RunspacePool.GetAvailableRunspaces(); DataStructureHandler.SendResponseToClient(callId, availableRunspaces); }
private void HandleSessionClosing(object sender, RemoteDataEventArgs<Exception> eventArgs) { this.closingReason = eventArgs.Data; }
/// <summary> /// Forces a state reset on a single runspace runspace pool. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void HandleResetRunspaceState(object sender, RemoteDataEventArgs<PSObject> eventArgs) { long callId = (long)((PSNoteProperty)(eventArgs.Data).Properties[RemoteDataNameStrings.CallId]).Value; bool response = ResetRunspaceState(); DataStructureHandler.SendResponseToClient(callId, response); }
private void HandleSessionReconnected(object sender, RemoteDataEventArgs<Exception> eventArgs) { bool flag = false; lock (base.syncObject) { if (base.stateInfo.State == RunspacePoolState.Connecting) { this.SetRunspacePoolState(new RunspacePoolStateInfo(RunspacePoolState.Opened, null)); flag = true; } } if (flag) { base.RaiseStateChangeEvent(base.stateInfo); this.SetReconnectAsCompleted(); } }
/// <summary> /// Handle the invocation of powershell /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs<RemoteDataObject<PSObject>> eventArgs) { RemoteDataObject<PSObject> data = eventArgs.Data; // it is sufficient to just construct the powershell // driver, the local powershell on server side is // invoked from within the driver HostInfo hostInfo = RemotingDecoder.GetHostInfo(data.Data); #if !CORECLR // No ApartmentState In CoreCLR ApartmentState apartmentState = RemotingDecoder.GetApartmentState(data.Data); #endif RemoteStreamOptions streamOptions = RemotingDecoder.GetRemoteStreamOptions(data.Data); PowerShell powershell = RemotingDecoder.GetPowerShell(data.Data); bool noInput = RemotingDecoder.GetNoInput(data.Data); bool addToHistory = RemotingDecoder.GetAddToHistory(data.Data); bool isNested = false; // The server would've dropped the protocol version of an older client was connecting if (_serverCapability.ProtocolVersion >= RemotingConstants.ProtocolVersionWin8RTM) { isNested = RemotingDecoder.GetIsNested(data.Data); } // Perform pre-processing of command for over the wire debugging commands. if (_serverRemoteDebugger != null) { DebuggerCommandArgument commandArgument; bool terminateImmediate = false; var result = PreProcessDebuggerCommand(powershell.Commands, _serverRemoteDebugger.IsActive, _serverRemoteDebugger.IsRemote, out commandArgument); switch (result) { case PreProcessCommandResult.SetDebuggerAction: // Run this directly on the debugger and terminate the remote command. _serverRemoteDebugger.SetDebuggerAction(commandArgument.ResumeAction.Value); terminateImmediate = true; break; case PreProcessCommandResult.SetDebugMode: // Set debug mode directly and terminate remote command. _serverRemoteDebugger.SetDebugMode(commandArgument.Mode.Value); terminateImmediate = true; break; case PreProcessCommandResult.SetDebuggerStepMode: // Enable debugger and set to step action, then terminate remote command. _serverRemoteDebugger.SetDebuggerStepMode(commandArgument.DebuggerStepEnabled.Value); terminateImmediate = true; break; case PreProcessCommandResult.SetPreserveUnhandledBreakpointMode: _serverRemoteDebugger.UnhandledBreakpointMode = commandArgument.UnhandledBreakpointMode.Value; terminateImmediate = true; break; case PreProcessCommandResult.ValidNotProcessed: terminateImmediate = true; break; } // If we don't want to run or queue a command to run in the server session then // terminate the command here by making it a No Op. if (terminateImmediate) { ServerPowerShellDriver noOpDriver = new ServerPowerShellDriver( powershell, null, noInput, data.PowerShellId, data.RunspacePoolId, this, #if !CORECLR // No ApartmentState In CoreCLR apartmentState, #endif hostInfo, streamOptions, addToHistory, null); noOpDriver.RunNoOpCommand(); return; } } if (_remoteHost.IsRunspacePushed) { // If we have a pushed runspace then execute there. // Ensure debugger is enabled to the original mode it was set to. if (_serverRemoteDebugger != null) { _serverRemoteDebugger.CheckDebuggerState(); } StartPowerShellCommandOnPushedRunspace( powershell, null, data.PowerShellId, data.RunspacePoolId, hostInfo, streamOptions, noInput, addToHistory); return; } else if (isNested) { if (RunspacePool.GetMaxRunspaces() == 1) { if (_driverNestedInvoker != null && _driverNestedInvoker.IsActive) { if (_driverNestedInvoker.IsAvailable == false) { // A nested command is already running. throw new PSInvalidOperationException( StringUtil.Format(RemotingErrorIdStrings.CannotInvokeNestedCommandNestedCommandRunning)); } // Handle as nested pipeline invocation. powershell.SetIsNested(true); // Always invoke PowerShell commands on pipeline worker thread // for single runspace case, to support nested invocation requests (debugging scenario). ServerPowerShellDriver srdriver = new ServerPowerShellDriver( powershell, null, noInput, data.PowerShellId, data.RunspacePoolId, this, #if !CORECLR // No ApartmentState In CoreCLR apartmentState, #endif hostInfo, streamOptions, addToHistory, _rsToUseForSteppablePipeline); _inputCollection = srdriver.InputCollection; _driverNestedInvoker.InvokeDriverAsync(srdriver); return; } else if (_serverRemoteDebugger != null && _serverRemoteDebugger.InBreakpoint && _serverRemoteDebugger.IsPushed) { _serverRemoteDebugger.StartPowerShellCommand( powershell, data.PowerShellId, data.RunspacePoolId, this, #if !CORECLR // No ApartmentState In CoreCLR apartmentState, #endif _remoteHost, hostInfo, streamOptions, addToHistory); return; } else if (powershell.Commands.Commands.Count == 1 && !powershell.Commands.Commands[0].IsScript && ((powershell.Commands.Commands[0].CommandText.IndexOf("Get-PSDebuggerStopArgs", StringComparison.OrdinalIgnoreCase) != -1) || (powershell.Commands.Commands[0].CommandText.IndexOf("Set-PSDebuggerAction", StringComparison.OrdinalIgnoreCase) != -1))) { // We do not want to invoke debugger commands in the steppable pipeline. // Consider adding IsSteppable message to PSRP to handle this. // This will be caught on the client. throw new PSInvalidOperationException(); } ServerPowerShellDataStructureHandler psHandler = DataStructureHandler.GetPowerShellDataStructureHandler(); if (psHandler != null) { // Have steppable invocation request. powershell.SetIsNested(false); // Execute command concurrently ServerSteppablePipelineDriver spDriver = new ServerSteppablePipelineDriver( powershell, noInput, data.PowerShellId, data.RunspacePoolId, this, #if !CORECLR // No ApartmentState In CoreCLR apartmentState, #endif hostInfo, streamOptions, addToHistory, _rsToUseForSteppablePipeline, _eventSubscriber, _inputCollection); spDriver.Start(); return; } } // Allow command to run as non-nested and non-stepping. powershell.SetIsNested(false); } // Invoke command normally. Ensure debugger is enabled to the // original mode it was set to. if (_serverRemoteDebugger != null) { _serverRemoteDebugger.CheckDebuggerState(); } // Invoke PowerShell on driver runspace pool. ServerPowerShellDriver driver = new ServerPowerShellDriver( powershell, null, noInput, data.PowerShellId, data.RunspacePoolId, this, #if !CORECLR // No ApartmentState In CoreCLR apartmentState, #endif hostInfo, streamOptions, addToHistory, null); _inputCollection = driver.InputCollection; driver.Start(); }
private void HandleURIDirectionReported(object sender, RemoteDataEventArgs<Uri> eventArgs) { WSManConnectionInfo connectionInfo = this.connectionInfo as WSManConnectionInfo; if (connectionInfo != null) { connectionInfo.ConnectionUri = eventArgs.Data; this.URIRedirectionReported.SafeInvoke<RemoteDataEventArgs<Uri>>(this, eventArgs); } }
protected void HandleURIDirectionReported(object sender, RemoteDataEventArgs <Uri> eventArgs) { string message = StringUtil.Format(RemotingErrorIdStrings.URIRedirectWarningToHost, eventArgs.Data.OriginalString); this.WriteWarning(message); }
private void HandleURIDirectionReported(object sender, RemoteDataEventArgs<Uri> eventArgs) { string message = StringUtil.Format(RemotingErrorIdStrings.URIRedirectWarningToHost, eventArgs.Data.OriginalString); Action<Cmdlet> action = cmdlet => cmdlet.WriteWarning(message); this.stream.Write(action); }
internal void HandleApplicationPrivateDataReceived(object sender, RemoteDataEventArgs<PSPrimitiveDictionary> eventArgs) { this.SetApplicationPrivateData(eventArgs.Data); }
internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataArg) { if (dataArg == null) { throw PSTraceSource.NewArgumentNullException("dataArg"); } RemoteDataObject<PSObject> receivedData = dataArg.ReceivedData; if (receivedData == null) { throw PSTraceSource.NewArgumentException("dataArg"); } RemotingDestination destination = receivedData.Destination; var d = receivedData.Data; if ((destination & (RemotingDestination.InvalidDestination | RemotingDestination.Client)) != (RemotingDestination.InvalidDestination | RemotingDestination.Client)) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RemotingDestinationNotForMe, new object[] { RemotingDestination.InvalidDestination | RemotingDestination.Client, destination }); } switch (receivedData.TargetInterface) { case RemotingTargetInterface.Session: this.ProcessSessionMessages(dataArg); return; case RemotingTargetInterface.RunspacePool: case RemotingTargetInterface.PowerShell: { RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived, null); if (!this.StateMachine.CanByPassRaiseEvent(arg)) { this.StateMachine.RaiseEvent(arg, false); return; } this.ProcessNonSessionMessages(dataArg.ReceivedData); return; } } }
internal void HandleInitInfoReceived(object sender, RemoteDataEventArgs<RunspacePoolInitInfo> eventArgs) { RunspacePoolStateInfo newStateInfo = new RunspacePoolStateInfo(RunspacePoolState.Opened, null); bool flag = false; lock (base.syncObject) { base.minPoolSz = eventArgs.Data.MinRunspaces; base.maxPoolSz = eventArgs.Data.MaxRunspaces; if (base.stateInfo.State == RunspacePoolState.Connecting) { flag = true; this.SetRunspacePoolState(newStateInfo); } } if (flag) { base.RaiseStateChangeEvent(newStateInfo); this.SetOpenAsCompleted(); } }
/// <summary> /// Handles host responses /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">arguments describing this event</param> private void HandleHostResponseReceived(object sender, RemoteDataEventArgs<RemoteHostResponse> eventArgs) { _remoteHost.ServerMethodExecutor.HandleRemoteHostResponseFromClient((eventArgs.Data)); }
internal abstract void RaiseDataReceivedEvent(RemoteDataEventArgs arg);
/// <summary> /// Handle a host message response received. /// </summary> /// <param name="sender">Sender of this event, unused.</param> /// <param name="eventArgs">Arguments describing this event.</param> internal void HandleHostResponseReceived(object sender, RemoteDataEventArgs <RemoteHostResponse> eventArgs) { RemoteHost.ServerMethodExecutor.HandleRemoteHostResponseFromClient(eventArgs.Data); }
/// <summary> /// Sets the minimum runspace of the runspace pool and sends a response back /// </summary> /// <param name="sender">sender of this event, unused</param> /// <param name="eventArgs">contains information about the new minRunspaces /// and the callId at the client</param> private void HandleSetMinRunspacesReceived(object sender, RemoteDataEventArgs<PSObject> eventArgs) { PSObject data = eventArgs.Data; int minRunspaces = (int)((PSNoteProperty)data.Properties[RemoteDataNameStrings.MinRunspaces]).Value; long callId = (long)((PSNoteProperty)data.Properties[RemoteDataNameStrings.CallId]).Value; bool response = RunspacePool.SetMinRunspaces(minRunspaces); DataStructureHandler.SendResponseToClient(callId, response); }