예제 #1
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();
        }
예제 #2
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);
        }