示例#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));
        }
示例#2
0
        internal static string WSManGetSessionOptionAsString(
            IntPtr wsManAPIHandle,
            WSManNativeApi.WSManSessionOption option)
        {
            string str = "";
            int    optionLengthUsed = 0;

            if (122 != WSManNativeApi.WSManGetSessionOptionAsString(wsManAPIHandle, option, 0, (byte[])null, out optionLengthUsed))
            {
                return(str);
            }
            byte[] numArray = new byte[optionLengthUsed * 2];
            if (WSManNativeApi.WSManGetSessionOptionAsString(wsManAPIHandle, option, optionLengthUsed * 2, numArray, out int _) != 0)
            {
                return(str);
            }
            try
            {
                str = Encoding.Unicode.GetString(numArray);
            }
            catch (ArgumentNullException ex)
            {
            }
            catch (DecoderFallbackException ex)
            {
            }
            return(str);
        }