internal static RequestStatisticsBase CreateRequestStatistics(Type t, RequestJobXML rj, bool acceptBase) { RequestStatisticsBase requestStatisticsBase = null; if (t.Equals(typeof(MoveRequestStatistics))) { requestStatisticsBase = new MoveRequestStatistics(rj); } else if (t.Equals(typeof(MergeRequestStatistics))) { requestStatisticsBase = new MergeRequestStatistics(rj); } else if (t.Equals(typeof(MailboxImportRequestStatistics))) { requestStatisticsBase = new MailboxImportRequestStatistics(rj); } else if (t.Equals(typeof(MailboxExportRequestStatistics))) { requestStatisticsBase = new MailboxExportRequestStatistics(rj); } else if (t.Equals(typeof(MailboxRelocationRequestStatistics))) { requestStatisticsBase = new MailboxRelocationRequestStatistics(rj); } else if (t.Equals(typeof(MailboxRestoreRequestStatistics))) { requestStatisticsBase = new MailboxRestoreRequestStatistics(rj); } else if (t.Equals(typeof(PublicFolderMoveRequestStatistics))) { requestStatisticsBase = new PublicFolderMoveRequestStatistics(rj); } else if (t.Equals(typeof(PublicFolderMigrationRequestStatistics))) { requestStatisticsBase = new PublicFolderMigrationRequestStatistics(rj); } else if (t.Equals(typeof(PublicFolderMailboxMigrationRequestStatistics))) { requestStatisticsBase = new PublicFolderMailboxMigrationRequestStatistics(rj); } else if (t.Equals(typeof(SyncRequestStatistics))) { requestStatisticsBase = new SyncRequestStatistics(rj); } else if (t.Equals(typeof(FolderMoveRequestStatistics))) { requestStatisticsBase = new FolderMoveRequestStatistics(rj); } else if (acceptBase && t.Equals(typeof(RequestStatisticsBase))) { return(RequestJobProvider.CreateRequestStatistics(rj)); } if (requestStatisticsBase != null) { rj.Retire(); } return(requestStatisticsBase); }
internal static RequestStatisticsBase CreateRequestStatistics(RequestJobXML rj) { RequestStatisticsBase requestStatisticsBase = null; switch (rj.RequestType) { case MRSRequestType.Move: requestStatisticsBase = new MoveRequestStatistics(rj); break; case MRSRequestType.Merge: requestStatisticsBase = new MergeRequestStatistics(rj); break; case MRSRequestType.MailboxImport: requestStatisticsBase = new MailboxImportRequestStatistics(rj); break; case MRSRequestType.MailboxExport: requestStatisticsBase = new MailboxExportRequestStatistics(rj); break; case MRSRequestType.MailboxRestore: requestStatisticsBase = new MailboxRestoreRequestStatistics(rj); break; case MRSRequestType.PublicFolderMove: requestStatisticsBase = new PublicFolderMoveRequestStatistics(rj); break; case MRSRequestType.PublicFolderMigration: requestStatisticsBase = new PublicFolderMigrationRequestStatistics(rj); break; case MRSRequestType.Sync: requestStatisticsBase = new SyncRequestStatistics(rj); break; case MRSRequestType.MailboxRelocation: requestStatisticsBase = new MailboxRelocationRequestStatistics(rj); break; case MRSRequestType.FolderMove: requestStatisticsBase = new FolderMoveRequestStatistics(rj); break; case MRSRequestType.PublicFolderMailboxMigration: requestStatisticsBase = new PublicFolderMailboxMigrationRequestStatistics(rj); break; } if (requestStatisticsBase != null) { rj.Retire(); } return(requestStatisticsBase); }
internal static RequestStatisticsBase CreateRequestStatistics(TransactionalRequestJob rj) { RequestStatisticsBase result = null; switch (rj.RequestType) { case MRSRequestType.Move: result = new MoveRequestStatistics(rj); break; case MRSRequestType.Merge: result = new MergeRequestStatistics(rj); break; case MRSRequestType.MailboxImport: result = new MailboxImportRequestStatistics(rj); break; case MRSRequestType.MailboxExport: result = new MailboxExportRequestStatistics(rj); break; case MRSRequestType.MailboxRestore: result = new MailboxRestoreRequestStatistics(rj); break; case MRSRequestType.PublicFolderMove: result = new PublicFolderMoveRequestStatistics(rj); break; case MRSRequestType.PublicFolderMigration: result = new PublicFolderMigrationRequestStatistics(rj); break; case MRSRequestType.Sync: result = new SyncRequestStatistics(rj); break; case MRSRequestType.MailboxRelocation: result = new MailboxRelocationRequestStatistics(rj); break; case MRSRequestType.FolderMove: result = new FolderMoveRequestStatistics(rj); break; case MRSRequestType.PublicFolderMailboxMigration: result = new PublicFolderMailboxMigrationRequestStatistics(rj); break; } return(result); }
internal static void ValidateRequestJob(RequestJobBase requestJob) { if (requestJob.IsFake || requestJob.WorkItemQueueMdb == null) { requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMissing); requestJob.ValidationMessage = MrsStrings.ValidationMoveRequestNotDeserialized; return; } if (requestJob.OriginatingMDBGuid != Guid.Empty && requestJob.OriginatingMDBGuid != requestJob.WorkItemQueueMdb.ObjectGuid) { requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.Orphaned); requestJob.ValidationMessage = MrsStrings.ValidationMoveRequestInWrongMDB(requestJob.OriginatingMDBGuid, requestJob.WorkItemQueueMdb.ObjectGuid); return; } if (requestJob.OriginatingMDBGuid == Guid.Empty) { requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.Valid); requestJob.ValidationMessage = LocalizedString.Empty; return; } MoveRequestStatistics.LoadAdditionalPropertiesFromUser(requestJob); if (requestJob.CancelRequest || requestJob.Status == RequestStatus.Completed || requestJob.Status == RequestStatus.CompletedWithWarning) { requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.Valid); requestJob.ValidationMessage = LocalizedString.Empty; return; } if (!requestJob.ValidateUser(requestJob.User, requestJob.UserId)) { return; } Guid guid; Guid guid2; RequestIndexEntryProvider.GetMoveGuids(requestJob.User, out guid, out guid2); if (guid != requestJob.ExchangeGuid) { MrsTracer.Common.Error("Orphaned RequestJob: mailbox guid does not match between AD {0} and workitem queue {1}.", new object[] { requestJob.User.ExchangeGuid, requestJob.ExchangeGuid }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMismatch); requestJob.ValidationMessage = MrsStrings.ValidationMailboxGuidsDontMatch(guid, requestJob.ExchangeGuid); return; } if (requestJob.User.MailboxMoveStatus == RequestStatus.None) { MrsTracer.Common.Warning("Orphaned RequestJob: AD user {0} is not being moved.", new object[] { requestJob.User.ToString() }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.Orphaned); requestJob.ValidationMessage = MrsStrings.ValidationADUserIsNotBeingMoved; return; } if (requestJob.Flags != requestJob.User.MailboxMoveFlags) { if ((requestJob.Flags & RequestJobBase.StaticFlags) != (requestJob.User.MailboxMoveFlags & RequestJobBase.StaticFlags)) { MrsTracer.Common.Error("Mismatched RequestJob: flags don't match: AD [{0}], workitem queue [{1}]", new object[] { requestJob.User.MailboxMoveFlags, requestJob.Flags }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMismatch); requestJob.ValidationMessage = MrsStrings.ValidationFlagsMismatch(requestJob.User.MailboxMoveFlags.ToString(), requestJob.Flags.ToString()); return; } MrsTracer.Common.Debug("Possibly mismatched RequestJob: flags don't match: AD [{0}], workitem queue [{1}]", new object[] { requestJob.User.MailboxMoveFlags, requestJob.Flags }); } if (requestJob.PrimaryIsMoving) { if (requestJob.SourceIsLocal && (requestJob.SourceDatabase == null || !requestJob.SourceDatabase.Equals(requestJob.User.MailboxMoveSourceMDB))) { MrsTracer.Common.Error("Mismatched RequestJob: Source database does not match between AD ({0}) and RequestJob ({1})", new object[] { requestJob.User.MailboxMoveSourceMDB, requestJob.SourceDatabase }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMismatch); requestJob.ValidationMessage = MrsStrings.ValidationSourceMDBMismatch((requestJob.User.MailboxMoveSourceMDB != null) ? requestJob.User.MailboxMoveSourceMDB.ToString() : "(null)", (requestJob.SourceDatabase != null) ? requestJob.SourceDatabase.ToString() : "(null)"); return; } if (requestJob.TargetIsLocal && (requestJob.TargetDatabase == null || (!requestJob.RehomeRequest && !requestJob.TargetDatabase.Equals(requestJob.User.MailboxMoveTargetMDB)))) { MrsTracer.Common.Error("Target database does not match between AD ({0}) and RequestJob ({1})", new object[] { requestJob.User.MailboxMoveTargetMDB, requestJob.TargetDatabase }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMismatch); requestJob.ValidationMessage = MrsStrings.ValidationTargetMDBMismatch((requestJob.User.MailboxMoveTargetMDB != null) ? requestJob.User.MailboxMoveTargetMDB.ToString() : "(null)", (requestJob.TargetDatabase != null) ? requestJob.TargetDatabase.ToString() : "(null)"); return; } } if (requestJob.JobType >= MRSJobType.RequestJobE14R5_PrimaryOrArchiveExclusiveMoves && requestJob.ArchiveIsMoving) { if (requestJob.SourceIsLocal && (requestJob.SourceArchiveDatabase == null || !requestJob.SourceArchiveDatabase.Equals(requestJob.User.MailboxMoveSourceArchiveMDB))) { MrsTracer.Common.Error("Mismatched RequestJob: Source archive database does not match between AD ({0}) and RequestJob ({1})", new object[] { requestJob.User.MailboxMoveSourceArchiveMDB, requestJob.SourceArchiveDatabase }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMismatch); requestJob.ValidationMessage = MrsStrings.ValidationSourceArchiveMDBMismatch((requestJob.User.MailboxMoveSourceArchiveMDB != null) ? requestJob.User.MailboxMoveSourceArchiveMDB.ToString() : "(null)", (requestJob.SourceArchiveDatabase != null) ? requestJob.SourceArchiveDatabase.ToString() : "(null)"); return; } if (requestJob.TargetIsLocal && (requestJob.TargetArchiveDatabase == null || (!requestJob.RehomeRequest && !requestJob.TargetArchiveDatabase.Equals(requestJob.User.MailboxMoveTargetArchiveMDB)))) { MrsTracer.Common.Error("Target archive database does not match between AD ({0}) and RequestJob ({1})", new object[] { requestJob.User.MailboxMoveTargetArchiveMDB, requestJob.TargetArchiveDatabase }); requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.DataMismatch); requestJob.ValidationMessage = MrsStrings.ValidationTargetArchiveMDBMismatch((requestJob.User.MailboxMoveTargetArchiveMDB != null) ? requestJob.User.MailboxMoveTargetArchiveMDB.ToString() : "(null)", (requestJob.TargetArchiveDatabase != null) ? requestJob.TargetArchiveDatabase.ToString() : "(null)"); return; } } requestJob.ValidationResult = new RequestJobBase.ValidationResultEnum?(RequestJobBase.ValidationResultEnum.Valid); requestJob.ValidationMessage = LocalizedString.Empty; }
public MoveRequestIdParameter(MoveRequestStatistics moveRequest) : this(moveRequest.MailboxIdentity) { }
private static void CleanADOrphanAndInconsistencyForMoves(IRecipientSession recipientSession, RequestJobProvider rjProvider, Guid dbGuid) { ADObjectId propertyValue = new ADObjectId(dbGuid); QueryFilter queryFilter = new AndFilter(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.NotEqual, ADUserSchema.MailboxMoveStatus, RequestStatus.None), new ExistsFilter(ADUserSchema.MailboxMoveStatus) }); QueryFilter queryFilter2 = QueryFilter.OrTogether(new QueryFilter[] { QueryFilter.AndTogether(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ADUserSchema.MailboxMoveSourceMDB, propertyValue), new BitMaskAndFilter(ADUserSchema.MailboxMoveFlags, 4UL) }), QueryFilter.AndTogether(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ADUserSchema.MailboxMoveTargetMDB, propertyValue), new BitMaskAndFilter(ADUserSchema.MailboxMoveFlags, 8UL) }) }); QueryFilter filter = new AndFilter(new QueryFilter[] { queryFilter, queryFilter2 }); ADRecipient[] array = recipientSession.Find(null, QueryScope.SubTree, filter, null, 1000); if (array == null || array.Length == 0) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves(): No move requests found for DB {0}", new object[] { dbGuid }); return; } bool needUpdateAD = false; ADRecipient[] array2 = array; for (int i = 0; i < array2.Length; i++) { ADRecipient request = array2[i]; CommonUtils.CatchKnownExceptions(delegate { needUpdateAD = false; ADUser aduser = request as ADUser; MoveRequestStatistics moveRequestStatistics = (MoveRequestStatistics)rjProvider.Read <MoveRequestStatistics>(new RequestJobObjectId(aduser.ExchangeGuid, dbGuid, null)); if (moveRequestStatistics == null || (!moveRequestStatistics.IsFake && moveRequestStatistics.Status == RequestStatus.None)) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():AD orphan {0} found for DB {1}", new object[] { aduser.ExchangeGuid, dbGuid }); CommonUtils.CleanupMoveRequestInAD(recipientSession, null, aduser); return; } if (moveRequestStatistics.IsFake) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():request {0} is uplevel/Fake, ignore it", new object[] { aduser.ExchangeGuid }); return; } if (moveRequestStatistics.User == null) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():request {0} has been deleted from AD, ignore it", new object[] { aduser.ExchangeGuid }); return; } if (moveRequestStatistics.TimeTracker.GetCurrentDurationChunk() > ADInconsistencyCheck.updateLatencyThreshhold) { RequestStatus versionAppropriateStatus = RequestJobBase.GetVersionAppropriateStatus(moveRequestStatistics.Status, aduser.ExchangeVersion); if (versionAppropriateStatus != moveRequestStatistics.User.MailboxMoveStatus) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():AD inconsistency {0} found for DB {1}, AD status is {2} but store status is {3} ({4})", new object[] { aduser.ExchangeGuid, dbGuid, aduser.MailboxMoveStatus, moveRequestStatistics.Status, versionAppropriateStatus }); aduser.MailboxMoveStatus = versionAppropriateStatus; needUpdateAD = true; } RequestFlags versionAppropriateFlags = RequestJobBase.GetVersionAppropriateFlags(moveRequestStatistics.Flags, aduser.ExchangeVersion); if (versionAppropriateFlags != moveRequestStatistics.User.MailboxMoveFlags) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():AD inconsistency {0} found for DB {1}, AD flags is {2} but store flags is {3} ({4})", new object[] { aduser.ExchangeGuid, dbGuid, aduser.MailboxMoveFlags, moveRequestStatistics.Flags, versionAppropriateFlags }); aduser.MailboxMoveFlags = versionAppropriateFlags; needUpdateAD = true; } if (needUpdateAD) { recipientSession.Save(request); } } }, delegate(Exception f) { MrsTracer.Service.Error("CleanADOrphanAndInconsistencyForMoves() failed for DB {0}. move request {1} Error: {2}", new object[] { dbGuid, ((ADUser)request).ExchangeGuid, CommonUtils.FullExceptionMessage(f, true) }); MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[] { dbGuid, MRSRequestType.Move.ToString(), ((ADUser)request).ExchangeGuid, CommonUtils.FullExceptionMessage(f, true) }); }); } }
public IConfigurable Read <T>(ObjectId identity, ReadJobFlags readJobFlags) where T : IConfigurable, new() { if (identity == null) { throw new ArgumentNullException("identity", "The identity of the object to be read must be specified."); } if (!(identity is RequestJobObjectId)) { throw new ArgumentException("RequestJobProvider can only identify RequestJobs based on RequestJobObjectIds.", "identity"); } if (!typeof(T).Equals(typeof(TransactionalRequestJob)) && !RequestJobProvider.IsRequestStatistics(typeof(T), true)) { throw new ArgumentException("RequestJobProvider can only Read *RequestStatistics or TransactionalRequestJob objects."); } bool flag = false; if (typeof(T).Equals(typeof(TransactionalRequestJob))) { flag = true; } RequestJobObjectId requestJobObjectId = (RequestJobObjectId)identity; Guid requestGuid = requestJobObjectId.RequestGuid; Guid mdbGuid = requestJobObjectId.MdbGuid; byte[] messageId = requestJobObjectId.MessageId; ADUser aduser = requestJobObjectId.User; ADUser aduser2 = requestJobObjectId.SourceUser; ADUser aduser3 = requestJobObjectId.TargetUser; IRequestIndexEntry indexEntry = requestJobObjectId.IndexEntry; List <IRequestIndexEntry> list = new List <IRequestIndexEntry>(); if (requestGuid == Guid.Empty || mdbGuid == Guid.Empty) { throw new NotEnoughInformationToFindMoveRequestPermanentException(); } this.EnsureStoreConnectionExists(mdbGuid); MoveObjectInfo <RequestJobXML> moveObjectInfo = null; IConfigurable result; try { moveObjectInfo = new MoveObjectInfo <RequestJobXML>(mdbGuid, this.store, messageId, RequestJobXML.RequestJobsFolderName, RequestJobXML.RequestJobsMessageClass, RequestJobXML.CreateMessageSubject(requestGuid), RequestJobXML.CreateMessageSearchKey(requestGuid)); RequestJobXML requestJobXML = null; if (moveObjectInfo.OpenMessage()) { if (moveObjectInfo.CheckObjectType(new MoveObjectInfo <RequestJobXML> .IsSupportedObjectTypeDelegate(RequestJobXML.IsMessageTypeSupported))) { requestJobXML = moveObjectInfo.ReadObject(ReadObjectFlags.DontThrowOnCorruptData); } else { MrsTracer.Common.Warning("Found unexpected JobType for move job {0}", new object[] { requestJobObjectId.ToString() }); } if (requestJobXML == null) { if (!this.AllowInvalid) { return(null); } requestJobXML = RequestJobBase.CreateDummyObject <RequestJobXML>(); requestJobXML.RequestGuid = requestGuid; requestJobXML.ExchangeGuid = requestGuid; } requestJobXML.OriginatingMDBGuid = mdbGuid; if (requestJobXML.Identity == null) { requestJobXML.Identity = requestJobObjectId; } requestJobXML.Identity.MessageId = moveObjectInfo.MessageId; RequestJobProvider.FixTenantInfo(requestJobXML); if (!requestJobXML.IsFake) { using (this.IndexProvider.RescopeTo(requestJobXML.DomainControllerToUpdate, requestJobXML.OrganizationId)) { if (aduser == null && requestJobXML.UserId != null) { aduser = this.IndexProvider.ReadADUser(requestJobXML.UserId, requestJobXML.ExchangeGuid); } if (aduser2 == null && requestJobXML.SourceUserId != null) { aduser2 = this.IndexProvider.ReadADUser(requestJobXML.SourceUserId, requestJobXML.SourceExchangeGuid); } if (aduser3 == null && requestJobXML.TargetUserId != null) { aduser3 = this.IndexProvider.ReadADUser(requestJobXML.TargetUserId, requestJobXML.TargetExchangeGuid); } if (!typeof(T).Equals(typeof(MoveRequestStatistics)) && requestJobXML.RequestType != MRSRequestType.Move && requestJobXML.IndexIds != null && requestJobXML.IndexIds.Count > 0) { int capacity = requestJobXML.IndexIds.Count - 1; bool flag2 = false; List <RequestIndexEntryObjectId> list2 = new List <RequestIndexEntryObjectId>(capacity); foreach (RequestIndexId requestIndexId in requestJobXML.IndexIds) { if (indexEntry != null && requestIndexId.Equals(indexEntry.RequestIndexId)) { if (!flag2) { list.Add(indexEntry); } flag2 = true; } else if (readJobFlags.HasFlag(ReadJobFlags.SkipReadingMailboxRequestIndexEntries) && requestIndexId.Location == RequestIndexLocation.Mailbox) { MrsTracer.Common.Debug("Skipping loading of an IRequestIndexEntry found in a mailbox.", new object[0]); } else { list2.Add(new RequestIndexEntryObjectId(requestJobXML.RequestGuid, requestJobXML.TargetExchangeGuid, requestJobXML.RequestType, requestJobXML.OrganizationId, requestIndexId, null)); } } foreach (RequestIndexEntryObjectId objectId in list2) { IRequestIndexEntry requestIndexEntry = this.IndexProvider.Read(objectId); if (requestIndexEntry != null) { list.Add(requestIndexEntry); } } } if (this.IndexProvider.DomainController == null && !string.IsNullOrEmpty(requestJobXML.DomainControllerToUpdate)) { requestJobXML.DomainControllerToUpdate = null; } } } requestJobXML.User = aduser; requestJobXML.SourceUser = aduser2; requestJobXML.TargetUser = aduser3; requestJobXML.IndexEntries = list; if (!readJobFlags.HasFlag(ReadJobFlags.SkipValidation)) { requestJobXML.ValidateRequestJob(); } if (this.AllowInvalid) { ValidationError[] array = requestJobXML.Validate(); if (array != null && array.Length > 0) { requestJobXML.IsFake = true; } } if (flag) { TransactionalRequestJob transactionalRequestJob = new TransactionalRequestJob(requestJobXML); requestJobXML.Retire(); transactionalRequestJob.Provider = this; transactionalRequestJob.MoveObject = moveObjectInfo; moveObjectInfo = null; result = transactionalRequestJob; } else { RequestStatisticsBase requestStatisticsBase = RequestJobProvider.CreateRequestStatistics(typeof(T), requestJobXML, true); if (requestStatisticsBase == null) { requestStatisticsBase = new MoveRequestStatistics(requestJobXML); requestJobXML.Retire(); } if (this.LoadReport) { ReportData reportData = new ReportData(requestStatisticsBase.IdentifyingGuid, requestStatisticsBase.ReportVersion); reportData.Load(this.SystemMailbox); requestStatisticsBase.Report = reportData.ToReport(); } result = requestStatisticsBase; } } else { result = null; } } finally { if (moveObjectInfo != null) { moveObjectInfo.Dispose(); moveObjectInfo = null; } } return(result); }