コード例 #1
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);
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
 }
コード例 #4
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);
        }
コード例 #5
0
ファイル: MapiUtils.cs プロジェクト: YHZX2013/exchange_diff
 public static PropValue[][] QueryAllRows(MapiTable msgTable, Restriction restriction, ICollection <PropTag> propTags)
 {
     return(MapiUtils.QueryAllRows(msgTable, restriction, propTags, 1000));
 }