Example #1
0
        internal static LocalizedException TranslateDirectoryException(LocalizedString exceptionMessage, LocalizedException exception, object thisObject, string traceMessage = "", params object[] traceMessageParameters)
        {
            LocalizedException ex;

            if (exception is ADNoSuchObjectException)
            {
                ex = new ObjectNotFoundException(exceptionMessage, exception);
            }
            else if (exception is DataValidationException || exception is DataConversionException || exception is NonUniqueRecipientException)
            {
                ex = new StoragePermanentException(exceptionMessage, exception);
            }
            else if (exception is ADTransientException || exception is ComputerNameNotCurrentlyAvailableException || exception is ADPossibleOperationException || exception is RusServerUnavailableException || exception is DataSourceTransientException)
            {
                ex = new StorageTransientException(exceptionMessage, exception);
            }
            else if (exception is ADOperationException || exception is ADObjectAlreadyExistsException || exception is ADFilterException || exception is ServerRoleOperationException || exception is RusOperationException || exception is NameConversionException || exception is GenerateUniqueLegacyDnException)
            {
                ex = new StoragePermanentException(exceptionMessage, exception);
            }
            else
            {
                if (!(exception is ADExternalException) && !(exception is CannotGetComputerNameException) && !(exception is CannotGetDomainInfoException) && !(exception is CannotGetSiteInfoException) && !(exception is CannotGetForestInfoException) && !(exception is LocalServerNotFoundException) && !(exception is DataSourceOperationException))
                {
                    throw new ArgumentException("exception is not a directory exception");
                }
                ex = new StoragePermanentException(exceptionMessage, exception);
            }
            if (ExTraceGlobals.StorageTracer.IsTraceEnabled(TraceType.ErrorTrace))
            {
                string arg = string.Format(CultureInfo.InvariantCulture, traceMessage, traceMessageParameters);
                ExTraceGlobals.StorageTracer.TraceError <string, LocalizedException>((long)((thisObject != null) ? thisObject.GetHashCode() : 0), "{0}. Throwing exception: {1}.", arg, ex);
            }
            return(ex);
        }
Example #2
0
        public static LocalizedException TranslateMapiException(LocalizedString exceptionMessage, LocalizedException exception, StoreSession session, object thisObject, string traceMessage, params object[] traceMessageParameters)
        {
            if (ExTraceGlobals.MapiConnectivityTracer.IsTraceEnabled(TraceType.ErrorTrace) && (exception is MapiExceptionBackupInProgress || exception is MapiExceptionNetworkError || exception is MapiExceptionEndOfSession || exception is MapiExceptionLogonFailed || exception is MapiExceptionExiting || exception is MapiExceptionRpcServerTooBusy || exception is MapiExceptionBusy))
            {
                Guid guid = (session == null) ? Guid.Empty : session.MdbGuid;
                ExTraceGlobals.MapiConnectivityTracer.TraceError((long)((thisObject != null) ? thisObject.GetHashCode() : 0), "MAPI exception: {0}\n\rClient: {1}\n\rServer: {2}\n\rMDB: {3}", new object[]
                {
                    exception.ToString(),
                    (session != null) ? session.ClientInfoString : null,
                    (session != null && !session.IsRemote) ? session.ServerFullyQualifiedDomainName : null,
                    guid
                });
            }
            LocalizedException ex = null;

            if (session != null && session.IsRemote)
            {
                if (exception is MapiExceptionBackupInProgress || exception is MapiExceptionNetworkError || exception is MapiExceptionEndOfSession || exception is MapiExceptionLogonFailed || exception is MapiExceptionExiting || exception is MapiExceptionRpcServerTooBusy || exception is MapiExceptionBusy || exception is MapiExceptionMailboxInTransit || exception is MapiExceptionNotEnoughDisk || exception is MapiExceptionNotEnoughResources || exception is MapiExceptionMdbOffline || exception is MapiExceptionServerPaused || exception is MapiExceptionMailboxDisabled || exception is MapiExceptionAccountDisabled || exception is MapiExceptionWrongMailbox || exception is MapiExceptionCorruptStore || exception is MapiExceptionNoAccess || exception is MapiExceptionNoSupport || exception is MapiExceptionNotAuthorized || exception is MapiExceptionPasswordChangeRequired || exception is MapiExceptionPasswordExpired || exception is MapiExceptionNoMoreConnections || exception is MapiExceptionWrongServer || exception is MapiExceptionSessionLimit || exception is MapiExceptionUnconfigured || exception is MapiExceptionUnknownUser || exception is MapiExceptionCallFailed)
                {
                    MailboxSession mailboxSession = session as MailboxSession;
                    string         text           = mailboxSession.MailboxOwner.MailboxInfo.RemoteIdentity.Value.ToString();
                    string         text2          = exception.ToString();
                    StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_XtcMapiError, text, new object[]
                    {
                        text,
                        text2
                    });
                    ExTraceGlobals.XtcTracer.TraceError <string, string>(0L, "The remote connection threw exception for user {0}. Exception: {1}", text, text2);
                }
            }
            else
            {
                ex = StorageGlobals.CheckHAState(exceptionMessage, exception, session);
            }
            if (ex == null)
            {
                if (exception is MapiExceptionBackupInProgress || exception is MapiExceptionNetworkError || exception is MapiExceptionEndOfSession || exception is MapiExceptionLogonFailed || exception is MapiExceptionExiting)
                {
                    ex = new ConnectionFailedTransientException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionMailboxInTransit)
                {
                    ex = new MailboxInTransitException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNotEnoughDisk || exception is MapiExceptionNotEnoughResources || exception is MapiExceptionBusy)
                {
                    ex = new ResourcesException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionObjectChanged)
                {
                    ex = new SaveConflictException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionCanNotComplete)
                {
                    ex = new CannotCompleteOperationException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionJetErrorCheckpointDepthTooDeep)
                {
                    ex = new CheckpointTooDeepException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionMdbOffline)
                {
                    ex = new MailboxOfflineException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionVirusScanInProgress)
                {
                    ex = new VirusScanInProgressException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionServerPaused)
                {
                    ex = new ServerPausedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionSearchEvaluationInProgress)
                {
                    ex = new QueryInProgressException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionGlobalCounterRangeExceeded)
                {
                    ex = new GlobalCounterRangeExceededException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionCorruptMidsetDeleted)
                {
                    ex = new CorruptMidsetDeletedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionMailboxDisabled || exception is MapiExceptionAccountDisabled || exception is MapiExceptionMailboxSoftDeleted)
                {
                    ex = new AccountDisabledException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionWrongMailbox || exception is MapiExceptionCorruptStore)
                {
                    ex = new ConnectionFailedPermanentException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNoAccess || exception is MapiExceptionNotAuthorized || exception is MapiExceptionPasswordChangeRequired || exception is MapiExceptionPasswordExpired || exception is MapiExceptionNoCreateRight || exception is MapiExceptionNoCreateSubfolderRight)
                {
                    ex = new AccessDeniedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionCorruptData)
                {
                    ex = new CorruptDataException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionQuotaExceeded || exception is MapiExceptionNamedPropsQuotaExceeded || exception is MapiExceptionShutoffQuotaExceeded)
                {
                    ex = new QuotaExceededException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionCollision)
                {
                    ex = new ObjectExistedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNotFound || exception is MapiExceptionInvalidEntryId || exception is MapiExceptionJetErrorRecordDeleted || exception is MapiExceptionObjectDeleted)
                {
                    ex = new ObjectNotFoundException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNoMoreConnections)
                {
                    ex = new NoMoreConnectionsException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionPartialCompletion)
                {
                    ex = new PartialCompletionException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionFolderCycle)
                {
                    ex = new FolderCycleException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionWrongServer)
                {
                    ex = new WrongServerException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionIllegalCrossServerConnection)
                {
                    ex = new IllegalCrossServerConnectionException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionInvalidRecipients)
                {
                    ex = new InvalidRecipientsException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionMessageTooBig)
                {
                    ex = new MessageTooBigException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionMaxSubmissionExceeded)
                {
                    ex = new MessageSubmissionExceededException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionMaxAttachmentExceeded)
                {
                    ex = new AttachmentExceededException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionVirusDetected)
                {
                    ex = new VirusDetectedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionVirusMessageDeleted)
                {
                    ex = new VirusMessageDeletedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNotInitialized)
                {
                    ex = new ObjectNotInitializedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionSendAsDenied)
                {
                    ex = new SendAsDeniedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionSessionLimit)
                {
                    ex = new TooManyObjectsOpenedException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionJetErrorTooManyOpenTablesAndCleanupTimedOut)
                {
                    ex = new ServerCleanupTimedOutException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionJetErrorInvalidLanguageId)
                {
                    ex = new InvalidFolderLanguageIdException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionEventsDeleted)
                {
                    ex = new EventNotFoundException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionUnconfigured)
                {
                    ex = new MailboxUnavailableException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionUnknownUser)
                {
                    ex = new MailboxUnavailableException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNoReplicaHere)
                {
                    ex = new NoReplicaHereException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNoReplicaAvailable)
                {
                    ex = new NoReplicaException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionConditionViolation)
                {
                    ex = new FolderSaveConditionViolationException(exceptionMessage, exception);
                }
                else if (exception is MapiExceptionNoSupport)
                {
                    ex = new NoSupportException(exceptionMessage, exception);
                }
                else if (exception is MapiPermanentException)
                {
                    ex = new StoragePermanentException(exceptionMessage, exception);
                }
                else if (exception is MapiRetryableException)
                {
                    ex = new StorageTransientException(exceptionMessage, exception);
                }
                else
                {
                    if (!(exception is MapiExceptionCallFailed))
                    {
                        throw new ArgumentException("Exception is not of type MapiException");
                    }
                    ex = new StoragePermanentException(exceptionMessage, exception);
                }
            }
            if (ExTraceGlobals.StorageTracer.IsTraceEnabled(TraceType.ErrorTrace))
            {
                string arg = string.Format(traceMessage, traceMessageParameters);
                ExTraceGlobals.StorageTracer.TraceError <string, LocalizedException>((long)((thisObject != null) ? thisObject.GetHashCode() : 0), "{0}. Throwing exception: {1}.", arg, ex);
            }
            return(ex);
        }