Beispiel #1
0
        internal static List <MoveHistoryEntryInternal> LoadMoveHistory(Guid mailboxGuid, Guid mdbGuid, UserMailboxFlags flags)
        {
            List <MoveHistoryEntryInternal> result;

            using (MapiStore userMailbox = MapiUtils.GetUserMailbox(mailboxGuid, mdbGuid, flags))
            {
                if (userMailbox == null)
                {
                    result = null;
                }
                else
                {
                    result = MoveHistoryEntryInternal.LoadMoveHistory(userMailbox);
                }
            }
            return(result);
        }
Beispiel #2
0
        public static MapiStore GetUserMailbox(Guid mailboxGuid, Guid mdbGuid, UserMailboxFlags umFlags)
        {
            OpenStoreFlag openStoreFlag = OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.NoLocalization | OpenStoreFlag.MailboxGuid;
            ConnectFlag   connectFlags  = ConnectFlag.UseAdminPrivilege | ConnectFlag.UseRpcContextPool | ConnectFlag.AllowLegacyStore;

            if (umFlags.HasFlag(UserMailboxFlags.RecoveryMDB))
            {
                openStoreFlag |= OpenStoreFlag.RestoreDatabase;
            }
            if (umFlags.HasFlag(UserMailboxFlags.Disconnected) || umFlags.HasFlag(UserMailboxFlags.SoftDeleted) || umFlags.HasFlag(UserMailboxFlags.MoveDestination))
            {
                openStoreFlag |= (OpenStoreFlag.OverrideHomeMdb | OpenStoreFlag.DisconnectedMailbox);
            }
            bool      flag = false;
            TimeSpan  localMailboxConnectionTimeout = TestIntegration.Instance.LocalMailboxConnectionTimeout;
            TimeSpan  localMailboxCallTimeout       = TestIntegration.Instance.LocalMailboxCallTimeout;
            MapiStore result;

            for (;;)
            {
                FindServerFlags findServerFlags = FindServerFlags.None;
                if (flag)
                {
                    findServerFlags |= FindServerFlags.ForceRediscovery;
                }
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, findServerFlags);
                try
                {
                    MrsTracer.Common.Debug("Opening MapiStore: serverFqdn=\"{0}\", mailboxGuid=\"{1}\", mdbGuid=\"{2}\", flags=[{3}].", new object[]
                    {
                        databaseInformation.ServerFqdn,
                        mailboxGuid,
                        mdbGuid,
                        openStoreFlag
                    });
                    MapiStore mapiStore = MapiStore.OpenMailbox(databaseInformation.ServerFqdn, Server.GetSystemAttendantLegacyDN(databaseInformation.ServerDN), mailboxGuid, mdbGuid, null, null, null, connectFlags, openStoreFlag, null, null, "Client=MSExchangeMigration", localMailboxConnectionTimeout, localMailboxCallTimeout, null);
                    MapiUtils.StartMapiDeadSessionChecking(mapiStore, mailboxGuid.ToString());
                    result = mapiStore;
                }
                catch (MapiExceptionWrongServer)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                catch (MapiExceptionLogonFailed)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                break;
            }
            return(result);
        }
        internal static List <MoveHistoryEntry> LoadMoveHistory(Guid mailboxGuid, Guid mdbGuid, bool includeMoveReport, UserMailboxFlags flags)
        {
            List <MoveHistoryEntryInternal> list = MoveHistoryEntryInternal.LoadMoveHistory(mailboxGuid, mdbGuid, flags);

            if (list == null || list.Count == 0)
            {
                return(null);
            }
            List <MoveHistoryEntry> list2 = new List <MoveHistoryEntry>(list.Count);

            foreach (MoveHistoryEntryInternal mhEntry in list)
            {
                list2.Add(new MoveHistoryEntry(mhEntry, includeMoveReport));
            }
            return(list2);
        }
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     foreach (Database database in this.databases)
     {
         try
         {
             Guid mailboxGuid = Guid.Empty;
             MailboxTableFlags mailboxTableFlags = MailboxTableFlags.MailboxTableFlagsNone;
             if (null != this.identity)
             {
                 mailboxGuid = this.identity.MailboxGuid;
             }
             if (this.isRunningMailboxStatisticsTask)
             {
                 mailboxTableFlags |= MailboxTableFlags.IncludeSoftDeletedMailbox;
             }
             QueryFilter filter = new MailboxContextFilter(mailboxGuid, (ulong)((long)mailboxTableFlags), this.NoADLookupForMailboxStatistics);
             IEnumerable <TPresentationObject> enumerable = this.mapiSession.FindPaged <TDataObject, TPresentationObject>(filter, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), QueryScope.SubTree, null, 0, 0);
             foreach (TPresentationObject tpresentationObject in enumerable)
             {
                 try
                 {
                     MailboxId mailboxId = tpresentationObject.Identity as MailboxId;
                     if (this.Identity == null || (null != mailboxId && ((Guid.Empty != this.identity.MailboxGuid && this.identity.MailboxGuid == mailboxId.MailboxGuid) || (!string.IsNullOrEmpty(this.identity.MailboxExchangeLegacyDn) && string.Equals(this.identity.MailboxExchangeLegacyDn, mailboxId.MailboxExchangeLegacyDn, StringComparison.OrdinalIgnoreCase)))))
                     {
                         if (this.isRunningLogonStatisticsTask)
                         {
                             ((LogonStatistics)((object)tpresentationObject)).ServerName   = database.ServerName;
                             ((LogonStatistics)((object)tpresentationObject)).DatabaseName = database.Name;
                         }
                         else if (this.isRunningResourceMonitorDigestTask)
                         {
                             ((MailboxResourceMonitor)((object)tpresentationObject)).ServerName           = this.server.Name;
                             ((MailboxResourceMonitor)((object)tpresentationObject)).DatabaseName         = database.Name;
                             ((MailboxResourceMonitor)((object)tpresentationObject)).IsDatabaseCopyActive = (database.Server.ObjectGuid == this.server.Guid);
                         }
                         else if (this.isRunningMailboxStatisticsTask)
                         {
                             Microsoft.Exchange.Management.MapiTasks.Presentation.MailboxStatistics mailboxStatistics = (Microsoft.Exchange.Management.MapiTasks.Presentation.MailboxStatistics)((object)tpresentationObject);
                             mailboxStatistics.ServerName           = this.server.Name;
                             mailboxStatistics.DatabaseName         = database.Name;
                             mailboxStatistics.Database             = database.Identity;
                             mailboxStatistics.IsDatabaseCopyActive = (database.Server.ObjectGuid == this.server.Guid);
                             MailboxDatabase mailboxDatabase = database as MailboxDatabase;
                             if (mailboxDatabase != null)
                             {
                                 mailboxStatistics.DatabaseIssueWarningQuota        = mailboxDatabase.IssueWarningQuota;
                                 mailboxStatistics.DatabaseProhibitSendQuota        = mailboxDatabase.ProhibitSendQuota;
                                 mailboxStatistics.DatabaseProhibitSendReceiveQuota = mailboxDatabase.ProhibitSendReceiveQuota;
                             }
                             if (mailboxId != null && this.GetMoveHistoryOption() != MoveHistoryOption.None)
                             {
                                 UserMailboxFlags userMailboxFlags = UserMailboxFlags.None;
                                 if (database.Recovery)
                                 {
                                     userMailboxFlags |= UserMailboxFlags.RecoveryMDB;
                                 }
                                 if (mailboxStatistics.IsMoveDestination ?? false)
                                 {
                                     userMailboxFlags |= UserMailboxFlags.MoveDestination;
                                 }
                                 else if (mailboxStatistics.DisconnectReason != null)
                                 {
                                     if (mailboxStatistics.DisconnectReason.Value == MailboxState.SoftDeleted)
                                     {
                                         userMailboxFlags |= UserMailboxFlags.SoftDeleted;
                                     }
                                     else
                                     {
                                         userMailboxFlags |= UserMailboxFlags.Disconnected;
                                     }
                                 }
                                 try
                                 {
                                     mailboxStatistics.MoveHistory = MoveHistoryEntry.LoadMoveHistory(mailboxId.MailboxGuid, database.Id.ObjectGuid, this.GetMoveHistoryOption() == MoveHistoryOption.IncludeMoveHistoryAndReport, userMailboxFlags);
                                 }
                                 catch (LocalizedException exception)
                                 {
                                     base.WriteError(exception, ErrorCategory.ResourceUnavailable, mailboxId);
                                 }
                             }
                         }
                         bool flag = true;
                         if (this.isRunningMailboxStatisticsTask)
                         {
                             Exception ex = null;
                             try
                             {
                                 QueryFilter internalFilter = this.InternalFilter;
                                 if (internalFilter != null && !OpathFilterEvaluator.FilterMatches(internalFilter, (Microsoft.Exchange.Data.Mapi.MailboxStatistics)((object)tpresentationObject)))
                                 {
                                     flag = false;
                                 }
                             }
                             catch (InvalidCastException ex2)
                             {
                                 ex = ex2;
                             }
                             catch (ParsingException ex3)
                             {
                                 ex = ex3;
                             }
                             catch (ArgumentOutOfRangeException ex4)
                             {
                                 ex = ex4;
                             }
                             if (ex != null)
                             {
                                 base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidMailboxStatisticsFilter(this.InternalFilter.ToString())), ErrorCategory.InvalidArgument, this.InternalFilter);
                             }
                         }
                         if (flag)
                         {
                             this.WriteResult(tpresentationObject);
                         }
                         if (this.Identity != null && this.isRunningMailboxStatisticsTask)
                         {
                             TaskLogger.LogExit();
                             return;
                         }
                     }
                 }
                 finally
                 {
                     if (tpresentationObject != null)
                     {
                         tpresentationObject.Dispose();
                     }
                 }
             }
         }
         catch (DatabaseUnavailableException ex5)
         {
             if (this.Identity == null && this.Database == null)
             {
                 base.WriteWarning(ex5.Message);
             }
             else
             {
                 base.WriteError(ex5, ErrorCategory.ResourceUnavailable, database);
             }
         }
         catch (MapiObjectNotFoundException exception2)
         {
             if (this.Identity == null || !this.isRunningMailboxStatisticsTask)
             {
                 base.WriteError(exception2, ErrorCategory.ObjectNotFound, this.Identity);
             }
         }
     }
     if (this.Identity != null && this.isRunningMailboxStatisticsTask)
     {
         TIdentity tidentity = this.Identity;
         this.WriteWarning(Strings.WarningMailboxNeverBeenLoggedOn(tidentity.ToString(), this.identity.ToString()));
     }
     TaskLogger.LogExit();
 }