Esempio n. 1
0
        internal static Exception GetExceptionFromCOMException(DirectoryContext?context, 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)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)0x80071392))
            {
                //
                // Object already exists
                //
                exception = new ActiveDirectoryObjectExistsException(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)))
            {
                //
                // ServerDown/Unavailable/Busy
                //

                if (context != null)
                {
                    exception = new ActiveDirectoryServerDownException(errorMessage, e, errorCode, context.GetServerName());
                }
                else
                {
                    exception = new ActiveDirectoryServerDownException(errorMessage, e, errorCode, null);
                }
            }
            else
            {
                //
                // Wrap the exception in a generic OperationException
                //
                exception = new ActiveDirectoryOperationException(errorMessage, e, errorCode);
            }

            return(exception);
        }
Esempio n. 2
0
        internal static Exception GetExceptionFromCOMException(DirectoryContext context, 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)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)0x80071392))
            {
                //
                // Object already exists
                //
                exception = new ActiveDirectoryObjectExistsException(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)))
            {
                //
                // ServerDown/Unavailable/Busy
                //

                if (context != null)
                {
                    exception = new ActiveDirectoryServerDownException(errorMessage, e, errorCode, context.GetServerName());
                }
                else
                {
                    exception = new ActiveDirectoryServerDownException(errorMessage, e, errorCode, null);
                }
            }
            else
            {
                //
                // Wrap the exception in a generic OperationException
                //
                exception = new ActiveDirectoryOperationException(errorMessage, e, errorCode);
            }

            return exception;
        }
Esempio n. 3
0
        internal static Exception GetExceptionFromCOMException(DirectoryContext context, COMException e)
        {
            Exception activeDirectoryServerDownException;
            int       errorCode = e.ErrorCode;
            string    message   = e.Message;

            if (errorCode != -2147024891)
            {
                if (errorCode != -2147023570)
                {
                    if (errorCode != -2147016657)
                    {
                        if (errorCode != -2147016651)
                        {
                            if (errorCode != -2147019886)
                            {
                                if (errorCode != -2147024888)
                                {
                                    if (errorCode == -2147016646 || errorCode == -2147016690 || errorCode == -2147016689)
                                    {
                                        if (context == null)
                                        {
                                            activeDirectoryServerDownException = new ActiveDirectoryServerDownException(message, e, errorCode, null);
                                        }
                                        else
                                        {
                                            activeDirectoryServerDownException = new ActiveDirectoryServerDownException(message, e, errorCode, context.GetServerName());
                                        }
                                    }
                                    else
                                    {
                                        activeDirectoryServerDownException = new ActiveDirectoryOperationException(message, e, errorCode);
                                    }
                                }
                                else
                                {
                                    activeDirectoryServerDownException = new OutOfMemoryException();
                                }
                            }
                            else
                            {
                                activeDirectoryServerDownException = new ActiveDirectoryObjectExistsException(message, e);
                            }
                        }
                        else
                        {
                            activeDirectoryServerDownException = new InvalidOperationException(message, e);
                        }
                    }
                    else
                    {
                        activeDirectoryServerDownException = new InvalidOperationException(message, e);
                    }
                }
                else
                {
                    activeDirectoryServerDownException = new AuthenticationException(message, e);
                }
            }
            else
            {
                activeDirectoryServerDownException = new UnauthorizedAccessException(message, e);
            }
            return(activeDirectoryServerDownException);
        }
Esempio n. 4
0
		internal static Exception GetExceptionFromCOMException(DirectoryContext context, COMException e)
		{
			Exception activeDirectoryServerDownException;
			int errorCode = e.ErrorCode;
			string message = e.Message;
			if (errorCode != -2147024891)
			{
				if (errorCode != -2147023570)
				{
					if (errorCode != -2147016657)
					{
						if (errorCode != -2147016651)
						{
							if (errorCode != -2147019886)
							{
								if (errorCode != -2147024888)
								{
									if (errorCode == -2147016646 || errorCode == -2147016690 || errorCode == -2147016689)
									{
										if (context == null)
										{
											activeDirectoryServerDownException = new ActiveDirectoryServerDownException(message, e, errorCode, null);
										}
										else
										{
											activeDirectoryServerDownException = new ActiveDirectoryServerDownException(message, e, errorCode, context.GetServerName());
										}
									}
									else
									{
										activeDirectoryServerDownException = new ActiveDirectoryOperationException(message, e, errorCode);
									}
								}
								else
								{
									activeDirectoryServerDownException = new OutOfMemoryException();
								}
							}
							else
							{
								activeDirectoryServerDownException = new ActiveDirectoryObjectExistsException(message, e);
							}
						}
						else
						{
							activeDirectoryServerDownException = new InvalidOperationException(message, e);
						}
					}
					else
					{
						activeDirectoryServerDownException = new InvalidOperationException(message, e);
					}
				}
				else
				{
					activeDirectoryServerDownException = new AuthenticationException(message, e);
				}
			}
			else
			{
				activeDirectoryServerDownException = new UnauthorizedAccessException(message, e);
			}
			return activeDirectoryServerDownException;
		}