public ManifestContentChangesFetcher(ISourceFolder folder, MapiFolder mapiFolder, MailboxProviderBase mailbox, bool isPagedEnumeration)
 {
     this.folder             = folder;
     this.mapiFolder         = mapiFolder;
     this.mailbox            = mailbox;
     this.isPagedEnumeration = isPagedEnumeration;
 }
Exemple #2
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);
        }
Exemple #3
0
 public static FolderRec Create(MapiFolder folder, PropTag[] additionalPtagsToLoad)
 {
     PropTag[] array;
     if (additionalPtagsToLoad == null)
     {
         array = FolderRec.PtagsToLoad;
     }
     else
     {
         List <PropTag> list = new List <PropTag>();
         list.AddRange(FolderRec.PtagsToLoad);
         list.AddRange(additionalPtagsToLoad);
         array = list.ToArray();
     }
     PropValue[] props  = folder.GetProps(array);
     byte[]      array2 = null;
     for (int i = 0; i < array.Length; i++)
     {
         PropTag propTag  = array[i];
         PropTag propTag2 = propTag;
         if (propTag2 != PropTag.EntryId)
         {
             if (propTag2 == PropTag.LTID)
             {
                 props[i] = new PropValue(PropTag.LTID, folder.MapiStore.GlobalIdFromId(folder.MapiStore.GetFidFromEntryId(array2)));
             }
         }
         else
         {
             array2 = (byte[])props[i].Value;
         }
     }
     return(FolderRec.Create(props));
 }
Exemple #4
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);
            }
        }
Exemple #5
0
 internal virtual void Config(byte[] folderId, MapiFolder folder, MapiMailbox mailbox)
 {
     this.folderId            = folderId;
     this.folder              = folder;
     this.mailbox             = mailbox;
     this.contentsRestriction = null;
 }
 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);
 }
Exemple #7
0
 public static byte[] GetSignatureBytes(MapiStore systemMailbox)
 {
     byte[] result = null;
     using (MapiFolder rootFolder = systemMailbox.GetRootFolder())
     {
         result = (rootFolder.GetProp(PropTag.MappingSignature).Value as byte[]);
     }
     return(result);
 }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
0
        public static MapiFolder OpenFolderUnderRoot(MapiStore mailbox, string folderName, bool createIfMissing)
        {
            MapiFolder result;

            using (MapiFolder nonIpmSubtreeFolder = mailbox.GetNonIpmSubtreeFolder())
            {
                MapiFolder mapiFolder = null;
                try
                {
                    mapiFolder = nonIpmSubtreeFolder.OpenSubFolderByName(folderName);
                }
                catch (MapiExceptionNotFound)
                {
                }
                if (mapiFolder == null && createIfMissing)
                {
                    MrsTracer.Common.Debug("Folder '{0}' does not exist, creating it.", new object[]
                    {
                        folderName
                    });
                    try
                    {
                        mapiFolder = nonIpmSubtreeFolder.CreateFolder(folderName, null, false);
                        MrsTracer.Common.Debug("Created '{0}' folder.", new object[]
                        {
                            folderName
                        });
                    }
                    catch (MapiExceptionCollision)
                    {
                        MrsTracer.Common.Debug("Somebody beat us to creating the folder. Will attempt to open it.", new object[0]);
                    }
                    if (mapiFolder == null)
                    {
                        mapiFolder = nonIpmSubtreeFolder.OpenSubFolderByName(folderName);
                        MrsTracer.Common.Debug("Opened '{0}' folder.", new object[]
                        {
                            folderName
                        });
                    }
                }
                result = mapiFolder;
            }
            return(result);
        }
        void IDestinationMailbox.DeleteFolder(FolderRec folderRec)
        {
            MrsTracer.Provider.Function("MapiDestinationMailbox.DeleteFolder(\"{0}\")", new object[]
            {
                folderRec.FolderName
            });
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            OpenEntryFlags flags = OpenEntryFlags.DeferredErrors | OpenEntryFlags.Modify;

            using (base.RHTracker.Start())
            {
                using (MapiFolder mapiFolder = (MapiFolder)base.MapiStore.OpenEntry(folderRec.ParentId, flags))
                {
                    mapiFolder.AllowWarnings = true;
                    mapiFolder.DeleteFolder(folderRec.EntryId);
                }
            }
        }
        void IDestinationMailbox.MoveFolder(byte[] folderId, byte[] oldParentId, byte[] newParentId)
        {
            MrsTracer.Provider.Function("MapiDestinationMailbox.MoveFolder", new object[0]);
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            OpenEntryFlags flags = OpenEntryFlags.DeferredErrors | OpenEntryFlags.Modify;

            using (base.RHTracker.Start())
            {
                using (MapiFolder mapiFolder = (MapiFolder)base.MapiStore.OpenEntry(oldParentId, flags))
                {
                    using (MapiFolder mapiFolder2 = (MapiFolder)base.MapiStore.OpenEntry(newParentId, flags))
                    {
                        mapiFolder.AllowWarnings = true;
                        mapiFolder.CopyFolder(CopyFolderFlags.FolderMove, mapiFolder2, folderId, null);
                    }
                }
            }
        }
 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
                 });
             }
         }
     }
 }
 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;
     }
 }
Exemple #15
0
        public LocalizedString ComputePositionInQueue(Guid requestGuid)
        {
            int crows = 1000;
            int num   = 0;
            int num2  = 0;

            if (requestGuid.Equals(Guid.Empty))
            {
                return(MrsStrings.ErrorEmptyMailboxGuid);
            }
            using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(this.SystemMailbox))
            {
                using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                {
                    RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(this.SystemMailbox);
                    contentsTable.SetColumns(requestJobNamedPropertySet.PropTags);
                    SortOrder sortOrder = new SortOrder(requestJobNamedPropertySet.PropTags[7], SortFlags.Ascend);
                    contentsTable.SortTable(sortOrder, SortTableFlags.None);
                    Restriction restriction = Restriction.EQ(requestJobNamedPropertySet.PropTags[0], RequestStatus.Queued);
                    contentsTable.Restrict(restriction);
                    contentsTable.SeekRow(BookMark.Beginning, 0);
                    PropValue[][] array = contentsTable.QueryRows(crows);
                    bool          flag  = false;
                    while (array != null && array.Length > 0)
                    {
                        int num3 = 0;
                        if (!flag)
                        {
                            foreach (PropValue[] array3 in array)
                            {
                                num3++;
                                if (num2 + num3 >= 10000)
                                {
                                    break;
                                }
                                Guid value = MapiUtils.GetValue <Guid>(array3[26], Guid.Empty);
                                if (requestGuid.Equals(value))
                                {
                                    flag = true;
                                    num  = num2 + num3;
                                    break;
                                }
                            }
                        }
                        num2 += array.Length;
                        if (num2 >= 10000)
                        {
                            break;
                        }
                        array = contentsTable.QueryRows(crows);
                    }
                }
            }
            LocalizedString value2 = LocalizedString.Empty;
            LocalizedString value3 = LocalizedString.Empty;

            if (num == 0)
            {
                if (num2 < 10000)
                {
                    value2 = MrsStrings.MoveRequestNotFoundInQueue;
                    value3 = MrsStrings.PositionInteger(num2);
                }
                else
                {
                    value2 = MrsStrings.PositionIntegerPlus(10000);
                    value3 = MrsStrings.PositionIntegerPlus(10000);
                }
            }
            else
            {
                value2 = MrsStrings.PositionInteger(num);
                if (num2 < 10000)
                {
                    value3 = MrsStrings.PositionInteger(num2);
                }
                else
                {
                    value3 = MrsStrings.PositionIntegerPlus(num2);
                }
            }
            return(MrsStrings.PositionOfMoveRequestInSystemMailboxQueue(value2, value3));
        }
        void IDestinationMailbox.CreateFolder(FolderRec sourceFolder, CreateFolderFlags createFolderFlags, out byte[] newFolderId)
        {
            MrsTracer.Provider.Function("MapiDestinationMailbox.CreateFolder(\"{0}\")", new object[]
            {
                sourceFolder.FolderName
            });
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            if (createFolderFlags.HasFlag(CreateFolderFlags.InternalAccess))
            {
                throw new InternalAccessFolderCreationIsNotSupportedException();
            }
            FolderRec folderRec = null;

            newFolderId = null;
            using (base.RHTracker.Start())
            {
                if (!createFolderFlags.HasFlag(CreateFolderFlags.FailIfExists) && sourceFolder.EntryId != null)
                {
                    OpenEntryFlags flags = OpenEntryFlags.DontThrowIfEntryIsMissing;
                    using (MapiFolder mapiFolder = (MapiFolder)base.MapiStore.OpenEntry(sourceFolder.EntryId, flags))
                    {
                        if (mapiFolder != null)
                        {
                            folderRec   = FolderRec.Create(mapiFolder, null);
                            newFolderId = folderRec.EntryId;
                        }
                    }
                }
                if (newFolderId == null)
                {
                    OpenEntryFlags flags2 = OpenEntryFlags.DeferredErrors | OpenEntryFlags.Modify;
                    using (MapiFolder mapiFolder2 = (MapiFolder)base.MapiStore.OpenEntry(sourceFolder.ParentId, flags2))
                    {
                        using (MapiFolder mapiFolder3 = mapiFolder2.CreateFolder(sourceFolder.FolderName, null, false, sourceFolder.FolderType == FolderType.Search, sourceFolder.EntryId))
                        {
                            newFolderId = mapiFolder3.GetProp(PropTag.EntryId).GetBytes();
                        }
                        goto IL_160;
                    }
                }
                if (!CommonUtils.IsSameEntryId(folderRec.ParentId, sourceFolder.ParentId))
                {
                    MrsTracer.Provider.Debug("Existing folder is under the wrong parent. Moving it.", new object[0]);
                    ((IDestinationMailbox)this).MoveFolder(folderRec.EntryId, folderRec.ParentId, sourceFolder.ParentId);
                }
IL_160:
                PropTag[] promotedProperties = sourceFolder.GetPromotedProperties();
                if ((promotedProperties != null && promotedProperties.Length > 0) || (sourceFolder.Restrictions != null && sourceFolder.Restrictions.Length > 0) || (sourceFolder.Views != null && sourceFolder.Views.Length > 0) || (sourceFolder.ICSViews != null && sourceFolder.ICSViews.Length > 0))
                {
                    using (MapiDestinationFolder folder = base.GetFolder <MapiDestinationFolder>(newFolderId))
                    {
                        ICSViewData[] icsViews = null;
                        if (this.ServerVersion >= Server.E15MinVersion)
                        {
                            icsViews = sourceFolder.ICSViews;
                        }
                        folder.SetExtendedProps(promotedProperties, sourceFolder.Restrictions, sourceFolder.Views, icsViews);
                    }
                }
            }
        }
Exemple #17
0
 public TitaniumContentChangesFetcher(ISourceFolder folder, MapiFolder mapiFolder, MailboxProviderBase mailbox)
 {
     this.folder     = folder;
     this.mapiFolder = mapiFolder;
     this.mailbox    = mailbox;
 }
Exemple #18
0
        protected override MapiFxProxyPool.FolderEntry OpenFolder(byte[] folderID)
        {
            MapiFolder folder = (MapiFolder)this.destMailbox.OpenMapiEntry(folderID, folderID, OpenEntryFlags.Modify | OpenEntryFlags.DontThrowIfEntryIsMissing);

            return(MapiFxProxyPool.FolderEntry.Wrap(folder));
        }
        public void PickupJobs(out string failure)
        {
            string dbName      = null;
            string scanFailure = null;

            failure = null;
            using (new DatabaseSettingsContext(this.MdbGuid, null).Activate())
            {
                CommonUtils.CatchKnownExceptions(delegate
                {
                    DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.MdbGuid, null, null, FindServerFlags.None);
                    dbName = databaseInformation.DatabaseName;
                    if (!databaseInformation.IsOnThisServer)
                    {
                        scanFailure = string.Format("MDB is mounted on remote server {0}", databaseInformation.ServerFqdn);
                        MRSQueue.RemoveQueue(this.MdbGuid);
                        return;
                    }
                    MrsTracer.Service.Debug("Picking up jobs from '{0}' ({1})", new object[]
                    {
                        dbName,
                        this.MdbGuid
                    });
                    using (MapiStore systemMailbox = MapiUtils.GetSystemMailbox(this.MdbGuid, false))
                    {
                        using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(systemMailbox))
                        {
                            using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                            {
                                if (contentsTable.GetRowCount() > 0)
                                {
                                    RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(systemMailbox);
                                    contentsTable.SetColumns(requestJobNamedPropertySet.PropTags);
                                    this.ProcessJobs(systemMailbox, contentsTable, requestJobNamedPropertySet);
                                }
                            }
                        }
                    }
                    MrsTracer.Service.Debug("Pick up jobs from Mdb: '{0}' - complete.", new object[]
                    {
                        dbName
                    });
                }, delegate(Exception f)
                {
                    if (dbName == null)
                    {
                        dbName = MrsStrings.MissingDatabaseName(this.MdbGuid).ToString();
                    }
                    MrsTracer.Service.Debug("PickupJobs() failed for mdb '{0}'. Error: {1}", new object[]
                    {
                        dbName,
                        CommonUtils.FullExceptionMessage(f)
                    });
                    scanFailure = CommonUtils.FullExceptionMessage(f, true);
                    MRSService.LogEvent(MRSEventLogConstants.Tuple_UnableToProcessJobsInDatabase, new object[]
                    {
                        dbName,
                        CommonUtils.FullExceptionMessage(f)
                    });
                });
            }
            failure = scanFailure;
        }
        public static List <T> LoadAll(byte[] searchKey, Restriction additionalRestriction, Guid mdbGuid, MapiStore store, string folderName, MoveObjectInfo <T> .IsSupportedObjectTypeDelegate isSupportedObjectType, MoveObjectInfo <T> .EmptyTDelegate emptyT)
        {
            List <T> list = new List <T>();

            using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(store, folderName, false))
            {
                if (mapiFolder == null)
                {
                    return(list);
                }
                using (MapiTable contentsTable = mapiFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                {
                    PropTag propTag = PropTag.ReplyTemplateID;
                    contentsTable.SortTable(new SortOrder(propTag, SortFlags.Ascend), SortTableFlags.None);
                    List <PropTag> list2 = new List <PropTag>();
                    list2.Add(PropTag.EntryId);
                    list2.Add(propTag);
                    Restriction restriction = null;
                    if (searchKey != null)
                    {
                        restriction = Restriction.EQ(propTag, searchKey);
                    }
                    if (additionalRestriction != null)
                    {
                        if (restriction == null)
                        {
                            restriction = additionalRestriction;
                        }
                        else
                        {
                            restriction = Restriction.And(new Restriction[]
                            {
                                restriction,
                                additionalRestriction
                            });
                        }
                    }
                    foreach (PropValue[] array2 in MapiUtils.QueryAllRows(contentsTable, restriction, list2))
                    {
                        byte[]         bytes  = array2[0].GetBytes();
                        byte[]         bytes2 = array2[1].GetBytes();
                        OpenEntryFlags flags  = OpenEntryFlags.Modify | OpenEntryFlags.DontThrowIfEntryIsMissing;
                        using (MapiMessage mapiMessage = (MapiMessage)store.OpenEntry(bytes, flags))
                        {
                            if (mapiMessage != null)
                            {
                                T t = default(T);
                                if (isSupportedObjectType != null)
                                {
                                    if (isSupportedObjectType(mapiMessage, store))
                                    {
                                        t = MoveObjectInfo <T> .ReadObjectFromMessage(mapiMessage, false);
                                    }
                                    if (t == null && emptyT != null)
                                    {
                                        t = emptyT(bytes2);
                                    }
                                }
                                else
                                {
                                    t = MoveObjectInfo <T> .ReadObjectFromMessage(mapiMessage, false);
                                }
                                if (t != null)
                                {
                                    list.Add(t);
                                }
                                else
                                {
                                    MrsTracer.Common.Error("Unable to deserialize message '{0}'.", new object[]
                                    {
                                        bytes
                                    });
                                }
                            }
                        }
                    }
                }
            }
            return(list);
        }
        public 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();
            }
        }
Exemple #22
0
 internal override void Config(byte[] folderId, MapiFolder folder, MapiMailbox mailbox)
 {
     base.Config(folderId, folder, mailbox);
     base.Folder.AllowWarnings = true;
 }