public static void ProcessMoveRequestCreatedNotification(Guid requestGuid, Guid mdbGuid) { using (RequestJobProvider requestJobProvider = new RequestJobProvider(mdbGuid)) { RequestStatisticsBase moveRequest = (RequestStatisticsBase)requestJobProvider.Read <RequestStatisticsBase>(new RequestJobObjectId(requestGuid, mdbGuid, null)); if (moveRequest != null && !(moveRequest.ValidationResult != RequestJobBase.ValidationResultEnum.Valid)) { if (moveRequest.RequestStyle == RequestStyle.CrossOrg && moveRequest.RequestType == MRSRequestType.Move) { CommonUtils.CatchKnownExceptions(delegate { Guid physicalMailboxGuid = moveRequest.ArchiveOnly ? (moveRequest.ArchiveGuid ?? Guid.Empty) : moveRequest.ExchangeGuid; ProxyControlFlags proxyControlFlags = ProxyControlFlags.DoNotApplyProxyThrottling | moveRequest.GetProxyControlFlags(); IMailbox mailbox; MailboxType mbxType; Guid mdbGuid2; if (moveRequest.Direction == RequestDirection.Pull) { if ((moveRequest.Flags & RequestFlags.RemoteLegacy) != RequestFlags.None) { mailbox = new MapiSourceMailbox(LocalMailboxFlags.None); mailbox.ConfigADConnection(moveRequest.SourceDCName, moveRequest.SourceDCName, moveRequest.SourceCredential); } else { mailbox = new RemoteSourceMailbox(moveRequest.RemoteHostName, moveRequest.RemoteOrgName, moveRequest.RemoteCredential, proxyControlFlags, null, true, LocalMailboxFlags.None); } mbxType = MailboxType.SourceMailbox; mdbGuid2 = Guid.Empty; } else { if ((moveRequest.Flags & RequestFlags.RemoteLegacy) != RequestFlags.None) { mailbox = new MapiDestinationMailbox(LocalMailboxFlags.None); mailbox.ConfigADConnection(moveRequest.TargetDCName, moveRequest.TargetDCName, moveRequest.TargetCredential); } else { mailbox = new RemoteDestinationMailbox(moveRequest.RemoteHostName, moveRequest.RemoteOrgName, moveRequest.RemoteCredential, proxyControlFlags, null, true, LocalMailboxFlags.None); } mbxType = MailboxType.DestMailboxCrossOrg; mdbGuid2 = ((moveRequest.ArchiveOnly ? moveRequest.RemoteArchiveDatabaseGuid : moveRequest.RemoteDatabaseGuid) ?? Guid.Empty); } using (mailbox) { mailbox.Config(null, moveRequest.ExchangeGuid, physicalMailboxGuid, null, mdbGuid2, mbxType, null); mailbox.Connect(MailboxConnectFlags.None); mailbox.UpdateRemoteHostName(moveRequest.UserOrgName); mailbox.Disconnect(); } }, null); } } } }
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); }
void IMailbox.Connect(MailboxConnectFlags connectFlags) { if (base.MrsProxy == null) { MailboxReplicationProxyClient mailboxReplicationProxyClient = null; IMailboxReplicationProxyService iMRPS = null; long handle = 0L; string database = null; if (!this.flags.HasFlag(LocalMailboxFlags.PstExport) && (this.mbxType == MailboxType.DestMailboxCrossOrg || this.restoreType != MailboxRestoreType.None)) { database = ((this.mdbGuid != Guid.Empty) ? this.mdbGuid.ToString() : this.mdbName); } try { if (this.proxyControlFlags.HasFlag(ProxyControlFlags.Olc)) { mailboxReplicationProxyClient = MailboxReplicationProxyClient.CreateForOlcConnection(this.serverName, this.proxyControlFlags); } else { mailboxReplicationProxyClient = MailboxReplicationProxyClient.Create(this.serverName, this.remoteOrgName, this.remoteCred, this.physicalMailboxGuid, this.primaryMailboxGuid, this.filePath, database, this.partitionHint, this.useHttps, this.proxyControlFlags, this.longOperationTimeout); } if (this.requiredCapabilities != null) { foreach (MRSProxyCapabilities mrsproxyCapabilities in this.requiredCapabilities) { if (!mailboxReplicationProxyClient.ServerVersion[(int)mrsproxyCapabilities]) { MrsTracer.ProxyClient.Error("Talking to downlevel server '{0}': no {1} support", new object[] { mailboxReplicationProxyClient.ServerVersion.ComputerName, mrsproxyCapabilities.ToString() }); throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerVersion.ComputerName, mailboxReplicationProxyClient.ServerVersion.ToString(), mrsproxyCapabilities.ToString()); } } } if (!mailboxReplicationProxyClient.ServerVersion[24]) { this.flags &= RemoteMailbox.PreE15LocalMailboxFlags; } if ((this.flags & ~LocalMailboxFlags.StripLargeRulesForDownlevelTargets) != LocalMailboxFlags.None && !mailboxReplicationProxyClient.ServerVersion[24]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "TenantHint"); } if (this.mailboxContainerGuid != null && !mailboxReplicationProxyClient.ServerVersion[46]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "ContainerOperations"); } if ((connectFlags & MailboxConnectFlags.DoNotOpenMapiSession) != MailboxConnectFlags.None && !mailboxReplicationProxyClient.ServerVersion[11]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "PostMoveCleanup"); } if (this.restoreType != MailboxRestoreType.None && !mailboxReplicationProxyClient.ServerVersion[34]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "IMailbox_ConfigRestore"); } iMRPS = mailboxReplicationProxyClient; if (this.flags.HasFlag(LocalMailboxFlags.PstImport) && !mailboxReplicationProxyClient.ServerVersion[39]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "Pst"); } if (this.flags.HasFlag(LocalMailboxFlags.PstExport) && !mailboxReplicationProxyClient.ServerVersion[57]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "RemotePstExport"); } if (this.flags.HasFlag(LocalMailboxFlags.EasSync) && !mailboxReplicationProxyClient.ServerVersion[44]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "Eas"); } if (mailboxReplicationProxyClient.ServerVersion[46]) { handle = iMRPS.IMailbox_Config7((this.reservation != null) ? this.reservation.Id : Guid.Empty, this.primaryMailboxGuid, this.physicalMailboxGuid, (this.partitionHint != null) ? this.partitionHint.GetPersistablePartitionHint() : null, this.mdbGuid, this.mdbName, this.mbxType, (int)this.proxyControlFlags, (int)this.flags, this.mailboxContainerGuid); } else if (mailboxReplicationProxyClient.ServerVersion[41]) { handle = iMRPS.IMailbox_Config5((this.reservation != null) ? this.reservation.Id : Guid.Empty, this.primaryMailboxGuid, this.physicalMailboxGuid, (this.partitionHint != null) ? this.partitionHint.GetPersistablePartitionHint() : null, this.mdbGuid, this.mdbName, this.mbxType, (int)this.proxyControlFlags, (int)this.flags); } else if (mailboxReplicationProxyClient.ServerVersion[39]) { handle = iMRPS.IMailbox_Config6((this.reservation != null) ? this.reservation.Id : Guid.Empty, this.primaryMailboxGuid, this.physicalMailboxGuid, this.filePath, (this.partitionHint != null) ? this.partitionHint.GetPersistablePartitionHint() : null, this.mdbGuid, this.mdbName, this.mbxType, (int)this.proxyControlFlags, (int)this.flags); } else if (mailboxReplicationProxyClient.ServerVersion[37]) { handle = iMRPS.IMailbox_Config5((this.reservation != null) ? this.reservation.Id : Guid.Empty, this.primaryMailboxGuid, this.physicalMailboxGuid, (this.partitionHint != null) ? this.partitionHint.GetPersistablePartitionHint() : null, this.mdbGuid, this.mdbName, this.mbxType, (int)this.proxyControlFlags, (int)this.flags); } else { RemoteReservation remoteReservation = this.reservation as RemoteReservation; if (remoteReservation != null) { remoteReservation.ConfirmLegacyReservation(mailboxReplicationProxyClient); } if (mailboxReplicationProxyClient.ServerVersion[24]) { handle = iMRPS.IMailbox_Config4(this.primaryMailboxGuid, this.physicalMailboxGuid, (this.partitionHint != null) ? this.partitionHint.GetPersistablePartitionHint() : null, this.mdbGuid, this.mdbName, this.mbxType, (int)this.proxyControlFlags, (int)this.flags); } else { ProxyControlFlags proxyControlFlags = this.proxyControlFlags; if ((this.flags & LocalMailboxFlags.StripLargeRulesForDownlevelTargets) != LocalMailboxFlags.None) { proxyControlFlags |= ProxyControlFlags.StripLargeRulesForDownlevelTargets; } handle = iMRPS.IMailbox_Config3(this.primaryMailboxGuid, this.physicalMailboxGuid, this.mdbGuid, this.mdbName, this.mbxType, (int)proxyControlFlags); } } if (!string.IsNullOrEmpty(this.preferredDomainControllerName)) { if (mailboxReplicationProxyClient.ServerVersion[48]) { iMRPS.IMailbox_ConfigPreferredADConnection(handle, this.preferredDomainControllerName); } else { MrsTracer.ProxyClient.Warning("IMailbox_ConfigPreferredADConnection not expected to be called for server:{0} version:{1}", new object[] { mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString() }); } } if ((this.flags.HasFlag(LocalMailboxFlags.PstImport) || this.flags.HasFlag(LocalMailboxFlags.PstExport)) && mailboxReplicationProxyClient.ServerVersion[41]) { iMRPS.IMailbox_ConfigPst(handle, this.filePath, this.contentCodePage); } if (this.flags.HasFlag(LocalMailboxFlags.EasSync)) { if (mailboxReplicationProxyClient.ServerVersion[53]) { iMRPS.IMailbox_ConfigEas2(handle, this.easConfiguration.UserCred.Password, this.easConfiguration.SmtpAddress, this.primaryMailboxGuid, this.easConfiguration.RemoteHostName); } else { iMRPS.IMailbox_ConfigEas(handle, this.easConfiguration.UserCred.Password, this.easConfiguration.SmtpAddress); } } if (this.proxyControlFlags.HasFlag(ProxyControlFlags.Olc)) { if (!mailboxReplicationProxyClient.ServerVersion[55]) { throw new UnsupportedRemoteServerVersionWithOperationPermanentException(mailboxReplicationProxyClient.ServerName, mailboxReplicationProxyClient.ServerVersion.ToString(), "IMailbox_ConfigOlc"); } iMRPS.IMailbox_ConfigOlc(handle, this.olcConfig); } if (mailboxReplicationProxyClient.ServerVersion[42]) { iMRPS.IMailbox_ConfigureProxyService(new ProxyConfiguration()); } if (this.restoreType != MailboxRestoreType.None) { iMRPS.IMailbox_ConfigRestore(handle, (int)this.restoreType); } if (mailboxReplicationProxyClient.ServerVersion[11]) { iMRPS.IMailbox_Connect2(handle, (int)connectFlags); } else { iMRPS.IMailbox_Connect(handle); } base.MrsProxy = mailboxReplicationProxyClient; base.Handle = handle; mailboxReplicationProxyClient = null; handle = 0L; } finally { if (handle != 0L) { CommonUtils.CatchKnownExceptions(delegate { iMRPS.CloseHandle(handle); }, null); } if (mailboxReplicationProxyClient != null) { mailboxReplicationProxyClient.Dispose(); } } } }
public RemoteMailbox(string serverName, string remoteOrgName, NetworkCredential remoteCred, ProxyControlFlags proxyControlFlags, IEnumerable <MRSProxyCapabilities> requiredCapabilities, bool useHttps, LocalMailboxFlags flags) : base(null, 0L) { this.serverName = serverName; this.remoteOrgName = remoteOrgName; this.remoteCred = remoteCred; this.proxyControlFlags = proxyControlFlags; this.requiredCapabilities = requiredCapabilities; this.useHttps = useHttps; this.flags = flags; TestIntegration.Instance.ForceRefresh(); this.longOperationTimeout = ConfigBase <MRSConfigSchema> .GetConfig <TimeSpan>("MRSProxyLongOperationTimeout"); this.ExportBufferSizeKB = ConfigBase <MRSConfigSchema> .GetConfig <int>("ExportBufferSizeKB"); }
public RemoteDestinationMailbox(string serverName, string remoteOrgName, NetworkCredential remoteCred, ProxyControlFlags proxyControlFlags, IEnumerable <MRSProxyCapabilities> requiredCapabilities, bool useHttps, LocalMailboxFlags flags) : base(serverName, remoteOrgName, remoteCred, proxyControlFlags, requiredCapabilities, useHttps, flags) { }