Beispiel #1
0
        public static void AssertSuccess(Win32ErrorCode code)
        {
            switch (code)
            {
            case Win32ErrorCode.Success:
            case Win32ErrorCode.MORE_DATA:
                // No error occured, so exit gracefully.
                return;
            }

            var       genericException = new Win32Exception((int)code);
            Exception exceptionToThrow;

            // We will try to translate the generic Win32 exception to a more specific built-in exception.
            switch (code)
            {
            case Win32ErrorCode.DS_INVALID_DN_SYNTAX:
            case Win32ErrorCode.INVALID_PARAMETER:
                exceptionToThrow = new ArgumentException(genericException.Message, genericException);
                break;

            case Win32ErrorCode.FILE_NOT_FOUND:
                exceptionToThrow = new FileNotFoundException(genericException.Message, genericException);
                break;

            case Win32ErrorCode.ACCESS_DENIED:
            case Win32ErrorCode.DS_DRA_ACCESS_DENIED:
            case Win32ErrorCode.WRONG_PASSWORD:
            case Win32ErrorCode.PASSWORD_EXPIRED:
                exceptionToThrow = new UnauthorizedAccessException(genericException.Message, genericException);
                break;

            case Win32ErrorCode.NOT_ENOUGH_MEMORY:
            case Win32ErrorCode.OUTOFMEMORY:
            case Win32ErrorCode.DS_DRA_OUT_OF_MEM:
            case Win32ErrorCode.RPC_S_OUT_OF_RESOURCES:
                exceptionToThrow = new OutOfMemoryException(genericException.Message, genericException);
                break;

            case Win32ErrorCode.NO_LOGON_SERVERS:
            case Win32ErrorCode.NO_SUCH_DOMAIN:
            case Win32ErrorCode.RPC_S_SERVER_UNAVAILABLE:
            case Win32ErrorCode.RPC_S_CALL_FAILED:
                exceptionToThrow = new ActiveDirectoryServerDownException(genericException.Message, genericException);
                break;

            case Win32ErrorCode.DS_OBJ_NOT_FOUND:
            // This error code means either a non-existing DN or Access Denied.
            case Win32ErrorCode.DS_DRA_BAD_DN:
                exceptionToThrow = new DirectoryObjectNotFoundException(null, genericException);
                break;

            // TODO: Add translation for ActiveDirectoryOperationException and for other exception types.
            default:
                // We were not able to translate the Win32Exception to a more specific type.
                exceptionToThrow = genericException;
                break;
            }
            throw exceptionToThrow;
        }
Beispiel #2
0
        public static bool IsEqual(this ActiveDirectoryServerDownException @this, ActiveDirectoryServerDownException other)
        {
            // Name and ToString are different by design

            return(@this != null &&
                   other != null &&
                   // On full framework, line number may be method body start
                   // On Net Native we can't reflect on Exceptions and change its StackTrace
                   ((PlatformDetection.IsFullFramework || PlatformDetection.IsNetNative) ? true :
                    (@this.StackTrace == other.StackTrace)) &&
                   @this.Data.CheckSequenceEquals(other.Data) &&
                   @this.Source == other.Source &&
                   // On Net Native we can't reflect on Exceptions and change its HResult
                   (PlatformDetection.IsNetNative ? true : @this.HResult == other.HResult) &&
                   @this.HelpLink == other.HelpLink &&
                   CheckEquals(@this.InnerException, other.InnerException));
        }