Exemple #1
0
 private static void FixTenantInfo(RequestJobXML requestJobXML)
 {
     if (!CommonUtils.IsMultiTenantEnabled())
     {
         requestJobXML.OrganizationId = OrganizationId.ForestWideOrgId;
         return;
     }
     if (requestJobXML.OrganizationId == OrganizationId.ForestWideOrgId && requestJobXML.ExternalDirectoryOrganizationId == Guid.Empty && requestJobXML.PartitionHint == null)
     {
         return;
     }
     if (requestJobXML.OrganizationId != OrganizationId.ForestWideOrgId && requestJobXML.PartitionHint == null)
     {
         if (requestJobXML.ExternalDirectoryOrganizationId != Guid.Empty)
         {
             requestJobXML.OrganizationId = OrganizationId.FromExternalDirectoryOrganizationId(requestJobXML.ExternalDirectoryOrganizationId);
         }
         requestJobXML.PartitionHint = TenantPartitionHint.FromOrganizationId(requestJobXML.OrganizationId);
         requestJobXML.ExternalDirectoryOrganizationId = requestJobXML.PartitionHint.GetExternalDirectoryOrganizationId();
         return;
     }
     if (requestJobXML.PartitionHint != null)
     {
         if (requestJobXML.ExternalDirectoryOrganizationId == Guid.Empty)
         {
             requestJobXML.ExternalDirectoryOrganizationId = requestJobXML.PartitionHint.GetExternalDirectoryOrganizationId();
         }
         requestJobXML.OrganizationId = OrganizationId.FromExternalDirectoryOrganizationId(requestJobXML.ExternalDirectoryOrganizationId);
     }
 }
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
        internal static bool IsMessageTypeSupported(MapiMessage message, MapiStore store)
        {
            RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(store);
            PropValue  prop  = message.GetProp(requestJobNamedPropertySet.PropTags[9]);
            MRSJobType value = MapiUtils.GetValue <MRSJobType>(prop, MRSJobType.RequestJobE14R3);

            return(RequestJobXML.IsKnownJobType(value));
        }
Exemple #4
0
        internal static RequestStatisticsBase CreateRequestStatistics(Type t, RequestJobXML rj, bool acceptBase)
        {
            RequestStatisticsBase requestStatisticsBase = null;

            if (t.Equals(typeof(MoveRequestStatistics)))
            {
                requestStatisticsBase = new MoveRequestStatistics(rj);
            }
            else if (t.Equals(typeof(MergeRequestStatistics)))
            {
                requestStatisticsBase = new MergeRequestStatistics(rj);
            }
            else if (t.Equals(typeof(MailboxImportRequestStatistics)))
            {
                requestStatisticsBase = new MailboxImportRequestStatistics(rj);
            }
            else if (t.Equals(typeof(MailboxExportRequestStatistics)))
            {
                requestStatisticsBase = new MailboxExportRequestStatistics(rj);
            }
            else if (t.Equals(typeof(MailboxRelocationRequestStatistics)))
            {
                requestStatisticsBase = new MailboxRelocationRequestStatistics(rj);
            }
            else if (t.Equals(typeof(MailboxRestoreRequestStatistics)))
            {
                requestStatisticsBase = new MailboxRestoreRequestStatistics(rj);
            }
            else if (t.Equals(typeof(PublicFolderMoveRequestStatistics)))
            {
                requestStatisticsBase = new PublicFolderMoveRequestStatistics(rj);
            }
            else if (t.Equals(typeof(PublicFolderMigrationRequestStatistics)))
            {
                requestStatisticsBase = new PublicFolderMigrationRequestStatistics(rj);
            }
            else if (t.Equals(typeof(PublicFolderMailboxMigrationRequestStatistics)))
            {
                requestStatisticsBase = new PublicFolderMailboxMigrationRequestStatistics(rj);
            }
            else if (t.Equals(typeof(SyncRequestStatistics)))
            {
                requestStatisticsBase = new SyncRequestStatistics(rj);
            }
            else if (t.Equals(typeof(FolderMoveRequestStatistics)))
            {
                requestStatisticsBase = new FolderMoveRequestStatistics(rj);
            }
            else if (acceptBase && t.Equals(typeof(RequestStatisticsBase)))
            {
                return(RequestJobProvider.CreateRequestStatistics(rj));
            }
            if (requestStatisticsBase != null)
            {
                rj.Retire();
            }
            return(requestStatisticsBase);
        }
Exemple #5
0
        internal static RequestStatisticsBase CreateRequestStatistics(RequestJobXML rj)
        {
            RequestStatisticsBase requestStatisticsBase = null;

            switch (rj.RequestType)
            {
            case MRSRequestType.Move:
                requestStatisticsBase = new MoveRequestStatistics(rj);
                break;

            case MRSRequestType.Merge:
                requestStatisticsBase = new MergeRequestStatistics(rj);
                break;

            case MRSRequestType.MailboxImport:
                requestStatisticsBase = new MailboxImportRequestStatistics(rj);
                break;

            case MRSRequestType.MailboxExport:
                requestStatisticsBase = new MailboxExportRequestStatistics(rj);
                break;

            case MRSRequestType.MailboxRestore:
                requestStatisticsBase = new MailboxRestoreRequestStatistics(rj);
                break;

            case MRSRequestType.PublicFolderMove:
                requestStatisticsBase = new PublicFolderMoveRequestStatistics(rj);
                break;

            case MRSRequestType.PublicFolderMigration:
                requestStatisticsBase = new PublicFolderMigrationRequestStatistics(rj);
                break;

            case MRSRequestType.Sync:
                requestStatisticsBase = new SyncRequestStatistics(rj);
                break;

            case MRSRequestType.MailboxRelocation:
                requestStatisticsBase = new MailboxRelocationRequestStatistics(rj);
                break;

            case MRSRequestType.FolderMove:
                requestStatisticsBase = new FolderMoveRequestStatistics(rj);
                break;

            case MRSRequestType.PublicFolderMailboxMigration:
                requestStatisticsBase = new PublicFolderMailboxMigrationRequestStatistics(rj);
                break;
            }
            if (requestStatisticsBase != null)
            {
                rj.Retire();
            }
            return(requestStatisticsBase);
        }
        internal static MailboxReplicationServiceClient Create(IConfigurationSession session, MRSJobType jobType, Guid mdbGuid, List <string> unreachableMrsServers)
        {
            MRSCapabilities     requiredCapability = RequestJobXML.MapJobTypeToCapability(jobType);
            string              text = null;
            DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.None);

            if (!string.IsNullOrEmpty(databaseInformation.ServerFqdn))
            {
                text = databaseInformation.ServerFqdn.ToLower(CultureInfo.InvariantCulture);
            }
            List <string> mrsServers = MailboxReplicationServiceClient.GetMrsServers(session, mdbGuid);
            List <string> list       = new List <string>(mrsServers.Count);

            foreach (string text2 in mrsServers)
            {
                string text3 = text2.ToLower(CultureInfo.InvariantCulture);
                if (string.Compare(text3, text, CultureInfo.InvariantCulture, CompareOptions.Ordinal) != 0 && !unreachableMrsServers.Contains(text3))
                {
                    list.Add(text2);
                }
            }
            List <string> list2 = CommonUtils.RandomizeSequence <string>(list);

            if (text != null)
            {
                list2.Insert(0, text);
            }
            foreach (string text4 in list2)
            {
                try
                {
                    return(MailboxReplicationServiceClient.Create(text4, requiredCapability));
                }
                catch (MailboxReplicationPermanentException ex)
                {
                    MrsTracer.Common.Warning("Attempt to connect to CAS Server {0} failed with error: {1}", new object[]
                    {
                        text4,
                        CommonUtils.FullExceptionMessage(ex)
                    });
                }
                catch (MailboxReplicationTransientException ex2)
                {
                    MrsTracer.Common.Warning("Attempt to connect to CAS Server {0} failed with error: {1}", new object[]
                    {
                        text4,
                        CommonUtils.FullExceptionMessage(ex2)
                    });
                }
                unreachableMrsServers.Add(text4.ToLower(CultureInfo.InvariantCulture));
            }
            throw new NoMRSAvailableTransientException();
        }
Exemple #7
0
        internal void Refresh()
        {
            RequestJobXML requestJobXML = this.MoveObject.ReadObject(ReadObjectFlags.Refresh);

            foreach (PropertyDefinition propertyDefinition in this.ObjectSchema.AllProperties)
            {
                if (propertyDefinition != SimpleProviderObjectSchema.ObjectState && propertyDefinition != SimpleProviderObjectSchema.ExchangeVersion && propertyDefinition != SimpleProviderObjectSchema.Identity)
                {
                    this[propertyDefinition] = requestJobXML[propertyDefinition];
                }
            }
            this.UnknownElements = requestJobXML.UnknownElements;
        }
Exemple #8
0
        private RequestJobXML CreateDummyFromSearchKey(byte[] key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            RequestJobXML requestJobXML = RequestJobBase.CreateDummyObject <RequestJobXML>();

            requestJobXML.Identity     = new RequestJobObjectId(new Guid(key), this.MdbGuid, null);
            requestJobXML.RequestGuid  = new Guid(key);
            requestJobXML.ExchangeGuid = new Guid(key);
            return(requestJobXML);
        }
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 MoveJob(PropValue[] properties, Guid requestQueueGuid)
 {
     this.JobType = MapiUtils.GetValue <MRSJobType>(properties[9], MRSJobType.Unknown);
     if (!RequestJobXML.IsKnownJobType(this.JobType))
     {
         MrsTracer.Service.Debug("Skipping unknown jobType {0}", new object[]
         {
             (int)this.JobType
         });
         return;
     }
     this.RequestGuid         = MapiUtils.GetValue <Guid>(properties[26], Guid.Empty);
     this.ExchangeGuid        = MapiUtils.GetValue <Guid>(properties[5], Guid.Empty);
     this.ArchiveGuid         = MapiUtils.GetValue <Guid>(properties[6], Guid.Empty);
     this.CancelRequest       = MapiUtils.GetValue <bool>(properties[4], false);
     this.MrsServerName       = MapiUtils.GetValue <string>(properties[2], null);
     this.Status              = MapiUtils.GetValue <RequestStatus>(properties[0], RequestStatus.None);
     this.JobState            = MapiUtils.GetValue <JobProcessingState>(properties[1], JobProcessingState.NotReady);
     this.LastUpdateTimeStamp = MapiUtils.GetValue <DateTime>(properties[7], DateTime.MinValue);
     this.Flags = MapiUtils.GetValue <RequestFlags>(properties[10], RequestFlags.None);
     this.SourceDatabaseGuid        = MapiUtils.GetValue <Guid>(properties[11], Guid.Empty);
     this.TargetDatabaseGuid        = MapiUtils.GetValue <Guid>(properties[12], Guid.Empty);
     this.SourceArchiveDatabaseGuid = MapiUtils.GetValue <Guid>(properties[15], Guid.Empty);
     this.TargetArchiveDatabaseGuid = MapiUtils.GetValue <Guid>(properties[16], Guid.Empty);
     this.Priority = MapiUtils.GetValue <int>(properties[17], -1);
     this.DoNotPickUntilTimestamp = MapiUtils.GetValue <DateTime>(properties[13], DateTime.MinValue);
     this.RequestType             = MapiUtils.GetValue <MRSRequestType>(properties[14], MRSRequestType.Move);
     this.MessageID          = MapiUtils.GetValue <byte[]>(properties[27], null);
     this.SourceExchangeGuid = MapiUtils.GetValue <Guid>(properties[18], Guid.Empty);
     this.TargetExchangeGuid = MapiUtils.GetValue <Guid>(properties[19], Guid.Empty);
     this.RehomeRequest      = MapiUtils.GetValue <bool>(properties[20], false);
     this.InternalFlags      = MapiUtils.GetValue <RequestJobInternalFlags>(properties[21], RequestJobInternalFlags.None);
     this.PoisonCount        = MapiUtils.GetValue <int>(properties[23], 0);
     this.FailureType        = MapiUtils.GetValue <string>(properties[24], null);
     this.WorkloadType       = MapiUtils.GetValue <RequestWorkloadType>(properties[25], RequestWorkloadType.None);
     byte[] value = MapiUtils.GetValue <byte[]>(properties[22], null);
     this.PartitionHint             = ((value != null && value.Length > 0) ? TenantPartitionHint.FromPersistablePartitionHint(value) : null);
     this.RequestQueueGuid          = requestQueueGuid;
     this.IsActiveOnThisMRSInstance = MRSService.JobIsActive(this.RequestGuid);
     this.isInteractive             = MoveJob.IsInteractive(this.RequestType, this.WorkloadType);
 }
        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;
        }
Exemple #12
0
 internal TransactionalRequestJob(RequestJobXML requestJob) : this((SimpleProviderPropertyBag)requestJob.propertyBag)
 {
     base.CopyNonSchematizedPropertiesFrom(requestJob);
     this.UnknownElements = requestJob.UnknownElements;
 }
        MailboxInformation IMailboxReplicationService.GetMailboxInformation4(string requestJobXml, Guid primaryMailboxGuid, Guid physicalMailboxGuid, byte[] partitionHint, Guid targetMdbGuid, string targetMdbName, string remoteHostName, string remoteOrgName, string remoteDCName, string username, string password, string domain)
        {
            MailboxInformation info = null;

            this.ForwardKnownExceptions(delegate
            {
                TenantPartitionHint partitionHint2 = (partitionHint != null) ? TenantPartitionHint.FromPersistablePartitionHint(partitionHint) : null;
                bool flag = string.IsNullOrEmpty(targetMdbName) && targetMdbGuid == Guid.Empty;
                NetworkCredential networkCredential = (!string.IsNullOrEmpty(username)) ? new NetworkCredential(username, password, domain) : null;
                MailboxType mbxType;
                IMailbox mailbox;
                if (string.IsNullOrEmpty(remoteHostName))
                {
                    if (!string.IsNullOrEmpty(remoteDCName))
                    {
                        if (flag)
                        {
                            mbxType = MailboxType.SourceMailbox;
                            mailbox = new MapiSourceMailbox(LocalMailboxFlags.Move);
                        }
                        else
                        {
                            mbxType = MailboxType.DestMailboxIntraOrg;
                            mailbox = new MapiDestinationMailbox(LocalMailboxFlags.None);
                        }
                        mailbox.ConfigADConnection(remoteDCName, remoteDCName, networkCredential);
                    }
                    else
                    {
                        ProxyServerSettings proxyServerSettings;
                        if (targetMdbGuid != Guid.Empty)
                        {
                            proxyServerSettings = CommonUtils.MapDatabaseToProxyServer(targetMdbGuid);
                        }
                        else
                        {
                            proxyServerSettings = CommonUtils.MapMailboxToProxyServer(new Guid?(physicalMailboxGuid), new Guid?(primaryMailboxGuid), partitionHint);
                        }
                        if (flag)
                        {
                            if (proxyServerSettings.Scenario == ProxyScenarios.LocalMdbAndProxy)
                            {
                                mailbox = new StorageSourceMailbox(LocalMailboxFlags.Move);
                            }
                            else
                            {
                                mailbox = new RemoteSourceMailbox(proxyServerSettings.Fqdn, null, null, ProxyControlFlags.DoNotApplyProxyThrottling, null, false, LocalMailboxFlags.Move);
                            }
                            mbxType = MailboxType.SourceMailbox;
                        }
                        else
                        {
                            if (proxyServerSettings.Scenario == ProxyScenarios.LocalMdbAndProxy)
                            {
                                mailbox = new StorageDestinationMailbox(LocalMailboxFlags.Move);
                            }
                            else
                            {
                                mailbox = new RemoteDestinationMailbox(proxyServerSettings.Fqdn, null, null, ProxyControlFlags.DoNotApplyProxyThrottling, null, false, LocalMailboxFlags.Move);
                            }
                            mbxType = MailboxType.DestMailboxIntraOrg;
                        }
                    }
                }
                else
                {
                    ProxyControlFlags proxyControlFlags = ProxyControlFlags.DoNotApplyProxyThrottling;
                    RequestJobXML requestJobXML         = XMLSerializableBase.Deserialize <RequestJobXML>(requestJobXml, true);
                    if (requestJobXML != null)
                    {
                        using (TransactionalRequestJob transactionalRequestJob = new TransactionalRequestJob(requestJobXML))
                        {
                            transactionalRequestJob.IsFake = true;
                            proxyControlFlags |= transactionalRequestJob.GetProxyControlFlags();
                        }
                    }
                    if (flag)
                    {
                        mailbox = new RemoteSourceMailbox(remoteHostName, remoteOrgName, networkCredential, proxyControlFlags, null, true, LocalMailboxFlags.Move);
                        mbxType = MailboxType.SourceMailbox;
                    }
                    else
                    {
                        mailbox = new RemoteDestinationMailbox(remoteHostName, remoteOrgName, networkCredential, proxyControlFlags, null, true, LocalMailboxFlags.Move);
                        mbxType = MailboxType.DestMailboxCrossOrg;
                    }
                }
                using (mailbox)
                {
                    mailbox.Config(null, primaryMailboxGuid, physicalMailboxGuid, partitionHint2, targetMdbGuid, mbxType, null);
                    if (!string.IsNullOrEmpty(targetMdbName))
                    {
                        mailbox.ConfigMDBByName(targetMdbName);
                    }
                    mailbox.Connect(MailboxConnectFlags.None);
                    using (SettingsContextBase.ActivateContext(mailbox as ISettingsContextProvider))
                    {
                        info          = mailbox.GetMailboxInformation();
                        ADUser aduser = mailbox.GetADUser();
                        if (!this.clientVersion[2] && aduser.HasSeparatedArchive)
                        {
                            throw new UnsupportedClientVersionPermanentException(this.clientVersion.ComputerName, this.clientVersion.ToString(), "ArchiveSeparation");
                        }
                        info.UserDataXML       = ConfigurableObjectXML.Serialize <ADUser>(aduser);
                        info.ServerInformation = mailbox.GetMailboxServerInformation();
                        mailbox.Disconnect();
                    }
                }
            }, null);
            return(info);
        }
        string IMailboxReplicationService.ValidateAndPopulateRequestJob(string requestJobXML, out string reportEntryXMLs)
        {
            string reportString = null;
            string resultString = null;

            try
            {
                this.ForwardKnownExceptions(delegate
                {
                    List <ReportEntry> list = new List <ReportEntry>();
                    try
                    {
                        RequestJobXML requestJob = XMLSerializableBase.Deserialize <RequestJobXML>(requestJobXML, true);
                        using (TransactionalRequestJob transactionalRequestJob = new TransactionalRequestJob(requestJob))
                        {
                            transactionalRequestJob.IsFake   = true;
                            transactionalRequestJob.Identity = new RequestJobObjectId((transactionalRequestJob.RequestType == MRSRequestType.Move) ? transactionalRequestJob.ExchangeGuid : transactionalRequestJob.RequestGuid, (transactionalRequestJob.WorkItemQueueMdb == null) ? Guid.Empty : transactionalRequestJob.WorkItemQueueMdb.ObjectGuid, null);
                            RequestIndexEntryProvider requestIndexEntryProvider = new RequestIndexEntryProvider();
                            using (requestIndexEntryProvider.RescopeTo(transactionalRequestJob.DomainControllerToUpdate, transactionalRequestJob.OrganizationId))
                            {
                                if (transactionalRequestJob.SourceUserId != null)
                                {
                                    transactionalRequestJob.SourceUser = requestIndexEntryProvider.ReadADUser(transactionalRequestJob.SourceUserId, transactionalRequestJob.SourceExchangeGuid);
                                }
                                if (transactionalRequestJob.TargetUserId != null)
                                {
                                    transactionalRequestJob.TargetUser = requestIndexEntryProvider.ReadADUser(transactionalRequestJob.TargetUserId, transactionalRequestJob.TargetExchangeGuid);
                                }
                            }
                            if (MailboxSyncerJobs.ContainsJob(transactionalRequestJob.IdentifyingGuid))
                            {
                                resultString = requestJobXML;
                            }
                            else
                            {
                                BaseJob baseJob = MailboxSyncerJobs.ConstructJob(transactionalRequestJob);
                                if (baseJob == null)
                                {
                                    MrsTracer.Service.Error("Don't know how to process '{0}' request", new object[]
                                    {
                                        transactionalRequestJob.RequestType
                                    });
                                    throw new RequestTypeNotUnderstoodPermanentException(CommonUtils.LocalComputerName, VersionInformation.MRS.ToString(), (int)transactionalRequestJob.RequestType);
                                }
                                using (baseJob)
                                {
                                    baseJob.Initialize(transactionalRequestJob);
                                    baseJob.ValidateAndPopulateRequestJob(list);
                                    transactionalRequestJob.Message              = baseJob.CachedRequestJob.Message;
                                    transactionalRequestJob.SourceVersion        = baseJob.CachedRequestJob.SourceVersion;
                                    transactionalRequestJob.SourceArchiveVersion = baseJob.CachedRequestJob.SourceArchiveVersion;
                                    transactionalRequestJob.SourceServer         = baseJob.CachedRequestJob.SourceServer;
                                    transactionalRequestJob.SourceArchiveServer  = baseJob.CachedRequestJob.SourceArchiveServer;
                                    transactionalRequestJob.TargetVersion        = baseJob.CachedRequestJob.TargetVersion;
                                    transactionalRequestJob.TargetArchiveVersion = baseJob.CachedRequestJob.TargetArchiveVersion;
                                    transactionalRequestJob.TargetServer         = baseJob.CachedRequestJob.TargetServer;
                                    transactionalRequestJob.TargetArchiveServer  = baseJob.CachedRequestJob.TargetArchiveServer;
                                    transactionalRequestJob.RemoteDatabaseGuid   = baseJob.CachedRequestJob.RemoteDatabaseGuid;
                                    resultString = XMLSerializableBase.Serialize(new RequestJobXML(transactionalRequestJob), false);
                                }
                            }
                        }
                    }
                    finally
                    {
                        reportString = XMLSerializableBase.Serialize(list, false);
                    }
                }, null);
            }
            finally
            {
                reportEntryXMLs = reportString;
            }
            return(resultString);
        }
Exemple #15
0
 internal PublicFolderMailboxMigrationRequestStatistics(RequestJobXML requestJob) : this((SimpleProviderPropertyBag)requestJob.propertyBag)
 {
     base.CopyNonSchematizedPropertiesFrom(requestJob);
 }
Exemple #16
0
        public JobPickupRec AttemptToPick(MapiStore systemMailbox)
        {
            if (!RequestJobXML.IsKnownRequestType(this.RequestType))
            {
                return(new JobPickupRec(this, JobPickupResult.UnknownJobType, DateTime.MaxValue, MrsStrings.PickupStatusRequestTypeNotSupported(this.RequestType.ToString()), null));
            }
            if (!RequestJobXML.IsKnownJobType(this.JobType))
            {
                return(new JobPickupRec(this, JobPickupResult.UnknownJobType, DateTime.MaxValue, MrsStrings.PickupStatusJobTypeNotSupported(this.JobType.ToString()), null));
            }
            if (this.PoisonCount >= ConfigBase <MRSConfigSchema> .GetConfig <int>("HardPoisonLimit"))
            {
                return(new JobPickupRec(this, JobPickupResult.PoisonedJob, DateTime.MaxValue, MrsStrings.PickupStatusJobPoisoned(this.PoisonCount), null));
            }
            if (this.IsActiveOnThisMRSInstance)
            {
                return(new JobPickupRec(this, JobPickupResult.JobAlreadyActive, DateTime.MaxValue, LocalizedString.Empty, null));
            }
            DateTime utcNow = DateTime.UtcNow;

            if (this.Status == RequestStatus.Completed && (!this.DoNotPickUntilHasElapsed || this.DoNotPickUntilTimestamp == DateTime.MinValue) && !this.RehomeRequest)
            {
                return(new JobPickupRec(this, JobPickupResult.CompletedJobSkipped, (this.DoNotPickUntilTimestamp == DateTime.MinValue) ? DateTime.MaxValue : this.DoNotPickUntilTimestamp, LocalizedString.Empty, null));
            }
            if (this.CancelRequest && !this.DoNotPickUntilHasElapsed)
            {
                return(new JobPickupRec(this, JobPickupResult.PostponeCancel, this.DoNotPickUntilTimestamp, LocalizedString.Empty, null));
            }
            if (!this.isInteractive && !this.IsLightRequest && !this.DoNotPickUntilHasElapsed)
            {
                MrsTracer.Service.Debug("Ignoring MoveJob '{0}' on queue '{1}' having DoNotPickUntilTimestamp of {2}.", new object[]
                {
                    this.RequestGuid,
                    this.RequestQueueGuid,
                    this.DoNotPickUntilTimestamp.ToLocalTime()
                });
                return(new JobPickupRec(this, JobPickupResult.JobIsPostponed, this.DoNotPickUntilTimestamp, LocalizedString.Empty, null));
            }
            if (this.InternalFlags.HasFlag(RequestJobInternalFlags.ExecutedByTransportSync))
            {
                MrsTracer.Service.Debug("Ignoring MoveJob '{0}' since Tranport Sync Owns Execution of the job.", new object[]
                {
                    this.RequestGuid
                });
                return(new JobPickupRec(this, JobPickupResult.JobOwnedByTransportSync, DateTime.MaxValue, LocalizedString.Empty, null));
            }
            JobPickupRec result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                using (RequestJobProvider requestJobProvider = new RequestJobProvider(this.RequestQueueGuid, systemMailbox))
                {
                    using (TransactionalRequestJob transactionalRequestJob = (TransactionalRequestJob)requestJobProvider.Read <TransactionalRequestJob>(new RequestJobObjectId(this.RequestGuid, this.RequestQueueGuid, this.MessageID)))
                    {
                        if (transactionalRequestJob == null)
                        {
                            result = new JobPickupRec(this, JobPickupResult.InvalidJob, DateTime.MaxValue, MrsStrings.PickupStatusCorruptJob, null);
                        }
                        else if (!transactionalRequestJob.IsSupported())
                        {
                            result = new JobPickupRec(this, JobPickupResult.UnknownJobType, DateTime.MaxValue, MrsStrings.PickupStatusSubTypeNotSupported(transactionalRequestJob.RequestType.ToString()), null);
                        }
                        else if (transactionalRequestJob.ValidationResult != RequestJobBase.ValidationResultEnum.Valid)
                        {
                            this.ProcessInvalidJob(transactionalRequestJob, requestJobProvider);
                            result = new JobPickupRec(this, JobPickupResult.InvalidJob, DateTime.MaxValue, MrsStrings.PickupStatusInvalidJob(transactionalRequestJob.ValidationResult.ToString(), transactionalRequestJob.ValidationMessage), null);
                        }
                        else if (transactionalRequestJob.Status == RequestStatus.Completed && !transactionalRequestJob.RehomeRequest)
                        {
                            this.CleanupCompletedJob(transactionalRequestJob, requestJobProvider);
                            result = new JobPickupRec(this, JobPickupResult.CompletedJobCleanedUp, DateTime.MaxValue, MrsStrings.PickupStatusCompletedJob, null);
                        }
                        else if (!transactionalRequestJob.ShouldProcessJob())
                        {
                            result = new JobPickupRec(this, JobPickupResult.DisabledJobPickup, DateTime.MaxValue, MrsStrings.PickupStatusDisabled, null);
                        }
                        else
                        {
                            ReservationContext reservationContext = null;
                            if (!this.IsLightRequest && !MoveJob.CacheJobQueues)
                            {
                                reservationContext = new ReservationContext();
                                disposeGuard.Add <ReservationContext>(reservationContext);
                                try
                                {
                                    this.ReserveLocalForestResources(reservationContext, transactionalRequestJob);
                                }
                                catch (LocalizedException ex)
                                {
                                    if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                                    {
                                        WellKnownException.ResourceReservation
                                    }))
                                    {
                                        return(new JobPickupRec(this, JobPickupResult.ReservationFailure, utcNow + MoveJob.JobPickupRetryInterval, MrsStrings.PickupStatusReservationFailure(CommonUtils.FullExceptionMessage(ex)), ex as ResourceReservationException));
                                    }
                                    throw;
                                }
                            }
                            if (!TestIntegration.Instance.DisableRemoteHostNameBlacklisting && transactionalRequestJob.RequestType == MRSRequestType.Move && (transactionalRequestJob.Flags & RequestFlags.CrossOrg) != RequestFlags.None && (transactionalRequestJob.Flags & RequestFlags.RemoteLegacy) == RequestFlags.None && !string.IsNullOrEmpty(transactionalRequestJob.RemoteHostName))
                            {
                                string   key = transactionalRequestJob.RemoteHostName.ToLowerInvariant();
                                DateTime nextRecommendedPickup;
                                if (MoveJob.RemoteHostsInProxyBackoff.TryGetValue(key, out nextRecommendedPickup))
                                {
                                    return(new JobPickupRec(this, JobPickupResult.ProxyBackoff, nextRecommendedPickup, MrsStrings.PickupStatusProxyBackoff(transactionalRequestJob.RemoteHostName), null));
                                }
                            }
                            MrsTracer.Service.Debug("Attempting to take over MoveJob '{0}' on queue '{1}', priority={2}", new object[]
                            {
                                transactionalRequestJob,
                                this.RequestQueueGuid,
                                transactionalRequestJob.Priority
                            });
                            transactionalRequestJob.RequestJobState = JobProcessingState.InProgress;
                            transactionalRequestJob.MRSServerName   = CommonUtils.LocalComputerName;
                            if (!this.IsLightRequest)
                            {
                                transactionalRequestJob.PoisonCount++;
                                transactionalRequestJob.LastPickupTime = new DateTime?(DateTime.UtcNow);
                            }
                            if (!transactionalRequestJob.Suspend && !transactionalRequestJob.RehomeRequest && transactionalRequestJob.Status != RequestStatus.Suspended && transactionalRequestJob.Status != RequestStatus.AutoSuspended && transactionalRequestJob.Status != RequestStatus.Failed && transactionalRequestJob.Status != RequestStatus.Completed && transactionalRequestJob.Status != RequestStatus.CompletedWithWarning)
                            {
                                transactionalRequestJob.Status = ((reservationContext == null) ? RequestStatus.Queued : RequestStatus.InProgress);
                            }
                            requestJobProvider.Save(transactionalRequestJob);
                            this.Status = transactionalRequestJob.Status;
                            JobPickupRec jobPickupRec;
                            if (this.IsLightRequest)
                            {
                                jobPickupRec = new JobPickupRec(this, JobPickupResult.JobPickedUp, DateTime.MaxValue, MrsStrings.PickupStatusLightJob(transactionalRequestJob.Suspend, transactionalRequestJob.RehomeRequest, transactionalRequestJob.Priority.ToString()), null);
                                MoveJob.PerformLightJobAction(requestJobProvider.SystemMailbox, RequestJobProvider.CreateRequestStatistics(transactionalRequestJob));
                            }
                            else
                            {
                                MailboxSyncerJobs.CreateJob(transactionalRequestJob, reservationContext);
                                jobPickupRec = new JobPickupRec(this, JobPickupResult.JobPickedUp, DateTime.MaxValue, MrsStrings.PickupStatusCreateJob(transactionalRequestJob.SyncStage.ToString(), transactionalRequestJob.CancelRequest, transactionalRequestJob.Priority.ToString()), null);
                            }
                            disposeGuard.Success();
                            result = jobPickupRec;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #17
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);
        }
Exemple #18
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));
        }
Exemple #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);
        }
Exemple #20
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();
        }
Exemple #21
0
 internal FolderMoveRequestStatistics(RequestJobXML requestJob) : this((SimpleProviderPropertyBag)requestJob.propertyBag)
 {
     base.CopyNonSchematizedPropertiesFrom(requestJob);
 }
 public static MailboxReplicationServiceClient Create(string serverName, MRSJobType jobType)
 {
     return(MailboxReplicationServiceClient.Create(serverName, RequestJobXML.MapJobTypeToCapability(jobType)));
 }