private static void OnRemoteSessionDataReceived( IntPtr operationContext, int flags, IntPtr error, IntPtr shellOperationHandle, IntPtr commandOperationHandle, IntPtr operationHandle, IntPtr data) { BaseClientTransportManager.tracer.WriteLine("Client Session TM: OnRemoteDataReceived callback.", new object[0]); long sessnTMId = 0; WSManClientSessionTransportManager sessnTransportManager = (WSManClientSessionTransportManager)null; if (!WSManClientSessionTransportManager.TryGetSessionTransportManager(operationContext, out sessnTransportManager, out sessnTMId)) { BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Unable to find a transport manager for context {0}.", (object)sessnTMId), new object[0]); } else { sessnTransportManager.ClearReceiveOrSendResources(flags, false); if (sessnTransportManager.isClosed) { BaseClientTransportManager.tracer.WriteLine("Client Session TM: Transport manager is closed. So returning", new object[0]); } else if (!shellOperationHandle.Equals((object)sessnTransportManager.wsManShellOperationHandle)) { TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(new PSRemotingTransportException(PSRemotingErrorId.ReceiveExFailed, new object[0]), TransportMethodEnum.ReceiveShellOutputEx); sessnTransportManager.RaiseErrorHandler(eventArgs); } else { if (IntPtr.Zero != error) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) { BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Got error with error code {0}. Message {1}", (object)errorStruct.errorCode, (object)errorStruct.errorDetail), new object[0]); TransportErrorOccuredEventArgs eventArgs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, sessnTransportManager.wsManSessionHandle, errorStruct, TransportMethodEnum.ReceiveShellOutputEx, PSRemotingErrorId.ReceiveExCallBackError, (object)WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail)); sessnTransportManager.RaiseErrorHandler(eventArgs); return; } } WSManNativeApi.WSManReceiveDataResult receiveDataResult = WSManNativeApi.WSManReceiveDataResult.UnMarshal(data); if (receiveDataResult.data == null) { return; } BaseClientTransportManager.tracer.WriteLine("Session Received Data : {0}", (object)receiveDataResult.data.Length); BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManReceiveShellOutputExCallbackReceived, PSOpcode.Receive, PSTask.None, (object)sessnTransportManager.RunspacePoolInstanceId, (object)Guid.Empty, (object)receiveDataResult.data.Length.ToString((IFormatProvider)CultureInfo.InvariantCulture)); sessnTransportManager.ProcessRawData(receiveDataResult.data, receiveDataResult.stream); } } }
private static void OnCloseSessionCompleted( IntPtr operationContext, int flags, IntPtr error, IntPtr shellOperationHandle, IntPtr commandOperationHandle, IntPtr operationHandle, IntPtr data) { BaseClientTransportManager.tracer.WriteLine("Client Session TM: CloseShell callback received", new object[0]); long sessnTMId = 0; WSManClientSessionTransportManager sessnTransportManager = (WSManClientSessionTransportManager)null; if (!WSManClientSessionTransportManager.TryGetSessionTransportManager(operationContext, out sessnTransportManager, out sessnTMId)) { BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Unable to find a transport manager for context {0}.", (object)sessnTMId), new object[0]); } else { BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManCloseShellCallbackReceived, PSOpcode.Disconnect, PSTask.None, (object)sessnTransportManager.RunspacePoolInstanceId); if (IntPtr.Zero != error) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) { BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Got error with error code {0}. Message {1}", (object)errorStruct.errorCode, (object)errorStruct.errorDetail), new object[0]); TransportErrorOccuredEventArgs eventArgs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, sessnTransportManager.wsManSessionHandle, errorStruct, TransportMethodEnum.CloseShellOperationEx, PSRemotingErrorId.CloseExCallBackError, (object)WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail)); sessnTransportManager.RaiseErrorHandler(eventArgs); return; } } sessnTransportManager.RaiseCloseCompleted(); } }
private static void OnCreateSessionCompleted( IntPtr operationContext, int flags, IntPtr error, IntPtr shellOperationHandle, IntPtr commandOperationHandle, IntPtr operationHandle, IntPtr data) { BaseClientTransportManager.tracer.WriteLine("Client Session TM: CreateShell callback received", new object[0]); long sessnTMId = 0; WSManClientSessionTransportManager sessnTransportManager = (WSManClientSessionTransportManager)null; if (!WSManClientSessionTransportManager.TryGetSessionTransportManager(operationContext, out sessnTransportManager, out sessnTMId)) { BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Unable to find a transport manager for context {0}.", (object)sessnTMId), new object[0]); } else { BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManCreateShellCallbackReceived, PSOpcode.Connect, PSTask.None, (object)sessnTransportManager.RunspacePoolInstanceId); if (sessnTransportManager.createSessionCompleted != null) { sessnTransportManager.createSessionCompletedGCHandle.Free(); sessnTransportManager.createSessionCompleted.Dispose(); sessnTransportManager.createSessionCompleted = (WSManNativeApi.WSManShellAsync)null; } sessnTransportManager.wsManShellOperationHandle = shellOperationHandle; bool flag = false; lock (sessnTransportManager.syncObject) { sessnTransportManager.isCreateCallbackReceived = true; if (sessnTransportManager.isClosePending) { flag = true; } } if (flag) { sessnTransportManager.CloseAsync(); } else { if (IntPtr.Zero != error) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) { BaseClientTransportManager.tracer.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Got error with error code {0}. Message {1}", (object)errorStruct.errorCode, (object)errorStruct.errorDetail), new object[0]); TransportErrorOccuredEventArgs eventArgs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, sessnTransportManager.wsManSessionHandle, errorStruct, TransportMethodEnum.CreateShellEx, PSRemotingErrorId.ConnectExCallBackError, (object)WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail)); sessnTransportManager.RaiseErrorHandler(eventArgs); return; } } if (sessnTransportManager.openContent != null) { sessnTransportManager.openContent.Dispose(); sessnTransportManager.openContent = (WSManNativeApi.WSManData)null; } lock (sessnTransportManager.syncObject) { if (sessnTransportManager.isClosed) { BaseClientTransportManager.tracer.WriteLine("Client Session TM: Transport manager is closed. So returning", new object[0]); return; } sessnTransportManager.RaiseConnectCompleted(); BaseClientTransportManager.tracer.WriteLine("Client Session TM: Placing Receive request using WSManReceiveShellOutputEx", new object[0]); BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManReceiveShellOutputEx, PSOpcode.Receive, PSTask.None, (object)sessnTransportManager.RunspacePoolInstanceId, (object)Guid.Empty); sessnTransportManager.receivedFromRemote = new WSManNativeApi.WSManShellAsync(operationContext, WSManClientSessionTransportManager.sessionReceiveCallback); WSManNativeApi.WSManReceiveShellOutputEx(sessnTransportManager.wsManShellOperationHandle, IntPtr.Zero, 0, (IntPtr)WSManClientSessionTransportManager.wsManApiStaticData.OutputStreamSet, (IntPtr)sessnTransportManager.receivedFromRemote, ref sessnTransportManager.wsManRecieveOperationHandle); } sessnTransportManager.SendOneItem(); } } }