Example #1
0
 /// <summary>
 /// Notifies the client that an item has been add to this PubSubNode.
 /// </summary>
 /// <param name="item">Item that was added.</param>
 public void ItemAdded(PubSubItem item)
 {
     if (OnItemAdd != null)
     {
         OnItemAdd(this, item);
     }
 }
Example #2
0
 /// <summary>
 /// Gets or sets the contents of the specified item.
 /// </summary>
 /// <param name="id">Id of the PubSubItem.</param>
 /// <returns>XmlElement representing the contents of the PubSubItem.</returns>
 public XmlElement this[string id]
 {
     get
     {
         object index = m_index[id];
         if (index == null)
         {
             return(null);
         }
         PubSubItem item = this[(int)index] as PubSubItem;
         if (item == null)
         {
             return(null);
         }
         return(item.Contents);
     }
     set
     {
         // wrap an item around the contents.
         PubSubItem item = new PubSubItem(value.OwnerDocument);
         item.Contents = value;
         item.ID       = id;
         Add(item);
     }
 }
Example #3
0
 /// <summary>
 /// Notifies the client that an item has been removed from this PubSubNode.
 /// </summary>
 /// <param name="item">Item that was removed.</param>
 public void ItemRemoved(PubSubItem item)
 {
     if (OnItemRemove != null)
     {
         OnItemRemove(this, item);
     }
 }
Example #4
0
 public void FireAdd(PubSubNode node, PubSubItem item)
 {
     if (OnAdd != null)
     {
         OnAdd(node, item);
     }
 }
Example #5
0
 public void FireRemove(PubSubNode node, PubSubItem item)
 {
     if (OnRemove != null)
     {
         OnRemove(node, item);
     }
 }
Example #6
0
        private void TrackChanged(object sender, EventArgs args)
        {
            NowPlayingService nowPlaying = ServiceManager.Get <NowPlayingService>();

            PubSubItem itemElement = new PubSubItem(m_Account.Client.Document);

            itemElement.SetAttribute("id", "current");

            Tune tune = new Tune(m_Account.Client.Document);

            itemElement.AppendChild(tune);

            if (nowPlaying.IsPlaying)
            {
                tune.Artist = nowPlaying.CurrentTrackArtist;
                tune.Length = nowPlaying.CurrentTrackLength;
                tune.Rating = nowPlaying.CurrentTrackRating;
                tune.Source = nowPlaying.CurrentTrackSource;
                tune.Title  = nowPlaying.CurrentTrackTitle;
                tune.Track  = nowPlaying.CurrentTrackNumber;
                tune.Uri    = nowPlaying.CurrentTrackUri;
            }

            m_Account.GetFeature <PersonalEventing>().Publish(Namespace.Tune, itemElement);
        }
Example #7
0
        /// <summary>
        ///   Publishes user tune information
        /// </summary>
        public IXmppSession PublishTune(XmppUserTuneEvent tuneEvent)
        {
            var iq      = new IQ();
            var pubsub  = new PubSub();
            var publish = new PubSubPublish();
            var item    = new PubSubItem();
            var tune    = new Tune();

            iq.Items.Add(pubsub);
            pubsub.Items.Add(publish);
            publish.Items.Add(item);

            iq.From      = UserId.ToString();
            iq.ID        = XmppIdentifierGenerator.Generate();
            iq.Type      = IQType.Set;
            publish.Node = XmppFeatures.UserMood;
            item.Item    = tune;
            tune.Artist  = tuneEvent.Artist;
            tune.Length  = tuneEvent.Length;
            tune.Rating  = tuneEvent.Rating;
            tune.Source  = tuneEvent.Source;
            tune.Title   = tuneEvent.Title;
            tune.Track   = tuneEvent.Track;
            tune.Uri     = tuneEvent.Uri;

            Send(iq);

            return(this);
        }
Example #8
0
        /// <summary>
        /// Adds to the end of the list, replacing any item with the same ID,
        /// or bumping the oldest item if the list is full.
        /// </summary>
        /// <param name="value">PubSubItem to add to the list.</param>
        /// <returns>Index where the PubSubItem was inserted.</returns>
        public override int Add(object value)
        {
            PubSubItem item = value as PubSubItem;

            if (item == null)
            {
                throw new ArgumentException("Must be an XmlElement", "value");
            }
            string id = item.ID;
            int    i;

            if (id == null)
            {
                if (Count == Capacity)
                {
                    RemoveAt(0);
                }
                i = base.Add(value);
                m_node.ItemAdded(item);
                return(i);
            }

            // RemoveId(id);
            if (!m_index.Contains(id) && (Count == Capacity))
            {
                RemoveAt(0);
            }

            i           = base.Add(value);
            m_index[id] = i;
            m_node.ItemAdded(item);
            return(i);
        }
Example #9
0
        void ReceivedMood(JID from, string node, PubSubItem item)
        {
            Mood mood = (Mood)item["mood"];

            m_FriendMoods[from.Bare] = mood;

            // Only show in feed if we know this is a recent event.
            if (mood["timestamp"] != null && DateTime.Now.Subtract(DateTime.Parse(mood["timestamp"].InnerText)).TotalSeconds <= 60)
            {
                m_Account.PostActivityFeedItem(from.ToString(), "mood", mood.MoodName, mood.Text);
            }
        }
Example #10
0
        private void ReceivedMicroblog(JID from, string node, PubSubItem item)
        {
            XmlNode entry = item["entry"];

            if (entry["published"] != null && !String.IsNullOrEmpty(entry["published"].InnerText))
            {
                var publishedDate = DateTime.Parse(entry["published"].InnerText);
                if ((DateTime.Now - publishedDate).TotalSeconds <= 60)
                {
                    string title = entry["title"].InnerText;
                    m_Account.PostActivityFeedItem(from, "shout", null, title);
                }
            }
        }
Example #11
0
        public void PublishMood(string mood, string reason)
        {
            XmlDocument doc = m_Account.Client.Document;

            PubSubItem itemElement = new PubSubItem(doc);
            itemElement.SetAttribute("id", "current");
            doc.AppendChild(itemElement);

            Mood moodElement = new Mood(doc, mood);
            moodElement.Text = reason;
            itemElement.AppendChild(moodElement);

            m_Account.GetFeature<PersonalEventing>().Publish(Namespace.Mood, itemElement);
        }
Example #12
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);
        }
Example #13
0
        private void ReceivedTune(JID from, string node, PubSubItem item)
        {
            Tune tune = (Tune)item["tune"];

            m_FriendTunes[from.Bare] = tune;
            if (!String.IsNullOrEmpty(tune.Artist) && !String.IsNullOrEmpty(tune.Title))
            {
                // Only show in feed if we know this is a recent event.
                if (tune["timestamp"] != null && DateTime.Now.Subtract(DateTime.Parse(tune["timestamp"].InnerText)).TotalSeconds <= 60)
                {
                    m_Account.PostActivityFeedItem(from, "music", null, String.Format("{0} - {1}", tune.Artist, tune.Title), tune.Uri);
                }
            }
        }
Example #14
0
        public void PublishMood(string mood, string reason)
        {
            XmlDocument doc = m_Account.Client.Document;

            PubSubItem itemElement = new PubSubItem(doc);

            itemElement.SetAttribute("id", "current");
            doc.AppendChild(itemElement);

            Mood moodElement = new Mood(doc, mood);

            moodElement.Text = reason;
            itemElement.AppendChild(moodElement);

            m_Account.GetFeature <PersonalEventing>().Publish(Namespace.Mood, itemElement);
        }
Example #15
0
        /// <summary>
        ///   Stops user tune publications
        /// </summary>
        public IXmppSession StopTunePublication()
        {
            var iq      = new IQ();
            var pubsub  = new PubSub();
            var publish = new PubSubPublish();
            var item    = new PubSubItem();
            var tune    = new Tune();

            iq.Items.Add(pubsub);
            pubsub.Items.Add(publish);
            publish.Items.Add(item);

            iq.From      = UserId.ToString();
            iq.ID        = XmppIdentifierGenerator.Generate();
            iq.Type      = IQType.Set;
            publish.Node = XmppFeatures.UserMood;
            item.Item    = tune;

            Send(iq);

            return(this);
        }
Example #16
0
        void ReceivedWebIdentities(JID from, string node, PubSubItem item)
        {
            WebIdentities identities = (WebIdentities)item["web-identities"];

            if (from == m_Account.Jid.BareJID)
            {
                lock (m_MyIdentities) {
                    m_MyIdentities.Clear();
                    foreach (XmlElement child in identities.ChildNodes)
                    {
                        m_MyIdentities.Add(child.Name, child.InnerText);
                    }
                    if (MyIdentitiesReceived != null)
                    {
                        MyIdentitiesReceived(this, EventArgs.Empty);
                    }
                }
            }
            else
            {
                m_IdentityCache[from] = identities;
            }
        }
Example #17
0
        /// <summary>
        /// Makes sure that the underlying ID index is in sync
        /// when an item is removed.
        /// </summary>
        /// <param name="index">Index of PubSubItem to remove.</param>
        public override void RemoveAt(int index)
        {
            PubSubItem item = (PubSubItem)this[index];
            string     id   = item.GetAttribute("id");

            if (id != "")
            {
                m_index.Remove(id);
            }
            base.RemoveAt(index);
            m_node.ItemRemoved(item);

            // renumber
            for (int i = index; i < Count; i++)
            {
                item = (PubSubItem)this[i];
                id   = item.ID;
                if (id != "")
                {
                    m_index[id] = i;
                }
            }
        }
Example #18
0
        /// <summary>
        ///   Publishes user mood information
        /// </summary>
        public IXmppSession PublishMood(XmppUserMoodEvent moodEvent)
        {
            var iq      = new IQ();
            var pubsub  = new PubSub();
            var publish = new PubSubPublish();
            var item    = new PubSubItem();
            var mood    = new Mood();

            iq.Items.Add(pubsub);
            pubsub.Items.Add(publish);
            publish.Items.Add(item);

            iq.From       = UserId.ToString();
            iq.ID         = XmppIdentifierGenerator.Generate();
            iq.Type       = IQType.Set;
            publish.Node  = XmppFeatures.UserMood;
            item.Item     = mood;
            mood.MoodType = (MoodType)Enum.Parse(typeof(MoodType), moodEvent.Mood);
            mood.Text     = moodEvent.Text;

            Send(iq);

            return(this);
        }
Example #19
0
 public void FireRemove(PubSubNode node, PubSubItem item)
 {
     if (OnRemove != null)
         OnRemove(node, item);
 }
Example #20
0
 public void FireAdd(PubSubNode node, PubSubItem item)
 {
     if (OnAdd != null)
         OnAdd(node, item);
 }
Example #21
0
 /// <summary>
 /// Gets or sets the contents of the specified item.
 /// </summary>
 /// <param name="id">Id of the PubSubItem.</param>
 /// <returns>XmlElement representing the contents of the PubSubItem.</returns>
 public XmlElement this[string id]
 {
     get
     {
         object index = m_index[id];
         if (index == null)
             return null;
         PubSubItem item = this[(int)index] as PubSubItem;
         if (item == null)
             return null;
         return item.Contents;
     }
     set
     {
         // wrap an item around the contents.
         PubSubItem item = new PubSubItem(value.OwnerDocument);
         item.Contents = value;
         item.ID = id;
         Add(item);
     }
 }
Example #22
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);
 }
Example #23
0
 /// <summary>
 /// Add a new item to the list
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public PubSubItem AddItem(string id)
 {
     PubSubItem item = new PubSubItem(OwnerDocument, URI.PUBSUB_EVENT);
     AddChild(item);
     item.ID = id;
     return item;
 }
Example #24
0
 private void m_node_OnItemRemove(PubSubNode node, PubSubItem item)
 {
     int index = lbID.Items.IndexOf(item.ID);
     if (lbID.SelectedIndex == index)
         rtItem.Clear();
     if (index >= 0)
         lbID.Items.RemoveAt(index);
 }
Example #25
0
 private void m_node_OnItemAdd(PubSubNode node, PubSubItem item)
 {
     // OnItemRemove should have fired first, so no reason to remove it here.
     // Hopefully.
     Debug.Assert(lbID.Items.IndexOf(item.ID) == -1);
     lbID.Items.Add(item.ID);
 }
Example #26
0
 private void ReceivedTune(JID from, string node, PubSubItem item)
 {
     Tune tune = (Tune)item["tune"];
     m_FriendTunes[from.Bare] = tune;
     if (!String.IsNullOrEmpty(tune.Artist) && !String.IsNullOrEmpty(tune.Title)) {
         // Only show in feed if we know this is a recent event.
         if (tune["timestamp"] != null && DateTime.Now.Subtract(DateTime.Parse(tune["timestamp"].InnerText)).TotalSeconds <= 60) {
             m_Account.PostActivityFeedItem(from, "music", null, String.Format("{0} - {1}", tune.Artist, tune.Title), tune.Uri);
         }
     }
 }
Example #27
0
 /// <summary>
 /// Notifies the client that an item has been add to this PubSubNode.
 /// </summary>
 /// <param name="item">Item that was added.</param>
 public void ItemAdded(PubSubItem item)
 {
     if (OnItemAdd != null)
         OnItemAdd(this, item);
 }
Example #28
0
        private void TrackChanged(object sender, EventArgs args)
        {
            NowPlayingService nowPlaying = ServiceManager.Get<NowPlayingService>();

            PubSubItem itemElement = new PubSubItem(m_Account.Client.Document);
            itemElement.SetAttribute("id", "current");

            Tune tune = new Tune(m_Account.Client.Document);
            itemElement.AppendChild(tune);

            if (nowPlaying.IsPlaying) {
                tune.Artist = nowPlaying.CurrentTrackArtist;
                tune.Length = nowPlaying.CurrentTrackLength;
                tune.Rating = nowPlaying.CurrentTrackRating;
                tune.Source = nowPlaying.CurrentTrackSource;
                tune.Title  = nowPlaying.CurrentTrackTitle;
                tune.Track  = nowPlaying.CurrentTrackNumber;
                tune.Uri    = nowPlaying.CurrentTrackUri;
            }

            m_Account.GetFeature<PersonalEventing>().Publish(Namespace.Tune, itemElement);
        }
Example #29
0
        void ReceivedMood(JID from, string node, PubSubItem item)
        {
            Mood mood = (Mood)item["mood"];

            m_FriendMoods[from.Bare] = mood;

            // Only show in feed if we know this is a recent event.
            if (mood["timestamp"] != null && DateTime.Now.Subtract(DateTime.Parse(mood["timestamp"].InnerText)).TotalSeconds <= 60) {
                m_Account.PostActivityFeedItem(from.ToString(), "mood", mood.MoodName, mood.Text);
            }
        }
Example #30
0
 /// <summary>
 /// Notifies the client that an item has been removed from this PubSubNode.
 /// </summary>
 /// <param name="item">Item that was removed.</param>
 public void ItemRemoved(PubSubItem item)
 {
     if (OnItemRemove != null)
         OnItemRemove(this, item);
 }
Example #31
0
 private void ReceivedMicroblog(JID from, string node, PubSubItem item)
 {
     XmlNode entry = item["entry"];
     if (entry["published"] != null && !String.IsNullOrEmpty(entry["published"].InnerText)) {
         var publishedDate = DateTime.Parse(entry["published"].InnerText);
         if ((DateTime.Now - publishedDate).TotalSeconds <= 60) {
             string title = entry["title"].InnerText;
             m_Account.PostActivityFeedItem(from, "shout", null, title);
         }
     }
 }