Esempio n. 1
0
 public IEnumerable <IParticipant <TRequest, TResponse> > GetParticipants <TRequest, TResponse>(string topic)
 {
     return(_channels.Get(typeof(TRequest).FullName, typeof(TResponse).FullName, topic.Split('.'))
            .OfType <Channel <TRequest, TResponse> >()
            .SelectMany(c => c.GetAll())
            .ToArray());
 }
        public IListener <TRequest, TResponse> GetListener <TRequest, TResponse>(string topic)
        {
            var allListeners = _listeners.Get(typeof(TRequest).FullName, typeof(TResponse).FullName, topic.Split('.'))
                               .OfType <IListener <TRequest, TResponse> >()
                               .ToArray();
            var toRemove = allListeners.Where(l => l.ShouldStopListening).ToArray();

            foreach (var removeListener in toRemove)
            {
                RemoveListener <TRequest, TResponse>(topic, removeListener.Id);
            }
            return(allListeners.FirstOrDefault(l => !l.ShouldStopListening));
        }
        public void InsertGet_Test()
        {
            var target = new StringTrie <int>();

            target.GetOrInsert("a", new string[0], () => 1);
            target.GetOrInsert("a", new[] { "b", }, () => 2);
            target.GetOrInsert("a", new[] { "b", "c" }, () => 3);
            target.GetOrInsert("a", new[] { "b", "c" }, () => 4);
            target.GetOrInsert("a", new[] { "b", "d" }, () => 5);

            target.Get("a", new string[] { }).Should().OnlyHaveUniqueItems().And.BeEquivalentTo(1);
            target.Get("a", new[] { "b" }).Should().OnlyHaveUniqueItems().And.BeEquivalentTo(2);
            target.Get("a", new[] { "b", "c" }).Should().OnlyHaveUniqueItems().And.BeEquivalentTo(3);
            target.Get("a", new[] { "b", "d" }).Should().OnlyHaveUniqueItems().And.BeEquivalentTo(5);
        }
 private IEnumerable <ISubscription <TPayload> > GetTopicSubscriptions <TPayload>(string topic)
 {
     return(_topicChannels.Get(typeof(TPayload).FullName, topic.Split('.'))
            .OfType <Channel <TPayload> >()
            .SelectMany(c => c.GetAllSubscriptions())
            .ToArray());
 }
        public void InsertGet_Wildcards_SecondAndThird()
        {
            var target = new StringTrie <int>();

            target.GetOrInsert("a", new[] { "a", "c" }, () => 1);
            target.GetOrInsert("a", new[] { "a", "d" }, () => 2);
            target.GetOrInsert("a", new[] { "b", "c" }, () => 3);
            target.GetOrInsert("a", new[] { "b", "d" }, () => 4);

            target.Get("a", new[] { "*", "*" }).Should().OnlyHaveUniqueItems().And.BeEquivalentTo(1, 2, 3, 4);
        }