Esempio n. 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);
            }
        }
Esempio n. 2
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);
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public void DeleteOldMessages()
 {
     using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, false))
     {
         if (mapiFolder != null)
         {
             for (int i = 0; i < 100; i++)
             {
                 byte[] array = this.FindMessageId();
                 if (array == null)
                 {
                     break;
                 }
                 mapiFolder.DeleteMessages(DeleteMessagesFlags.None, new byte[][]
                 {
                     array
                 });
             }
         }
     }
 }
Esempio n. 5
0
 public void DeleteMessage()
 {
     if (this.MessageId != null)
     {
         using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, false))
         {
             if (mapiFolder != null)
             {
                 mapiFolder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, new byte[][]
                 {
                     this.MessageId
                 });
             }
         }
         if (this.message != null)
         {
             this.message.Dispose();
             this.message = null;
         }
         this.MessageId = null;
         this.FolderId  = null;
     }
 }
Esempio n. 6
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);
        }
Esempio n. 7
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();
            }
        }
Esempio n. 8
0
 internal static MapiFolder GetRequestJobsFolder(MapiStore systemMbx)
 {
     return(MapiUtils.OpenFolderUnderRoot(systemMbx, RequestJobXML.RequestJobsFolderName, true));
 }