private byte[] FindMessageId() { using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, false)) { if (mapiFolder == null) { return(null); } this.FolderId = mapiFolder.GetProp(PropTag.EntryId).GetBytes(); using (MapiTable contentsTable = mapiFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { PropTag propTag = PropTag.ReplyTemplateID; contentsTable.SetColumns(new PropTag[] { PropTag.EntryId }); contentsTable.SortTable(new SortOrder(propTag, SortFlags.Ascend), SortTableFlags.None); if (contentsTable.FindRow(Restriction.EQ(propTag, this.searchKey), BookMark.Beginning, FindRowFlag.None)) { PropValue[][] array = contentsTable.QueryRows(1); if (array == null || array.Length == 0 || array[0].Length == 0) { return(null); } return(array[0][0].GetBytes()); } } } return(null); }
internal void SaveToMailbox(MapiStore mailbox, int maxMoveHistoryLength) { MrsTracer.Common.Function("MoveHistoryEntryInternal.SaveToMailbox(maxHistoryLength={0})", new object[] { maxMoveHistoryLength }); List <byte[]> list = new List <byte[]>(); using (MapiFolder folder = MapiUtils.OpenFolderUnderRoot(mailbox, MoveHistoryEntryInternal.MHEFolderName, true)) { using (MapiTable contentsTable = folder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { contentsTable.SortTable(new SortOrder(PropTag.LastModificationTime, SortFlags.Ascend), SortTableFlags.None); PropValue[][] array = MapiUtils.QueryAllRows(contentsTable, null, new PropTag[] { PropTag.EntryId }); foreach (PropValue[] array3 in array) { list.Add(array3[0].GetBytes()); } } MrsTracer.Common.Debug("Move history contains {0} items.", new object[] { list.Count }); List <byte[]> list2 = new List <byte[]>(); while (list.Count >= maxMoveHistoryLength && list.Count > 0) { list2.Add(list[0]); list.RemoveAt(0); } if (list2.Count > 0) { MrsTracer.Common.Debug("Clearing {0} entries from move history", new object[] { list2.Count }); MapiUtils.ProcessMapiCallInBatches <byte[]>(list2.ToArray(), delegate(byte[][] batch) { folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, batch); }); } } if (maxMoveHistoryLength <= 0) { MrsTracer.Common.Debug("Move history saving is disabled.", new object[0]); return; } DateTime dateTime = this.TimeTracker.GetTimestamp(RequestJobTimestamp.Creation) ?? DateTime.MinValue; string subject = string.Format("MoveHistoryEntry {0}", dateTime.ToString()); byte[] bytes = BitConverter.GetBytes(dateTime.ToBinary()); MoveObjectInfo <MoveHistoryEntryInternal> moveObjectInfo = new MoveObjectInfo <MoveHistoryEntryInternal>(Guid.Empty, mailbox, null, MoveHistoryEntryInternal.MHEFolderName, MoveHistoryEntryInternal.MHEMessageClass, subject, bytes); using (moveObjectInfo) { moveObjectInfo.SaveObject(this); } }
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 List <MoveHistoryEntryInternal> LoadMoveHistory(MapiStore mailbox) { MrsTracer.Common.Function("MoveHistoryEntryInternal.LoadMoveHistory", new object[0]); List <MoveHistoryEntryInternal> list = new List <MoveHistoryEntryInternal>(); using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(mailbox, MoveHistoryEntryInternal.MHEFolderName, false)) { if (mapiFolder == null) { return(list); } using (MapiTable contentsTable = mapiFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { PropValue[][] array = MapiUtils.QueryAllRows(contentsTable, null, new PropTag[] { PropTag.EntryId }); foreach (PropValue[] array3 in array) { byte[] bytes = array3[0].GetBytes(); string subject = string.Format("MoveHistoryEntry {0}", TraceUtils.DumpEntryId(bytes)); MoveObjectInfo <MoveHistoryEntryInternal> moveObjectInfo = new MoveObjectInfo <MoveHistoryEntryInternal>(Guid.Empty, mailbox, bytes, MoveHistoryEntryInternal.MHEFolderName, MoveHistoryEntryInternal.MHEMessageClass, subject, null); using (moveObjectInfo) { MoveHistoryEntryInternal moveHistoryEntryInternal = null; try { moveHistoryEntryInternal = moveObjectInfo.ReadObject(ReadObjectFlags.DontThrowOnCorruptData); } catch (MailboxReplicationPermanentException ex) { MrsTracer.Common.Warning("Failed to read move history entry: {0}", new object[] { ex.ToString() }); } if (moveHistoryEntryInternal != null) { list.Add(moveHistoryEntryInternal); } else if (moveObjectInfo.CreationTimestamp < DateTime.UtcNow - TimeSpan.FromDays(365.0)) { MrsTracer.Common.Warning("Removing old corrupt MHEI entry {0}", new object[] { TraceUtils.DumpEntryId(bytes) }); moveObjectInfo.DeleteMessage(); } } } } } list.Sort(); return(list); }
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 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; }
public static List <T> LoadAll(byte[] searchKey, Restriction additionalRestriction, Guid mdbGuid, MapiStore store, string folderName, MoveObjectInfo <T> .IsSupportedObjectTypeDelegate isSupportedObjectType, MoveObjectInfo <T> .EmptyTDelegate emptyT) { List <T> list = new List <T>(); using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(store, folderName, false)) { if (mapiFolder == null) { return(list); } using (MapiTable contentsTable = mapiFolder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { PropTag propTag = PropTag.ReplyTemplateID; contentsTable.SortTable(new SortOrder(propTag, SortFlags.Ascend), SortTableFlags.None); List <PropTag> list2 = new List <PropTag>(); list2.Add(PropTag.EntryId); list2.Add(propTag); Restriction restriction = null; if (searchKey != null) { restriction = Restriction.EQ(propTag, searchKey); } if (additionalRestriction != null) { if (restriction == null) { restriction = additionalRestriction; } else { restriction = Restriction.And(new Restriction[] { restriction, additionalRestriction }); } } foreach (PropValue[] array2 in MapiUtils.QueryAllRows(contentsTable, restriction, list2)) { byte[] bytes = array2[0].GetBytes(); byte[] bytes2 = array2[1].GetBytes(); OpenEntryFlags flags = OpenEntryFlags.Modify | OpenEntryFlags.DontThrowIfEntryIsMissing; using (MapiMessage mapiMessage = (MapiMessage)store.OpenEntry(bytes, flags)) { if (mapiMessage != null) { T t = default(T); if (isSupportedObjectType != null) { if (isSupportedObjectType(mapiMessage, store)) { t = MoveObjectInfo <T> .ReadObjectFromMessage(mapiMessage, false); } if (t == null && emptyT != null) { t = emptyT(bytes2); } } else { t = MoveObjectInfo <T> .ReadObjectFromMessage(mapiMessage, false); } if (t != null) { list.Add(t); } else { MrsTracer.Common.Error("Unable to deserialize message '{0}'.", new object[] { bytes }); } } } } } } 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)); }