internal static bool TryGetBackEndWebServicesUrlFromSmtp(string smtpString, Func <SmtpAddress, IRecipientSession> createRecipientSession, out Uri ewsUri) { ewsUri = null; ProxyAddress proxyAddress; if (!ProxyAddress.TryParse(smtpString, out proxyAddress)) { ExTraceGlobals.CafeTracer.TraceDebug <string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] The smtp address was invalid: {0}", smtpString); return(false); } if (proxyAddress.Prefix != ProxyAddressPrefix.Smtp) { ExTraceGlobals.CafeTracer.TraceDebug <string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] Non-SMTP address is not supported: {0}", smtpString); return(false); } SmtpAddress arg = new SmtpAddress(proxyAddress.AddressString); IRecipientSession session = createRecipientSession(arg); try { ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromProxyAddress(session, smtpString); ewsUri = BackEndLocator.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo); } catch (ObjectNotFoundException ex) { ExTraceGlobals.CafeTracer.TraceDebug <string, string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] Couldn't find exchange principal for smtp address: {0}. Exception {1}", smtpString, ex.ToString()); return(false); } catch (BackEndLocatorException ex2) { ExTraceGlobals.CafeTracer.TraceDebug <string, string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] Couldn't find exchange services url for smtp address: {0}. Exception: {1}", smtpString, ex2.ToString()); return(false); } return(true); }
// Token: 0x06000779 RID: 1913 RVA: 0x0001D180 File Offset: 0x0001B380 public IAsyncResult BeginGetBackEndServerList(MiniRecipient miniRecipient, int maxServers, AsyncCallback callback, object state) { if (miniRecipient == null) { throw new ArgumentNullException("miniRecipient"); } if (maxServers <= 0) { throw new ArgumentException("maxServers needs to be greater than zero"); } this.database = miniRecipient.Database; this.maxServers = maxServers; OrganizationId organizationId = miniRecipient.OrganizationId; SmtpAddress primarySmtpAddress = miniRecipient.PrimarySmtpAddress; if (this.database == null) { ADUser defaultOrganizationMailbox = HttpProxyBackEndHelper.GetDefaultOrganizationMailbox(organizationId, null); if (defaultOrganizationMailbox == null || defaultOrganizationMailbox.Database == null) { ExTraceGlobals.CafeTracer.TraceError <OrganizationId>(0L, "[BackEndLocator.BeginGetBackEndServerList] Cannot find organization mailbox for organization {1}", organizationId); throw new AdUserNotFoundException(ServerStrings.ADUserNotFound); } this.database = defaultOrganizationMailbox.Database; primarySmtpAddress = defaultOrganizationMailbox.PrimarySmtpAddress; } string domainName = null; if (organizationId != null && !organizationId.Equals(OrganizationId.ForestWideOrgId)) { domainName = primarySmtpAddress.Domain; } this.serverLocator = MailboxServerLocator.Create(this.database.ObjectGuid, domainName, this.database.PartitionFQDN); bool flag = true; IAsyncResult result; try { result = this.serverLocator.BeginGetServer(callback, state); flag = false; } catch (Exception ex) { ExTraceGlobals.CafeTracer.TraceError <Exception>(0L, "[AsyncBackEndLocator.BeginGetBackEndServerList] Caught exception {0}.", ex); if (BackEndLocator.ShouldWrapInBackendLocatorException(ex)) { throw new BackEndLocatorException(ex); } throw; } finally { if (flag) { this.serverLocator.Dispose(); this.serverLocator = null; } } return(result); }
public static BackEndServer GetBackEndServer(MiniRecipient miniRecipient) { if (miniRecipient == null) { throw new ArgumentNullException("miniRecipient"); } return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(() => BackEndLocator.GetBackEndServerByDatabase(miniRecipient.Database, miniRecipient.OrganizationId, miniRecipient.PrimarySmtpAddress))); }
public static BackEndServer GetBackEndServer(ADObjectId database) { if (database == null) { throw new ArgumentNullException("database"); } return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(() => BackEndLocator.GetBackEndServerByDatabase(database, null, default(SmtpAddress)))); }
private static Uri GetBackEndHttpServiceUrl <ServiceType>(BackEndServer backEndServer) where ServiceType : HttpService { if (backEndServer == null) { throw new ArgumentNullException("backEndServer"); } return(BackEndLocator.CallWithExceptionHandling <Uri>(() => HttpProxyBackEndHelper.GetBackEndServiceUrlByServer <ServiceType>(backEndServer))); }
public static IList <BackEndServer> GetBackEndServerList(MiniRecipient miniRecipient, int maxServers) { if (miniRecipient == null) { throw new ArgumentNullException("miniRecipient"); } return(BackEndLocator.CallWithExceptionHandling <IList <BackEndServer> >(() => BackEndLocator.GetBackEndServerListForDatabase(miniRecipient.Database, miniRecipient.OrganizationId, miniRecipient.PrimarySmtpAddress, maxServers))); }
public static BackEndServer GetBackEndServer(ADUser aduser) { if (aduser == null) { throw new ArgumentNullException("aduser"); } return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(() => BackEndLocator.GetBackEndServerByDatabase(aduser.Database, aduser.OrganizationId, aduser.PrimarySmtpAddress))); }
private static BackEndServer GetBackEndServerByOrganization(OrganizationId organizationId) { ADUser defaultOrganizationMailbox = HttpProxyBackEndHelper.GetDefaultOrganizationMailbox(organizationId, null); if (defaultOrganizationMailbox == null || defaultOrganizationMailbox.Database == null) { ExTraceGlobals.CafeTracer.TraceError <OrganizationId>(0L, "[BackEndLocator.GetBackEndServerByOrganization] Cannot find organization mailbox for organization {1}", organizationId); throw new AdUserNotFoundException(ServerStrings.ADUserNotFound); } return(BackEndLocator.GetBackEndServerByDatabase(defaultOrganizationMailbox.Database, organizationId, defaultOrganizationMailbox.PrimarySmtpAddress)); }
private static Uri GetBackEndHttpServiceUrl <ServiceType>(IMailboxInfo mailbox) where ServiceType : HttpService { if (mailbox == null) { throw new ArgumentNullException("mailbox"); } return(BackEndLocator.CallWithExceptionHandling <Uri>(delegate { BackEndServer backEndServer = BackEndLocator.GetBackEndServer(mailbox); return HttpProxyBackEndHelper.GetBackEndServiceUrlByServer <ServiceType>(backEndServer); })); }
public static BackEndServer GetBackEndServer(IMailboxInfo mailbox) { if (mailbox == null) { throw new ArgumentNullException("mailbox"); } return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(delegate { if (mailbox.Location != null) { BackEndServer backEndServer = new BackEndServer(mailbox.Location.ServerFqdn, mailbox.Location.ServerVersion); ExTraceGlobals.CafeTracer.TraceDebug <BackEndServer, IMailboxInfo>(0L, "[BackEndLocator.GetBackEndServer] Returns back end server {0} for Mailbox {1}", backEndServer, mailbox); return backEndServer; } return BackEndLocator.GetBackEndServerByDatabase(mailbox.MailboxDatabase, mailbox.OrganizationId, mailbox.PrimarySmtpAddress); })); }
// Token: 0x0600077A RID: 1914 RVA: 0x0001D2EC File Offset: 0x0001B4EC public IList <BackEndServer> EndGetBackEndServerList(IAsyncResult asyncResult) { IList <BackEndServer> result; try { BackEndServer backEndServer = this.serverLocator.EndGetServer(asyncResult); ExTraceGlobals.CafeTracer.TraceDebug <BackEndServer, ADObjectId>(0L, "[MailboxServerLocator.EndGetServer] called inside [AsyncBackEndLocator.EndGetBackEndServerList] returned back end server {0} for database {1}", backEndServer, this.database); IList <BackEndServer> list = new List <BackEndServer>(); list.Add(backEndServer); int num = 1; Random localRandom = new Random(AsyncBackEndLocator.GetRandomNumber(int.MaxValue)); IEnumerable <KeyValuePair <Guid, BackEndServer> > enumerable = from x in this.serverLocator.AvailabilityGroupServers orderby localRandom.Next() select x; foreach (KeyValuePair <Guid, BackEndServer> keyValuePair in enumerable) { if (num >= this.maxServers) { break; } if (!this.IsServerInBackendList(list, keyValuePair.Value)) { list.Add(keyValuePair.Value); num++; } } result = list; } catch (Exception ex) { ExTraceGlobals.CafeTracer.TraceError <Exception>(0L, "[AsyncBackEndLocator.EndGetBackEndServerList] Caught exception {0}.", ex); if (BackEndLocator.ShouldWrapInBackendLocatorException(ex)) { throw new BackEndLocatorException(ex); } throw; } finally { this.serverLocator.Dispose(); this.serverLocator = null; } return(result); }
private static IList <BackEndServer> GetBackEndServerListForDatabase(ADObjectId database, OrganizationId organizationId, SmtpAddress primarySmtpAddress, int maxServers) { if (maxServers == 0) { return(new BackEndServer[0]); } if (database == null) { return(BackEndLocator.GetBackEndServerListForOrganization(organizationId, maxServers)); } string domainName = null; if (organizationId != null && !organizationId.Equals(OrganizationId.ForestWideOrgId)) { domainName = primarySmtpAddress.Domain; } IList <BackEndServer> result; using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.Create(database.ObjectGuid, domainName, database.PartitionFQDN)) { BackEndServer server = mailboxServerLocator.GetServer(); ExTraceGlobals.CafeTracer.TraceDebug <BackEndServer, ADObjectId>(0L, "[BackEndLocator.GetBackEndServerByDatabase] Returns back end server {0} for database {1}", server, database); IList <BackEndServer> list = new List <BackEndServer>(); list.Add(server); int num = 1; foreach (KeyValuePair <Guid, BackEndServer> keyValuePair in mailboxServerLocator.AvailabilityGroupServers) { if (num >= maxServers) { break; } if (!string.Equals(keyValuePair.Value.Fqdn, server.Fqdn, StringComparison.OrdinalIgnoreCase)) { list.Add(keyValuePair.Value); num++; } } result = list; } return(result); }
private static BackEndServer GetBackEndServerByDatabase(ADObjectId database, OrganizationId organizationId, SmtpAddress primarySmtpAddress) { if (database == null) { return(BackEndLocator.GetBackEndServerByOrganization(organizationId)); } string domainName = null; if (organizationId != null && !organizationId.Equals(OrganizationId.ForestWideOrgId)) { domainName = primarySmtpAddress.Domain; } BackEndServer result; using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.Create(database.ObjectGuid, domainName, database.PartitionFQDN)) { BackEndServer server = mailboxServerLocator.GetServer(); ExTraceGlobals.CafeTracer.TraceDebug <BackEndServer, ADObjectId>(0L, "[BackEndLocator.GetBackEndServerByDatabase] Returns back end server {0} for database {1}", server, database); result = server; } return(result); }
private static T CallWithExceptionHandling <T>(Func <T> actualCall) { T result; try { result = actualCall(); } catch (BackEndLocatorException) { throw; } catch (Exception ex) { ExTraceGlobals.CafeTracer.TraceError <Exception>(0L, "[BackEndLocator.CallWithExceptionHandling] Caught exception {0}.", ex); if (BackEndLocator.ShouldWrapInBackendLocatorException(ex)) { throw new BackEndLocatorException(ex); } throw; } return(result); }
public static Uri GetBackEndOwaUrl(IMailboxInfo mailbox) { return(BackEndLocator.GetBackEndHttpServiceUrl <OwaService>(mailbox)); }
public static Uri GetBackEndWebServicesUrl(BackEndServer backEndServer) { return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(backEndServer)); }
public static Uri GetBackEndWebServicesUrl(IMailboxInfo mailbox) { return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(mailbox)); }
public static Uri GetBackEndWebServicesUrl(MiniRecipient miniRecipient) { return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(miniRecipient)); }
public static Uri GetBackEndWebServicesUrl(ADUser aduser) { return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(aduser)); }
public static BackEndServer GetAnyBackEndServer() { return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(() => HttpProxyBackEndHelper.GetAnyBackEndServer())); }