public static void ExportRoutine(IMailboxReplicationProxyService mrsProxy, long dataExportHandle, IDataImport destProxy, DataExportBatch firstBatch, bool useCompression) { try { DataExportBatch dataExportBatch; do { if (firstBatch != null) { dataExportBatch = firstBatch; firstBatch = null; } else { if (TestIntegration.Instance.AbortConnectionDuringFX) { MailboxReplicationProxyClient mailboxReplicationProxyClient = (MailboxReplicationProxyClient)mrsProxy; mailboxReplicationProxyClient.Abort(); } dataExportBatch = mrsProxy.DataExport_ExportData2(dataExportHandle); if (dataExportBatch.IsLastBatch) { dataExportHandle = 0L; } } bool flag = false; try { if (dataExportBatch.Opcode != 0) { IDataMessage message = DataMessageSerializer.Deserialize(dataExportBatch.Opcode, dataExportBatch.Data, useCompression); destProxy.SendMessage(message); } if (dataExportBatch.FlushAfterImport) { destProxy.SendMessageAndWaitForReply(FlushMessage.Instance); } flag = true; } finally { if (!flag && dataExportHandle != 0L) { MrsTracer.ProxyClient.Error("Exception was thrown during import/flush, canceling export.", new object[0]); mrsProxy.DataExport_CancelExport(dataExportHandle); dataExportHandle = 0L; } } }while (!dataExportBatch.IsLastBatch); } finally { if (dataExportHandle != 0L) { mrsProxy.CloseHandle(dataExportHandle); } } }
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(); } } } }