Exemplo n.º 1
0
 public void FireRemove(PubSubNode node, PubSubItem item)
 {
     if (OnRemove != null)
     {
         OnRemove(node, item);
     }
 }
Exemplo n.º 2
0
 public void FireAdd(PubSubNode node, PubSubItem item)
 {
     if (OnAdd != null)
     {
         OnAdd(node, item);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Subscribes to a publish-subscribe node.
        /// </summary>
        /// <param name="service">Component that handles PubSub requests.</param>
        /// <param name="node">The node on the component that the client wants to interact with.</param>
        /// <param name="maxItems">Maximum number of items to retain.  First one to call Subscribe gets their value, for now.</param>
        /// <returns>
        /// The existing node will be returned if there is already a subscription.
        /// If the node does not exist, the PubSubNode object will be returned
        /// in a subscribing state.
        /// </returns>
        public PubSubNode GetNode(JID service, string node, int maxItems)
        {
            JIDNode    jn = new JIDNode(service, node);
            PubSubNode n  = null;

            if (m_nodes.TryGetValue(jn, out n))
            {
                return(n);
            }
            n           = new PubSubNode(Stream, service, node, maxItems);
            m_nodes[jn] = n;
            n.OnError  += OnError;
            return(n);
        }
Exemplo n.º 4
0
        ///<summary>
        /// Removes the publish-subscribe node from the manager and sends a delete
        /// node to the XMPP server.
        ///</summary>
        /// <param name="service">
        /// Component that handles PubSub requests.
        /// </param>
        /// <param name="node">
        /// The node on the component that the client wants to interact with.
        /// </param>
        /// <param name="errorHandler">
        /// Callback for any errors with the publish-subscribe node deletion.
        /// </param>
        public void RemoveNode(JID service, string node, bedrock.ExceptionHandler errorHandler)
        {
            JIDNode jn = new JIDNode(service, node);

            PubSubNode psNode = null;

            if (m_nodes.TryGetValue(jn, out psNode))
            {
                m_nodes.Remove(jn);
            }
            else
            {
                psNode = new PubSubNode(Stream, service, node, 10);
            }

            psNode.OnError += errorHandler;

            psNode.Delete();
        }
Exemplo n.º 5
0
        private void m_stream_OnProtocol(object sender, XmlElement rp)
        {
            Message msg = rp as Message;

            if (msg == null)
            {
                return;
            }
            PubSubEvent evt = msg["event", URI.PUBSUB_EVENT] as PubSubEvent;

            if (evt == null)
            {
                return;
            }

            EventItems items = evt.GetChildElement <EventItems>();

            if (items == null)
            {
                return;
            }

            string     node = items.Node;
            JID        from = msg.From.BareJID;
            JIDNode    jn   = new JIDNode(from, node);
            PubSubNode psn  = null;

            if (!m_nodes.TryGetValue(jn, out psn))
            {
                CBHolder holder = null;
                if (!m_callbacks.TryGetValue(node, out holder))
                {
                    Console.WriteLine("WARNING: notification received for unknown pubsub node");
                    return;
                }
                psn               = new PubSubNode(m_stream, from, node, holder.Max);
                psn.OnItemAdd    += holder.FireAdd;
                psn.OnItemRemove += holder.FireRemove;
                m_nodes[jn]       = psn;
            }
            psn.FireItems(items);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates an item list, which will have at most some number of items.
 /// </summary>
 /// <param name="node">The node to which this item list applies.</param>
 /// <param name="maxItems">Maximum size of the list.  Delete notifications will be sent if this size is exceeded.</param>
 public ItemList(PubSubNode node, int maxItems) : base(maxItems)
 {
     m_node = node;
 }