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