Exemplo n.º 1
0
 public void SaveObject(T obj, MoveObjectInfo <T> .GetAdditionalProperties getAdditionalPropertiesCallback)
 {
     this.SaveObjectChunks(new List <T>(1)
     {
         obj
     }, 1, getAdditionalPropertiesCallback);
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        private static T ReadObjectFromMessage(MapiMessage mapiMessage, bool throwOnDeserializationError)
        {
            T result;

            using (MapiStream mapiStream = mapiMessage.OpenStream(PropTag.Body, OpenPropertyFlags.BestAccess))
            {
                result = MoveObjectInfo <T> .DeserializeFromStream(mapiStream, throwOnDeserializationError);
            }
            return(result);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 void IReportHelper.Delete(ReportData report, MapiStore storeToUse)
 {
     MapiUtils.RetryOnObjectChanged(delegate
     {
         using (MoveObjectInfo <T> moveObjectInfo = new MoveObjectInfo <T>(Guid.Empty, storeToUse, report.MessageId, this.reportFolderName, this.reportMessageClass, this.CreateMessageSubject(report), this.CreateMessageSearchKey(report)))
         {
             moveObjectInfo.OpenMessage();
             if (moveObjectInfo.MessageFound)
             {
                 moveObjectInfo.DeleteMessage();
             }
         }
     });
     report.MessageId = null;
 }
Exemplo n.º 7
0
 void IReportHelper.Load(ReportData report, MapiStore storeToUse)
 {
     using (MoveObjectInfo <T> moveObjectInfo = new MoveObjectInfo <T>(Guid.Empty, storeToUse, report.MessageId, this.reportFolderName, this.reportMessageClass, this.CreateMessageSubject(report), this.CreateMessageSearchKey(report)))
     {
         if (!moveObjectInfo.OpenMessage())
         {
             report.Entries = null;
         }
         else
         {
             report.MessageId = moveObjectInfo.MessageId;
             report.Entries   = this.DeserializeEntries(moveObjectInfo, false);
         }
     }
 }
        protected override List <ReportEntry> DeserializeEntries(MoveObjectInfo <CompressedReport> moveObjectInfo, bool loadLastChunkOnly)
        {
            ReadObjectFlags readObjectFlags = ReadObjectFlags.DontThrowOnCorruptData;

            if (loadLastChunkOnly)
            {
                readObjectFlags |= ReadObjectFlags.LastChunkOnly;
            }
            List <CompressedReport> list = moveObjectInfo.ReadObjectChunks(readObjectFlags);

            if (list == null)
            {
                return(null);
            }
            List <ReportEntry> list2 = new List <ReportEntry>();

            foreach (CompressedReport compressedReport in list)
            {
                list2.AddRange(compressedReport.Entries);
            }
            return(list2);
        }
 protected override void SaveEntries(List <ReportEntry> entries, MoveObjectInfo <CompressedReport> moveObjectInfo)
 {
     if (entries != null && entries.Count > 100)
     {
         List <CompressedReport> list = new List <CompressedReport>();
         int num = 0;
         while (num + 100 < entries.Count)
         {
             list.Add(new CompressedReport(entries.GetRange(num, 100)));
             num += 100;
         }
         list.Add(new CompressedReport(entries.GetRange(num, entries.Count - num)));
         int num2 = TestIntegration.Instance.MaxReportEntryCount / 100;
         if (num2 < 1)
         {
             num2 = 1;
         }
         moveObjectInfo.SaveObjectChunks(list, num2, null);
         return;
     }
     moveObjectInfo.SaveObject(new CompressedReport(entries));
 }
Exemplo n.º 10
0
 void IReportHelper.Flush(ReportData report, MapiStore storeToUse)
 {
     MapiUtils.RetryOnObjectChanged(delegate
     {
         using (MoveObjectInfo <T> moveObjectInfo = new MoveObjectInfo <T>(Guid.Empty, storeToUse, report.MessageId, this.reportFolderName, this.reportMessageClass, this.CreateMessageSubject(report), this.CreateMessageSearchKey(report)))
         {
             if (moveObjectInfo.OpenMessage())
             {
                 report.MessageId            = moveObjectInfo.MessageId;
                 List <ReportEntry> entries  = this.DeserializeEntries(moveObjectInfo, true);
                 List <ReportEntry> entries2 = ReportHelper <T> .MergeEntries(entries, report.NewEntries) ?? new List <ReportEntry>();
                 this.SaveEntries(entries2, moveObjectInfo);
             }
             else
             {
                 List <ReportEntry> entries2 = report.Entries ?? new List <ReportEntry>();
                 this.SaveEntries(entries2, moveObjectInfo);
                 report.MessageId = moveObjectInfo.MessageId;
             }
             report.Entries = null;
         }
     });
 }
Exemplo n.º 11
0
 protected override void SaveEntries(List <ReportEntry> entries, MoveObjectInfo <List <ReportEntry> > moveObjectInfo)
 {
     moveObjectInfo.SaveObject(entries);
 }
Exemplo n.º 12
0
        public IConfigurable Read <T>(ObjectId identity, ReadJobFlags readJobFlags) where T : IConfigurable, new()
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity", "The identity of the object to be read must be specified.");
            }
            if (!(identity is RequestJobObjectId))
            {
                throw new ArgumentException("RequestJobProvider can only identify RequestJobs based on RequestJobObjectIds.", "identity");
            }
            if (!typeof(T).Equals(typeof(TransactionalRequestJob)) && !RequestJobProvider.IsRequestStatistics(typeof(T), true))
            {
                throw new ArgumentException("RequestJobProvider can only Read *RequestStatistics or TransactionalRequestJob objects.");
            }
            bool flag = false;

            if (typeof(T).Equals(typeof(TransactionalRequestJob)))
            {
                flag = true;
            }
            RequestJobObjectId requestJobObjectId = (RequestJobObjectId)identity;
            Guid requestGuid = requestJobObjectId.RequestGuid;
            Guid mdbGuid     = requestJobObjectId.MdbGuid;

            byte[]                    messageId  = requestJobObjectId.MessageId;
            ADUser                    aduser     = requestJobObjectId.User;
            ADUser                    aduser2    = requestJobObjectId.SourceUser;
            ADUser                    aduser3    = requestJobObjectId.TargetUser;
            IRequestIndexEntry        indexEntry = requestJobObjectId.IndexEntry;
            List <IRequestIndexEntry> list       = new List <IRequestIndexEntry>();

            if (requestGuid == Guid.Empty || mdbGuid == Guid.Empty)
            {
                throw new NotEnoughInformationToFindMoveRequestPermanentException();
            }
            this.EnsureStoreConnectionExists(mdbGuid);
            MoveObjectInfo <RequestJobXML> moveObjectInfo = null;
            IConfigurable result;

            try
            {
                moveObjectInfo = new MoveObjectInfo <RequestJobXML>(mdbGuid, this.store, messageId, RequestJobXML.RequestJobsFolderName, RequestJobXML.RequestJobsMessageClass, RequestJobXML.CreateMessageSubject(requestGuid), RequestJobXML.CreateMessageSearchKey(requestGuid));
                RequestJobXML requestJobXML = null;
                if (moveObjectInfo.OpenMessage())
                {
                    if (moveObjectInfo.CheckObjectType(new MoveObjectInfo <RequestJobXML> .IsSupportedObjectTypeDelegate(RequestJobXML.IsMessageTypeSupported)))
                    {
                        requestJobXML = moveObjectInfo.ReadObject(ReadObjectFlags.DontThrowOnCorruptData);
                    }
                    else
                    {
                        MrsTracer.Common.Warning("Found unexpected JobType for move job {0}", new object[]
                        {
                            requestJobObjectId.ToString()
                        });
                    }
                    if (requestJobXML == null)
                    {
                        if (!this.AllowInvalid)
                        {
                            return(null);
                        }
                        requestJobXML              = RequestJobBase.CreateDummyObject <RequestJobXML>();
                        requestJobXML.RequestGuid  = requestGuid;
                        requestJobXML.ExchangeGuid = requestGuid;
                    }
                    requestJobXML.OriginatingMDBGuid = mdbGuid;
                    if (requestJobXML.Identity == null)
                    {
                        requestJobXML.Identity = requestJobObjectId;
                    }
                    requestJobXML.Identity.MessageId = moveObjectInfo.MessageId;
                    RequestJobProvider.FixTenantInfo(requestJobXML);
                    if (!requestJobXML.IsFake)
                    {
                        using (this.IndexProvider.RescopeTo(requestJobXML.DomainControllerToUpdate, requestJobXML.OrganizationId))
                        {
                            if (aduser == null && requestJobXML.UserId != null)
                            {
                                aduser = this.IndexProvider.ReadADUser(requestJobXML.UserId, requestJobXML.ExchangeGuid);
                            }
                            if (aduser2 == null && requestJobXML.SourceUserId != null)
                            {
                                aduser2 = this.IndexProvider.ReadADUser(requestJobXML.SourceUserId, requestJobXML.SourceExchangeGuid);
                            }
                            if (aduser3 == null && requestJobXML.TargetUserId != null)
                            {
                                aduser3 = this.IndexProvider.ReadADUser(requestJobXML.TargetUserId, requestJobXML.TargetExchangeGuid);
                            }
                            if (!typeof(T).Equals(typeof(MoveRequestStatistics)) && requestJobXML.RequestType != MRSRequestType.Move && requestJobXML.IndexIds != null && requestJobXML.IndexIds.Count > 0)
                            {
                                int  capacity = requestJobXML.IndexIds.Count - 1;
                                bool flag2    = false;
                                List <RequestIndexEntryObjectId> list2 = new List <RequestIndexEntryObjectId>(capacity);
                                foreach (RequestIndexId requestIndexId in requestJobXML.IndexIds)
                                {
                                    if (indexEntry != null && requestIndexId.Equals(indexEntry.RequestIndexId))
                                    {
                                        if (!flag2)
                                        {
                                            list.Add(indexEntry);
                                        }
                                        flag2 = true;
                                    }
                                    else if (readJobFlags.HasFlag(ReadJobFlags.SkipReadingMailboxRequestIndexEntries) && requestIndexId.Location == RequestIndexLocation.Mailbox)
                                    {
                                        MrsTracer.Common.Debug("Skipping loading of an IRequestIndexEntry found in a mailbox.", new object[0]);
                                    }
                                    else
                                    {
                                        list2.Add(new RequestIndexEntryObjectId(requestJobXML.RequestGuid, requestJobXML.TargetExchangeGuid, requestJobXML.RequestType, requestJobXML.OrganizationId, requestIndexId, null));
                                    }
                                }
                                foreach (RequestIndexEntryObjectId objectId in list2)
                                {
                                    IRequestIndexEntry requestIndexEntry = this.IndexProvider.Read(objectId);
                                    if (requestIndexEntry != null)
                                    {
                                        list.Add(requestIndexEntry);
                                    }
                                }
                            }
                            if (this.IndexProvider.DomainController == null && !string.IsNullOrEmpty(requestJobXML.DomainControllerToUpdate))
                            {
                                requestJobXML.DomainControllerToUpdate = null;
                            }
                        }
                    }
                    requestJobXML.User         = aduser;
                    requestJobXML.SourceUser   = aduser2;
                    requestJobXML.TargetUser   = aduser3;
                    requestJobXML.IndexEntries = list;
                    if (!readJobFlags.HasFlag(ReadJobFlags.SkipValidation))
                    {
                        requestJobXML.ValidateRequestJob();
                    }
                    if (this.AllowInvalid)
                    {
                        ValidationError[] array = requestJobXML.Validate();
                        if (array != null && array.Length > 0)
                        {
                            requestJobXML.IsFake = true;
                        }
                    }
                    if (flag)
                    {
                        TransactionalRequestJob transactionalRequestJob = new TransactionalRequestJob(requestJobXML);
                        requestJobXML.Retire();
                        transactionalRequestJob.Provider   = this;
                        transactionalRequestJob.MoveObject = moveObjectInfo;
                        moveObjectInfo = null;
                        result         = transactionalRequestJob;
                    }
                    else
                    {
                        RequestStatisticsBase requestStatisticsBase = RequestJobProvider.CreateRequestStatistics(typeof(T), requestJobXML, true);
                        if (requestStatisticsBase == null)
                        {
                            requestStatisticsBase = new MoveRequestStatistics(requestJobXML);
                            requestJobXML.Retire();
                        }
                        if (this.LoadReport)
                        {
                            ReportData reportData = new ReportData(requestStatisticsBase.IdentifyingGuid, requestStatisticsBase.ReportVersion);
                            reportData.Load(this.SystemMailbox);
                            requestStatisticsBase.Report = reportData.ToReport();
                        }
                        result = requestStatisticsBase;
                    }
                }
                else
                {
                    result = null;
                }
            }
            finally
            {
                if (moveObjectInfo != null)
                {
                    moveObjectInfo.Dispose();
                    moveObjectInfo = null;
                }
            }
            return(result);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
 public static List <T> LoadAll(byte[] searchKey, Guid mdbGuid, MapiStore store, string folderName, MoveObjectInfo <T> .IsSupportedObjectTypeDelegate isSupportedObjectType, MoveObjectInfo <T> .EmptyTDelegate emptyT)
 {
     return(MoveObjectInfo <T> .LoadAll(searchKey, null, mdbGuid, store, folderName, isSupportedObjectType, emptyT));
 }
Exemplo n.º 15
0
 public static List <T> LoadAll(byte[] searchKey, Guid mdbGuid, MapiStore store, string folderName)
 {
     return(MoveObjectInfo <T> .LoadAll(searchKey, mdbGuid, store, folderName, null, null));
 }
Exemplo n.º 16
0
 public static List <T> LoadAll(Guid mdbGuid, MapiStore store, string folderName)
 {
     return(MoveObjectInfo <T> .LoadAll(null, mdbGuid, store, folderName));
 }
Exemplo n.º 17
0
        private void SaveOrDelete(TransactionalRequestJob requestJob, bool save)
        {
            if (!save && (requestJob.MoveObject == null || requestJob.Provider == null || requestJob.Provider != this))
            {
                throw new ArgumentException("RequestJobProvider can only Delete TransactionalRequestJob objects created by this RequestJobProvider.", "instance");
            }
            if (requestJob.Provider != null && requestJob.Provider != this)
            {
                throw new ArgumentException("RequestJobProvider can only work on TransactionalRequestJob objects created by this RequestJobProvider.", "instance");
            }
            Guid guid  = Guid.Empty;
            Guid guid2 = Guid.Empty;

            byte[] messageId = null;
            ADUser aduser    = null;
            List <IRequestIndexEntry> list = null;
            RequestJobObjectId        requestJobObjectId = requestJob.Identity;

            if (requestJobObjectId != null)
            {
                messageId = requestJobObjectId.MessageId;
                guid      = requestJobObjectId.RequestGuid;
                guid2     = requestJobObjectId.MdbGuid;
            }
            else
            {
                if (requestJob.RequestType == MRSRequestType.Move)
                {
                    guid = requestJob.ExchangeGuid;
                }
                else
                {
                    guid = requestJob.RequestGuid;
                }
                guid2 = requestJob.WorkItemQueueMdb.ObjectGuid;
            }
            if (requestJob.RequestQueue == null)
            {
                requestJob.RequestQueue = requestJob.WorkItemQueueMdb;
            }
            if (!(guid == Guid.Empty) && !(guid2 == Guid.Empty))
            {
                if (requestJobObjectId == null)
                {
                    requestJobObjectId  = new RequestJobObjectId(guid, guid2, messageId);
                    requestJob.Identity = requestJobObjectId;
                }
                requestJob.ValidateRequestJob();
                if (requestJob.IsValid)
                {
                    aduser = requestJob.User;
                    list   = requestJob.IndexEntries;
                }
                bool flag = false;
                MoveObjectInfo <RequestJobXML> moveObjectInfo = null;
                try
                {
                    MoveObjectInfo <RequestJobXML> moveObjectInfo2;
                    if (requestJob.MoveObject != null)
                    {
                        moveObjectInfo2 = requestJob.MoveObject;
                    }
                    else
                    {
                        this.EnsureStoreConnectionExists(guid2);
                        moveObjectInfo  = new MoveObjectInfo <RequestJobXML>(guid2, this.store, messageId, RequestJobXML.RequestJobsFolderName, RequestJobXML.RequestJobsMessageClass, RequestJobXML.CreateMessageSubject(guid), RequestJobXML.CreateMessageSearchKey(guid));
                        moveObjectInfo2 = moveObjectInfo;
                    }
                    flag = (moveObjectInfo2.MessageFound || moveObjectInfo2.OpenMessage());
                    if (save)
                    {
                        RequestJobXML requestJobXML = new RequestJobXML(requestJob);
                        requestJobXML.TimeTracker.SetTimestamp(RequestJobTimestamp.LastUpdate, new DateTime?(DateTime.UtcNow));
                        if (!flag)
                        {
                            moveObjectInfo2.DeleteOldMessages();
                        }
                        moveObjectInfo2.SaveObject(requestJobXML, new MoveObjectInfo <RequestJobXML> .GetAdditionalProperties(requestJobXML.GetPropertiesWrittenOnRequestJob));
                        requestJobXML.Retire();
                    }
                    else if (flag)
                    {
                        moveObjectInfo2.DeleteMessage();
                        requestJob.TimeTracker.CurrentState = RequestState.Removed;
                    }
                    else
                    {
                        MrsTracer.Common.Warning("Request job message could not be removed for Request '{0}'.  AD data will still be removed", new object[]
                        {
                            requestJobObjectId
                        });
                    }
                }
                finally
                {
                    if (moveObjectInfo != null)
                    {
                        moveObjectInfo.Dispose();
                        moveObjectInfo = null;
                    }
                }
                if ((aduser != null && requestJob.RequestType == MRSRequestType.Move) || (list != null && requestJob.RequestType != MRSRequestType.Move))
                {
                    if (save && !requestJob.CancelRequest)
                    {
                        using (this.IndexProvider.RescopeTo(requestJob.DomainControllerToUpdate, requestJob.OrganizationId))
                        {
                            MrsTracer.Common.Debug("Updating Index/ADUser data for RequestJob '{0}'.", new object[]
                            {
                                requestJobObjectId
                            });
                            bool flag2 = false;
                            for (;;)
                            {
                                try
                                {
                                    if (requestJob.RequestType == MRSRequestType.Move)
                                    {
                                        this.IndexProvider.UpdateADData(aduser, requestJob, save);
                                        this.IndexProvider.RecipientSession.Save(aduser);
                                    }
                                    else
                                    {
                                        foreach (IRequestIndexEntry requestIndexEntry in list)
                                        {
                                            RequestJobProvider.UpdateIndexEntryData(requestIndexEntry, requestJob);
                                            this.IndexProvider.Save(requestIndexEntry);
                                        }
                                    }
                                }
                                catch (ADTransientException ex)
                                {
                                    if (!flag2 && this.IndexProvider.OwnsSessions)
                                    {
                                        this.IndexProvider.DomainController = null;
                                        flag2 = true;
                                        continue;
                                    }
                                    CommonUtils.LogEvent(MRSEventLogConstants.Tuple_ADWriteFailed, new object[]
                                    {
                                        requestJob.Identity,
                                        requestJob.RequestType,
                                        requestJob.RequestGuid.ToString(),
                                        (requestJob.RequestQueue != null) ? requestJob.RequestQueue.ToString() : "null",
                                        requestJob.Status,
                                        requestJob.StatusDetail,
                                        requestJob.Flags,
                                        CommonUtils.FullExceptionMessage(ex)
                                    });
                                    throw;
                                }
                                break;
                            }
                            return;
                        }
                    }
                    MrsTracer.Common.Warning("Not updating Index/ADUser data for RequestJob '{0}'.", new object[]
                    {
                        requestJobObjectId
                    });
                    return;
                }
                MrsTracer.Common.Warning("Not updating Index/ADUser data for orphaned RequestJob '{0}'.", new object[]
                {
                    requestJobObjectId
                });
                if (!flag && !save)
                {
                    throw new UnableToDeleteMoveRequestMessagePermanentException();
                }
                return;
            }
            if (save)
            {
                throw new MoveRequestMissingInfoSavePermanentException();
            }
            throw new MoveRequestMissingInfoDeletePermanentException();
        }
Exemplo n.º 18
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();
            }
        }
Exemplo n.º 19
0
        private List <T> InternalFind <T>(QueryFilter filter, ObjectId rootId, bool deepSearch, SortBy sortBy, int pageSize) where T : IConfigurable, new()
        {
            if (!RequestJobProvider.IsRequestStatistics(typeof(T), false))
            {
                throw new ArgumentException("RequestJobProvider can only find *RequestStatistics objects.");
            }
            List <T> list = new List <T>();
            RequestJobQueryFilter requestJobQueryFilter = filter as RequestJobQueryFilter;

            if (requestJobQueryFilter != null)
            {
                MRSRequestType?requestType = requestJobQueryFilter.RequestType;
                Guid           mdbGuid     = requestJobQueryFilter.MdbGuid;
                Guid           requestGuid = requestJobQueryFilter.RequestGuid;
                this.EnsureStoreConnectionExists(mdbGuid);
                Restriction restriction = null;
                if (requestType != null)
                {
                    RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(this.SystemMailbox);
                    restriction = Restriction.EQ(requestJobNamedPropertySet.PropTags[14], requestType.Value);
                    if (requestType.Value == MRSRequestType.Move)
                    {
                        restriction = Restriction.Or(new Restriction[]
                        {
                            Restriction.Not(Restriction.Exist(requestJobNamedPropertySet.PropTags[14])),
                            restriction
                        });
                    }
                }
                byte[] searchKey = null;
                if (requestGuid != Guid.Empty)
                {
                    searchKey = RequestJobXML.CreateMessageSearchKey(requestGuid);
                }
                List <RequestJobXML> list2 = MoveObjectInfo <RequestJobXML> .LoadAll(searchKey, restriction, mdbGuid, this.store, RequestJobXML.RequestJobsFolderName, new MoveObjectInfo <RequestJobXML> .IsSupportedObjectTypeDelegate(RequestJobXML.IsMessageTypeSupported), new MoveObjectInfo <RequestJobXML> .EmptyTDelegate(this.CreateDummyFromSearchKey));

                if (list2 == null || list2.Count == 0)
                {
                    MrsTracer.Common.Debug("No RequestJob messages found.", new object[0]);
                }
                else
                {
                    foreach (RequestJobXML requestJobXML in list2)
                    {
                        RequestJobProvider.FixTenantInfo(requestJobXML);
                        RequestStatisticsBase requestStatisticsBase = RequestJobProvider.CreateRequestStatistics(typeof(T), requestJobXML, true);
                        requestStatisticsBase.OriginatingMDBGuid = mdbGuid;
                        if (requestStatisticsBase.Identity == null)
                        {
                            requestStatisticsBase.Identity = new RequestJobObjectId(requestStatisticsBase.IdentifyingGuid, mdbGuid, null);
                        }
                        if (!requestStatisticsBase.IsFake)
                        {
                            using (this.IndexProvider.RescopeTo(requestStatisticsBase.DomainControllerToUpdate, requestStatisticsBase.OrganizationId))
                            {
                                if (requestStatisticsBase.UserId != null)
                                {
                                    requestStatisticsBase.User = this.IndexProvider.ReadADUser(requestStatisticsBase.UserId, requestStatisticsBase.ExchangeGuid);
                                }
                                if (requestStatisticsBase.SourceUserId != null)
                                {
                                    requestStatisticsBase.SourceUser = this.IndexProvider.ReadADUser(requestStatisticsBase.SourceUserId, requestStatisticsBase.SourceExchangeGuid);
                                }
                                if (requestStatisticsBase.TargetUserId != null)
                                {
                                    requestStatisticsBase.TargetUser = this.IndexProvider.ReadADUser(requestStatisticsBase.TargetUserId, requestStatisticsBase.TargetExchangeGuid);
                                }
                                if (!typeof(T).Equals(typeof(MoveRequestStatistics)) && requestStatisticsBase.RequestType != MRSRequestType.Move)
                                {
                                    List <IRequestIndexEntry> list3 = new List <IRequestIndexEntry>();
                                    if (requestStatisticsBase.IndexIds != null && requestStatisticsBase.IndexIds.Count > 0)
                                    {
                                        foreach (RequestIndexId indexId in requestStatisticsBase.IndexIds)
                                        {
                                            IRequestIndexEntry requestIndexEntry;
                                            try
                                            {
                                                requestIndexEntry = this.IndexProvider.Read(new RequestIndexEntryObjectId(requestStatisticsBase.RequestGuid, requestStatisticsBase.TargetExchangeGuid, requestStatisticsBase.RequestType, requestStatisticsBase.OrganizationId, indexId, null));
                                            }
                                            catch (TenantOrgContainerNotFoundException)
                                            {
                                                requestIndexEntry = null;
                                            }
                                            if (requestIndexEntry != null)
                                            {
                                                list3.Add(requestIndexEntry);
                                            }
                                        }
                                    }
                                    requestStatisticsBase.IndexEntries = list3;
                                }
                                if (this.IndexProvider.DomainController == null && !string.IsNullOrEmpty(requestStatisticsBase.DomainControllerToUpdate))
                                {
                                    requestStatisticsBase.DomainControllerToUpdate = null;
                                }
                            }
                        }
                        requestStatisticsBase.ValidateRequestJob();
                        if (this.LoadReport)
                        {
                            ReportData reportData = new ReportData(requestStatisticsBase.IdentifyingGuid, requestStatisticsBase.ReportVersion);
                            reportData.Load(this.SystemMailbox);
                            requestStatisticsBase.Report = reportData.ToReport();
                        }
                        if (requestStatisticsBase != null && requestStatisticsBase.GetType().Equals(typeof(T)))
                        {
                            list.Add((T)((object)requestStatisticsBase));
                        }
                    }
                }
            }
            return(list);
        }
Exemplo n.º 20
0
 public bool CheckObjectType(MoveObjectInfo <T> .IsSupportedObjectTypeDelegate isSupportedObjectType)
 {
     return(isSupportedObjectType(this.message, this.store));
 }
Exemplo n.º 21
0
 protected abstract void SaveEntries(List <ReportEntry> entries, MoveObjectInfo <T> moveObjectInfo);
Exemplo n.º 22
0
 protected override List <ReportEntry> DeserializeEntries(MoveObjectInfo <List <ReportEntry> > moveObjectInfo, bool loadLastChunkOnly)
 {
     return(moveObjectInfo.ReadObject(ReadObjectFlags.DontThrowOnCorruptData));
 }
Exemplo n.º 23
0
        public override void Run()
        {
            Guid currentQueueGuid        = this.CurrentRequestQueue.ObjectGuid;
            Guid newQueueGuid            = this.NewRequestQueue.ObjectGuid;
            RequestJobObjectId currentId = new RequestJobObjectId(base.RequestGuid, currentQueueGuid, this.MessageId);
            RequestJobObjectId newId     = new RequestJobObjectId(base.RequestGuid, newQueueGuid, null);

            CommonUtils.CatchKnownExceptions(delegate
            {
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.NewRequestQueue, null, null, FindServerFlags.None);
                if (databaseInformation.ServerVersion < Server.E15MinVersion)
                {
                    throw new UnsupportedRehomeTargetVersionPermanentException(newQueueGuid.ToString(), new ServerVersion(databaseInformation.ServerVersion).ToString());
                }
                this.NewSystemMailbox = MapiUtils.GetSystemMailbox(newQueueGuid);
                using (RequestJobProvider currentQueueProvider = new RequestJobProvider(currentQueueGuid, this.CurrentSystemMailbox))
                {
                    using (RequestJobProvider newQueueProvider = new RequestJobProvider(newQueueGuid, this.NewSystemMailbox))
                    {
                        using (TransactionalRequestJob requestJob = (TransactionalRequestJob)currentQueueProvider.Read <TransactionalRequestJob>(currentId))
                        {
                            if (requestJob != null)
                            {
                                RequestJobProvider origProvider       = requestJob.Provider;
                                MoveObjectInfo <RequestJobXML> origMO = requestJob.MoveObject;
                                ReportData currentReport = new ReportData(requestJob.IdentifyingGuid, requestJob.ReportVersion);
                                currentReport.Load(currentQueueProvider.SystemMailbox);
                                ReportData newReport = new ReportData(currentReport.IdentifyingGuid, requestJob.ReportVersion);
                                newReport.Append(currentReport.Entries);
                                try
                                {
                                    requestJob.Provider           = null;
                                    requestJob.MoveObject         = null;
                                    requestJob.RequestQueue       = this.NewRequestQueue;
                                    requestJob.Identity           = newId;
                                    requestJob.OriginatingMDBGuid = Guid.Empty;
                                    requestJob.RehomeRequest      = false;
                                    if (requestJob.IndexEntries != null)
                                    {
                                        foreach (IRequestIndexEntry requestIndexEntry in requestJob.IndexEntries)
                                        {
                                            requestIndexEntry.StorageMDB = this.NewRequestQueue;
                                        }
                                    }
                                    newQueueProvider.Save(requestJob);
                                    CommonUtils.CatchKnownExceptions(delegate
                                    {
                                        newReport.Append(MrsStrings.ReportJobRehomed(currentQueueGuid.ToString(), newQueueGuid.ToString()));
                                        newReport.Flush(newQueueProvider.SystemMailbox);
                                    }, null);
                                    CommonUtils.CatchKnownExceptions(delegate
                                    {
                                        requestJob.Provider           = origProvider;
                                        requestJob.MoveObject         = origMO;
                                        requestJob.RequestQueue       = this.CurrentRequestQueue;
                                        requestJob.Identity           = currentId;
                                        requestJob.OriginatingMDBGuid = currentQueueGuid;
                                        requestJob.RehomeRequest      = true;
                                        MapiUtils.RetryOnObjectChanged(delegate
                                        {
                                            currentQueueProvider.Delete(requestJob);
                                        });
                                        currentReport.Delete(currentQueueProvider.SystemMailbox);
                                    }, null);
                                }
                                catch
                                {
                                    requestJob.Provider           = origProvider;
                                    requestJob.MoveObject         = origMO;
                                    requestJob.RequestQueue       = this.CurrentRequestQueue;
                                    requestJob.Identity           = currentId;
                                    requestJob.OriginatingMDBGuid = currentQueueGuid;
                                    requestJob.RehomeRequest      = true;
                                    throw;
                                }
                            }
                        }
                    }
                }
            }, delegate(Exception failure)
            {
                MrsTracer.Service.Warning("Failed to rehome request.", new object[0]);
                this.RehomeFailure = failure;
            });
            base.Run();
        }
Exemplo n.º 24
0
 protected abstract List <ReportEntry> DeserializeEntries(MoveObjectInfo <T> moveObjectInfo, bool loadLastChunkOnly);