internal static string Serialize <T>(T obj) where T : ConfigurableObject
        {
            ConfigurableObjectXML configurableObjectXML = ConfigurableObjectXML.Create(obj);

            if (configurableObjectXML == null)
            {
                return(null);
            }
            return(configurableObjectXML.Serialize(false));
        }
Ejemplo n.º 2
0
        protected override void UpdateMovedMailbox()
        {
            if (CommonUtils.IsImplicitSplit(base.CachedRequestJob.Flags, base.GetRootMailboxContext().SourceMailbox.GetADUser()))
            {
                throw new ImplicitSplitPermanentException();
            }
            ReportEntry[]         entries   = null;
            ADUser                adUser    = base.GetRootMailboxContext().DestMailbox.GetADUser();
            ConfigurableObjectXML configObj = ConfigurableObjectXML.Create(adUser);

            base.Report.Append(MrsStrings.ReportMailboxBeforeFinalization2(adUser.ToString(), adUser.OriginatingServer), configObj, ReportEntryFlags.Source | ReportEntryFlags.Before);
            try
            {
                MrsTracer.Service.Debug("Updating destination mailbox only (local move)...", new object[0]);
                UpdateMovedMailboxOperation op = base.CachedRequestJob.ArchiveOnly ? UpdateMovedMailboxOperation.UpdateArchiveOnly : UpdateMovedMailboxOperation.UpdateMailbox;
                Guid newArchiveDatabaseGuid;
                if (base.CachedRequestJob.ArchiveIsMoving)
                {
                    newArchiveDatabaseGuid = base.CachedRequestJob.TargetArchiveMDBGuid;
                }
                else
                {
                    newArchiveDatabaseGuid = ((adUser.ArchiveDatabase != null) ? adUser.ArchiveDatabase.ObjectGuid : Guid.Empty);
                }
                UpdateMovedMailboxFlags updateMovedMailboxFlags = UpdateMovedMailboxFlags.None;
                if (base.CachedRequestJob.SkipMailboxReleaseCheck)
                {
                    updateMovedMailboxFlags |= UpdateMovedMailboxFlags.SkipMailboxReleaseCheck;
                }
                if (base.CachedRequestJob.SkipProvisioningCheck)
                {
                    updateMovedMailboxFlags |= UpdateMovedMailboxFlags.SkipProvisioningCheck;
                }
                base.GetRootMailboxContext().DestMailbox.UpdateMovedMailbox(op, null, base.CachedRequestJob.DestDomainControllerToUpdate, out entries, base.CachedRequestJob.TargetMDBGuid, newArchiveDatabaseGuid, (adUser.ArchiveDomain != null) ? adUser.ArchiveDomain.ToString() : null, adUser.ArchiveStatus, updateMovedMailboxFlags, base.CachedRequestJob.TargetContainerGuid, base.CachedRequestJob.TargetUnifiedMailboxId);
            }
            finally
            {
                base.AppendReportEntries(entries);
            }
            CommonUtils.CatchKnownExceptions(delegate
            {
                adUser    = this.GetRootMailboxContext().DestMailbox.GetADUser();
                configObj = ConfigurableObjectXML.Create(adUser);
                this.Report.Append(MrsStrings.ReportMailboxAfterFinalization2(adUser.ToString(), adUser.OriginatingServer), configObj, ReportEntryFlags.Target | ReportEntryFlags.After);
            }, null);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
            }
        }