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);
        }
Exemplo n.º 2
0
        private void InitializeRegex()
        {
            var namespacePattern = Pattern;

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

                namespacePattern += RosNameRegex.AnyPlaceholder;
            }

            _regex = RosNameRegex.Create(namespacePattern);
        }
        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));
        }