public static IEnumerable <IRecordedMessage> InTopic(this IEnumerable <IRecordedMessage> messages, string topicNamePattern)
 {
     if (RosNameRegex.IsGlobalPattern(topicNamePattern))
     {
         return(InGlobalTopic(messages, topicNamePattern));
     }
     else
     {
         return(InRelativeTopic(messages, topicNamePattern));
     }
 }
        public static IEnumerable <IGrouping <string, IRecordedMessage <TType> > > GroupByNamespace <TType>(this IEnumerable <IRecordedMessage <TType> > messages, string namespacePattern)
        {
            // Do not use NamespacePattern here because we need an exact match on the namespace
            // and not on a topic in the namespace.
            var regex = RosNameRegex.Create(namespacePattern);

            var filteredNamespaces = messages
                                     .GroupByNamespace()
                                     .Where(g => regex.IsMatch(g.Key));

            return(filteredNamespaces);
        }
示例#3
0
        private void InitializeRegex()
        {
            var namespacePattern = Pattern;

            if (!namespacePattern.EndsWith(RosNameRegex.AnyPlaceholder))
            {
                if (!namespacePattern.EndsWith("/"))
                {
                    namespacePattern += "/";
                }

                namespacePattern += RosNameRegex.AnyPlaceholder;
            }

            _regex = RosNameRegex.Create(namespacePattern);
        }
        public static bool IsInTopic(this IRecordedMessage message, string topicNamePattern)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (RosNameRegex.IsGlobalPattern(topicNamePattern))
            {
                return(IsInGlobalTopic(message, topicNamePattern));
            }
            else
            {
                return(IsInRelativeTopic(message, topicNamePattern));
            }
        }
        private static bool IsInRelativeTopic(this IRecordedMessage message, string relativeTopicNamePattern,
                                              RosNameRegexCache regexCache = null)
        {
            var scopedMessage = message as INamespaceScopedTopicMessage <IRecordedMessage>;

            if (scopedMessage == null)
            {
                throw new InvalidRosNamePatternException(
                          "Relative topic name patterns are only supported if messages were filtered by namespace before.");
            }

            var globalName = scopedMessage.NamespacePattern + "/" + relativeTopicNamePattern;
            var regex      = regexCache != null
                ? regexCache.GetOrCreate(globalName)
                : RosNameRegex.Create(globalName);

            return(regex.IsMatch(message.Topic));
        }
        private static IEnumerable <IRecordedMessage> InGlobalTopic(IEnumerable <IRecordedMessage> messages, string globalTopicPattern)
        {
            var regex = RosNameRegex.Create(globalTopicPattern);

            return(messages.Where(m => regex.IsMatch(m.Topic)));
        }
        private static bool IsInGlobalTopic(this IRecordedMessage message, string globalTopicNamePattern)
        {
            var regex = RosNameRegex.Create(globalTopicNamePattern);

            return(regex.IsMatch(message.Topic));
        }