示例#1
0
        // public static uint ERROR_LDAP_INVALID_CREDENTIALS = 49; //fix error CS0414: Warning as Error: is assigned but its value is never used
        //
        // This method maps some common COM Hresults to
        // existing clr exceptions
        //

        internal static Exception GetExceptionFromCOMException(COMException e)
        {
            Exception exception;
            int errorCode = e.ErrorCode;
            string errorMessage = e.Message;

            //
            // Check if we can throw a more specific exception
            //
            if (errorCode == unchecked((int)0x80070005))
            {
                //
                // Access Denied
                //
                exception = new UnauthorizedAccessException(errorMessage, e);
            }
            else if (errorCode == unchecked((int)0x800708c5) || errorCode == unchecked((int)0x80070056) || errorCode == unchecked((int)0x8007052))
            {
                //
                // Password does not meet complexity requirements or old password does not match or policy restriction has been enforced.
                //
                exception = new PasswordException(errorMessage, e);
            }
            else if (errorCode == unchecked((int)0x800708b0) || errorCode == unchecked((int)0x80071392))
            {
                //
                // Principal already exists
                //
                exception = new PrincipalExistsException(errorMessage, e);
            }
            else if (errorCode == unchecked((int)0x8007052e))
            {
                //
                // Logon Failure
                //
                exception = new AuthenticationException(errorMessage, e);
            }
            else if (errorCode == unchecked((int)0x8007202f))
            {
                //
                // Constraint Violation
                //
                exception = new InvalidOperationException(errorMessage, e);
            }
            else if (errorCode == unchecked((int)0x80072035))
            {
                //
                // Unwilling to perform
                //
                exception = new InvalidOperationException(errorMessage, e);
            }
            else if (errorCode == unchecked((int)0x80070008))
            {
                //
                // No Memory
                //
                exception = new OutOfMemoryException();
            }
            else if ((errorCode == unchecked((int)0x8007203a)) || (errorCode == unchecked((int)0x8007200e)) || (errorCode == unchecked((int)0x8007200f)))
            {
                exception = new PrincipalServerDownException(errorMessage, e, errorCode, null);
            }
            else
            {
                //
                // Wrap the exception in a generic OperationException
                //
                exception = new PrincipalOperationException(errorMessage, e, errorCode);
            }

            return exception;
        }
示例#2
0
		internal static Exception GetExceptionFromCOMException(COMException e)
		{
			Exception passwordException;
			int errorCode = e.ErrorCode;
			string message = e.Message;
			if (errorCode != -2147024891)
			{
				if (errorCode == -2147022651 || errorCode == -2147024810 || errorCode == 0x8007052)
				{
					passwordException = new PasswordException(message, e);
				}
				else
				{
					if (errorCode == -2147022672 || errorCode == -2147019886)
					{
						passwordException = new PrincipalExistsException(message, e);
					}
					else
					{
						if (errorCode != -2147023570)
						{
							if (errorCode != -2147016657)
							{
								if (errorCode != -2147016651)
								{
									if (errorCode != -2147024888)
									{
										if (errorCode == -2147016646 || errorCode == -2147016690 || errorCode == -2147016689)
										{
											passwordException = new PrincipalServerDownException(message, e, errorCode, null);
										}
										else
										{
											passwordException = new PrincipalOperationException(message, e, errorCode);
										}
									}
									else
									{
										passwordException = new OutOfMemoryException();
									}
								}
								else
								{
									passwordException = new InvalidOperationException(message, e);
								}
							}
							else
							{
								passwordException = new InvalidOperationException(message, e);
							}
						}
						else
						{
							passwordException = new AuthenticationException(message, e);
						}
					}
				}
			}
			else
			{
				passwordException = new UnauthorizedAccessException(message, e);
			}
			return passwordException;
		}
示例#3
0
        // public const uint ERROR_LDAP_INVALID_CREDENTIALS = 49; //fix error CS0414: Warning as Error: is assigned but its value is never used
        //
        // This method maps some common COM Hresults to
        // existing clr exceptions
        //

        internal static Exception GetExceptionFromCOMException(COMException e)
        {
            Exception exception;
            int       errorCode    = e.ErrorCode;
            string    errorMessage = e.Message;

            //
            // Check if we can throw a more specific exception
            //
            if (errorCode == unchecked ((int)0x80070005))
            {
                //
                // Access Denied
                //
                exception = new UnauthorizedAccessException(errorMessage, e);
            }
            else if (errorCode == unchecked ((int)0x800708c5) || errorCode == unchecked ((int)0x80070056) || errorCode == unchecked ((int)0x8007052))
            {
                //
                // Password does not meet complexity requirements or old password does not match or policy restriction has been enforced.
                //
                exception = new PasswordException(errorMessage, e);
            }
            else if (errorCode == unchecked ((int)0x800708b0) || errorCode == unchecked ((int)0x80071392))
            {
                //
                // Principal already exists
                //
                exception = new PrincipalExistsException(errorMessage, e);
            }
            else if (errorCode == unchecked ((int)0x8007052e))
            {
                //
                // Logon Failure
                //
                exception = new AuthenticationException(errorMessage, e);
            }
            else if (errorCode == unchecked ((int)0x8007202f))
            {
                //
                // Constraint Violation
                //
                exception = new InvalidOperationException(errorMessage, e);
            }
            else if (errorCode == unchecked ((int)0x80072035))
            {
                //
                // Unwilling to perform
                //
                exception = new InvalidOperationException(errorMessage, e);
            }
            else if (errorCode == unchecked ((int)0x80070008))
            {
                //
                // No Memory
                //
                exception = new OutOfMemoryException();
            }
            else if ((errorCode == unchecked ((int)0x8007203a)) || (errorCode == unchecked ((int)0x8007200e)) || (errorCode == unchecked ((int)0x8007200f)))
            {
                exception = new PrincipalServerDownException(errorMessage, e, errorCode, null);
            }
            else
            {
                //
                // Wrap the exception in a generic OperationException
                //
                exception = new PrincipalOperationException(errorMessage, e, errorCode);
            }

            return(exception);
        }
示例#4
0
        internal static Exception GetExceptionFromCOMException(COMException e)
        {
            Exception passwordException;
            int       errorCode = e.ErrorCode;
            string    message   = e.Message;

            if (errorCode != -2147024891)
            {
                if (errorCode == -2147022651 || errorCode == -2147024810 || errorCode == 0x8007052)
                {
                    passwordException = new PasswordException(message, e);
                }
                else
                {
                    if (errorCode == -2147022672 || errorCode == -2147019886)
                    {
                        passwordException = new PrincipalExistsException(message, e);
                    }
                    else
                    {
                        if (errorCode != -2147023570)
                        {
                            if (errorCode != -2147016657)
                            {
                                if (errorCode != -2147016651)
                                {
                                    if (errorCode != -2147024888)
                                    {
                                        if (errorCode == -2147016646 || errorCode == -2147016690 || errorCode == -2147016689)
                                        {
                                            passwordException = new PrincipalServerDownException(message, e, errorCode, null);
                                        }
                                        else
                                        {
                                            passwordException = new PrincipalOperationException(message, e, errorCode);
                                        }
                                    }
                                    else
                                    {
                                        passwordException = new OutOfMemoryException();
                                    }
                                }
                                else
                                {
                                    passwordException = new InvalidOperationException(message, e);
                                }
                            }
                            else
                            {
                                passwordException = new InvalidOperationException(message, e);
                            }
                        }
                        else
                        {
                            passwordException = new AuthenticationException(message, e);
                        }
                    }
                }
            }
            else
            {
                passwordException = new UnauthorizedAccessException(message, e);
            }
            return(passwordException);
        }