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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public virtual ServerLocatorReturn LocateServer(IRoutingKey[] keys, IRouteSelectorDiagnostics diagnostics)
        {
            IRoutingKey           successKey     = null;
            IRoutingEntry         routingEntry   = null;
            IList <IRoutingEntry> routingEntries = null;
            string value;

            if (keys != null)
            {
                foreach (IRoutingKey routingKey in keys)
                {
                    if (routingKey != null)
                    {
                        if (this.ResolveRoute(routingKey, diagnostics, out routingEntry, out routingEntries))
                        {
                            successKey = routingKey;
                            break;
                        }
                    }
                    else
                    {
                        value = "[ServerLocator::LocateServer]: null key value in collection.";
                        diagnostics.AddErrorInfo(value);
                    }
                }
            }
            else
            {
                value = "[ServerLocator::LocateServer]: null keys collection.";
                diagnostics.AddErrorInfo(value);
            }
            SuccessfulDatabaseGuidRoutingEntry successfulDatabaseGuidRoutingEntry = routingEntry as SuccessfulDatabaseGuidRoutingEntry;

            if (successfulDatabaseGuidRoutingEntry != null)
            {
                ServerRoutingDestination serverRoutingDestination = successfulDatabaseGuidRoutingEntry.Destination as ServerRoutingDestination;
                return(new ServerLocatorReturn(serverRoutingDestination.Fqdn, serverRoutingDestination.Version, successKey, routingEntries));
            }
            SuccessfulServerRoutingEntry successfulServerRoutingEntry = routingEntry as SuccessfulServerRoutingEntry;

            if (successfulServerRoutingEntry != null)
            {
                ServerRoutingDestination serverRoutingDestination2 = successfulServerRoutingEntry.Destination as ServerRoutingDestination;
                return(new ServerLocatorReturn(serverRoutingDestination2.Fqdn, serverRoutingDestination2.Version, successKey, routingEntries));
            }
            value = string.Format("[ServerLocator::LocateServer]: RoutingEntry returned was of an unexpected type: {0}", (routingEntry != null) ? routingEntry.GetType() : null);
            diagnostics.AddErrorInfo(value);
            return(null);
        }
Ejemplo n.º 4
0
        public static bool AddEntry(this ISharedCacheClient cacheClient, IRoutingEntry entry)
        {
            SuccessfulMailboxRoutingEntry firstRoutingEntry = entry as SuccessfulMailboxRoutingEntry;

            if (firstRoutingEntry != null)
            {
                DatabaseGuidRoutingDestination databaseGuidRoutingDestination = entry.Destination as DatabaseGuidRoutingDestination;
                if (databaseGuidRoutingDestination != null)
                {
                    string sharedCacheKeyFromRoutingKey             = cacheClient.GetSharedCacheKeyFromRoutingKey(entry.Key);
                    AnchorMailboxCacheEntry anchorMailboxCacheEntry = new AnchorMailboxCacheEntry();
                    anchorMailboxCacheEntry.Database   = new ADObjectId(databaseGuidRoutingDestination.DatabaseGuid, databaseGuidRoutingDestination.ResourceForest);
                    anchorMailboxCacheEntry.DomainName = databaseGuidRoutingDestination.DomainName;
                    DateTime utcNow = DateTime.UtcNow;
                    string   text;
                    return(cacheClient.TryInsert(sharedCacheKeyFromRoutingKey, anchorMailboxCacheEntry.ToByteArray(), utcNow, out text));
                }
            }
            else
            {
                SuccessfulDatabaseGuidRoutingEntry successfulDatabaseGuidRoutingEntry = entry as SuccessfulDatabaseGuidRoutingEntry;
                if (successfulDatabaseGuidRoutingEntry != null)
                {
                    ServerRoutingDestination serverRoutingDestination = entry.Destination as ServerRoutingDestination;
                    if (serverRoutingDestination != null)
                    {
                        BackEndServer backEndServer = new BackEndServer(serverRoutingDestination.Fqdn, serverRoutingDestination.Version ?? 0);
                        string        resourceForest;
                        if (Utilities.TryExtractForestFqdnFromServerFqdn(backEndServer.Fqdn, out resourceForest))
                        {
                            MailboxServerCacheEntry value = new MailboxServerCacheEntry(backEndServer, resourceForest, DateTime.UtcNow, false);
                            DateTime utcNow2 = DateTime.UtcNow;
                            DatabaseGuidRoutingKey databaseGuidRoutingKey = successfulDatabaseGuidRoutingEntry.Key as DatabaseGuidRoutingKey;
                            string text2;
                            return(cacheClient.TryInsert(databaseGuidRoutingKey.DatabaseGuid.ToString(), value, utcNow2, out text2));
                        }
                    }
                }
            }
            return(false);
        }