Exemple #1
0
        public void AffiliationsTest()
        {
            PubSubIQ     iq   = new PubSubIQ(doc, PubSubCommandType.affiliations, NODE);
            Affiliations test = iq.Command as Affiliations;

            Assert.IsNotNull(test);
        }
Exemple #2
0
        /// <summary>
        /// Deletes a single item from the XMPP server.
        /// </summary>
        /// <param name="id">Id of item.</param>
        public void DeleteItem(string id)
        {
            PubSubIQ iq      = createCommand(PubSubCommandType.retract);
            Retract  retract = (Retract)iq.Command;

            retract.AddItem(id);
            BeginIQ(iq, OnDeleteNode, null);
        }
Exemple #3
0
        private PubSubIQ createCommand(PubSubCommandType type)
        {
            PubSubIQ iq = new PubSubIQ(m_stream.Document, type, m_node);

            iq.To   = m_jid;
            iq.Type = IQType.set;

            return(iq);
        }
        public void DownloadDataNode(JID jidto, string strNodeName, string strItem)
        {
            PubSubIQ iq = new PubSubIQ();
             iq.Type = IQType.set.ToString();
             iq.To = null; /// null for personal eventing pub sub
             iq.From = XMPPClient.JID;
             iq.PubSub.Publish = new Publish() { Node = strNodeName, Item = new PubSubItem() { Id = strNodeName } };

             ListSentIQs.Add(iq.ID);
             XMPPClient.SendObject(iq);
        }
Exemple #5
0
        public void PubSubCreateTest()
        {
            PubSubIQ iq = new PubSubIQ(doc, PubSubCommandType.create, NODE);
            Assert.IsFalse(((Create)iq.Command).HasConfigure);

            Create create = (Create)iq.Command;

            create.HasConfigure = true;
            Assert.IsTrue(create.HasConfigure);
            Assert.IsNotNull(create.GetConfiguration());
        }
Exemple #6
0
        public void PubSubCreateTest()
        {
            PubSubIQ iq = new PubSubIQ(doc, PubSubCommandType.create, NODE);

            Assert.IsFalse(((Create)iq.Command).HasConfigure);

            Create create = (Create)iq.Command;

            create.HasConfigure = true;
            Assert.IsTrue(create.HasConfigure);
            Assert.IsNotNull(create.GetConfiguration());
        }
Exemple #7
0
        /// <summary>
        /// Publishes an item to the node.
        /// </summary>
        /// <param name="id">If null, the server will assign an item ID.</param>
        /// <param name="contents">The XML inside the item.  Should be in a new namespace.</param>
        public void PublishItem(string id, XmlElement contents)
        {
            PubSubIQ   iq   = createCommand(PubSubCommandType.publish);
            Publish    pub  = (Publish)iq.Command;
            PubSubItem item = new PubSubItem(m_stream.Document);

            if (id != null)
            {
                item.ID = id;
            }
            item.AddChild(contents);
            pub.AddChild(item);
            BeginIQ(iq, new IqCB(OnPublished), item);
        }
Exemple #8
0
        /// <summary>
        /// Gets the items from the node on the XMPP server.
        /// </summary>
        public void GetItems()
        {
            lock (this)
            {
                if (!NeedsAsking(this[Op.ITEMS]))
                {
                    return;
                }
                this[Op.ITEMS] = STATE.Asking;
            }
            PubSubIQ piq = new PubSubIQ(m_stream.Document, PubSubCommandType.items, m_node);

            piq.To   = m_jid;
            piq.Type = IQType.get;
            BeginIQ(piq, GotItems, null);
        }
Exemple #9
0
        /// <summary>
        /// Sends a subscription request.
        /// Items request will be sent automatically on successful subscribe.
        /// </summary>
        public void Subscribe()
        {
            lock (this)
            {
                if (!NeedsAsking(this[Op.SUBSCRIBE]))
                {
                    return;
                }

                this[Op.SUBSCRIBE] = STATE.Asking;
            }

            PubSubIQ iq = createCommand(PubSubCommandType.subscribe);

            addInfo(iq);
            BeginIQ(iq, GotSubscribed, null);
            // don't parallelize getItems, in case sub fails.
        }
        public bool PublishAvatarData(byte [] bImageData, int nWidth, int nHeight)
        {
            // publish avatar data node
            avatardata data = new avatardata();
            data.ImageData = bImageData;
            //string strAvatarInfo = Utility.GetXMLStringFromObject(data);

            string strHash = XMPPClient.AvatarStorage.WriteAvatar(bImageData);

            PubSubIQ iq = new PubSubIQ();
            iq.Type = IQType.set.ToString();
            iq.To = null; /// null for personal eventing pub sub
            iq.From = XMPPClient.JID;
            iq.PubSub.Publish = new Publish() { Node = "urn:xmpp:avatar:data", Item = new PubSubItem() };
            iq.PubSub.Publish.Item.SetNodeFromObject(data);

            ListSentIQs.Add(iq.ID);
            XMPPClient.SendObject(iq);

             // publish avatar meta data node
            avatarmetadata metadata = new avatarmetadata();
            metadata.ImageInfo.ByteLength = bImageData.Length;
            metadata.ImageInfo.Width = nWidth;
            metadata.ImageInfo.Height = nHeight;
            //string strAvatarMetaData = Utility.GetXMLStringFromObject(metadata);

            PubSubIQ iqmeta = new PubSubIQ();
            iqmeta.Type = IQType.set.ToString();
            iqmeta.To = null; /// null for personal eventing pub sub
            iqmeta.From = XMPPClient.JID;
            iqmeta.PubSub.Publish = new Publish() { Node = "urn:xmpp:avatar:metadata", Item = new PubSubItem() {Id = strHash } };
            iqmeta.PubSub.Publish.Item.SetNodeFromObject(metadata);

            ListSentIQs.Add(iqmeta.ID);
            XMPPClient.SendObject(iqmeta);

            return true;
        }
Exemple #11
0
 public void AffiliationsTest()
 {
     PubSubIQ iq = new PubSubIQ(doc, PubSubCommandType.affiliations, NODE);
     Affiliations test = iq.Command as Affiliations;
     Assert.IsNotNull(test);
 }
Exemple #12
0
 /// <summary>
 /// Gets the items from the node on the XMPP server.
 /// </summary>
 public void GetItems()
 {
     lock (this)
     {
         if (!NeedsAsking(this[Op.ITEMS]))
             return;
         this[Op.ITEMS] = STATE.Asking;
     }
     PubSubIQ piq = new PubSubIQ(m_stream.Document, PubSubCommandType.items, m_node);
     piq.To = m_jid;
     piq.Type = IQType.get;
     BeginIQ(piq, GotItems, null);
 }
Exemple #13
0
 private void addInfo(PubSubIQ iq)
 {
     Subscribe sub = (Subscribe) iq.Command;
     sub.JID = m_stream.JID;
 }
Exemple #14
0
        private PubSubIQ createCommand(PubSubCommandType type)
        {
            PubSubIQ iq = new PubSubIQ(m_stream.Document, type, m_node);
            iq.To = m_jid;
            iq.Type = IQType.set;

            return iq;
        }
        public bool PublishTuneInfo(TuneItem item)
        {
            //string strTuneXML = Utility.GetXMLStringFromObject(item);

            PubSubIQ iq = new PubSubIQ();
            iq.Type = IQType.set.ToString();
            iq.To = null; /// null for personal eventing pub sub
            iq.From = XMPPClient.JID;
            iq.PubSub.Publish = new Publish() { Node = "http://jabber.org/protocol/tune", Item = new PubSubItem() };
            iq.PubSub.Publish.Item.SetNodeFromObject(item);

            ListSentIQs.Add(iq.ID);

            XMPPClient.SendObject(iq);
            return true;
        }
Exemple #16
0
        private void addInfo(PubSubIQ iq)
        {
            Subscribe sub = (Subscribe)iq.Command;

            sub.JID = m_stream.JID;
        }
        public bool PublishGeoInfo(geoloc item)
        {
            string strGeoInfo = Utility.GetXMLStringFromObject(item);

            PubSubIQ iq = new PubSubIQ();
            iq.Type = IQType.set.ToString();
            iq.To = null; /// null for personal eventing pub sub
            iq.From = XMPPClient.JID;
            iq.PubSub.Publish = new Publish() { Node = "http://jabber.org/protocol/geoloc", Item = new PubSubItem()};
            iq.PubSub.Publish.Item.SetNodeFromObject(item);
            iq.PubSub.Publish.Item.Id = "lastlocation";

            ListSentIQs.Add(iq.ID);
            try
            {
                XMPPClient.SendObject(iq);
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        public static PubSubItem[] GetNodeItems(XMPPClient connection, string strNode, out string strNodeJID)
        {
            strNodeJID = "";
            List<PubSubItem> returnnodes = new List<PubSubItem>();
            PubSubIQ IQRequest = new PubSubIQ();
            IQRequest.Type = IQType.get.ToString();
            IQRequest.From = connection.JID;
            IQRequest.To = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.PubSub = new PubSub();
            IQRequest.PubSub.Items = new PubSubItems();
            IQRequest.PubSub.Items.Node = strNode;
            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 30000, SerializationMethod.XMLSerializeObject);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return returnnodes.ToArray();
            }

            if (IQResponse is PubSubIQ)
            {
                PubSubIQ psiq = IQResponse as PubSubIQ;
                if ((psiq.PubSub != null) && (psiq.PubSub.Items != null))
                {
                    strNodeJID = psiq.PubSub.Items.Node;

                    if (psiq.PubSub.Items.Items != null)
                    {
                        foreach (PubSubItem item in psiq.PubSub.Items.Items)
                        {
                            returnnodes.Add(item);
                        }
                    }
                }
            }

            return returnnodes.ToArray();
        }
Exemple #19
0
        /// <summary>
        /// Unsubscribes from the node.
        /// </summary>
        public void Unsubscribe()
        {
            PubSubIQ iq = createCommand(PubSubCommandType.unsubscribe);

            BeginIQ(iq, GotUnsubsribed, null);
        }
        public static string[] GetNodeItemStrings(XMPPClient connection, string strNode, out string strNodeJID)
        {
            strNodeJID = "";
            List<string> returnnodes = new List<string>();
            PubSubIQ IQRequest = new PubSubIQ();
            IQRequest.Type = IQType.get.ToString();
            IQRequest.From = connection.JID;
            IQRequest.To = string.Format("pubsub.{0}", connection.Domain);
            IQRequest.PubSub = new PubSub();
            IQRequest.PubSub.Items = new PubSubItems();
            IQRequest.PubSub.Items.Node = strNode;

            //IQRequest.InnerXML = GetNodeItemsXML.Replace("#NODE#", strNode);;

            IQ IQResponse = connection.SendRecieveIQ(IQRequest, 30000, SerializationMethod.XMLSerializeObject);

            if (IQResponse.Type == IQType.error.ToString())
            {
                return returnnodes.ToArray();
            }

            if (IQResponse is PubSubIQ)
            {
                PubSubIQ psiq = IQResponse as PubSubIQ;
                if ((psiq.PubSub != null) && (psiq.PubSub.Items != null) )
                {
                    strNodeJID = psiq.PubSub.Items.Node;

                    if (psiq.PubSub.Items.Items != null)
                    {
                        foreach (PubSubItem item in psiq.PubSub.Items.Items)
                        {
                            returnnodes.Add(item.InnerItemXML.Value);
                        }
                    }
                }
            }

            //var nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/pubsub}items");
            //foreach (XElement elem in nodes)
            //{
            //    strNodeJID = elem.Attribute("node").Value;
            //}

            //nodes = IQResponse.InitalXMLElement.Descendants("{http://jabber.org/protocol/pubsub}item");
            //foreach (XElement elem in nodes)
            //{
            //    returnnodes.Add(elem.Value);
            //}
            return returnnodes.ToArray();
        }