Пример #1
0
 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);
 }
Пример #2
0
 internal MapiTableWrapper(MapiTable mapiTable, MapiMessageStoreSession mapiSession, MapiObjectId mapiObjectId)
 {
     this.mapiTable      = mapiTable;
     this.mapiSession    = mapiSession;
     this.mapiObjectId   = mapiObjectId;
     this.disposeTracker = this.GetDisposeTracker();
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        private SortOrder GetSortOrder(MapiTable table, SortBy[] sortColumns, GroupByAndOrder[] groupBy, int expandCount, ref List <PropTag> alteredProperties)
        {
            if ((sortColumns == null || sortColumns.Length == 0) && (groupBy == null || groupBy.Length == 0))
            {
                return(null);
            }
            SortOrder sortOrder = new SortOrder();

            if (groupBy != null)
            {
                for (int i = 0; i < groupBy.Length; i++)
                {
                    NativeStorePropertyDefinition nativeGroupBy = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupByColumn).GetNativeGroupBy();
                    PropTag   sortPropertyTag  = this.GetSortPropertyTag(nativeGroupBy, ref alteredProperties);
                    GroupSort nativeGroupSort  = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupSortColumn.ColumnDefinition).GetNativeGroupSort(groupBy[i].GroupSortColumn.SortOrder, groupBy[i].GroupSortColumn.Aggregate);
                    PropTag   sortPropertyTag2 = this.GetSortPropertyTag((NativeStorePropertyDefinition)nativeGroupSort.ColumnDefinition, ref alteredProperties);
                    SortFlags sortFlag;
                    switch (nativeGroupSort.Aggregate)
                    {
                    case Aggregate.Min:
                        sortFlag = SortFlags.CategoryMin;
                        break;

                    case Aggregate.Max:
                        sortFlag = SortFlags.CategoryMax;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("groupBy", nativeGroupSort.Aggregate, ServerStrings.ExInvalidAggregate);
                    }
                    sortOrder.AddCategory(sortPropertyTag, QueryExecutor.SortOrderToSortFlags(nativeGroupSort.SortOrder));
                    if (sortPropertyTag != sortPropertyTag2)
                    {
                        sortOrder.Add(sortPropertyTag2, sortFlag);
                    }
                }
                sortOrder.ExpandCount = expandCount;
            }
            if (sortOrder.GetSortCount() > 4)
            {
                throw new ArgumentException(ServerStrings.ExTooComplexGroupSortParameter, "groupBy");
            }
            if (sortColumns != null && sortColumns.Length > 0)
            {
                SortBy[] nativeSortBy = QueryExecutor.GetNativeSortBy(sortColumns);
                if (nativeSortBy.Length + sortOrder.GetSortCount() > 6)
                {
                    throw new ArgumentOutOfRangeException("sortColumns", ServerStrings.ExTooManySortColumns);
                }
                for (int j = 0; j < nativeSortBy.Length; j++)
                {
                    PropertyDefinition columnDefinition = nativeSortBy[j].ColumnDefinition;
                    PropTag            sortPropertyTag3 = this.GetSortPropertyTag((NativeStorePropertyDefinition)columnDefinition, ref alteredProperties);
                    sortOrder.Add(sortPropertyTag3, QueryExecutor.SortOrderToSortFlags(nativeSortBy[j].SortOrder));
                }
            }
            return(sortOrder);
        }
Пример #6
0
 public static void InitQueryAllRows(MapiTable msgTable, Restriction restriction, ICollection <PropTag> propTags)
 {
     if (restriction != null)
     {
         msgTable.Restrict(restriction);
     }
     msgTable.SeekRow(BookMark.Beginning, 0);
     msgTable.SetColumns(propTags);
 }
Пример #7
0
        private QueryResult CreateConversationMembersQueryResult(MapiTable mapiTable, QueryFilter queryFilter, SortBy[] sortColumns, ICollection <PropertyDefinition> dataColumns, AggregationExtension aggregationExtension)
        {
            List <PropTag> alteredProperties = null;

            this.SetTableFilter(mapiTable, queryFilter);
            SortOrder sortOrder = this.GetSortOrder(mapiTable, sortColumns, null, 0, ref alteredProperties);

            return(new ConversationMembersQueryResult(mapiTable, dataColumns, alteredProperties, this.Session, true, sortOrder, aggregationExtension));
        }
        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);
        }
Пример #9
0
        public MapiTableWrapper GetTable(GetTableFlags flags)
        {
            MapiTable mapiTable = null;

            this.MapiSession.InvokeWithWrappedException(delegate()
            {
                mapiTable = this.mapiModifyTable.GetTable(GetTableFlags.None);
            }, Strings.ErrorGetMapiTableWithIdentityAndServer(this.mapiObjectId.ToString(), this.MapiSession.ServerName), this.mapiObjectId);
            return(new MapiTableWrapper(mapiTable, this.MapiSession, this.mapiObjectId));
        }
Пример #10
0
        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);
        }
Пример #11
0
        public virtual QueryResult GroupedItemQuery(QueryFilter queryFilter, ItemQueryType queryFlags, GroupByAndOrder[] groupBy, int expandCount, SortBy[] sortColumns, params PropertyDefinition[] dataColumns)
        {
            EnumValidator.ThrowIfInvalid <ItemQueryType>(queryFlags, "queryFlags");
            if (groupBy == null)
            {
                throw new ArgumentNullException("groupBy");
            }
            if (dataColumns == null)
            {
                throw new ArgumentNullException("dataColumns");
            }
            if (expandCount > groupBy.Length)
            {
                throw new ArgumentException("expandCount should be less or equal to groupBy lengths");
            }
            ContentsTableFlags flags       = QueryExecutor.ItemQueryTypeToContentsTableFlags(queryFlags) | ContentsTableFlags.DeferredErrors;
            MapiTable          mapiTable   = this.GetContentsTable(flags);
            QueryResult        queryResult = null;
            bool        flag = false;
            QueryResult result;

            try
            {
                List <PropTag> alteredProperties = null;
                this.SetTableFilter(mapiTable, queryFilter);
                SortOrder sortOrder = this.GetSortOrder(mapiTable, sortColumns, groupBy, expandCount, ref alteredProperties);
                queryResult = new QueryResult(mapiTable, dataColumns, alteredProperties, this.Session, true, sortOrder);
                if (this.Session != null)
                {
                    this.Session.MessagesWereDownloaded = true;
                }
                flag   = true;
                result = queryResult;
            }
            finally
            {
                if (!flag)
                {
                    if (queryResult != null)
                    {
                        queryResult.Dispose();
                        queryResult = null;
                    }
                    if (mapiTable != null)
                    {
                        mapiTable.Dispose();
                        mapiTable = null;
                    }
                }
            }
            return(result);
        }
Пример #12
0
        public List <T> ReadObjectChunks(ReadObjectFlags flags)
        {
            if ((flags & ReadObjectFlags.Refresh) != ReadObjectFlags.None)
            {
                this.message.Dispose();
                this.message = null;
            }
            if (this.message == null && !this.OpenMessage())
            {
                return(null);
            }
            List <T> list = new List <T>();
            T        t;

            if ((flags & ReadObjectFlags.LastChunkOnly) == ReadObjectFlags.None)
            {
                using (MapiTable attachmentTable = this.message.GetAttachmentTable())
                {
                    if (attachmentTable != null)
                    {
                        PropValue[][] array = attachmentTable.QueryAllRows(null, MoveObjectInfo <T> .AttachmentTagsToLoad);
                        foreach (PropValue[] array3 in array)
                        {
                            int @int = array3[0].GetInt();
                            using (MapiAttach mapiAttach = this.message.OpenAttach(@int))
                            {
                                using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.BestAccess))
                                {
                                    t = MoveObjectInfo <T> .DeserializeFromStream(mapiStream, (flags & ReadObjectFlags.DontThrowOnCorruptData) == ReadObjectFlags.None);
                                }
                                if (t != null)
                                {
                                    list.Add(t);
                                }
                            }
                        }
                    }
                }
            }
            t = MoveObjectInfo <T> .ReadObjectFromMessage(this.message, (flags & ReadObjectFlags.DontThrowOnCorruptData) == ReadObjectFlags.None);

            if (t != null)
            {
                list.Add(t);
            }
            if (list.Count <= 0)
            {
                return(null);
            }
            return(list);
        }
Пример #13
0
 private void DeleteOldTestFolders()
 {
     using (MapiTable hierarchyTable = this.parentFolder.GetHierarchyTable())
     {
         PropValue[][] array = hierarchyTable.QueryAllRows(Restriction.Content(PropTag.DisplayName, "test-exchangesearch-folder-", ContentFlags.Prefix), new PropTag[]
         {
             PropTag.EntryId
         });
         foreach (PropValue[] array3 in array)
         {
             this.threadExit.CheckStop();
             this.parentFolder.DeleteFolder(array3[0].GetBytes(), DeleteFolderFlags.DeleteMessages | DeleteFolderFlags.DelSubFolders | DeleteFolderFlags.ForceHardDelete);
         }
     }
 }
        private static void CleanUpInbox(MapiFolder folder)
        {
            DateTime  t = DateTime.UtcNow.AddMinutes(-20.0);
            MapiTable contentsTable;
            MapiTable mapiTable = contentsTable = folder.GetContentsTable();

            try
            {
                mapiTable.SetColumns(new PropTag[]
                {
                    PropTag.EntryId,
                    PropTag.MessageDeliveryTime,
                    PropTag.NormalizedSubject,
                    PropTag.OriginalSubject
                });
                Restriction restriction = Restriction.Or(new Restriction[]
                {
                    Restriction.Content(PropTag.NormalizedSubject, "66c7004a-6860-44b2-983a-327aa3c9cfec", ContentFlags.SubString | ContentFlags.IgnoreCase),
                    Restriction.Content(PropTag.OriginalSubject, "66c7004a-6860-44b2-983a-327aa3c9cfec", ContentFlags.SubString | ContentFlags.IgnoreCase)
                });
                mapiTable.Restrict(restriction);
                mapiTable.SortTable(new SortOrder(PropTag.MessageDeliveryTime, SortFlags.Ascend), SortTableFlags.None);
                PropValue[][] array = mapiTable.QueryRows(100, QueryRowsFlags.None);
                List <byte[]> list  = new List <byte[]>(100);
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    if (TestMailFlowHelper.IsValidPropData(array, i, 2))
                    {
                        if (array[i][1].GetDateTime() > t)
                        {
                            break;
                        }
                        list.Add(array[i][0].GetBytes());
                    }
                }
                if (list.Count > 0)
                {
                    folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list.ToArray());
                }
            }
            finally
            {
                if (contentsTable != null)
                {
                    ((IDisposable)contentsTable).Dispose();
                }
            }
        }
Пример #15
0
        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);
        }
Пример #16
0
        public static PropValue[][] QueryAllRows(MapiTable msgTable, Restriction restriction, ICollection <PropTag> propTags, int pageSize)
        {
            MapiUtils.InitQueryAllRows(msgTable, restriction, propTags);
            List <PropValue[]> list = new List <PropValue[]>();

            for (;;)
            {
                PropValue[][] array = msgTable.QueryRows(pageSize);
                if (array.GetLength(0) == 0)
                {
                    break;
                }
                list.AddRange(array);
            }
            return(list.ToArray());
        }
Пример #17
0
 PropValueData[][] IFolder.GetACL(SecurityProp secProp)
 {
     if (!this.HasSecurityDescriptor(secProp))
     {
         return(null);
     }
     if (this.Mailbox.ServerVersion >= Server.E15MinVersion)
     {
         MrsTracer.Provider.Warning("MAPI provider does not support GetACL against E15+ mailboxes", new object[0]);
         return(null);
     }
     PropValueData[][] result;
     using (this.Mailbox.RHTracker.Start())
     {
         using (MapiModifyTable mapiModifyTable = (MapiModifyTable)this.Folder.OpenProperty(PropTag.AclTable, InterfaceIds.IExchangeModifyTable, 0, OpenPropertyFlags.DeferredErrors))
         {
             GetTableFlags getTableFlags = GetTableFlags.DeferredErrors;
             if (secProp == SecurityProp.FreeBusyNTSD)
             {
                 getTableFlags |= GetTableFlags.FreeBusy;
             }
             using (MapiTable table = mapiModifyTable.GetTable(getTableFlags))
             {
                 PropTag[] propTags = new PropTag[]
                 {
                     PropTag.EntryId,
                     PropTag.MemberId,
                     PropTag.MemberRights,
                     PropTag.MemberName
                 };
                 table.SeekRow(BookMark.Beginning, 0);
                 PropValue[][]     array  = MapiUtils.QueryAllRows(table, null, propTags);
                 PropValueData[][] array2 = new PropValueData[array.Length][];
                 int num = 0;
                 foreach (PropValue[] a in array)
                 {
                     array2[num++] = DataConverter <PropValueConverter, PropValue, PropValueData> .GetData(a);
                 }
                 result = array2;
             }
         }
     }
     return(result);
 }
        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);
        }
Пример #19
0
 private bool FoundMessage(int docIdToLookFor)
 {
     this.AddMonitoringEvent(this.searchResult, Strings.TestSearchFindMessage(this.searchResult.Database, this.searchResult.Mailbox));
     try
     {
         using (MapiTable contentsTable = this.searchFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
         {
             this.threadExit.CheckStop();
             Restriction restriction = new Restriction.PropertyRestriction(Restriction.RelOp.Equal, PropTag.DocumentId, docIdToLookFor);
             if (contentsTable.QueryOneValue(PropTag.DocumentId, restriction) != null)
             {
                 return(true);
             }
         }
     }
     catch (MapiExceptionNotFound)
     {
         return(false);
     }
     return(false);
 }
Пример #20
0
        protected static MapiMessage GetDeliveryReceipt(MapiFolder folder, string subject, bool dsnOnly)
        {
            string    value = DsnHumanReadableWriter.GetLocalizedSubjectPrefix(DsnFlags.Relay).ToString();
            MapiTable contentsTable;
            MapiTable mapiTable = contentsTable = folder.GetContentsTable();

            try
            {
                mapiTable.SetColumns(new PropTag[]
                {
                    PropTag.EntryId,
                    PropTag.Subject,
                    PropTag.MessageClass
                });
                PropValue[][] array = mapiTable.QueryRows(1000, QueryRowsFlags.None);
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    if (!dsnOnly || ObjectClass.IsDsnPositive(array[i][2].Value.ToString()))
                    {
                        string text = array[i][1].Value.ToString();
                        if ((!text.StartsWith(value, StringComparison.OrdinalIgnoreCase) || subject.StartsWith(value, StringComparison.OrdinalIgnoreCase)) && text.EndsWith(subject, StringComparison.OrdinalIgnoreCase))
                        {
                            byte[] bytes = array[i][0].GetBytes();
                            return((MapiMessage)folder.OpenEntry(bytes));
                        }
                    }
                }
            }
            finally
            {
                if (contentsTable != null)
                {
                    ((IDisposable)contentsTable).Dispose();
                }
            }
            return(null);
        }
Пример #21
0
        public void ProcessJobsInBatches(Restriction restriction, bool applyManualSort, SortOrder sort, MapiTable contentsTable, MapiStore systemMbx, Func <MoveJob, bool> stoppingCondition)
        {
            List <MoveJob> allMoveJobs = SystemMailboxJobs.GetAllMoveJobs(restriction, sort, contentsTable, this.MdbGuid, stoppingCondition);

            if (allMoveJobs != null)
            {
                if (applyManualSort)
                {
                    allMoveJobs.Sort();
                }
                MrsTracer.Throttling.Debug("Sorted jobs for Mdb: {0}", new object[]
                {
                    this.MdbGuid
                });
                SystemMailboxJobs.TraceJobs(allMoveJobs);
                using (List <MoveJob> .Enumerator enumerator = allMoveJobs.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        MoveJob moveJob = enumerator.Current;
                        try
                        {
                            using (SettingsContextBase.ActivateContext(moveJob))
                            {
                                JobPickupRec pickupResult = null;
                                CommonUtils.CatchKnownExceptions(delegate
                                {
                                    pickupResult = moveJob.AttemptToPick(systemMbx);
                                    this.PerformPickupAccounting(moveJob.Status, pickupResult);
                                }, delegate(Exception failure)
                                {
                                    LocalizedString localizedString = CommonUtils.FullExceptionMessage(failure);
                                    pickupResult = new JobPickupRec(moveJob, JobPickupResult.PickupFailure, DateTime.UtcNow + MoveJob.JobPickupRetryInterval, localizedString, null);
                                    MrsTracer.Service.Error("Unexpected failure occurred trying to pick up MoveJob '{0}' from database '{1}', skipping it. {2}", new object[]
                                    {
                                        moveJob.RequestGuid,
                                        this.MdbGuid,
                                        localizedString
                                    });
                                    MailboxReplicationService.LogEvent(MRSEventLogConstants.Tuple_UnableToProcessRequest, new object[]
                                    {
                                        moveJob.RequestGuid.ToString(),
                                        this.MdbGuid.ToString(),
                                        localizedString
                                    });
                                });
                                this.ProcessPickupResults(pickupResult);
                            }
                        }
                        catch (Exception exception)
                        {
                            BaseJob.PerformCrashingFailureActions(moveJob.IdentifyingGuid, moveJob.RequestGuid, exception, RequestState.None, SyncStage.None);
                            throw;
                        }
                    }
                }
            }
        }
Пример #22
0
        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;
        }
Пример #23
0
        public static List <MoveJob> GetAllMoveJobs(Restriction restriction, SortOrder sort, MapiTable contentsTable, Guid mdbGuid, Func <MoveJob, bool> stoppingCondition)
        {
            List <MoveJob> list = null;
            bool           flag = false;

            if (restriction != null)
            {
                contentsTable.Restrict(restriction, RestrictFlags.Batch);
            }
            if (sort != null)
            {
                contentsTable.SortTable(sort, SortTableFlags.Batch);
            }
            contentsTable.SeekRow(BookMark.Beginning, 0);
            do
            {
                PropValue[][] array = contentsTable.QueryRows(1000);
                if (array == null || array.Length <= 0)
                {
                    break;
                }
                if (list == null)
                {
                    list = new List <MoveJob>();
                }
                foreach (PropValue[] properties in array)
                {
                    MoveJob moveJob = new MoveJob(properties, mdbGuid);
                    if (stoppingCondition != null && stoppingCondition(moveJob))
                    {
                        flag = true;
                        break;
                    }
                    list.Add(moveJob);
                }
            }while (!flag);
            return(list);
        }
Пример #24
0
 protected abstract void ProcessJobs(MapiStore systemMbx, MapiTable contentsTable, RequestJobNamedPropertySet nps);
Пример #25
0
 internal ConversationMembersQueryResult(MapiTable mapiTable, ICollection <PropertyDefinition> propertyDefinitions, IList <PropTag> alteredProperties, StoreSession session, bool isTableOwned, SortOrder sortOrder, AggregationExtension aggregationExtension) : base(mapiTable, PropertyDefinitionCollection.Merge <PropertyDefinition>(propertyDefinitions, ConversationMembersQueryResult.RequiredProperties), alteredProperties, session, isTableOwned, sortOrder)
 {
     this.originalProperties   = propertyDefinitions;
     this.aggregationExtension = aggregationExtension;
 }
 public void SetExtendedProps(PropTag[] promotedProperties, RestrictionData[] restrictions, SortOrderData[] views, ICSViewData[] icsViews)
 {
     MrsTracer.Provider.Function("MapiDestinationFolder.SetExtendedProps", new object[0]);
     if (promotedProperties != null && promotedProperties.Length > 0)
     {
         ExecutionContext.Create(new DataContext[]
         {
             new OperationDataContext("MapiDestinationFolder.SetPromotedProps", OperationType.None),
             new PropTagsDataContext(promotedProperties)
         }).Execute(delegate
         {
             using (this.Mailbox.RHTracker.Start())
             {
                 using (MapiTable contentsTable = this.Folder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                 {
                     contentsTable.SetColumns(promotedProperties);
                     contentsTable.QueryRows(1);
                 }
             }
         });
     }
     if (restrictions != null && restrictions.Length > 0)
     {
         MrsTracer.Provider.Debug("Applying restrictions.", new object[0]);
         for (int i = 0; i < restrictions.Length; i++)
         {
             RestrictionData rd = restrictions[i];
             ExecutionContext.Create(new DataContext[]
             {
                 new OperationDataContext("MapiDestinationFolder.ApplyRestriction", OperationType.None),
                 new RestrictionDataContext(rd)
             }).Execute(delegate
             {
                 Restriction native = DataConverter <RestrictionConverter, Restriction, RestrictionData> .GetNative(rd);
                 using (this.Mailbox.RHTracker.Start())
                 {
                     using (MapiTable contentsTable = this.Folder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                     {
                         using (new SortLCIDContext(this.Folder.MapiStore, rd.LCID))
                         {
                             contentsTable.Restrict(native);
                             contentsTable.QueryRows(1);
                         }
                     }
                 }
             });
         }
     }
     if (views != null && views.Length > 0)
     {
         MrsTracer.Provider.Debug("Applying views.", new object[0]);
         for (int j = 0; j < views.Length; j++)
         {
             SortOrderData sod = views[j];
             ExecutionContext.Create(new DataContext[]
             {
                 new OperationDataContext("MapiDestinationFolder.ApplySortOrder", OperationType.None),
                 new SortOrderDataContext(sod)
             }).Execute(delegate
             {
                 SortOrder native = DataConverter <SortOrderConverter, SortOrder, SortOrderData> .GetNative(sod);
                 ContentsTableFlags contentsTableFlags = ContentsTableFlags.DeferredErrors;
                 if (sod.FAI)
                 {
                     contentsTableFlags |= ContentsTableFlags.Associated;
                 }
                 else if (sod.Conversation)
                 {
                     contentsTableFlags |= ContentsTableFlags.ShowConversations;
                 }
                 using (this.Mailbox.RHTracker.Start())
                 {
                     using (MapiTable contentsTable = this.Folder.GetContentsTable(contentsTableFlags))
                     {
                         using (new SortLCIDContext(this.Folder.MapiStore, sod.LCID))
                         {
                             contentsTable.SortTable(native, SortTableFlags.None);
                             contentsTable.QueryRows(1);
                         }
                     }
                 }
             });
         }
     }
     if (icsViews != null && icsViews.Length > 0)
     {
         MrsTracer.Provider.Debug("Applying ICS views.", new object[0]);
         for (int k = 0; k < icsViews.Length; k++)
         {
             ICSViewData icsView = icsViews[k];
             ExecutionContext.Create(new DataContext[]
             {
                 new OperationDataContext("MapiDestinationFolder.ApplyICSView", OperationType.None),
                 new ICSViewDataContext(icsView)
             }).Execute(delegate
             {
                 ManifestConfigFlags flags = ManifestConfigFlags.Associated | ManifestConfigFlags.Normal;
                 if (icsView.Conversation)
                 {
                     flags = ManifestConfigFlags.Conversations;
                 }
                 using (this.Mailbox.RHTracker.Start())
                 {
                     using (MapiManifest mapiManifest = this.Folder.CreateExportManifest())
                     {
                         PropTag[] array = Array <PropTag> .Empty;
                         if (icsView.CoveringPropertyTags != null)
                         {
                             array = new PropTag[icsView.CoveringPropertyTags.Length];
                             for (int l = 0; l < icsView.CoveringPropertyTags.Length; l++)
                             {
                                 array[l] = (PropTag)icsView.CoveringPropertyTags[l];
                             }
                         }
                         mapiManifest.Configure(flags, null, null, MapiDestinationFolder.DummyManifestContentsCallback.Instance, array);
                         while (mapiManifest.Synchronize() != ManifestStatus.Done)
                         {
                         }
                     }
                 }
             });
         }
     }
 }
Пример #27
0
        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);
        }
Пример #28
0
        public void SaveObjectChunks(List <T> chunks, int maxChunks, MoveObjectInfo <T> .GetAdditionalProperties getAdditionalPropertiesCallback)
        {
            if (chunks.Count > maxChunks)
            {
                MrsTracer.Common.Warning("Too many chunks supplied, truncating", new object[0]);
                chunks.RemoveRange(0, chunks.Count - maxChunks);
            }
            bool flag = false;

            if (this.message == null)
            {
                using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, true))
                {
                    this.FolderId = mapiFolder.GetProp(PropTag.EntryId).GetBytes();
                    this.message  = mapiFolder.CreateMessage();
                }
                this.message.SetProps(new PropValue[]
                {
                    new PropValue(PropTag.MessageClass, this.messageClass),
                    new PropValue(PropTag.Subject, this.subject),
                    new PropValue(PropTag.ReplyTemplateID, this.searchKey)
                });
                flag = true;
            }
            if (chunks.Count > 1)
            {
                using (MapiTable attachmentTable = this.message.GetAttachmentTable())
                {
                    if (attachmentTable != null)
                    {
                        int num = attachmentTable.GetRowCount() - (maxChunks - chunks.Count);
                        if (num > 0)
                        {
                            attachmentTable.SetColumns(MoveObjectInfo <T> .AttachmentTagsToLoad);
                            PropValue[][] array = attachmentTable.QueryRows(num);
                            for (int i = 0; i < num; i++)
                            {
                                this.message.DeleteAttach(array[i][0].GetInt());
                            }
                        }
                    }
                }
                for (int j = 0; j < chunks.Count - 1; j++)
                {
                    int num2;
                    using (MapiAttach mapiAttach = this.message.CreateAttach(out num2))
                    {
                        using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                        {
                            MoveObjectInfo <T> .SerializeToStream(chunks[j], mapiStream);
                        }
                        mapiAttach.SetProps(new PropValue[]
                        {
                            new PropValue(PropTag.AttachFileName, string.Format("MOI_Chunk_{0:yyyymmdd_HHmmssfff}", DateTime.UtcNow)),
                            new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                        });
                        mapiAttach.SaveChanges();
                    }
                }
            }
            T obj = chunks[chunks.Count - 1];

            if (getAdditionalPropertiesCallback != null)
            {
                this.message.SetProps(getAdditionalPropertiesCallback(this.store));
            }
            using (MapiStream mapiStream2 = this.message.OpenStream(PropTag.Body, OpenPropertyFlags.Create))
            {
                MoveObjectInfo <T> .SerializeToStream(obj, mapiStream2);
            }
            this.message.SaveChanges();
            if (flag)
            {
                this.MessageId = this.message.GetProp(PropTag.EntryId).GetBytes();
            }
        }
Пример #29
0
        public void ModifyPermissions(StoreId folderId, AclTableEntry.ModifyOperation[] modifyOperations, ModifyTableOptions options, bool replaceAllRows)
        {
            using (PublicFolderConnectionLimitsTracker.Instance.GetToken(this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn))
            {
                StoreSession storeSession = null;
                object       thisObject   = null;
                bool         flag         = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    using (MapiStore hierarchyStore = this.GetHierarchyStore())
                    {
                        using (MapiFolder mapiFolder = (MapiFolder)hierarchyStore.OpenEntry(this.GetDestinationSpecificEntryId(hierarchyStore, folderId)))
                        {
                            using (MapiModifyTable mapiModifyTable = (MapiModifyTable)mapiFolder.OpenProperty(PropTag.AclTable, InterfaceIds.IExchangeModifyTable, 0, OpenPropertyFlags.DeferredErrors))
                            {
                                GetTableFlags    getTableFlags    = GetTableFlags.None;
                                ModifyTableFlags modifyTableFlags = ModifyTableFlags.None;
                                if (options == ModifyTableOptions.FreeBusyAware)
                                {
                                    getTableFlags    |= GetTableFlags.FreeBusy;
                                    modifyTableFlags |= ModifyTableFlags.FreeBusy;
                                }
                                if (replaceAllRows)
                                {
                                    modifyTableFlags |= ModifyTableFlags.RowListReplace;
                                }
                                using (MapiTable table = mapiModifyTable.GetTable(getTableFlags))
                                {
                                    Dictionary <byte[], long> entryIdToMemberIdMap = RPCPrimaryHierarchyProvider.GetEntryIdToMemberIdMap(table.QueryAllRows(null, RPCPrimaryHierarchyProvider.MapiAclTableColumns));
                                    List <RowEntry>           list = new List <RowEntry>(modifyOperations.Length);
                                    foreach (AclTableEntry.ModifyOperation modifyOperation in modifyOperations)
                                    {
                                        switch (modifyOperation.Operation)
                                        {
                                        case ModifyTableOperationType.Add:
                                            list.Add(RPCPrimaryHierarchyProvider.ConvertToRowEntry(modifyOperation));
                                            break;

                                        case ModifyTableOperationType.Modify:
                                        case ModifyTableOperationType.Remove:
                                        {
                                            AclTableEntry.ModifyOperation modifyOperation2 = modifyOperation;
                                            if (modifyOperation.Entry.MemberId != -1L && modifyOperation.Entry.MemberId != 0L)
                                            {
                                                if (entryIdToMemberIdMap.ContainsKey(modifyOperation.Entry.MemberEntryId))
                                                {
                                                    modifyOperation2 = new AclTableEntry.ModifyOperation(modifyOperation.Operation, new AclTableEntry(entryIdToMemberIdMap[modifyOperation.Entry.MemberEntryId], null, null, modifyOperation.Entry.MemberRights));
                                                }
                                                else if (modifyOperation.Operation == ModifyTableOperationType.Modify)
                                                {
                                                    modifyOperation2 = new AclTableEntry.ModifyOperation(ModifyTableOperationType.Add, new AclTableEntry(0L, modifyOperation.Entry.MemberEntryId, null, modifyOperation.Entry.MemberRights));
                                                }
                                                else
                                                {
                                                    modifyOperation2 = null;
                                                }
                                            }
                                            if (modifyOperation2 != null)
                                            {
                                                list.Add(RPCPrimaryHierarchyProvider.ConvertToRowEntry(modifyOperation2));
                                            }
                                            break;
                                        }
                                        }
                                    }
                                    mapiModifyTable.ModifyTable(modifyTableFlags, list.ToArray());
                                }
                            }
                        }
                    }
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExWrappedStreamFailure, ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("RPCPrimaryHierarchyProvider.WriteAclPropertyStream : folderId = {0}", folderId),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExWrappedStreamFailure, ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("RPCPrimaryHierarchyProvider.WriteAclPropertyStream : folderId = {0}", folderId),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
            }
        }
 private void MatchCrossPremiseMessages(MapiFolder responseFolder, MapiFolder probeFolder, SmtpAddress source, List <SmtpAddress> targets)
 {
     using (MapiTable contentsTable = responseFolder.GetContentsTable())
     {
         using (MapiTable contentsTable2 = probeFolder.GetContentsTable())
         {
             contentsTable.SetColumns(new PropTag[]
             {
                 PropTag.EntryId,
                 PropTag.Subject,
                 PropTag.ClientSubmitTime
             });
             contentsTable2.SetColumns(new PropTag[]
             {
                 PropTag.EntryId,
                 PropTag.Subject,
                 PropTag.ClientSubmitTime
             });
             PropValue[][] array  = contentsTable.QueryRows(1000, QueryRowsFlags.None);
             PropValue[][] array2 = contentsTable2.QueryRows(1000, QueryRowsFlags.None);
             List <byte[]> list   = new List <byte[]>();
             List <byte[]> list2  = new List <byte[]>();
             Dictionary <SmtpAddress, CrossPremiseTestMailFlowHelper.HealthData> dictionary = new Dictionary <SmtpAddress, CrossPremiseTestMailFlowHelper.HealthData>(targets.Count);
             for (int i = 0; i <= array2.GetUpperBound(0); i++)
             {
                 if (TestMailFlowHelper.IsValidPropData(array2, i, 3))
                 {
                     string text = (string)array2[i][1].Value;
                     if (text.StartsWith("CrossPremiseMailFlowMonitoring-", StringComparison.OrdinalIgnoreCase))
                     {
                         byte[] bytes = array2[i][0].GetBytes();
                         using (MapiMessage mapiMessage = (MapiMessage)probeFolder.OpenEntry(bytes))
                         {
                             SmtpAddress key = SmtpAddress.Parse((string)mapiMessage.GetProp(PropTag.ReceivedByEmailAddress).Value);
                             if (!dictionary.ContainsKey(key))
                             {
                                 dictionary.Add(key, new CrossPremiseTestMailFlowHelper.HealthData(EnhancedTimeSpan.Zero, EnhancedTimeSpan.Zero, 0, 0, 0, 0));
                             }
                             ExDateTime exDateTime = (ExDateTime)array2[i][2].GetDateTime();
                             if (exDateTime.Add(base.Task.CrossPremisesExpirationTimeout) < ExDateTime.UtcNow)
                             {
                                 dictionary[key].ExpiredNumber++;
                                 list.Add(bytes);
                             }
                             else
                             {
                                 for (int j = 0; j <= array.GetUpperBound(0); j++)
                                 {
                                     if (TestMailFlowHelper.IsValidPropData(array, j, 3))
                                     {
                                         string text2 = (string)array[j][1].Value;
                                         if (text2.EndsWith(text, StringComparison.OrdinalIgnoreCase))
                                         {
                                             byte[] bytes2 = array[j][0].GetBytes();
                                             if (((ExDateTime)array[j][2].GetDateTime()).Add(base.Task.CrossPremisesExpirationTimeout) < ExDateTime.UtcNow)
                                             {
                                                 list2.Add(bytes2);
                                             }
                                             else
                                             {
                                                 using (MapiMessage mapiMessage2 = (MapiMessage)responseFolder.OpenEntry(bytes2))
                                                 {
                                                     EnhancedTimeSpan t;
                                                     EnhancedTimeSpan t2;
                                                     if (this.ProcessCrossPremiseMessagePair(mapiMessage, mapiMessage2, source.ToString(), key.ToString(), out t, out t2))
                                                     {
                                                         dictionary[key].ProbeLatency    += t;
                                                         dictionary[key].ResponseLatency += t2;
                                                         dictionary[key].SuccessNumber++;
                                                     }
                                                     else
                                                     {
                                                         dictionary[key].FailedNumber++;
                                                     }
                                                 }
                                                 list2.Add(bytes2);
                                                 list.Add(bytes);
                                             }
                                         }
                                     }
                                 }
                                 if (!list.Contains(bytes) && exDateTime.AddMinutes(10.0) < ExDateTime.UtcNow)
                                 {
                                     dictionary[key].PendingNumber++;
                                 }
                             }
                         }
                     }
                 }
             }
             this.SaveHealthData(source, dictionary);
             if (list2.Count > 0)
             {
                 responseFolder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list2.ToArray());
             }
             if (list.Count > 0)
             {
                 probeFolder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list.ToArray());
             }
         }
     }
 }