public static InboundRouteDefinition Create(IEnumerable <string> templates, RouteDestinationType type)
        {
            var route = new InboundRouteDefinition(templates, type);

            route.Validate();
            return(route);
        }
        /// <summary>
        /// Tries to route the message to the destination and appends route properties to message metadata
        /// </summary>
        /// <param name="path"></param>
        /// <param name="message"></param>
        /// <param name="routeType"></param>
        /// <returns></returns>
        public bool TryRouteIncomingMessage(string path, IMessage message, out RouteDestinationType routeType)
        {
            Collection<UriTemplateMatch> matches = this.topicTemplateTable.Match(new Uri(BaseUri, path));

            if (matches.Count == 0)
            {
                routeType = RouteDestinationType.Unknown;
                return false;
            }

            if (matches.Count > 1)
            {
                if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
                {
                    MqttIotHubAdapterEventSource.Log.Verbose("Topic name matches more than one route.", path);
                }
            }

            UriTemplateMatch match = matches[0];
            var route = (InboundRouteDefinition)match.Data;
            routeType = route.Type;
            int variableCount = match.BoundVariables.Count;
            for (int i = 0; i < variableCount; i++)
            {
                // todo: this will unconditionally set property values - is it acceptable to overwrite existing value?
                message.Properties.Add(match.BoundVariables.GetKey(i), match.BoundVariables.Get(i));
            }
            return true;
        }
        public bool TryMapTopicNameToRoute(string topicName, out RouteDestinationType routeType, IDictionary<string, string> contextOutput)
        {
            Collection<UriTemplateMatch> matches = this.topicTemplateTable.Match(new Uri(BaseUri, topicName));

            if (matches.Count == 0)
            {
                routeType = RouteDestinationType.Unknown;
                return false;
            }

            if (matches.Count > 1)
            {
                if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
                {
                    MqttIotHubAdapterEventSource.Log.Verbose("Topic name matches more than one route.", topicName);
                }
            }

            UriTemplateMatch match = matches[0];
            var route = (InboundRouteDefinition)match.Data;
            routeType = route.Type;
            int variableCount = match.BoundVariables.Count;
            for (int i = 0; i < variableCount; i++)
            {
                // todo: this will unconditionally set property values - is it acceptable to overwrite existing value?
                contextOutput[match.BoundVariables.GetKey(i)] = match.BoundVariables.Get(i);
            }
            return true;
        }
Пример #4
0
        public bool TryMapTopicNameToRoute(string topicName, out RouteDestinationType routeType, IDictionary <string, string> contextOutput)
        {
            Collection <UriTemplateMatch> matches = this.topicTemplateTable.Match(new Uri(BaseUri, topicName));

            if (matches.Count == 0)
            {
                routeType = RouteDestinationType.Unknown;
                return(false);
            }

            if (matches.Count > 1)
            {
                if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
                {
                    MqttIotHubAdapterEventSource.Log.Verbose("Topic name matches more than one route.", topicName);
                }
            }

            UriTemplateMatch match = matches[0];
            var route = (InboundRouteDefinition)match.Data;

            routeType = route.Type;
            int variableCount = match.BoundVariables.Count;

            for (int i = 0; i < variableCount; i++)
            {
                // todo: this will unconditionally set property values - is it acceptable to overwrite existing value?
                contextOutput[match.BoundVariables.GetKey(i)] = match.BoundVariables.Get(i);
            }
            return(true);
        }
        /// <summary>
        /// Tries to route the message to the destination and appends route properties to message metadata
        /// </summary>
        /// <param name="path"></param>
        /// <param name="message"></param>
        /// <param name="routeType"></param>
        /// <returns></returns>
        public bool TryRouteIncomingMessage(string path, IMessage message, out RouteDestinationType routeType)
        {
            Collection <UriTemplateMatch> matches = this.topicTemplateTable.Match(new Uri(BaseUri, path));

            if (matches.Count == 0)
            {
                routeType = RouteDestinationType.Unknown;
                return(false);
            }

            if (matches.Count > 1)
            {
                if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
                {
                    MqttIotHubAdapterEventSource.Log.Verbose("Topic name matches more than one route.", path);
                }
            }

            UriTemplateMatch match = matches[0];
            var route = (InboundRouteDefinition)match.Data;

            routeType = route.Type;
            int variableCount = match.BoundVariables.Count;

            for (int i = 0; i < variableCount; i++)
            {
                // todo: this will unconditionally set property values - is it acceptable to overwrite existing value?
                message.Properties.Add(match.BoundVariables.GetKey(i), match.BoundVariables.Get(i));
            }
            return(true);
        }
 InboundRouteDefinition(IEnumerable <string> templates, RouteDestinationType type)
 {
     this.Type      = type;
     this.Templates = templates.ToArray();
 }
 public static InboundRouteDefinition Create(IEnumerable<string> templates, RouteDestinationType type)
 {
     var route = new InboundRouteDefinition(templates, type);
     route.Validate();
     return route;
 }
 InboundRouteDefinition(IEnumerable<string> templates, RouteDestinationType type)
 {
     this.Type = type;
     this.Templates = templates.ToArray();
 }