internal static void Dispatch( BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream <ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, RemoteHostCall remoteHostCall) { ClientMethodExecutor clientMethodExecutor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); if (clientPowerShellId == Guid.Empty) { clientMethodExecutor.Execute(errorStream); } else if (remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled) { runspacePool.Close(); } else if (isMethodExecutorStreamEnabled) { methodExecutorStream.Write((object)clientMethodExecutor); } else { clientMethodExecutor.Execute(errorStream); } }
internal static void Dispatch(BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream <ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall) { ClientMethodExecutor executor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); if (clientPowerShellId == Guid.Empty) { executor.Execute(errorStream); } else { bool flag = false; if (clientHost != null) { PSObject privateData = clientHost.PrivateData; if (privateData != null) { PSNoteProperty property = privateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty; flag = ((property != null) && (property.Value is bool)) ? ((bool)property.Value) : false; } } if ((remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled) && !flag) { runspacePool.Close(); } else if (isMethodExecutorStreamEnabled) { methodExecutorStream.Write(executor); } else { executor.Execute(errorStream); } } }
/// <summary> /// Create a new ClientMethodExecutor object and then dispatch it. /// </summary> internal static void Dispatch( BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream <ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, RemoteHostCall remoteHostCall) { ClientMethodExecutor methodExecutor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); // If the powershell id is not specified, this message is for the runspace pool, execute // it immediately and return if (clientPowerShellId == Guid.Empty) { methodExecutor.Execute(errorStream); return; } // Check client host to see if SetShouldExit should be allowed bool hostAllowSetShouldExit = false; if (clientHost != null) { PSObject hostPrivateData = clientHost.PrivateData as PSObject; if (hostPrivateData != null) { PSNoteProperty allowSetShouldExit = hostPrivateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty; hostAllowSetShouldExit = allowSetShouldExit != null && allowSetShouldExit.Value is bool && (bool)allowSetShouldExit.Value; } } // Should we kill remote runspace? Check if "SetShouldExit" and if we are in the // cmdlet case. In the API case (when we are invoked from an API not a cmdlet) we // should not interpret "SetShouldExit" but should pass it on to the host. The // variable IsMethodExecutorStreamEnabled is only true in the cmdlet case. In the // API case it is false. if (remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled && !hostAllowSetShouldExit) { runspacePool.Close(); return; } // Cmdlet case: queue up the executor in the pipeline stream. if (isMethodExecutorStreamEnabled) { Dbg.Assert(methodExecutorStream != null, "method executor stream can't be null when enabled"); methodExecutorStream.Write(methodExecutor); } // API case: execute it immediately. else { methodExecutor.Execute(errorStream); } }
private static SqlLongString CreateData(IQuery query, byte[] data) { var lob = query.Session.CreateLargeObject(2048, true); using (var stream = new ObjectStream(lob)) { stream.Write(data, 0, data.Length); stream.Flush(); } lob.Complete(); return(SqlLongString.Ascii(lob)); }
static void Main(string[] args) { TestStruct test = new TestStruct(); test.Bar = 100; test.Foo = 200; using (MemoryStream ms = new MemoryStream()) { using (ObjectStream os = new ObjectStream(ms, false)) { os.Write(test); } ms.Seek(0, SeekOrigin.Begin); Console.WriteLine(BitConverter.ToString(ms.ToArray())); using (ObjectStream os = new ObjectStream(ms, false)) { TestStruct result = os.Read <TestStruct>(); Console.WriteLine(result.Bar); Console.WriteLine(result.Foo); } } Console.ReadLine(); }