Ejemplo n.º 1
0
 internal static TransportErrorOccuredEventArgs ConstructTransportErrorEventArgs(IntPtr wsmanAPIHandle, WSManClientSessionTransportManager wsmanSessionTM, WSManNativeApi.WSManError errorStruct, TransportMethodEnum transportMethodReportingError, string resourceString, params object[] resourceArgs)
 {
     PSRemotingTransportException exception;
     if ((errorStruct.errorCode == -2144108135) && (wsmanSessionTM != null))
     {
         string redirectLocation = WSManNativeApi.WSManGetSessionOptionAsString(wsmanSessionTM.SessionHandle, WSManNativeApi.WSManSessionOption.WSMAN_OPTION_REDIRECT_LOCATION);
         string str2 = ParseEscapeWSManErrorMessage(WSManNativeApi.WSManGetErrorMessage(wsmanAPIHandle, errorStruct.errorCode)).Trim();
         exception = new PSRemotingTransportRedirectException(redirectLocation, PSRemotingErrorId.URIEndPointNotResolved, RemotingErrorIdStrings.URIEndPointNotResolved, new object[] { str2, redirectLocation });
     }
     else if ((errorStruct.errorCode == -2144108485) && (wsmanSessionTM != null))
     {
         string str3 = wsmanSessionTM.ConnectionInfo.ShellUri.Replace("http://schemas.microsoft.com/powershell/", string.Empty);
         string str4 = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.InvalidConfigurationName, new object[] { str3, wsmanSessionTM.ConnectionInfo.ComputerName });
         exception = new PSRemotingTransportException(PSRemotingErrorId.InvalidConfigurationName, RemotingErrorIdStrings.ConnectExCallBackError, new object[] { wsmanSessionTM.ConnectionInfo.ComputerName, str4 }) {
             TransportMessage = ParseEscapeWSManErrorMessage(WSManNativeApi.WSManGetErrorMessage(wsmanAPIHandle, errorStruct.errorCode))
         };
     }
     else
     {
         string str5 = PSRemotingErrorInvariants.FormatResourceString(resourceString, resourceArgs);
         exception = new PSRemotingTransportException(PSRemotingErrorId.TroubleShootingHelpTopic, RemotingErrorIdStrings.TroubleShootingHelpTopic, new object[] { str5 }) {
             TransportMessage = ParseEscapeWSManErrorMessage(WSManNativeApi.WSManGetErrorMessage(wsmanAPIHandle, errorStruct.errorCode))
         };
     }
     exception.ErrorCode = errorStruct.errorCode;
     return new TransportErrorOccuredEventArgs(exception, transportMethodReportingError);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handler which handles transport errors.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void HandleTransportError(object sender, TransportErrorOccuredEventArgs e)
        {
            Dbg.Assert(e != null, "HandleTransportError expects non-null eventargs");
            // handle uri redirections
            PSRemotingTransportRedirectException redirectException = e.Exception as PSRemotingTransportRedirectException;

            if ((redirectException != null) && (_maxUriRedirectionCount > 0))
            {
                Exception exception = null;

                try
                {
                    // honor max redirection count given by the user.
                    _maxUriRedirectionCount--;
                    PerformURIRedirection(redirectException.RedirectLocation);
                    return;
                }
                catch (ArgumentNullException argumentException)
                {
                    exception = argumentException;
                }
                catch (UriFormatException uriFormatException)
                {
                    exception = uriFormatException;
                }
                // if we are here, there must be an exception constructing a uri
                if (exception != null)
                {
                    PSRemotingTransportException newException =
                        new PSRemotingTransportException(PSRemotingErrorId.RedirectedURINotWellFormatted, RemotingErrorIdStrings.RedirectedURINotWellFormatted,
                                                         _session.Context.RemoteAddress.OriginalString,
                                                         redirectException.RedirectLocation);
                    newException.TransportMessage = e.Exception.TransportMessage;
                    e.Exception = newException;
                }
            }

            RemoteSessionEvent sessionEvent = RemoteSessionEvent.ConnectFailed;

            switch (e.ReportingTransportMethod)
            {
            case TransportMethodEnum.CreateShellEx:
                sessionEvent = RemoteSessionEvent.ConnectFailed;
                break;

            case TransportMethodEnum.SendShellInputEx:
            case TransportMethodEnum.CommandInputEx:
                sessionEvent = RemoteSessionEvent.SendFailed;
                break;

            case TransportMethodEnum.ReceiveShellOutputEx:
            case TransportMethodEnum.ReceiveCommandOutputEx:
                sessionEvent = RemoteSessionEvent.ReceiveFailed;
                break;

            case TransportMethodEnum.CloseShellOperationEx:
                sessionEvent = RemoteSessionEvent.CloseFailed;
                break;

            case TransportMethodEnum.DisconnectShellEx:
                sessionEvent = RemoteSessionEvent.DisconnectFailed;
                break;

            case TransportMethodEnum.ReconnectShellEx:
                sessionEvent = RemoteSessionEvent.ReconnectFailed;
                break;
            }

            RemoteSessionStateMachineEventArgs errorArgs =
                new RemoteSessionStateMachineEventArgs(sessionEvent, e.Exception);

            _stateMachine.RaiseEvent(errorArgs);
        }
Ejemplo n.º 3
0
        internal void HandleTransportError(object sender, TransportErrorOccuredEventArgs e)
        {
            PSRemotingTransportRedirectException exception = e.Exception as PSRemotingTransportRedirectException;

            if ((exception != null) && (this.maxUriRedirectionCount > 0))
            {
                Exception exception2 = null;
                try
                {
                    this.maxUriRedirectionCount--;
                    this.PerformURIRedirection(exception.RedirectLocation);
                    return;
                }
                catch (ArgumentNullException exception3)
                {
                    exception2 = exception3;
                }
                catch (UriFormatException exception4)
                {
                    exception2 = exception4;
                }
                if (exception2 != null)
                {
                    PSRemotingTransportException exception5 = new PSRemotingTransportException(PSRemotingErrorId.RedirectedURINotWellFormatted, RemotingErrorIdStrings.RedirectedURINotWellFormatted, new object[] { this._session.Context.RemoteAddress.OriginalString, exception.RedirectLocation })
                    {
                        TransportMessage = e.Exception.TransportMessage
                    };
                    e.Exception = exception5;
                }
            }
            RemoteSessionEvent connectFailed = RemoteSessionEvent.ConnectFailed;

            switch (e.ReportingTransportMethod)
            {
            case TransportMethodEnum.CreateShellEx:
                connectFailed = RemoteSessionEvent.ConnectFailed;
                break;

            case TransportMethodEnum.SendShellInputEx:
            case TransportMethodEnum.CommandInputEx:
                connectFailed = RemoteSessionEvent.SendFailed;
                break;

            case TransportMethodEnum.ReceiveShellOutputEx:
            case TransportMethodEnum.ReceiveCommandOutputEx:
                connectFailed = RemoteSessionEvent.ReceiveFailed;
                break;

            case TransportMethodEnum.CloseShellOperationEx:
                connectFailed = RemoteSessionEvent.CloseFailed;
                break;

            case TransportMethodEnum.DisconnectShellEx:
                connectFailed = RemoteSessionEvent.DisconnectFailed;
                break;

            case TransportMethodEnum.ReconnectShellEx:
                connectFailed = RemoteSessionEvent.ReconnectFailed;
                break;
            }
            RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(connectFailed, e.Exception);

            this._stateMachine.RaiseEvent(arg, false);
        }