コード例 #1
0
        /// <summary>
        /// Determines if both the jid and the node are equal.
        /// </summary>
        /// <param name="obj">JIDNode to compare to.</param>
        /// <returns>True if both the jid and the node are equal.</returns>
        public override bool Equals(object obj)
        {
            JIDNode other = obj as JIDNode;

            if (other == null)
            {
                return(false);
            }

            return((m_jid == other.m_jid) && (m_node == other.m_node));
        }
コード例 #2
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);
        }
コード例 #3
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();
        }
コード例 #4
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(String.Format("WARNING: notification received for unknown pubsub node: {0}", 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);
        }