Ejemplo n.º 1
0
        public void add_event(PubSub_Event _event)
        {
            if (max_events != 0 && events.Count >= max_events)
            {
                lock (events)
                {
                    if (max_events == 1)
                        events.Clear();

                    else
                        events.OrderBy(e => e.timestamp).ToList().RemoveAt(0);
                }
            }

            lock (events)
                events.Add(_event);
        }
Ejemplo n.º 2
0
        // publish a message to a channel
        public void publish_channel(publish p)
        {
            if (protocol.pubsub != null)
            {
                // attempt to pull the channel from pubsub
                PubSub_Channel c = protocol.pubsub.GetChannel(p.channel_name_or_uri);

                // make sure channel exists
                if (c != null)
                {
                    // create the pubsub event
                    PubSub_Event e = new PubSub_Event(p.message);

                    // add the event to the channel
                    c.add_event(e);

                    // generate event object
                    _event ev = new _event(p.channel_name_or_uri, e);

                    // setup subscribers list
                    List<WS3V_Client> subscribers;

                    if (p.echo)
                        // blast the event to all subscribed
                        subscribers = protocol.WS3V_Clients.Select(g => g.Value).Where(s => s.subscriptions != null && s.subscriptions.Any(y => y.channel_name_or_uri == p.channel_name_or_uri)).ToList();

                    else
                        // blast the event to all subscribed except current client
                        subscribers = protocol.WS3V_Clients.Select(g => g.Value).Where(s => s.protocol.clientID != protocol.clientID && s.subscriptions != null && s.subscriptions.Any(y => y.channel_name_or_uri == p.channel_name_or_uri)).ToList();

                    // serialize event
                    string msg = ev.ToString();

                    // loop over clients and send message blast
                    for (int i = 0; i < subscribers.Count; i++)
                        subscribers[i].SocketSend(msg);
                }

            }
        }
Ejemplo n.º 3
0
 public _event(string channel_name_or_uri, PubSub_Event p)
 {
     this.channel_name_or_uri = channel_name_or_uri;
     this.p = p;
 }
Ejemplo n.º 4
0
        public void acknowledge()
        {
            // documentation example 1
            PubSub_Listing core = new PubSub_Listing();
            core.CreateChannel("/rss/news/latest");

            acknowledge a = new acknowledge(core.channels[0], false);
            string expected = "[11,\"\\/rss\\/news\\/latest\"]";
            string result = a.ToString();
            Assert.AreEqual(expected, result);

            // documentation example 2
            a.allow_publishing = true;
            expected = "[11,\"\\/rss\\/news\\/latest\",true]";
            result = a.ToString();
            Assert.AreEqual(expected, result);

            a.allow_publishing = false;
            a.channel.Set_Max(99);
            for (int i = 0; i < 120; i++)
            {
                a.channel.add_event("test");
            }
            PubSub_Event e = new PubSub_Event("test old", 41267360);
            a.channel.add_event(e);
            expected = "[11,\"\\/rss\\/news\\/latest\",false,99,41267360]";
        }