Example #1
0
        internal static string OrganizationNameForLogging(IRoutingKey key)
        {
            RoutingItemType routingItemType = key.RoutingItemType;

            if (routingItemType != RoutingItemType.ArchiveSmtp)
            {
                switch (routingItemType)
                {
                case RoutingItemType.MailboxGuid:
                {
                    MailboxGuidRoutingKey mailboxGuidRoutingKey = key as MailboxGuidRoutingKey;
                    return(mailboxGuidRoutingKey.TenantDomain);
                }

                case RoutingItemType.Smtp:
                {
                    SmtpRoutingKey smtpRoutingKey = key as SmtpRoutingKey;
                    return(smtpRoutingKey.SmtpAddress.Domain);
                }

                case RoutingItemType.LiveIdMemberName:
                {
                    LiveIdMemberNameRoutingKey liveIdMemberNameRoutingKey = key as LiveIdMemberNameRoutingKey;
                    return(liveIdMemberNameRoutingKey.OrganizationDomain);
                }
                }
                return(string.Empty);
            }
            ArchiveSmtpRoutingKey archiveSmtpRoutingKey = key as ArchiveSmtpRoutingKey;

            return(archiveSmtpRoutingKey.SmtpAddress.Domain);
        }
 internal ServerLocatorReturn(string serverFqdn, int?serverVersion, IRoutingKey successKey, IList <IRoutingEntry> routingEntries)
 {
     this.ServerFqdn     = serverFqdn;
     this.ServerVersion  = serverVersion;
     this.SuccessKey     = successKey;
     this.RoutingEntries = routingEntries;
 }
Example #3
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            List <IRoutingKey> list = new List <IRoutingKey>();

            if (!source.Headers.IsNullOrEmpty())
            {
                IRoutingKey routingKey = RoutingHintAddressFinder.FindByTargetServer(source.Headers[WellKnownHeader.XTargetServer], diagnostics);
                if (routingKey != null)
                {
                    list.Add(routingKey);
                }
                else
                {
                    IRoutingKey[] collection = RoutingHintAddressFinder.FindByAnchorMailbox(source.Headers[WellKnownHeader.AnchorMailbox], diagnostics);
                    if (!collection.IsNullOrEmpty())
                    {
                        list.AddRange(collection);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            return(list.ToArray());
        }
        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 #5
0
 public SuccessfulMailboxRoutingEntry(IRoutingKey key, DatabaseGuidRoutingDestination destination, long timestamp) : base(key, timestamp)
 {
     if (destination == null)
     {
         throw new ArgumentNullException("destination");
     }
     this.destination = destination;
 }
Example #6
0
 public FailedMailboxRoutingEntry(IRoutingKey key, ErrorRoutingDestination destination, long timestamp) : base(key, timestamp)
 {
     if (destination == null)
     {
         throw new ArgumentNullException("destination");
     }
     this.destination = destination;
 }
 protected MailboxRoutingEntry(IRoutingKey key, long timestamp)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     this.key       = key;
     this.timestamp = timestamp;
 }
        public override IRoutingEntry GetRoutingEntry()
        {
            IRoutingKey routingKey = this.GetRoutingKey();
            DatabaseGuidRoutingDestination databaseGuidRoutingDestination = this.GetRoutingDestination() as DatabaseGuidRoutingDestination;

            if (routingKey != null && databaseGuidRoutingDestination != null)
            {
                return(new SuccessfulMailboxRoutingEntry(routingKey, databaseGuidRoutingDestination, 0L));
            }
            return(base.GetRoutingEntry());
        }
Example #9
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 ProcessRoutingKey(IRoutingKey key)
 {
     if (ServerLocator.IsMailboxServerCacheKey(key))
     {
         PerfCounters.HttpProxyCacheCountersInstance.BackEndServerOverallCacheHitsRateBase.Increment();
         PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerOverallCacheHitsRate);
     }
     if (ServerLocator.IsAnchorMailboxCacheKey(key))
     {
         PerfCounters.HttpProxyCacheCountersInstance.OverallCacheEffectivenessRateBase.Increment();
         PerfCounters.HttpProxyCacheCountersInstance.AnchorMailboxOverallCacheHitsRateBase.Increment();
     }
 }
Example #11
0
 internal static bool IsAnchorMailboxCacheKey(IRoutingKey key)
 {
     switch (key.RoutingItemType)
     {
     case RoutingItemType.ArchiveSmtp:
     case RoutingItemType.MailboxGuid:
     case RoutingItemType.Smtp:
     case RoutingItemType.ExternalDirectoryObjectId:
     case RoutingItemType.LiveIdMemberName:
         return(true);
     }
     return(false);
 }
        string ISharedCache.GetSharedCacheKeyFromRoutingKey(IRoutingKey key)
        {
            string text = string.Empty;

            switch (key.RoutingItemType)
            {
            case RoutingItemType.ArchiveSmtp:
            {
                ArchiveSmtpRoutingKey archiveSmtpRoutingKey = key as ArchiveSmtpRoutingKey;
                text  = SharedCacheClientWrapper.MakeCacheKey(SharedCacheClientWrapper.AnchorSource.Smtp, archiveSmtpRoutingKey.SmtpAddress);
                text += "_Archive";
                break;
            }

            case RoutingItemType.DatabaseGuid:
            {
                DatabaseGuidRoutingKey databaseGuidRoutingKey = key as DatabaseGuidRoutingKey;
                text = SharedCacheClientWrapper.MakeCacheKey(SharedCacheClientWrapper.AnchorSource.DatabaseGuid, databaseGuidRoutingKey.DatabaseGuid);
                break;
            }

            case RoutingItemType.MailboxGuid:
            {
                MailboxGuidRoutingKey mailboxGuidRoutingKey = key as MailboxGuidRoutingKey;
                text = SharedCacheClientWrapper.MakeCacheKey(SharedCacheClientWrapper.AnchorSource.MailboxGuid, mailboxGuidRoutingKey.MailboxGuid);
                break;
            }

            case RoutingItemType.Smtp:
            {
                SmtpRoutingKey smtpRoutingKey = key as SmtpRoutingKey;
                text = SharedCacheClientWrapper.MakeCacheKey(SharedCacheClientWrapper.AnchorSource.Smtp, smtpRoutingKey.SmtpAddress);
                break;
            }

            case RoutingItemType.ExternalDirectoryObjectId:
            {
                ExternalDirectoryObjectIdRoutingKey externalDirectoryObjectIdRoutingKey = key as ExternalDirectoryObjectIdRoutingKey;
                text = SharedCacheClientWrapper.MakeCacheKey(SharedCacheClientWrapper.AnchorSource.ExternalDirectoryObjectId, externalDirectoryObjectIdRoutingKey.UserGuid);
                break;
            }

            case RoutingItemType.LiveIdMemberName:
            {
                LiveIdMemberNameRoutingKey liveIdMemberNameRoutingKey = key as LiveIdMemberNameRoutingKey;
                text = SharedCacheClientWrapper.MakeCacheKey(SharedCacheClientWrapper.AnchorSource.LiveIdMemberName, liveIdMemberNameRoutingKey.LiveIdMemberName);
                break;
            }
            }
            return(text);
        }
Example #13
0
 public GenericRoutingEntry(IRoutingKey key, IRoutingDestination destination, long timestamp)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     if (destination == null)
     {
         throw new ArgumentNullException("destination");
     }
     this.key         = key;
     this.destination = destination;
     this.timestamp   = timestamp;
 }
Example #14
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);
        }
Example #15
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);
        }
Example #16
0
        public static IRoutingEntry Deserialize(string headerValue)
        {
            if (headerValue == null)
            {
                throw new ArgumentNullException("headerValue");
            }
            RoutingEntryHeaderSerializer.RoutingEntryParts routingEntryParts;
            if (!RoutingEntryHeaderSerializer.TrySplitEntry(headerValue, out routingEntryParts))
            {
                throw new ArgumentException("Value is incorrectly formatted", "headerValue");
            }
            IRoutingKey         key         = RoutingEntryHeaderSerializer.DeserializeRoutingKey(routingEntryParts.KeyType, routingEntryParts.KeyValue);
            IRoutingDestination destination = RoutingEntryHeaderSerializer.DeserializeRoutingDestination(routingEntryParts.DestinationType, routingEntryParts.DestinationValue);

            return(RoutingEntryHeaderSerializer.AssembleRoutingEntry(key, destination, routingEntryParts.Timestamp));
        }
Example #17
0
        // Token: 0x0600014B RID: 331 RVA: 0x00007380 File Offset: 0x00005580
        protected override IRoutingKey GetRoutingKey()
        {
            IRoutingKey result = null;
            NetID       netID  = null;

            if (NetID.TryParse(this.Puid, ref netID))
            {
                if (!string.IsNullOrEmpty(this.Domain))
                {
                    result = new PuidAndTenantDomainRoutingKey(netID, this.Domain);
                }
                else
                {
                    result = new PuidAndTenantGuidRoutingKey(netID, this.TenantGuid);
                }
            }
            return(result);
        }
Example #18
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 #19
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            List <IRoutingKey> list       = new List <IRoutingKey>();
            IRoutingKey        routingKey = MapiAddressFinder.FindByMailboxId(source.QueryString["mailboxId"], diagnostics);

            if (routingKey != null)
            {
                list.Add(routingKey);
            }
            routingKey = MapiAddressFinder.FindBySmtpAddress(source.QueryString["smtpAddress"], diagnostics);
            if (routingKey != null)
            {
                list.Add(routingKey);
            }
            if (list.Count == 0)
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            return(list.ToArray());
        }
Example #20
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 #21
0
 private static IRoutingEntry AssembleRoutingEntry(IRoutingKey key, IRoutingDestination destination, long timestamp)
 {
     if (key is ServerRoutingKey)
     {
         if (destination is ServerRoutingDestination)
         {
             return(new SuccessfulServerRoutingEntry((ServerRoutingKey)key, (ServerRoutingDestination)destination, timestamp));
         }
         if (destination is ErrorRoutingDestination)
         {
             return(new FailedServerRoutingEntry((ServerRoutingKey)key, (ErrorRoutingDestination)destination, timestamp));
         }
     }
     if (key is DatabaseGuidRoutingKey)
     {
         if (destination is ServerRoutingDestination)
         {
             return(new SuccessfulDatabaseGuidRoutingEntry((DatabaseGuidRoutingKey)key, (ServerRoutingDestination)destination, timestamp));
         }
         if (destination is ErrorRoutingDestination)
         {
             return(new FailedDatabaseGuidRoutingEntry((DatabaseGuidRoutingKey)key, (ErrorRoutingDestination)destination, timestamp));
         }
     }
     else if (key is ArchiveSmtpRoutingKey || key is MailboxGuidRoutingKey || key is SmtpRoutingKey || key is ExternalDirectoryObjectIdRoutingKey || key is LiveIdMemberNameRoutingKey)
     {
         if (destination is DatabaseGuidRoutingDestination)
         {
             return(new SuccessfulMailboxRoutingEntry(key, (DatabaseGuidRoutingDestination)destination, timestamp));
         }
         if (destination is ErrorRoutingDestination)
         {
             return(new FailedMailboxRoutingEntry(key, (ErrorRoutingDestination)destination, timestamp));
         }
     }
     return(new GenericRoutingEntry(key, destination, timestamp));
 }
Example #22
0
 internal static bool IsMailboxServerCacheKey(IRoutingKey key)
 {
     return(key.RoutingItemType == RoutingItemType.DatabaseGuid);
 }
Example #23
0
 public void AddRoutingkey(IRoutingKey routingKey, string routingHint)
 {
     this.routingKeyLogs.Add(new Tuple <IRoutingKey, string>(routingKey, routingHint));
 }
Example #24
0
        private FailedMailboxRoutingEntry CreateFailedEntry(IRoutingKey smtpRoutingKey, string message)
        {
            ErrorRoutingDestination destination = new ErrorRoutingDestination(message);

            return(new FailedMailboxRoutingEntry(smtpRoutingKey, destination, DateTime.UtcNow.ToFileTimeUtc()));
        }