Example #1
0
        public static RemoteReservation Create(string serverFQDN, NetworkCredential credentials, Guid mailboxGuid, TenantPartitionHint partitionHint, Guid mdbGuid, ReservationFlags flags)
        {
            RemoteReservation result;

            using (MailboxReplicationProxyClient mailboxReplicationProxyClient = MailboxReplicationProxyClient.CreateWithoutThrottling(serverFQDN, credentials, mailboxGuid, mdbGuid))
            {
                Guid reservationID;
                if (mailboxReplicationProxyClient.ServerVersion[37])
                {
                    byte[] partitionHintBytes = (partitionHint != null) ? partitionHint.GetPersistablePartitionHint() : null;
                    reservationID = ((IMailboxReplicationProxyService)mailboxReplicationProxyClient).IReservationManager_ReserveResources(mailboxGuid, partitionHintBytes, mdbGuid, (int)flags);
                }
                else if (mailboxReplicationProxyClient.ServerVersion[28])
                {
                    reservationID = Guid.NewGuid();
                    LegacyReservationStatus legacyReservationStatus = (LegacyReservationStatus)((IMailboxReplicationProxyService)mailboxReplicationProxyClient).IMailbox_ReserveResources(reservationID, mdbGuid, (int)RemoteReservation.ConvertReservationFlagsToLegacy(flags, true));
                    if (legacyReservationStatus != LegacyReservationStatus.Success)
                    {
                        throw new CapacityExceededReservationException(string.Format("{0}:{1}:{2}", serverFQDN, mdbGuid, flags), 1);
                    }
                }
                else
                {
                    reservationID = RemoteReservation.DownlevelReservationId;
                }
                result = new RemoteReservation(reservationID, serverFQDN, credentials, mailboxGuid, mdbGuid, flags);
            }
            return(result);
        }
 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);
         }
     }
 }
        public static IEnumerable <ContainerMailboxInformation> GetMailboxContainerMailboxes(string serverFQDN, Guid mdbGuid, Guid primaryMailboxGuid)
        {
            IEnumerable <ContainerMailboxInformation> mailboxContainerMailboxes;

            using (MailboxReplicationProxyClient mailboxReplicationProxyClient = MailboxReplicationProxyClient.CreateWithoutThrottling(serverFQDN, null, primaryMailboxGuid, mdbGuid))
            {
                mailboxContainerMailboxes = ((IMailboxReplicationProxyService)mailboxReplicationProxyClient).GetMailboxContainerMailboxes(mdbGuid, primaryMailboxGuid);
            }
            return(mailboxContainerMailboxes);
        }
Example #4
0
 public void ConfirmLegacyReservation(MailboxReplicationProxyClient client)
 {
     if (client.ServerVersion[28])
     {
         LegacyReservationStatus legacyReservationStatus = (LegacyReservationStatus)((IMailboxReplicationProxyService)client).IMailbox_ReserveResources(this.reservationId, this.mdbGuid, (int)RemoteReservation.ConvertReservationFlagsToLegacy(this.flags, false));
         if (legacyReservationStatus != LegacyReservationStatus.Success)
         {
             throw new CapacityExceededReservationException(string.Format("{0}:{1}:{2}", this.serverFQDN, this.mdbGuid, this.flags), 1);
         }
     }
 }
 void IMailboxReplicationService.AttemptConnectToMRSProxy(string remoteHostName, Guid mbxGuid, string username, string password, string domain)
 {
     if (TestIntegration.Instance.SkipMrsProxyValidation)
     {
         return;
     }
     this.ForwardKnownExceptions(delegate
     {
         using (MailboxReplicationProxyClient.CreateConnectivityTestClient(remoteHostName, new NetworkCredential(username, password, domain), true))
         {
         }
     }, (Exception exception) => exception == null || exception.Message.IndexOf("The value of wsrm:Identifier is not a known Sequence identifier.", StringComparison.OrdinalIgnoreCase) >= 0);
 }
        void IMailboxReplicationService.PingMRSProxy(string serverFqdn, string username, string password, string domain, bool useHttps)
        {
            NetworkCredential credentials = null;

            if (!string.IsNullOrEmpty(username))
            {
                credentials = new NetworkCredential(username, password, domain);
            }
            this.ForwardKnownExceptions(delegate
            {
                using (MailboxReplicationProxyClient.CreateConnectivityTestClient(serverFqdn, credentials, useHttps))
                {
                }
            }, null);
        }
Example #7
0
        public static IMailboxReplicationProxyService CreateChannel(MailboxReplicationProxyClient proxyClient)
        {
            ChannelFactory <IMailboxReplicationProxyService> channelFactory = proxyClient.ChannelFactory;
            EndpointAddress address = proxyClient.Endpoint.Address;

            if (address.Uri != null && (address.Uri.Scheme == Uri.UriSchemeHttps || address.Uri.Scheme == Uri.UriSchemeHttp))
            {
                if (!ExchangeSessionAwareClientsHelper.webRequestCreator.IsDisabled)
                {
                    UriBuilder uriBuilder = new UriBuilder(address.Uri);
                    uriBuilder.Path = proxyClient.RequestContext.Id.ToString();
                    if (proxyClient.UseCertificateToAuthenticate)
                    {
                        string config = ConfigBase <MRSConfigSchema> .GetConfig <string>("ProxyClientCertificateSubject");

                        try
                        {
                            channelFactory.Credentials.ClientCertificate.Certificate = TlsCertificateInfo.FindFirstCertWithSubjectDistinguishedName(config, false);
                        }
                        catch (ArgumentException ex)
                        {
                            throw new CertificateLoadErrorException(config, ex.Message, ex);
                        }
                    }
                    return(channelFactory.CreateChannel(address, uriBuilder.Uri));
                }
                CustomBinding customBinding = channelFactory.Endpoint.Binding as CustomBinding;
                if (customBinding != null)
                {
                    HttpsTransportBindingElement httpsTransportBindingElement = customBinding.Elements.Find <HttpsTransportBindingElement>();
                    if (httpsTransportBindingElement != null)
                    {
                        httpsTransportBindingElement.AllowCookies = true;
                    }
                }
            }
            return(channelFactory.CreateChannel(address));
        }
Example #8
0
 protected override void InternalDispose(bool calledFromDispose)
 {
     if (calledFromDispose && this.reservationId != Guid.Empty)
     {
         if (this.reservationId == RemoteReservation.DownlevelReservationId)
         {
             return;
         }
         CommonUtils.CatchKnownExceptions(delegate
         {
             using (MailboxReplicationProxyClient mailboxReplicationProxyClient = MailboxReplicationProxyClient.CreateWithoutThrottling(this.serverFQDN, this.credentials, this.mailboxGuid, this.mdbGuid))
             {
                 if (mailboxReplicationProxyClient.ServerVersion[37])
                 {
                     ((IMailboxReplicationProxyService)mailboxReplicationProxyClient).IReservationManager_ReleaseResources(this.reservationId);
                 }
                 else if (mailboxReplicationProxyClient.ServerVersion[28])
                 {
                     ((IMailboxReplicationProxyService)mailboxReplicationProxyClient).IMailbox_ReserveResources(this.reservationId, Guid.Empty, 3);
                 }
             }
         }, null);
     }
 }
Example #9
0
 // Token: 0x0600003C RID: 60 RVA: 0x00002E94 File Offset: 0x00001094
 protected virtual MigrationAccount[] SelectAccountsToMigrate(long maximumAccounts, long?maximumTotalSize, int?constraintId)
 {
     for (int i = 3; i > 0; i--)
     {
         try
         {
             IMailboxReplicationProxyService mailboxReplicationProxyService = MailboxReplicationProxyClient.CreateForOlcConnection(OlcTopology.Instance.FindServerByLocalDatacenter(), ProxyControlFlags.DoNotApplyProxyThrottling);
             return(mailboxReplicationProxyService.SelectAccountsToMigrate(maximumAccounts, maximumTotalSize, constraintId));
         }
         catch (TimeoutException ex)
         {
             base.Context.Logger.Log(MigrationEventType.Warning, "Encountered timeout error when trying to make wcf call, iteration {0}", new object[]
             {
                 i,
                 ex
             });
             if (i <= 1)
             {
                 throw;
             }
         }
         catch (CommunicationException ex2)
         {
             base.Context.Logger.Log(MigrationEventType.Warning, "Encountered error when trying to make wcf call, iteration {0}", new object[]
             {
                 i,
                 ex2
             });
             if (i <= 1)
             {
                 throw;
             }
         }
     }
     return(null);
 }
Example #10
0
 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();
             }
         }
     }
 }