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); }
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); }