Exemplo n.º 1
0
 public void ProcessRoutingUpdates(string headerValue)
 {
     if (string.IsNullOrEmpty(headerValue))
     {
         throw new ArgumentNullException("headerValue");
     }
     string[] array = headerValue.Split(new char[]
     {
         ','
     });
     foreach (string text in array)
     {
         try
         {
             IRoutingEntry routingEntry = RoutingEntryHeaderSerializer.Deserialize(text);
             if (ServerLocator.IsMailboxServerCacheKey(routingEntry.Key) && routingEntry.Destination.RoutingItemType == RoutingItemType.Server)
             {
                 this.routeRefresherDiagnostics.IncrementTotalMailboxServerCacheUpdateAttempts();
                 if (this.mailboxServerCacheClient.AddEntry(routingEntry))
                 {
                     string value = "MailboxServerCacheUpdate:" + text;
                     this.routeRefresherDiagnostics.AddGenericInfo(value);
                     this.routeRefresherDiagnostics.IncrementSuccessfulMailboxServerCacheUpdates();
                 }
                 else
                 {
                     string value2 = "MailboxServerCacheFailure:" + text;
                     this.routeRefresherDiagnostics.AddErrorInfo(value2);
                 }
             }
             else if (ServerLocator.IsAnchorMailboxCacheKey(routingEntry.Key) && routingEntry.Destination.RoutingItemType == RoutingItemType.DatabaseGuid)
             {
                 this.routeRefresherDiagnostics.IncrementTotalAnchorMailboxCacheUpdateAttempts();
                 if (this.anchorMailboxCacheClient.AddEntry(routingEntry))
                 {
                     string value3 = "AnchorMailboxCacheUpdate:" + text;
                     this.routeRefresherDiagnostics.AddGenericInfo(value3);
                     this.routeRefresherDiagnostics.IncrementSuccessfulAnchorMailboxCacheUpdates();
                 }
                 else
                 {
                     string value4 = "AnchorMailboxCacheFailure:" + text;
                     this.routeRefresherDiagnostics.AddErrorInfo(value4);
                 }
             }
             else
             {
                 string value5 = "UnrecognizedRoutingEntry:" + text;
                 this.routeRefresherDiagnostics.AddErrorInfo(value5);
             }
         }
         catch (ArgumentException)
         {
             string value6 = "DeserializationException:" + text;
             this.routeRefresherDiagnostics.AddErrorInfo(value6);
         }
     }
 }
Exemplo n.º 2
0
 private bool ShouldSendRoutingEntryUpdate(IRoutingEntry originalRoutingEntry, IRoutingEntry updatedRoutingEntry)
 {
     if (!originalRoutingEntry.Destination.Equals(updatedRoutingEntry.Destination))
     {
         DatabaseGuidRoutingDestination databaseGuidRoutingDestination  = originalRoutingEntry.Destination as DatabaseGuidRoutingDestination;
         DatabaseGuidRoutingDestination databaseGuidRoutingDestination2 = updatedRoutingEntry.Destination as DatabaseGuidRoutingDestination;
         return(!(databaseGuidRoutingDestination2 != null) || !(databaseGuidRoutingDestination != null) || !(databaseGuidRoutingDestination.DatabaseGuid == databaseGuidRoutingDestination2.DatabaseGuid) || !(databaseGuidRoutingDestination.DomainName == databaseGuidRoutingDestination2.DomainName) || !string.IsNullOrEmpty(databaseGuidRoutingDestination.ResourceForest) || !HttpProxyGlobals.LocalMachineForest.Member.Equals(databaseGuidRoutingDestination2.ResourceForest, StringComparison.OrdinalIgnoreCase));
     }
     return(false);
 }
Exemplo n.º 3
0
 internal bool ResolveRoute(IRoutingKey routingKey, IRouteSelectorDiagnostics diagnostics, out IRoutingEntry foundEntry, out IList <IRoutingEntry> routingEntries)
 {
     routingEntries = new List <IRoutingEntry>();
     for (int i = 0; i < 5; i++)
     {
         diagnostics.ProcessRoutingKey(routingKey);
         IRoutingEntry routingEntry = ServerLocator.GetRoutingEntry(routingKey, this.sharedCacheLookupFactory, diagnostics);
         if (routingEntry != null)
         {
             diagnostics.ProcessRoutingEntry(routingEntry);
         }
         if (routingEntry == null)
         {
             routingEntry = ServerLocator.GetRoutingEntry(routingKey, this.locatorServiceLookupFactory, diagnostics);
             if (routingEntry != null)
             {
                 if (ServerLocator.IsMailboxServerCacheKey(routingEntry.Key) && !this.mailboxServerCacheClient.AddEntry(routingEntry))
                 {
                     string value = string.Format("[ServerLocator::ResolveRoute]: RoutingEntry returned from MBLS could not be added to MailboxServer cache: {0}", routingEntry);
                     diagnostics.AddErrorInfo(value);
                 }
                 if (ServerLocator.IsAnchorMailboxCacheKey(routingEntry.Key) && !this.anchorMailboxCacheClient.AddEntry(routingEntry))
                 {
                     string value2 = string.Format("[ServerLocator::ResolveRoute]: RoutingEntry returned from MBLS could not be added to AnchorMailbox cache: {0}", routingEntry);
                     diagnostics.AddErrorInfo(value2);
                 }
             }
             else
             {
                 string value3 = string.Format("[ServerLocator::ResolveRoute]: MBLS could not find entry for key {0}", routingKey);
                 diagnostics.AddErrorInfo(value3);
             }
         }
         if (routingEntry == null)
         {
             break;
         }
         routingEntries.Add(routingEntry);
         string text = ServerLocator.OrganizationNameForLogging(routingEntry.Key);
         if (!string.IsNullOrEmpty(text))
         {
             diagnostics.SetOrganization(text);
         }
         IRoutingKey routingKey2 = routingEntry.Destination.CreateRoutingKey();
         if (routingKey2 == null)
         {
             foundEntry = routingEntry;
             return(true);
         }
         routingKey = routingKey2;
     }
     foundEntry = null;
     return(false);
 }
 public void ProcessRoutingEntry(IRoutingEntry entry)
 {
     if (ServerLocator.IsMailboxServerCacheKey(entry.Key))
     {
         PerfCounters.HttpProxyCacheCountersInstance.BackEndServerOverallCacheHitsRate.Increment();
         PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerOverallCacheHitsRate);
         return;
     }
     if (ServerLocator.IsAnchorMailboxCacheKey(entry.Key))
     {
         PerfCounters.HttpProxyCacheCountersInstance.AnchorMailboxOverallCacheHitsRate.Increment();
         PerfCounters.HttpProxyCacheCountersInstance.OverallCacheEffectivenessRate.Increment();
     }
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        internal IEnumerable <string> GetRoutingUpdates(IEnumerable <IRoutingEntry> routingEntries)
        {
            if (routingEntries == null)
            {
                throw new ArgumentNullException("routingEntries");
            }
            List <string> list = new List <string>();

            foreach (IRoutingEntry routingEntry in routingEntries)
            {
                IRoutingLookup lookupForType = this.lookupFactory.GetLookupForType(routingEntry.Key.RoutingItemType);
                if (lookupForType != null)
                {
                    IRoutingEntry routingEntry2 = lookupForType.GetRoutingEntry(routingEntry.Key, this.diagnostics);
                    if (routingEntry2 != null && this.ShouldSendRoutingEntryUpdate(routingEntry, routingEntry2))
                    {
                        list.Add(RoutingEntryHeaderSerializer.Serialize(routingEntry2));
                    }
                }
            }
            return(list);
        }
Exemplo n.º 9
0
        public static string Serialize(IRoutingEntry routingEntry)
        {
            if (routingEntry == null)
            {
                throw new ArgumentNullException("routingEntry");
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(RoutingEntryHeaderSerializer.SerializableRoutingTypeToString(routingEntry.Key.RoutingItemType));
            stringBuilder.Append(':');
            stringBuilder.Append(Uri.EscapeDataString(routingEntry.Key.Value));
            stringBuilder.Append('=');
            stringBuilder.Append(RoutingEntryHeaderSerializer.SerializableRoutingTypeToString(routingEntry.Destination.RoutingItemType));
            stringBuilder.Append(':');
            stringBuilder.Append(Uri.EscapeDataString(routingEntry.Destination.Value));
            foreach (string value in routingEntry.Destination.Properties)
            {
                stringBuilder.Append('+');
                stringBuilder.Append(value);
            }
            stringBuilder.Append('@');
            stringBuilder.Append(routingEntry.Timestamp);
            return(stringBuilder.ToString());
        }