예제 #1
0
        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);
        }
예제 #3
0
 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)));
 }
예제 #4
0
 public static BackEndServer GetBackEndServer(ADObjectId database)
 {
     if (database == null)
     {
         throw new ArgumentNullException("database");
     }
     return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(() => BackEndLocator.GetBackEndServerByDatabase(database, null, default(SmtpAddress))));
 }
예제 #5
0
 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)));
 }
예제 #6
0
 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)));
 }
예제 #7
0
 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)));
 }
예제 #8
0
        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));
        }
예제 #9
0
 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);
     }));
 }
예제 #10
0
 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);
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
 public static Uri GetBackEndOwaUrl(IMailboxInfo mailbox)
 {
     return(BackEndLocator.GetBackEndHttpServiceUrl <OwaService>(mailbox));
 }
예제 #16
0
 public static Uri GetBackEndWebServicesUrl(BackEndServer backEndServer)
 {
     return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(backEndServer));
 }
예제 #17
0
 public static Uri GetBackEndWebServicesUrl(IMailboxInfo mailbox)
 {
     return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(mailbox));
 }
예제 #18
0
 public static Uri GetBackEndWebServicesUrl(MiniRecipient miniRecipient)
 {
     return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(miniRecipient));
 }
예제 #19
0
 public static Uri GetBackEndWebServicesUrl(ADUser aduser)
 {
     return(BackEndLocator.GetBackEndHttpServiceUrl <WebServicesService>(aduser));
 }
예제 #20
0
 public static BackEndServer GetAnyBackEndServer()
 {
     return(BackEndLocator.CallWithExceptionHandling <BackEndServer>(() => HttpProxyBackEndHelper.GetAnyBackEndServer()));
 }