public TransactionalRequestJob ValidateAndPopulateRequestJob(TransactionalRequestJob requestJob, out List <ReportEntry> entries)
        {
            List <ReportEntry> entriesInternal = null;
            string             resultString    = null;
            string             requestJobXML   = XMLSerializableBase.Serialize(new RequestJobXML(requestJob), false);

            try
            {
                this.CallService(delegate()
                {
                    string text = null;
                    try
                    {
                        resultString = this.Channel.ValidateAndPopulateRequestJob(requestJobXML, out text);
                    }
                    finally
                    {
                        if (text != null)
                        {
                            entriesInternal = XMLSerializableBase.Deserialize <List <ReportEntry> >(text, false);
                        }
                    }
                });
            }
            finally
            {
                entries = entriesInternal;
            }
            return(new TransactionalRequestJob(XMLSerializableBase.Deserialize <RequestJobXML>(resultString, false)));
        }
        public MailboxInformation GetMailboxInformation(TransactionalRequestJob requestJob, Guid primaryMailboxGuid, Guid physicalMailboxGuid, TenantPartitionHint partitionHint, Guid targetMdbGuid, string targetMdbName, string remoteHostName, string remoteOrgName, string remoteDCName, NetworkCredential cred)
        {
            MailboxInformation result = null;

            this.CallService(delegate()
            {
                string username = (cred != null) ? cred.UserName : null;
                string password = (cred != null) ? cred.Password : null;
                string domain   = (cred != null) ? cred.Domain : null;
                if (this.ServerVersion[11])
                {
                    string requestJobXml = XMLSerializableBase.Serialize(new RequestJobXML(requestJob), false);
                    result = this.Channel.GetMailboxInformation4(requestJobXml, primaryMailboxGuid, physicalMailboxGuid, (partitionHint != null) ? partitionHint.GetPersistablePartitionHint() : null, targetMdbGuid, targetMdbName, remoteHostName, remoteOrgName, remoteDCName, username, password, domain);
                    return;
                }
                if (this.ServerVersion[4])
                {
                    result = this.Channel.GetMailboxInformation3(primaryMailboxGuid, physicalMailboxGuid, (partitionHint != null) ? partitionHint.GetPersistablePartitionHint() : null, targetMdbGuid, targetMdbName, remoteHostName, remoteOrgName, remoteDCName, username, password, domain);
                    return;
                }
                result = this.Channel.GetMailboxInformation2(primaryMailboxGuid, physicalMailboxGuid, targetMdbGuid, targetMdbName, remoteHostName, remoteOrgName, remoteDCName, username, password, domain);
            });
            return(result);
        }
        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);
        }
예제 #4
0
        protected override void UpdateSourceMailbox()
        {
            ReportEntry[]         entries  = null;
            MailboxCopierBase     rootCtx  = base.GetRootMailboxContext();
            ADUser                srcUser  = rootCtx.SourceMailbox.GetADUser();
            ADUser                destUser = null;
            ConfigurableObjectXML configObj;

            CommonUtils.CatchKnownExceptions(delegate
            {
                destUser  = rootCtx.DestMailbox.GetADUser();
                configObj = ConfigurableObjectXML.Create(destUser);
                this.Report.Append(MrsStrings.ReportTargetMailboxAfterFinalization2(destUser.ToString(), destUser.OriginatingServer), configObj, ReportEntryFlags.Target | ReportEntryFlags.After);
            }, delegate(Exception failure)
            {
                this.Report.Append(MrsStrings.ReportUnableToLoadDestinationUser(CommonUtils.GetFailureType(failure)), failure, ReportEntryFlags.Cleanup | ReportEntryFlags.Target);
                FailureLog.Write(this.RequestJobGuid, failure, false, RequestState.Cleanup, SyncStage.CleanupUnableToLoadTargetMailbox, null, null);
                destUser = (ADUser)srcUser.Clone();
            });
            if (base.CachedRequestJob.PrimaryIsMoving)
            {
                SmtpAddress?smtpAddress = null;
                foreach (ProxyAddress proxyAddress in destUser.EmailAddresses)
                {
                    SmtpProxyAddress smtpProxyAddress = proxyAddress as SmtpProxyAddress;
                    if (smtpProxyAddress != null)
                    {
                        SmtpAddress value = new SmtpAddress(smtpProxyAddress.SmtpAddress);
                        if (StringComparer.OrdinalIgnoreCase.Equals(value.Domain, base.CachedRequestJob.TargetDeliveryDomain))
                        {
                            smtpAddress = new SmtpAddress?(value);
                            break;
                        }
                    }
                }
                if (smtpAddress == null)
                {
                    LocalizedString localizedString = MrsStrings.ReportUnableToComputeTargetAddress(base.CachedRequestJob.TargetDeliveryDomain, destUser.PrimarySmtpAddress.ToString());
                    base.Report.Append(localizedString);
                    base.Warnings.Add(localizedString);
                    FailureLog.Write(base.RequestJobGuid, new MailboxReplicationTransientException(localizedString), false, RequestState.Cleanup, SyncStage.CleanupUnableToComputeTargetAddress, null, null);
                    smtpAddress = new SmtpAddress?(destUser.PrimarySmtpAddress);
                }
                SmtpProxyAddress smtpProxyAddress2 = new SmtpProxyAddress(smtpAddress.Value.ToString(), true);
                destUser.ExternalEmailAddress = smtpProxyAddress2;
                List <PropertyUpdateXML> list = new List <PropertyUpdateXML>();
                PropertyUpdateXML.Add(list, ADRecipientSchema.ExternalEmailAddress, smtpProxyAddress2, PropertyUpdateOperation.Replace);
                if (rootCtx.SyncState.ExternalLegacyExchangeDN != null)
                {
                    PropertyUpdateXML.Add(list, ADRecipientSchema.LegacyExchangeDN, rootCtx.SyncState.ExternalLegacyExchangeDN, PropertyUpdateOperation.Replace);
                    this.AddX500ProxyAddressIfNeeded(list, srcUser, srcUser.LegacyExchangeDN, srcUser.Identity.ToString());
                }
                if (rootCtx.SyncState.InternalLegacyExchangeDN != null)
                {
                    this.AddX500ProxyAddressIfNeeded(list, srcUser, rootCtx.SyncState.InternalLegacyExchangeDN, destUser.Identity.ToString());
                }
                destUser.LinkedMasterAccount = XMLSerializableBase.Serialize(list.ToArray(), false);
            }
            try
            {
                Guid?newMailboxContainerGuid            = null;
                CrossTenantObjectId newUnifiedMailboxId = null;
                MrsTracer.Service.Debug("Updating source mailbox...", new object[0]);
                UpdateMovedMailboxOperation op;
                Guid newArchiveDatabaseGuid;
                ArchiveStatusFlags archiveStatus;
                string             archiveDomain;
                if (base.CachedRequestJob.PrimaryOnly)
                {
                    op = UpdateMovedMailboxOperation.MorphToMailUser;
                    newArchiveDatabaseGuid = ((srcUser.ArchiveDatabase != null) ? srcUser.ArchiveDatabase.ObjectGuid : Guid.Empty);
                    archiveStatus          = ((srcUser.ArchiveDatabase != null) ? ArchiveStatusFlags.Active : ArchiveStatusFlags.None);
                    archiveDomain          = null;
                }
                else if (base.CachedRequestJob.ArchiveOnly)
                {
                    op = UpdateMovedMailboxOperation.UpdateArchiveOnly;
                    newArchiveDatabaseGuid  = Guid.Empty;
                    archiveStatus           = ArchiveStatusFlags.None;
                    archiveDomain           = ((srcUser.Database != null) ? base.CachedRequestJob.ArchiveDomain : null);
                    newMailboxContainerGuid = srcUser.MailboxContainerGuid;
                    newUnifiedMailboxId     = srcUser.UnifiedMailbox;
                }
                else
                {
                    op = UpdateMovedMailboxOperation.MorphToMailUser;
                    newArchiveDatabaseGuid = Guid.Empty;
                    archiveDomain          = null;
                    archiveStatus          = ArchiveStatusFlags.None;
                }
                UpdateMovedMailboxFlags updateMovedMailboxFlags = UpdateMovedMailboxFlags.None;
                if (base.CachedRequestJob.SkipMailboxReleaseCheck)
                {
                    updateMovedMailboxFlags |= UpdateMovedMailboxFlags.SkipMailboxReleaseCheck;
                }
                rootCtx.SourceMailbox.UpdateMovedMailbox(op, destUser, base.CachedRequestJob.SourceDomainControllerToUpdate ?? srcUser.OriginatingServer, out entries, Guid.Empty, newArchiveDatabaseGuid, archiveDomain, archiveStatus, updateMovedMailboxFlags, newMailboxContainerGuid, newUnifiedMailboxId);
            }
            finally
            {
                base.AppendReportEntries(entries);
            }
            CommonUtils.CatchKnownExceptions(delegate
            {
                srcUser   = rootCtx.SourceMailbox.GetADUser();
                configObj = ConfigurableObjectXML.Create(srcUser);
                this.Report.Append(MrsStrings.ReportSourceMailUserAfterFinalization2(srcUser.ToString(), srcUser.OriginatingServer), configObj, ReportEntryFlags.Source | ReportEntryFlags.After);
            }, null);
        }
예제 #5
0
        protected override void UpdateMovedMailbox()
        {
            ReportEntry[]         entries      = null;
            ADUser                aduser       = base.GetRootMailboxContext().SourceMailbox.GetADUser();
            ConfigurableObjectXML configObject = ConfigurableObjectXML.Create(aduser);

            base.Report.Append(MrsStrings.ReportSourceMailboxBeforeFinalization2(aduser.ToString(), aduser.OriginatingServer), configObject, ReportEntryFlags.Source | ReportEntryFlags.Before);
            ADUser aduser2 = base.GetRootMailboxContext().DestMailbox.GetADUser();

            configObject = ConfigurableObjectXML.Create(aduser2);
            base.Report.Append(MrsStrings.ReportTargetMailUserBeforeFinalization2(aduser2.ToString(), aduser2.OriginatingServer), configObject, ReportEntryFlags.Target | ReportEntryFlags.Before);
            bool isFromDatacenter  = aduser.IsFromDatacenter;
            bool isFromDatacenter2 = aduser2.IsFromDatacenter;

            if (base.CachedRequestJob.PrimaryIsMoving)
            {
                CommonUtils.ValidateTargetDeliveryDomain(aduser2.EmailAddresses, base.CachedRequestJob.TargetDeliveryDomain);
                MailboxCopierBase rootMailboxContext = base.GetRootMailboxContext();
                if (!isFromDatacenter && isFromDatacenter2)
                {
                    rootMailboxContext.SyncState.ExternalLegacyExchangeDN = FreeBusyFolder.GetExternalLegacyDN(aduser);
                }
                else if (isFromDatacenter && !isFromDatacenter2)
                {
                    string mdbLegDN = base.GetRootMailboxContext().DestMailbox.GetMailboxInformation().MdbLegDN;
                    rootMailboxContext.SyncState.InternalLegacyExchangeDN = FreeBusyFolder.GetInternalLegacyDN(aduser2, mdbLegDN);
                }
                List <PropertyUpdateXML> list = new List <PropertyUpdateXML>();
                if (rootMailboxContext.SyncState.ExternalLegacyExchangeDN != null)
                {
                    this.AddX500ProxyAddressIfNeeded(list, aduser2, rootMailboxContext.SyncState.ExternalLegacyExchangeDN, aduser.Identity.ToString());
                }
                if (rootMailboxContext.SyncState.InternalLegacyExchangeDN != null)
                {
                    PropertyUpdateXML.Add(list, ADRecipientSchema.LegacyExchangeDN, rootMailboxContext.SyncState.InternalLegacyExchangeDN, PropertyUpdateOperation.Replace);
                    this.AddX500ProxyAddressIfNeeded(list, aduser2, aduser2.LegacyExchangeDN, aduser2.Identity.ToString());
                }
                aduser.LinkedMasterAccount = XMLSerializableBase.Serialize(list.ToArray(), false);
            }
            MrsTracer.Service.Debug("Updating destination mailbox...", new object[0]);
            UpdateMovedMailboxOperation op;
            Guid newDatabaseGuid;
            Guid newArchiveDatabaseGuid;
            ArchiveStatusFlags archiveStatus;
            string             archiveDomain;

            if (base.CachedRequestJob.PrimaryOnly)
            {
                op = UpdateMovedMailboxOperation.MorphToMailbox;
                newDatabaseGuid        = base.CachedRequestJob.TargetMDBGuid;
                newArchiveDatabaseGuid = ((aduser2.ArchiveDatabase != null) ? aduser2.ArchiveDatabase.ObjectGuid : Guid.Empty);
                archiveStatus          = ArchiveStatusFlags.None;
                archiveDomain          = ((aduser2.ArchiveDatabase == null) ? base.CachedRequestJob.ArchiveDomain : null);
            }
            else if (base.CachedRequestJob.ArchiveOnly)
            {
                op = UpdateMovedMailboxOperation.UpdateArchiveOnly;
                newDatabaseGuid        = Guid.Empty;
                newArchiveDatabaseGuid = base.CachedRequestJob.TargetArchiveMDBGuid;
                archiveStatus          = ((aduser2.Database == null) ? ArchiveStatusFlags.Active : ArchiveStatusFlags.None);
                archiveDomain          = null;
            }
            else
            {
                op = UpdateMovedMailboxOperation.MorphToMailbox;
                newDatabaseGuid        = base.CachedRequestJob.TargetMDBGuid;
                newArchiveDatabaseGuid = base.CachedRequestJob.TargetArchiveMDBGuid;
                archiveDomain          = null;
                archiveStatus          = ArchiveStatusFlags.None;
            }
            UpdateMovedMailboxFlags updateMovedMailboxFlags = UpdateMovedMailboxFlags.None;

            if (base.CachedRequestJob.SkipMailboxReleaseCheck)
            {
                updateMovedMailboxFlags |= UpdateMovedMailboxFlags.SkipMailboxReleaseCheck;
            }
            if (base.CachedRequestJob.SkipProvisioningCheck)
            {
                updateMovedMailboxFlags |= UpdateMovedMailboxFlags.SkipProvisioningCheck;
            }
            try
            {
                base.GetRootMailboxContext().DestMailbox.UpdateMovedMailbox(op, aduser, base.CachedRequestJob.DestDomainControllerToUpdate, out entries, newDatabaseGuid, newArchiveDatabaseGuid, archiveDomain, archiveStatus, updateMovedMailboxFlags, null, null);
            }
            finally
            {
                base.AppendReportEntries(entries);
            }
        }