bool ISharedCache.TryGet <T>(string key, out T value, IRoutingDiagnostics diagnostics)
        {
            bool result;

            try
            {
                Stopwatch stopwatch = new Stopwatch();
                string    text;
                bool      flag;
                try
                {
                    stopwatch.Start();
                    flag = this.client.TryGet <T>(key, out value, out text);
                }
                finally
                {
                    stopwatch.Stop();
                    diagnostics.AddSharedCacheLatency(TimeSpan.FromMilliseconds((double)stopwatch.ElapsedMilliseconds));
                }
                diagnostics.AddDiagnosticText(text);
                result = flag;
            }
            catch (CacheClientException innerException)
            {
                throw new SharedCacheException("SharedCacheClient.TryGet(T) failed", innerException);
            }
            return(result);
        }
        IRoutingEntry IRoutingLookup.GetRoutingEntry(IRoutingKey routingKey, IRoutingDiagnostics diagnostics)
        {
            if (routingKey == null)
            {
                throw new ArgumentNullException("routingKey");
            }
            if (diagnostics == null)
            {
                throw new ArgumentNullException("diagnostics");
            }
            ServerRoutingKey serverRoutingKey = routingKey as ServerRoutingKey;

            if (serverRoutingKey == null)
            {
                string message = string.Format("Routing key type {0} is not supported", routingKey.GetType());
                throw new ArgumentException(message, "routingKey");
            }
            if (!string.IsNullOrEmpty(serverRoutingKey.Server))
            {
                int?version = null;
                if (serverRoutingKey.Version != null)
                {
                    version = serverRoutingKey.Version;
                }
                else
                {
                    version = this.versionLookup.LookupVersion(serverRoutingKey.Server);
                }
                return(new SuccessfulServerRoutingEntry(serverRoutingKey, new ServerRoutingDestination(serverRoutingKey.Server, version), DateTime.UtcNow.ToFileTimeUtc()));
            }
            ErrorRoutingDestination destination = new ErrorRoutingDestination("Could not extract server from ServerRoutingKey");

            return(new FailedServerRoutingEntry(serverRoutingKey, destination, DateTime.UtcNow.ToFileTimeUtc()));
        }
Example #3
0
 public User FindByExternalDirectoryObjectId(Guid userGuid, Guid tenantGuid, IRoutingDiagnostics diagnostics)
 {
     return(this.Execute <User>(delegate
     {
         ADSessionSettings sessionSettings = ActiveDirectoryUserProvider.FromExternalDirectoryOrganizationId(tenantGuid, diagnostics);
         IRecipientSession tenantOrRootOrgRecipientSession = this.directorySessionFactoryInstance.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 111, "FindByExternalDirectoryObjectId", "f:\\15.00.1497\\sources\\dev\\cafe\\src\\Routing\\Providers\\ActiveDirectoryUserProvider.cs");
         ADRawEntry rawEntry = ActiveDirectoryUserProvider.FindAdUserByExternalDirectoryObjectId(userGuid, tenantOrRootOrgRecipientSession, diagnostics);
         return ActiveDirectoryUserProvider.CreateUserFromAdRawEntry(rawEntry);
     }, "FindByExternalDirectoryObjectId failed"));
 }
Example #4
0
 public User FindBySmtpAddress(SmtpAddress smtpAddress, IRoutingDiagnostics diagnostics)
 {
     return(this.Execute <User>(delegate
     {
         SmtpProxyAddress proxyAddress = new SmtpProxyAddress(smtpAddress.ToString(), true);
         ADSessionSettings sessionSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(smtpAddress.Domain);
         IRecipientSession tenantOrRootOrgRecipientSession = this.directorySessionFactoryInstance.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 88, "FindBySmtpAddress", "f:\\15.00.1497\\sources\\dev\\cafe\\src\\Routing\\Providers\\ActiveDirectoryUserProvider.cs");
         ADRawEntry rawEntry = ActiveDirectoryUserProvider.FindByProxyAddress(proxyAddress, tenantOrRootOrgRecipientSession, diagnostics);
         return ActiveDirectoryUserProvider.CreateUserFromAdRawEntry(rawEntry);
     }, "FindBySmtpAddress failed"));
 }
Example #5
0
        IRoutingEntry IRoutingLookup.GetRoutingEntry(IRoutingKey routingKey, IRoutingDiagnostics diagnostics)
        {
            if (routingKey == null)
            {
                throw new ArgumentNullException("routingKey");
            }
            if (diagnostics == null)
            {
                throw new ArgumentNullException("diagnostics");
            }
            T t = routingKey as T;

            if (t == null)
            {
                string message = string.Format("Routing key type {0} is not supported", routingKey.GetType());
                throw new ArgumentException(message, "routingKey");
            }
            return(this.GetMailboxRoutingEntry(t, diagnostics));
        }
Example #6
0
        public MailboxRoutingEntry GetMailboxRoutingEntry(T routingKey, IRoutingDiagnostics diagnostics)
        {
            if (routingKey == null)
            {
                throw new ArgumentNullException("routingKey");
            }
            MailboxRoutingEntry result;

            try
            {
                User user = this.FindUser(routingKey, diagnostics);
                if (user == null)
                {
                    result = this.CreateFailedEntry(routingKey, "Unable to find user");
                }
                else
                {
                    Guid?  guid           = null;
                    string resourceForest = null;
                    this.SelectDatabaseGuidResourceForest(routingKey, user, out guid, out resourceForest);
                    if (guid == null)
                    {
                        result = this.CreateFailedEntry(routingKey, "User object missing database GUID");
                    }
                    else
                    {
                        long   timestamp  = (user.LastModifiedTime != null) ? user.LastModifiedTime.Value.ToFileTimeUtc() : DateTime.UtcNow.ToFileTimeUtc();
                        string domainName = this.GetDomainName(routingKey);
                        result = new SuccessfulMailboxRoutingEntry(routingKey, new DatabaseGuidRoutingDestination(guid.Value, domainName, resourceForest), timestamp);
                    }
                }
            }
            catch (UserProviderException ex)
            {
                ErrorRoutingDestination destination = new ErrorRoutingDestination(ex.Message);
                result = new FailedMailboxRoutingEntry(routingKey, destination, DateTime.UtcNow.ToFileTimeUtc());
            }
            return(result);
        }
Example #7
0
        IRoutingEntry IRoutingLookup.GetRoutingEntry(IRoutingKey routingKey, IRoutingDiagnostics diagnostics)
        {
            if (routingKey == null)
            {
                throw new ArgumentNullException("routingKey");
            }
            if (diagnostics == null)
            {
                throw new ArgumentNullException("diagnostics");
            }
            if (routingKey.RoutingItemType != this.validItemType)
            {
                string message = string.Format("Routing key type {0} is not supported in {1}", RoutingEntryHeaderSerializer.RoutingTypeToString(routingKey.RoutingItemType), base.GetType());
                throw new ArgumentException(message, "routingKey");
            }
            string sharedCacheKeyFromRoutingKey = this.sharedCache.GetSharedCacheKeyFromRoutingKey(routingKey);

            try
            {
                byte[] bytes;
                if (this.sharedCache.TryGet(sharedCacheKeyFromRoutingKey, out bytes, diagnostics))
                {
                    AnchorMailboxCacheEntry anchorMailboxCacheEntry = new AnchorMailboxCacheEntry();
                    anchorMailboxCacheEntry.FromByteArray(bytes);
                    if (anchorMailboxCacheEntry.Database != null)
                    {
                        DatabaseGuidRoutingDestination destination = new DatabaseGuidRoutingDestination(anchorMailboxCacheEntry.Database.ObjectGuid, anchorMailboxCacheEntry.DomainName, anchorMailboxCacheEntry.Database.PartitionFQDN);
                        return(new SuccessfulMailboxRoutingEntry(routingKey, destination, DateTime.Now.ToFileTimeUtc()));
                    }
                }
            }
            catch (SharedCacheException ex)
            {
                ErrorRoutingDestination destination2 = new ErrorRoutingDestination(ex.Message);
                return(new FailedMailboxRoutingEntry(routingKey, destination2, DateTime.UtcNow.ToFileTimeUtc()));
            }
            return(null);
        }
Example #8
0
 protected override User FindUser(SmtpRoutingKey smtpRoutingKey, IRoutingDiagnostics diagnostics)
 {
     return(base.UserProvider.FindBySmtpAddress(smtpRoutingKey.SmtpAddress, diagnostics));
 }
        public DatabaseGuidRoutingEntry GetDatabaseGuidRoutingEntry(DatabaseGuidRoutingKey databaseGuidRoutingKey, IRoutingDiagnostics diagnostics)
        {
            if (databaseGuidRoutingKey == null)
            {
                throw new ArgumentNullException("databaseGuidRoutingKey");
            }
            DatabaseGuidRoutingEntry result;

            try
            {
                MailboxServerCacheEntry mailboxServerCacheEntry;
                if (this.sharedCache.TryGet <MailboxServerCacheEntry>(databaseGuidRoutingKey.DatabaseGuid.ToString(), out mailboxServerCacheEntry, diagnostics))
                {
                    result = new SuccessfulDatabaseGuidRoutingEntry(databaseGuidRoutingKey, new ServerRoutingDestination(mailboxServerCacheEntry.BackEndServer.Fqdn, new int?(mailboxServerCacheEntry.BackEndServer.Version)), DateTime.UtcNow.ToFileTimeUtc());
                }
                else
                {
                    result = null;
                }
            }
            catch (SharedCacheException ex)
            {
                ErrorRoutingDestination destination = new ErrorRoutingDestination(ex.Message);
                result = new FailedDatabaseGuidRoutingEntry(databaseGuidRoutingKey, destination, DateTime.UtcNow.ToFileTimeUtc());
            }
            return(result);
        }
Example #10
0
        private static IRoutingEntry GetRoutingEntry(IRoutingKey routingKey, IRoutingLookupFactory factory, IRoutingDiagnostics diagnostics)
        {
            IRoutingLookup lookupForType = factory.GetLookupForType(routingKey.RoutingItemType);
            IRoutingEntry  routingEntry  = null;

            if (lookupForType != null)
            {
                routingEntry = lookupForType.GetRoutingEntry(routingKey, diagnostics);
                if (routingEntry != null && (routingEntry.Destination.RoutingItemType == RoutingItemType.Error || routingEntry.Destination.RoutingItemType == RoutingItemType.Unknown))
                {
                    routingEntry = null;
                }
            }
            return(routingEntry);
        }
 protected override User FindUser(LiveIdMemberNameRoutingKey liveIdMemberNameRoutingKey, IRoutingDiagnostics diagnostics)
 {
     return(base.UserProvider.FindByLiveIdMemberName(liveIdMemberNameRoutingKey.LiveIdMemberName, liveIdMemberNameRoutingKey.OrganizationContext, diagnostics));
 }
 public RoutingUpdateModule(IRoutingLookupFactory lookupFactory = null, IRoutingDiagnostics diagnostics = null)
 {
     this.lookupFactory = (lookupFactory ?? new RoutingEntryLookupFactory(RoutingUpdateModule.activeCopiesCacheProvider, new ActiveDirectoryUserProvider(RoutingUpdateModule.RUMUseADCache.Value)));
     this.diagnostics   = (diagnostics ?? new RoutingUpdateDiagnostics());
 }
Example #13
0
        private static ADRawEntry FindByExchangeGuidIncludingAlternate(Guid exchangeGuid, IRecipientSession recipientSession, IRoutingDiagnostics diagnostics)
        {
            DateTime   utcNow = DateTime.UtcNow;
            ADRawEntry result;

            try
            {
                result = recipientSession.FindByExchangeGuidIncludingAlternate(exchangeGuid, ActiveDirectoryUserProvider.AdRawEntryProperties);
            }
            finally
            {
                diagnostics.AddAccountForestLatency(DateTime.UtcNow - utcNow);
            }
            return(result);
        }
Example #14
0
 public string FindResourceForestFqdnByExternalDirectoryOrganizationId(Guid externalDirectoryOrganizationId, IRoutingDiagnostics diagnostics)
 {
     return(ADAccountPartitionLocator.GetResourceForestFqdnByExternalDirectoryOrganizationId(externalDirectoryOrganizationId));
 }
Example #15
0
 protected abstract User FindUser(T routingKey, IRoutingDiagnostics diagnostics);
 protected override User FindUser(ExternalDirectoryObjectIdRoutingKey externalDirectoryObjectIdRoutingKey, IRoutingDiagnostics diagnostics)
 {
     return(base.UserProvider.FindByExternalDirectoryObjectId(externalDirectoryObjectIdRoutingKey.UserGuid, externalDirectoryObjectIdRoutingKey.TenantGuid, diagnostics));
 }
Example #17
0
 public User FindByExchangeGuidIncludingAlternate(Guid exchangeGuid, string tenantDomain, IRoutingDiagnostics diagnostics)
 {
     return(this.Execute <User>(delegate
     {
         ADSessionSettings sessionSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(tenantDomain);
         IRecipientSession tenantOrRootOrgRecipientSession = this.directorySessionFactoryInstance.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 64, "FindByExchangeGuidIncludingAlternate", "f:\\15.00.1497\\sources\\dev\\cafe\\src\\Routing\\Providers\\ActiveDirectoryUserProvider.cs");
         ADRawEntry rawEntry = ActiveDirectoryUserProvider.FindByExchangeGuidIncludingAlternate(exchangeGuid, tenantOrRootOrgRecipientSession, diagnostics);
         return ActiveDirectoryUserProvider.CreateUserFromAdRawEntry(rawEntry);
     }, "FindByExchangeGuidIncludingAlternate failed"));
 }
Example #18
0
        public DatabaseGuidRoutingEntry GetDatabaseGuidRoutingEntry(DatabaseGuidRoutingKey databaseGuidRoutingKey, IRoutingDiagnostics diagnostics)
        {
            if (databaseGuidRoutingKey == null)
            {
                throw new ArgumentNullException("databaseGuidRoutingKey");
            }
            DatabaseGuidRoutingEntry result;

            try
            {
                BackEndServer backEndServerForDatabase = this.databaseLocationProvider.GetBackEndServerForDatabase(databaseGuidRoutingKey.DatabaseGuid, databaseGuidRoutingKey.DomainName, databaseGuidRoutingKey.ResourceForest, diagnostics);
                if (backEndServerForDatabase == null)
                {
                    result = this.CreateFailedEntry(databaseGuidRoutingKey, "Could not find database");
                }
                else
                {
                    result = new SuccessfulDatabaseGuidRoutingEntry(databaseGuidRoutingKey, new ServerRoutingDestination(backEndServerForDatabase.Fqdn, new int?(backEndServerForDatabase.Version)), 0L);
                }
            }
            catch (DatabaseLocationProviderException ex)
            {
                result = this.CreateFailedEntry(databaseGuidRoutingKey, ex.Message);
            }
            return(result);
        }
Example #19
0
        private static ADRawEntry FindAdUserByExternalDirectoryObjectId(Guid userGuid, IRecipientSession recipientSession, IRoutingDiagnostics diagnostics)
        {
            DateTime   utcNow = DateTime.UtcNow;
            ADRawEntry result;

            try
            {
                result = recipientSession.FindADUserByExternalDirectoryObjectId(userGuid.ToString());
            }
            finally
            {
                diagnostics.AddAccountForestLatency(DateTime.UtcNow - utcNow);
            }
            return(result);
        }
Example #20
0
        private static ADRawEntry FindByLiveIdMemberName(SmtpAddress liveIdMemberName, ITenantRecipientSession recipientSession, IRoutingDiagnostics diagnostics)
        {
            DateTime   utcNow = DateTime.UtcNow;
            ADRawEntry result;

            try
            {
                result = recipientSession.FindByLiveIdMemberName(liveIdMemberName.ToString(), ActiveDirectoryUserProvider.AdRawEntryProperties);
            }
            finally
            {
                diagnostics.AddAccountForestLatency(DateTime.UtcNow - utcNow);
            }
            return(result);
        }
Example #21
0
        private static ADRawEntry FindByProxyAddress(ProxyAddress proxyAddress, IRecipientSession recipientSession, IRoutingDiagnostics diagnostics)
        {
            DateTime   utcNow = DateTime.UtcNow;
            ADRawEntry result;

            try
            {
                result = recipientSession.FindByProxyAddress(proxyAddress, ActiveDirectoryUserProvider.AdRawEntryProperties);
            }
            finally
            {
                diagnostics.AddAccountForestLatency(DateTime.UtcNow - utcNow);
            }
            return(result);
        }
Example #22
0
        public BackEndServer GetBackEndServerForDatabase(Guid databaseGuid, string domainName, string resourceForest, IRoutingDiagnostics diagnostics)
        {
            DatabaseServerInformation databaseServerInformation = this.activeCopiesList.FirstOrDefault((DatabaseServerInformation info) => info.DatabaseGuid == databaseGuid);

            if (databaseServerInformation != null)
            {
                return(new BackEndServer(databaseServerInformation.ServerFqdn, databaseServerInformation.ServerVersion));
            }
            return(null);
        }
Example #23
0
 public string FindResourceForestFqdnByAcceptedDomainName(string acceptedDomain, IRoutingDiagnostics diagnostics)
 {
     return(ADAccountPartitionLocator.GetResourceForestFqdnByAcceptedDomainName(acceptedDomain));
 }
Example #24
0
 protected override User FindUser(MailboxGuidRoutingKey mailboxGuidRoutingKey, IRoutingDiagnostics diagnostics)
 {
     return(base.UserProvider.FindByExchangeGuidIncludingAlternate(mailboxGuidRoutingKey.MailboxGuid, mailboxGuidRoutingKey.TenantDomain, diagnostics));
 }
Example #25
0
        private static ADSessionSettings FromExternalDirectoryOrganizationId(Guid tenantGuid, IRoutingDiagnostics diagnostics)
        {
            DateTime          utcNow = DateTime.UtcNow;
            ADSessionSettings result;

            try
            {
                result = ADSessionSettings.FromExternalDirectoryOrganizationId(tenantGuid);
            }
            finally
            {
                diagnostics.AddGlobalLocatorLatency(DateTime.UtcNow - utcNow);
            }
            return(result);
        }
Example #26
0
        public BackEndServer GetBackEndServerForDatabase(Guid databaseGuid, string domainName, string resourceForest, IRoutingDiagnostics diagnostics)
        {
            Exception     ex = null;
            BackEndServer result;

            using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.Create(databaseGuid, domainName, resourceForest))
            {
                BackEndServer backEndServer = null;
                try
                {
                    backEndServer = mailboxServerLocator.GetServer();
                }
                catch (ServerLocatorClientException ex2)
                {
                    ex = ex2;
                }
                catch (ServerLocatorClientTransientException ex3)
                {
                    ex = ex3;
                }
                catch (MailboxServerLocatorException ex4)
                {
                    ex = ex4;
                }
                catch (AmServerTransientException ex5)
                {
                    ex = ex5;
                }
                catch (AmServerException ex6)
                {
                    ex = ex6;
                }
                catch (DatabaseNotFoundException ex7)
                {
                    ex = ex7;
                }
                catch (ADTransientException ex8)
                {
                    ex = ex8;
                }
                catch (DataValidationException ex9)
                {
                    ex = ex9;
                }
                catch (DataSourceOperationException ex10)
                {
                    ex = ex10;
                }
                foreach (long num in mailboxServerLocator.DirectoryLatencies)
                {
                    diagnostics.AddResourceForestLatency(TimeSpan.FromMilliseconds((double)num));
                }
                foreach (long num2 in mailboxServerLocator.GlsLatencies)
                {
                    diagnostics.AddGlobalLocatorLatency(TimeSpan.FromMilliseconds((double)num2));
                }
                if (ex != null)
                {
                    throw new DatabaseLocationProviderException("MailboxServerLocator.GetServer failed", ex);
                }
                result = backEndServer;
            }
            return(result);
        }
Example #27
0
 public User FindByLiveIdMemberName(SmtpAddress liveIdMemberName, string organizationContext, IRoutingDiagnostics diagnostics)
 {
     return(this.Execute <User>(delegate
     {
         string text = organizationContext;
         if (string.IsNullOrEmpty(text))
         {
             text = liveIdMemberName.Domain;
         }
         ADSessionSettings sessionSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(text);
         ITenantRecipientSession recipientSession = this.directorySessionFactoryInstance.CreateTenantRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 140, "FindByLiveIdMemberName", "f:\\15.00.1497\\sources\\dev\\cafe\\src\\Routing\\Providers\\ActiveDirectoryUserProvider.cs");
         ADRawEntry rawEntry = ActiveDirectoryUserProvider.FindByLiveIdMemberName(liveIdMemberName, recipientSession, diagnostics);
         return ActiveDirectoryUserProvider.CreateUserFromAdRawEntry(rawEntry);
     }, "FindByLiveIdMemberName failed"));
 }