public int GetQueueLength() { MrsTracer.Common.Function("RequestJobProvider.GetQueueLength", new object[0]); RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(this.SystemMailbox); Restriction restriction = Restriction.EQ(requestJobNamedPropertySet.PropTags[4], true); Restriction restriction2 = Restriction.BitMaskNonZero(requestJobNamedPropertySet.PropTags[10], 256); Restriction restriction3 = Restriction.EQ(requestJobNamedPropertySet.PropTags[0], RequestStatus.Completed); Restriction restriction4 = Restriction.EQ(requestJobNamedPropertySet.PropTags[0], RequestStatus.CompletedWithWarning); Restriction restriction5 = Restriction.Or(new Restriction[] { restriction, restriction2, restriction3, restriction4 }); Restriction restriction6 = Restriction.Not(restriction5); int result; using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(this.SystemMailbox)) { using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { contentsTable.Restrict(restriction6); int rowCount = contentsTable.GetRowCount(); MrsTracer.Common.Debug("Queue length is {0}", new object[] { rowCount }); result = rowCount; } } return(result); }
internal static bool IsMessageTypeSupported(MapiMessage message, MapiStore store) { RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(store); PropValue prop = message.GetProp(requestJobNamedPropertySet.PropTags[9]); MRSJobType value = MapiUtils.GetValue <MRSJobType>(prop, MRSJobType.RequestJobE14R3); return(RequestJobXML.IsKnownJobType(value)); }
protected override ICollection <ServiceIssue> RunFullIssueScan() { ICollection <ServiceIssue> collection = new List <ServiceIssue>(); foreach (Guid mdbGuid in MapiUtils.GetDatabasesOnThisServer()) { using (new DatabaseSettingsContext(mdbGuid, null).Activate()) { try { DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.None); string databaseName = databaseInformation.DatabaseName; if (!databaseInformation.IsOnThisServer) { return(null); } using (MapiStore systemMailbox = MapiUtils.GetSystemMailbox(mdbGuid, false)) { using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(systemMailbox)) { using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { if (contentsTable.GetRowCount() > 0) { RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(systemMailbox); contentsTable.SetColumns(requestJobNamedPropertySet.PropTags); Restriction restriction = Restriction.GT(requestJobNamedPropertySet.PropTags[23], ConfigBase <MRSConfigSchema> .GetConfig <int>("PoisonLimit")); List <MoveJob> allMoveJobs = SystemMailboxJobs.GetAllMoveJobs(restriction, null, contentsTable, mdbGuid, null); if (allMoveJobs != null) { foreach (MoveJob job in allMoveJobs) { collection.Add(new MRSPoisonedJobIssue(job)); } } } } } } } catch (LocalizedException lastScanError) { base.LastScanError = lastScanError; } } } return(collection); }
public static RequestJobNamedPropertySet Get(MapiStore systemMailbox) { byte[] signatureBytes = MapiUtils.GetSignatureBytes(systemMailbox); RequestJobNamedPropertySet result; lock (RequestJobNamedPropertySet.locker) { RequestJobNamedPropertySet requestJobNamedPropertySet; if (signatureBytes != null && RequestJobNamedPropertySet.mappings.TryGetValue(signatureBytes, out requestJobNamedPropertySet)) { result = requestJobNamedPropertySet; } else { requestJobNamedPropertySet = new RequestJobNamedPropertySet(systemMailbox); if (signatureBytes != null) { RequestJobNamedPropertySet.mappings.Add(signatureBytes, requestJobNamedPropertySet); } result = requestJobNamedPropertySet; } } return(result); }
public void PickupJobs(out string failure) { string dbName = null; string scanFailure = null; failure = null; using (new DatabaseSettingsContext(this.MdbGuid, null).Activate()) { CommonUtils.CatchKnownExceptions(delegate { DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.MdbGuid, null, null, FindServerFlags.None); dbName = databaseInformation.DatabaseName; if (!databaseInformation.IsOnThisServer) { scanFailure = string.Format("MDB is mounted on remote server {0}", databaseInformation.ServerFqdn); MRSQueue.RemoveQueue(this.MdbGuid); return; } MrsTracer.Service.Debug("Picking up jobs from '{0}' ({1})", new object[] { dbName, this.MdbGuid }); using (MapiStore systemMailbox = MapiUtils.GetSystemMailbox(this.MdbGuid, false)) { using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(systemMailbox)) { using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { if (contentsTable.GetRowCount() > 0) { RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(systemMailbox); contentsTable.SetColumns(requestJobNamedPropertySet.PropTags); this.ProcessJobs(systemMailbox, contentsTable, requestJobNamedPropertySet); } } } } MrsTracer.Service.Debug("Pick up jobs from Mdb: '{0}' - complete.", new object[] { dbName }); }, delegate(Exception f) { if (dbName == null) { dbName = MrsStrings.MissingDatabaseName(this.MdbGuid).ToString(); } MrsTracer.Service.Debug("PickupJobs() failed for mdb '{0}'. Error: {1}", new object[] { dbName, CommonUtils.FullExceptionMessage(f) }); scanFailure = CommonUtils.FullExceptionMessage(f, true); MRSService.LogEvent(MRSEventLogConstants.Tuple_UnableToProcessJobsInDatabase, new object[] { dbName, CommonUtils.FullExceptionMessage(f) }); }); } failure = scanFailure; }
protected abstract void ProcessJobs(MapiStore systemMbx, MapiTable contentsTable, RequestJobNamedPropertySet nps);
protected override void ProcessJobs(MapiStore systemMbx, MapiTable contentsTable, RequestJobNamedPropertySet nps) { MrsTracer.Service.Debug("Initializing searches...", new object[0]); SortOrder sortOrder = new SortOrder(nps.PropTags[17], SortFlags.Descend); sortOrder.Add(nps.PropTags[7], SortFlags.Ascend); Restriction restriction = Restriction.And(new Restriction[] { Restriction.EQ(nps.PropTags[4], true), Restriction.EQ(nps.PropTags[20], false) }); Restriction restriction2 = Restriction.And(new Restriction[] { Restriction.BitMaskZero(nps.PropTags[10], 256), Restriction.EQ(nps.PropTags[4], false), Restriction.EQ(nps.PropTags[20], false), Restriction.Or(new Restriction[] { Restriction.EQ(nps.PropTags[0], RequestStatus.Queued), Restriction.EQ(nps.PropTags[0], RequestStatus.InProgress), Restriction.EQ(nps.PropTags[0], RequestStatus.CompletionInProgress) }) }); base.ProcessJobsInBatches(Restriction.Or(new Restriction[] { restriction2, restriction }), true, sortOrder, contentsTable, systemMbx, null); Restriction restriction3 = Restriction.And(new Restriction[] { Restriction.BitMaskZero(nps.PropTags[10], 256), Restriction.EQ(nps.PropTags[4], false), Restriction.EQ(nps.PropTags[20], false), Restriction.EQ(nps.PropTags[0], RequestStatus.Synced) }); SortOrder sort = new SortOrder(nps.PropTags[13], SortFlags.Ascend); DateTime utcNow = DateTime.UtcNow; base.ProcessJobsInBatches(restriction3, false, sort, contentsTable, systemMbx, (MoveJob moveJob) => moveJob.DoNotPickUntilTimestamp > utcNow); }
protected override void ProcessJobs(MapiStore systemMbx, MapiTable contentsTable, RequestJobNamedPropertySet nps) { SortOrder sortOrder = new SortOrder(nps.PropTags[17], SortFlags.Descend); sortOrder.Add(nps.PropTags[7], SortFlags.Ascend); MrsTracer.Service.Debug("Searching for MRs to Rehome...", new object[0]); Restriction restriction = Restriction.And(new Restriction[] { Restriction.EQ(nps.PropTags[4], false), Restriction.EQ(nps.PropTags[20], true) }); MrsTracer.Service.Debug("Searching for MRs to Suspend...", new object[0]); base.ProcessJobsInBatches(restriction, false, sortOrder, contentsTable, systemMbx, null); Restriction restriction2 = Restriction.And(new Restriction[] { Restriction.BitMaskNonZero(nps.PropTags[10], 256), Restriction.EQ(nps.PropTags[4], false), Restriction.EQ(nps.PropTags[20], false), Restriction.NE(nps.PropTags[0], RequestStatus.Failed), Restriction.NE(nps.PropTags[0], RequestStatus.Suspended), Restriction.NE(nps.PropTags[0], RequestStatus.AutoSuspended), Restriction.NE(nps.PropTags[0], RequestStatus.Completed), Restriction.NE(nps.PropTags[0], RequestStatus.CompletedWithWarning) }); base.ProcessJobsInBatches(restriction2, false, sortOrder, contentsTable, systemMbx, null); MrsTracer.Service.Debug("Searching for MRs to Resume...", new object[0]); Restriction restriction3 = Restriction.And(new Restriction[] { Restriction.BitMaskZero(nps.PropTags[10], 256), Restriction.EQ(nps.PropTags[4], false), Restriction.EQ(nps.PropTags[20], false), Restriction.Or(new Restriction[] { Restriction.EQ(nps.PropTags[0], RequestStatus.Failed), Restriction.EQ(nps.PropTags[0], RequestStatus.Suspended), Restriction.EQ(nps.PropTags[0], RequestStatus.AutoSuspended) }) }); base.ProcessJobsInBatches(restriction3, false, sortOrder, contentsTable, systemMbx, null); SortOrder sort = new SortOrder(nps.PropTags[13], SortFlags.Ascend); DateTime utcNow = DateTime.UtcNow; MrsTracer.Service.Debug("Searching for Completed MRs to clean up...", new object[0]); Restriction restriction4 = Restriction.And(new Restriction[] { Restriction.EQ(nps.PropTags[20], false), Restriction.EQ(nps.PropTags[4], false), Restriction.EQ(nps.PropTags[0], RequestStatus.Completed), Restriction.NE(nps.PropTags[13], SystemMailboxLightJobs.defaultDoNotPickUntil) }); base.ProcessJobsInBatches(restriction4, false, sort, contentsTable, systemMbx, (MoveJob moveJob) => moveJob.DoNotPickUntilTimestamp > utcNow); }
internal PropValue[] GetPropertiesWrittenOnRequestJob(MapiStore store) { RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(store); return(requestJobNamedPropertySet.GetValuesFromRequestJob(this)); }
private List <T> InternalFind <T>(QueryFilter filter, ObjectId rootId, bool deepSearch, SortBy sortBy, int pageSize) where T : IConfigurable, new() { if (!RequestJobProvider.IsRequestStatistics(typeof(T), false)) { throw new ArgumentException("RequestJobProvider can only find *RequestStatistics objects."); } List <T> list = new List <T>(); RequestJobQueryFilter requestJobQueryFilter = filter as RequestJobQueryFilter; if (requestJobQueryFilter != null) { MRSRequestType?requestType = requestJobQueryFilter.RequestType; Guid mdbGuid = requestJobQueryFilter.MdbGuid; Guid requestGuid = requestJobQueryFilter.RequestGuid; this.EnsureStoreConnectionExists(mdbGuid); Restriction restriction = null; if (requestType != null) { RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(this.SystemMailbox); restriction = Restriction.EQ(requestJobNamedPropertySet.PropTags[14], requestType.Value); if (requestType.Value == MRSRequestType.Move) { restriction = Restriction.Or(new Restriction[] { Restriction.Not(Restriction.Exist(requestJobNamedPropertySet.PropTags[14])), restriction }); } } byte[] searchKey = null; if (requestGuid != Guid.Empty) { searchKey = RequestJobXML.CreateMessageSearchKey(requestGuid); } List <RequestJobXML> list2 = MoveObjectInfo <RequestJobXML> .LoadAll(searchKey, restriction, mdbGuid, this.store, RequestJobXML.RequestJobsFolderName, new MoveObjectInfo <RequestJobXML> .IsSupportedObjectTypeDelegate(RequestJobXML.IsMessageTypeSupported), new MoveObjectInfo <RequestJobXML> .EmptyTDelegate(this.CreateDummyFromSearchKey)); if (list2 == null || list2.Count == 0) { MrsTracer.Common.Debug("No RequestJob messages found.", new object[0]); } else { foreach (RequestJobXML requestJobXML in list2) { RequestJobProvider.FixTenantInfo(requestJobXML); RequestStatisticsBase requestStatisticsBase = RequestJobProvider.CreateRequestStatistics(typeof(T), requestJobXML, true); requestStatisticsBase.OriginatingMDBGuid = mdbGuid; if (requestStatisticsBase.Identity == null) { requestStatisticsBase.Identity = new RequestJobObjectId(requestStatisticsBase.IdentifyingGuid, mdbGuid, null); } if (!requestStatisticsBase.IsFake) { using (this.IndexProvider.RescopeTo(requestStatisticsBase.DomainControllerToUpdate, requestStatisticsBase.OrganizationId)) { if (requestStatisticsBase.UserId != null) { requestStatisticsBase.User = this.IndexProvider.ReadADUser(requestStatisticsBase.UserId, requestStatisticsBase.ExchangeGuid); } if (requestStatisticsBase.SourceUserId != null) { requestStatisticsBase.SourceUser = this.IndexProvider.ReadADUser(requestStatisticsBase.SourceUserId, requestStatisticsBase.SourceExchangeGuid); } if (requestStatisticsBase.TargetUserId != null) { requestStatisticsBase.TargetUser = this.IndexProvider.ReadADUser(requestStatisticsBase.TargetUserId, requestStatisticsBase.TargetExchangeGuid); } if (!typeof(T).Equals(typeof(MoveRequestStatistics)) && requestStatisticsBase.RequestType != MRSRequestType.Move) { List <IRequestIndexEntry> list3 = new List <IRequestIndexEntry>(); if (requestStatisticsBase.IndexIds != null && requestStatisticsBase.IndexIds.Count > 0) { foreach (RequestIndexId indexId in requestStatisticsBase.IndexIds) { IRequestIndexEntry requestIndexEntry; try { requestIndexEntry = this.IndexProvider.Read(new RequestIndexEntryObjectId(requestStatisticsBase.RequestGuid, requestStatisticsBase.TargetExchangeGuid, requestStatisticsBase.RequestType, requestStatisticsBase.OrganizationId, indexId, null)); } catch (TenantOrgContainerNotFoundException) { requestIndexEntry = null; } if (requestIndexEntry != null) { list3.Add(requestIndexEntry); } } } requestStatisticsBase.IndexEntries = list3; } if (this.IndexProvider.DomainController == null && !string.IsNullOrEmpty(requestStatisticsBase.DomainControllerToUpdate)) { requestStatisticsBase.DomainControllerToUpdate = null; } } } requestStatisticsBase.ValidateRequestJob(); if (this.LoadReport) { ReportData reportData = new ReportData(requestStatisticsBase.IdentifyingGuid, requestStatisticsBase.ReportVersion); reportData.Load(this.SystemMailbox); requestStatisticsBase.Report = reportData.ToReport(); } if (requestStatisticsBase != null && requestStatisticsBase.GetType().Equals(typeof(T))) { list.Add((T)((object)requestStatisticsBase)); } } } } return(list); }
public LocalizedString ComputePositionInQueue(Guid requestGuid) { int crows = 1000; int num = 0; int num2 = 0; if (requestGuid.Equals(Guid.Empty)) { return(MrsStrings.ErrorEmptyMailboxGuid); } using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(this.SystemMailbox)) { using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(this.SystemMailbox); contentsTable.SetColumns(requestJobNamedPropertySet.PropTags); SortOrder sortOrder = new SortOrder(requestJobNamedPropertySet.PropTags[7], SortFlags.Ascend); contentsTable.SortTable(sortOrder, SortTableFlags.None); Restriction restriction = Restriction.EQ(requestJobNamedPropertySet.PropTags[0], RequestStatus.Queued); contentsTable.Restrict(restriction); contentsTable.SeekRow(BookMark.Beginning, 0); PropValue[][] array = contentsTable.QueryRows(crows); bool flag = false; while (array != null && array.Length > 0) { int num3 = 0; if (!flag) { foreach (PropValue[] array3 in array) { num3++; if (num2 + num3 >= 10000) { break; } Guid value = MapiUtils.GetValue <Guid>(array3[26], Guid.Empty); if (requestGuid.Equals(value)) { flag = true; num = num2 + num3; break; } } } num2 += array.Length; if (num2 >= 10000) { break; } array = contentsTable.QueryRows(crows); } } } LocalizedString value2 = LocalizedString.Empty; LocalizedString value3 = LocalizedString.Empty; if (num == 0) { if (num2 < 10000) { value2 = MrsStrings.MoveRequestNotFoundInQueue; value3 = MrsStrings.PositionInteger(num2); } else { value2 = MrsStrings.PositionIntegerPlus(10000); value3 = MrsStrings.PositionIntegerPlus(10000); } } else { value2 = MrsStrings.PositionInteger(num); if (num2 < 10000) { value3 = MrsStrings.PositionInteger(num2); } else { value3 = MrsStrings.PositionIntegerPlus(num2); } } return(MrsStrings.PositionOfMoveRequestInSystemMailboxQueue(value2, value3)); }