private static void CleanADOrphanAndInconsistencyForRequests(IRecipientSession recipientSession, IConfigurationSession configSession, Guid dbGuid) { MrsTracer.Service.Debug("Try to CleanADOrphanAndInconsistencyForRequests for Database {0} name is {1}", new object[] { dbGuid, dbGuid }); using (RequestJobProvider rjProvider = new RequestJobProvider(dbGuid)) { rjProvider.LoadReport = false; rjProvider.AllowInvalid = true; foreach (object obj in Enum.GetValues(typeof(MRSRequestType))) { MRSRequestType requestType = (MRSRequestType)obj; MrsTracer.Service.Debug("Try to CleanADOrphanAndInconsistencyForRequests for request type {0}", new object[] { requestType }); CommonUtils.CatchKnownExceptions(delegate { if (requestType == MRSRequestType.Move) { ADInconsistencyCheck.CleanADOrphanAndInconsistencyForMoves(recipientSession, rjProvider, dbGuid); return; } ADInconsistencyCheck.CleanADOrphanAndInconsistencyForNonMoves(configSession, requestType, rjProvider, dbGuid); }, delegate(Exception f) { MrsTracer.Service.Error("CleanADOrphanAndInconsistencyForRequests() failed for DB {0}. Request type {1} Error: {2}", new object[] { dbGuid, requestType.ToString(), CommonUtils.FullExceptionMessage(f, true) }); MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[] { dbGuid, requestType.ToString(), string.Empty, CommonUtils.FullExceptionMessage(f, true) }); }); } } }
internal static MRSRequestWrapper Read(IConfigurationSession configSession, Guid requestGuid, MRSRequestType type) { QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, MRSRequestSchema.MailboxMoveRequestGuid, requestGuid); ADObjectId rootId = ADHandler.GetRootId(configSession, type); IEnumerable <MRSRequestWrapper> enumerable = configSession.FindPaged <MRSRequestWrapper>(filter, rootId, !configSession.SessionSettings.IsTenantScoped, null, 2); MRSRequestWrapper result = null; using (IEnumerator <MRSRequestWrapper> enumerator = enumerable.GetEnumerator()) { if (enumerator.MoveNext()) { result = enumerator.Current; if (enumerator.MoveNext()) { throw new RequestGuidNotUniquePermanentException(requestGuid.ToString(), type.ToString()); } } } return(result); }
private static void CleanADOrphanAndInconsistencyForNonMoves(IConfigurationSession configSession, MRSRequestType requestType, RequestJobProvider rjProvider, Guid dbGuid) { ADObjectId requestQueueId = new ADObjectId(dbGuid); RequestIndexEntryQueryFilter requestIndexEntryQueryFilter = new RequestIndexEntryQueryFilter(); requestIndexEntryQueryFilter.IndexId = new RequestIndexId(RequestIndexLocation.AD); requestIndexEntryQueryFilter.RequestType = requestType; requestIndexEntryQueryFilter.RequestQueueId = requestQueueId; MRSRequestWrapper[] array = ADHandler.Find(configSession, requestIndexEntryQueryFilter, null, true, null); if (array != null && array.Length > 0) { bool needUpdateAD = false; MRSRequestWrapper[] array2 = array; for (int i = 0; i < array2.Length; i++) { MRSRequestWrapper request = array2[i]; CommonUtils.CatchKnownExceptions(delegate { needUpdateAD = false; if (request.Status != RequestStatus.None) { RequestStatisticsBase requestStatisticsBase = (RequestStatisticsBase)rjProvider.Read <RequestStatisticsBase>(new RequestJobObjectId(request.RequestGuid, dbGuid, null)); if (requestStatisticsBase == null || (!requestStatisticsBase.IsFake && requestStatisticsBase.Status == RequestStatus.None)) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():AD orphan {0} found for DB {1}", new object[] { request.RequestGuid, dbGuid }); ADHandler.Delete(configSession, request); return; } if (requestStatisticsBase.IsFake) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():request {0} is uplevel/Fake, ignoring it", new object[] { request.RequestGuid }); return; } if (requestStatisticsBase.IndexEntries == null || requestStatisticsBase.IndexEntries.Count == 0) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():request {0} has been removed from AD, ignoring it", new object[] { request.RequestGuid }); return; } if (requestStatisticsBase.TimeTracker.GetCurrentDurationChunk() > ADInconsistencyCheck.updateLatencyThreshhold) { if (requestStatisticsBase.Status != requestStatisticsBase.IndexEntries[0].Status) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():AD inconsistency {0} found for DB {1}, AD status is {2} but store status is {3}", new object[] { request.RequestGuid, dbGuid, request.Status, requestStatisticsBase.Status }); request.Status = requestStatisticsBase.Status; needUpdateAD = true; } if (requestStatisticsBase.Flags != requestStatisticsBase.IndexEntries[0].Flags) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():AD inconsistency {0} found for DB {1}, AD flags is {2} but store flags is {3}", new object[] { request.RequestGuid, dbGuid, request.Flags, requestStatisticsBase.Flags }); request.Flags = requestStatisticsBase.Flags; needUpdateAD = true; } if (needUpdateAD) { ADHandler.Save(configSession, request); return; } } } else { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():request {0} for {1} has been removed from AD, store orphan will be handled by MRS pick up job logic", new object[] { request.RequestGuid, dbGuid }); } }, delegate(Exception f) { MrsTracer.Service.Error("CleanADOrphanAndInconsistencyForRequests() failed for DB {0}. Request type {1} Request guid {2} Error: {3}", new object[] { dbGuid, requestType.ToString(), request.RequestGuid, CommonUtils.FullExceptionMessage(f, true) }); MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[] { dbGuid, requestType.ToString(), request.RequestGuid, CommonUtils.FullExceptionMessage(f, true) }); }); } return; } MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests(): No {0} requests found for DB {1}", new object[] { requestType, dbGuid }); }
protected virtual string CheckRequestNameAvailability(string name, ADObjectId identifyingObjectId, bool objectIsMailbox, MRSRequestType requestType, object errorObject, bool wildcardedSearch) { string text = string.Format("{0}*", name); RequestIndexEntryQueryFilter requestIndexEntryQueryFilter = new RequestIndexEntryQueryFilter(wildcardedSearch ? text : name, identifyingObjectId, requestType, this.DefaultRequestIndexId, objectIsMailbox); requestIndexEntryQueryFilter.WildcardedNameSearch = wildcardedSearch; ObjectId rootId = ADHandler.GetRootId(this.CurrentOrgConfigSession, requestType); IEnumerable <TRequest> enumerable = ((RequestJobProvider)base.DataSession).IndexProvider.FindPaged <TRequest>(requestIndexEntryQueryFilter, rootId, rootId == null, null, 10); string result; using (IEnumerator <TRequest> enumerator = enumerable.GetEnumerator()) { if (!enumerator.MoveNext()) { result = name; } else if (!wildcardedSearch) { if (requestType.Equals(MRSRequestType.PublicFolderMigration) || requestType.Equals(MRSRequestType.PublicFolderMove)) { base.WriteError(new MultipleSamePublicFolderMRSJobInstancesNotAllowedException(requestType.ToString()), ErrorCategory.InvalidArgument, errorObject); } else { base.WriteError(new NameMustBeUniquePermanentException(name, (identifyingObjectId == null) ? string.Empty : identifyingObjectId.ToString()), ErrorCategory.InvalidArgument, errorObject); } result = null; } else { Regex regex = new Regex(string.Format("^{0}(\\d)?$", name)); List <uint> list = new List <uint>(10); for (uint num = 0U; num < 10U; num += 1U) { list.Add(num); } do { TRequest trequest = enumerator.Current; Match match = regex.Match(trequest.Name); if (match.Success) { string value = match.Groups[1].Value; uint num2; if (string.IsNullOrEmpty(value)) { list.Remove(0U); } else if (uint.TryParse(value, out num2) && list.Contains(num2) && num2 != 0U) { list.Remove(num2); } } }while (enumerator.MoveNext() && list.Count > 0); if (list.Count == 0) { base.WriteError(new NoAvailableDefaultNamePermanentException(identifyingObjectId.ToString()), ErrorCategory.InvalidArgument, errorObject); result = null; } else if (list.Contains(0U)) { result = name; } else { result = string.Format("{0}{1}", name, list[0]); } } } return(result); }