private static void OnRemoteCmdSignalCompleted(
            IntPtr operationContext,
            int flags,
            IntPtr error,
            IntPtr shellOperationHandle,
            IntPtr commandOperationHandle,
            IntPtr operationHandle,
            IntPtr data)
        {
            BaseClientTransportManager.tracer.WriteLine("Signal Completed callback received.", new object[0]);
            long cmdTMId = 0;
            WSManClientCommandTransportManager cmdTransportManager = (WSManClientCommandTransportManager)null;

            if (!WSManClientCommandTransportManager.TryGetCmdTransportManager(operationContext, out cmdTransportManager, out cmdTMId))
            {
                BaseClientTransportManager.tracer.WriteLine("Unable to find a transport manager for the given command context {0}.", (object)cmdTMId);
            }
            else
            {
                BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManSignalCallbackReceived, PSOpcode.Disconnect, PSTask.None, (object)cmdTransportManager.RunspacePoolInstanceId, (object)cmdTransportManager.powershellInstanceId);
                if (!shellOperationHandle.Equals((object)cmdTransportManager.wsManShellOperationHandle) || !commandOperationHandle.Equals((object)cmdTransportManager.wsManCmdOperationHandle))
                {
                    BaseClientTransportManager.tracer.WriteLine("Cmd Signal callback: ShellOperationHandles are not the same as the signal is initiated with", new object[0]);
                    TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(new PSRemotingTransportException(PSRemotingErrorId.CommandSendExFailed, new object[0]), TransportMethodEnum.CommandInputEx);
                    cmdTransportManager.RaiseErrorHandler(eventArgs);
                }
                else
                {
                    if (IntPtr.Zero != cmdTransportManager.cmdSignalOperationHandle)
                    {
                        WSManNativeApi.WSManCloseOperation(cmdTransportManager.cmdSignalOperationHandle, 0);
                        cmdTransportManager.cmdSignalOperationHandle = IntPtr.Zero;
                    }
                    if (cmdTransportManager.signalCmdCompleted != null)
                    {
                        cmdTransportManager.signalCmdCompleted.Dispose();
                        cmdTransportManager.signalCmdCompleted = (WSManNativeApi.WSManShellAsync)null;
                    }
                    if (cmdTransportManager.isClosed)
                    {
                        BaseClientTransportManager.tracer.WriteLine("Client Command TM: Transport manager is closed. So returning", new object[0]);
                    }
                    else
                    {
                        if (IntPtr.Zero != error)
                        {
                            WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error);
                            if (errorStruct.errorCode != 0)
                            {
                                BaseClientTransportManager.tracer.WriteLine("Cmd Signal callback: WSMan reported an error: {0}", (object)errorStruct.errorDetail);
                                TransportErrorOccuredEventArgs eventArgs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, IntPtr.Zero, errorStruct, TransportMethodEnum.CommandInputEx, PSRemotingErrorId.CommandSendExCallBackError, (object)WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail));
                                cmdTransportManager.RaiseErrorHandler(eventArgs);
                                return;
                            }
                        }
                        cmdTransportManager.EnqueueAndStartProcessingThread((RemoteDataObject <PSObject>)null, (PSRemotingTransportException)null, (object)true);
                    }
                }
            }
        }
Beispiel #2
0
        private static void OnRemoteCmdSignalCompleted(IntPtr operationContext, int flags, IntPtr error, IntPtr shellOperationHandle, IntPtr commandOperationHandle, IntPtr operationHandle, IntPtr data)
        {
            BaseClientTransportManager.tracer.WriteLine("Signal Completed callback received.", new object[0]);
            long cmdTMId = 0L;
            WSManClientCommandTransportManager cmdTransportManager = null;

            if (!TryGetCmdTransportManager(operationContext, out cmdTransportManager, out cmdTMId))
            {
                BaseClientTransportManager.tracer.WriteLine("Unable to find a transport manager for the given command context {0}.", new object[] { cmdTMId });
            }
            else
            {
                PSEtwLog.LogAnalyticInformational(PSEventId.WSManSignalCallbackReceived, PSOpcode.Disconnect, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { cmdTransportManager.RunspacePoolInstanceId.ToString(), cmdTransportManager.powershellInstanceId.ToString() });
                if (!shellOperationHandle.Equals(cmdTransportManager.wsManShellOperationHandle) || !commandOperationHandle.Equals(cmdTransportManager.wsManCmdOperationHandle))
                {
                    BaseClientTransportManager.tracer.WriteLine("Cmd Signal callback: ShellOperationHandles are not the same as the signal is initiated with", new object[0]);
                    PSRemotingTransportException   e         = new PSRemotingTransportException(RemotingErrorIdStrings.CommandSendExFailed);
                    TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(e, TransportMethodEnum.CommandInputEx);
                    cmdTransportManager.ProcessWSManTransportError(eventArgs);
                }
                else
                {
                    if (IntPtr.Zero != cmdTransportManager.cmdSignalOperationHandle)
                    {
                        WSManNativeApi.WSManCloseOperation(cmdTransportManager.cmdSignalOperationHandle, 0);
                        cmdTransportManager.cmdSignalOperationHandle = IntPtr.Zero;
                    }
                    if (cmdTransportManager.signalCmdCompleted != null)
                    {
                        cmdTransportManager.signalCmdCompleted.Dispose();
                        cmdTransportManager.signalCmdCompleted = null;
                    }
                    if (cmdTransportManager.isClosed)
                    {
                        BaseClientTransportManager.tracer.WriteLine("Client Command TM: Transport manager is closed. So returning", new object[0]);
                    }
                    else
                    {
                        if (IntPtr.Zero != error)
                        {
                            WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error);
                            if (errorStruct.errorCode != 0)
                            {
                                BaseClientTransportManager.tracer.WriteLine("Cmd Signal callback: WSMan reported an error: {0}", new object[] { errorStruct.errorDetail });
                                TransportErrorOccuredEventArgs args2 = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, null, errorStruct, TransportMethodEnum.CommandInputEx, RemotingErrorIdStrings.CommandSendExCallBackError, new object[] { WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail) });
                                cmdTransportManager.ProcessWSManTransportError(args2);
                                return;
                            }
                        }
                        cmdTransportManager.EnqueueAndStartProcessingThread(null, null, true);
                    }
                }
            }
        }