Exemple #1
0
 public ActivityChangedEventArgs(S22.Xmpp.Jid jid, GeneralActivity activity, SpecificActivity specific = SpecificActivity.Other, string description = null)
 {
     jid.ThrowIfNull <S22.Xmpp.Jid>("jid");
     this.Jid         = jid;
     this.Activity    = activity;
     this.Specific    = specific;
     this.Description = description;
 }
		/// <summary>
		/// Initializes a new instance of the ActivityChangedEventArgs class.
		/// </summary>
		/// <param name="jid">The JID of the XMPP entity that published the
		/// activity information.</param>
		/// <param name="activity">One of the values from the GeneralActivity
		/// enumeration.</param>
		/// <param name="specific">A value from the SpecificActivity enumeration
		/// best describing the user's activity in more detail.</param>
		/// <param name="description">A natural-language description of, or
		/// reason for, the activity.</param>
		/// <exception cref="ArgumentNullException">The jid parameter is
		/// null.</exception>
		public ActivityChangedEventArgs(Jid jid, GeneralActivity activity,
			SpecificActivity specific = SpecificActivity.Other,
			string description = null) {
			jid.ThrowIfNull("jid");
			Jid = jid;
			Activity = activity;
			Specific = specific;
			Description = description;
		}
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the ActivityChangedEventArgs class.
 /// </summary>
 /// <param name="jid">The JID of the XMPP entity that published the
 /// activity information.</param>
 /// <param name="activity">One of the values from the GeneralActivity
 /// enumeration.</param>
 /// <param name="specific">A value from the SpecificActivity enumeration
 /// best describing the user's activity in more detail.</param>
 /// <param name="description">A natural-language description of, or
 /// reason for, the activity.</param>
 /// <exception cref="ArgumentNullException">The jid parameter is
 /// null.</exception>
 public ActivityChangedEventArgs(Jid jid, GeneralActivity activity,
                                 SpecificActivity specific = SpecificActivity.Other,
                                 string description        = null)
 {
     jid.ThrowIfNull("jid");
     Jid         = jid;
     Activity    = activity;
     Specific    = specific;
     Description = description;
 }
Exemple #4
0
		/// <summary>
		/// Sets the user's activity to the specified activity value(s).
		/// </summary>
		/// <param name="activity">A value from the GeneralActivity enumeration to
		/// set the user's general activity to.</param>
		/// <param name="specific">A value from the SpecificActivity enumeration
		/// best describing the user's activity in more detail.</param>
		/// <param name="description">A natural-language description of, or reason
		/// for, the activity.</param>
		public void SetActivity(GeneralActivity activity, SpecificActivity specific =
			SpecificActivity.Other, string description = null) {
			var xml = Xml.Element("activity", "http://jabber.org/protocol/activity");
			var e = Xml.Element(GeneralActivityToTagName(activity));
			if (specific != SpecificActivity.Other)
				e.Child(Xml.Element(SpecificActivityToTagName(specific)));
			xml.Child(e);
			if (description != null)
				xml.Child(Xml.Element("text").Text(description));
			pep.Publish("http://jabber.org/protocol/activity", null, xml);
		}
Exemple #5
0
        /// <summary>
        /// Invoked when a contact has published his or her activity.
        /// </summary>
        /// <param name="jid">The JID of the XMPP entity that published the
        /// activity information.</param>
        /// <param name="item">The 'item' Xml element of the pubsub publish
        /// event.</param>
        private void onActivity(Jid jid, XmlElement item)
        {
            if (item == null || item["activity"] == null)
            {
                return;
            }
            var             activityElement = item["activity"];
            XmlElement      temp            = null;
            GeneralActivity?activity        = null;

            if (activityElement.IsEmpty)
            {
                activity = GeneralActivity.Undefined;
            }
            else
            {
                // Look for a GeneralActivity value element.
                foreach (var v in Enum.GetValues(typeof(GeneralActivity)))
                {
                    string s = GeneralActivityToTagName((GeneralActivity)v);
                    if (activityElement[s] != null)
                    {
                        activity = (GeneralActivity)v;
                        temp     = activityElement[s];
                    }
                }
            }
            SpecificActivity specific = SpecificActivity.Other;

            if (temp != null)
            {
                // Look for a SpecificActivity value element.
                foreach (var v in Enum.GetValues(typeof(SpecificActivity)))
                {
                    string s = SpecificActivityToTagName((SpecificActivity)v);
                    if (temp[s] != null)
                    {
                        specific = (SpecificActivity)v;
                    }
                }
            }
            string text = activityElement["text"] != null ?
                          activityElement["text"].InnerText : null;

            // Raise the 'ActivityChanged' event.
            if (activity.HasValue)
            {
                ActivityChanged.Raise(this, new ActivityChangedEventArgs(jid,
                                                                         activity.Value, specific, text));
            }
        }
Exemple #6
0
        /// <summary>
        /// Returns the XMPP element name of the specified specific activity value.
        /// </summary>
        /// <param name="activity">A value from the SpecificActivity enumeration
        /// to convert into an element name.</param>
        /// <returns>The XML element name of the specified activity value.</returns>
        private string SpecificActivityToTagName(SpecificActivity activity)
        {
            StringBuilder b = new StringBuilder();
            string        s = activity.ToString();

            for (int i = 0; i < s.Length; i++)
            {
                if (char.IsUpper(s, i) && i > 0)
                {
                    b.Append('_');
                }
                b.Append(char.ToLower(s[i]));
            }
            return(b.ToString());
        }
        public void SetActivity(GeneralActivity activity, SpecificActivity specific = SpecificActivity.Other, string description = null)
        {
            XmlElement e        = Xml.Element("activity", "http://jabber.org/protocol/activity");
            XmlElement element2 = Xml.Element(this.GeneralActivityToTagName(activity), null);

            if (specific != SpecificActivity.Other)
            {
                element2.Child(Xml.Element(this.SpecificActivityToTagName(specific), null));
            }
            e.Child(element2);
            if (description != null)
            {
                e.Child(Xml.Element("text", null).Text(description));
            }
            this.pep.Publish("http://jabber.org/protocol/activity", null, new XmlElement[] { e });
        }
Exemple #8
0
        /// <summary>
        /// Sets the user's activity to the specified activity value(s).
        /// </summary>
        /// <param name="activity">A value from the GeneralActivity enumeration to
        /// set the user's general activity to.</param>
        /// <param name="specific">A value from the SpecificActivity enumeration
        /// best describing the user's activity in more detail.</param>
        /// <param name="description">A natural-language description of, or reason
        /// for, the activity.</param>
        public void SetActivity(GeneralActivity activity, SpecificActivity specific =
                                SpecificActivity.Other, string description          = null)
        {
            var xml = Xml.Element("activity", "http://jabber.org/protocol/activity");
            var e   = Xml.Element(GeneralActivityToTagName(activity));

            if (specific != SpecificActivity.Other)
            {
                e.Child(Xml.Element(SpecificActivityToTagName(specific)));
            }
            xml.Child(e);
            if (description != null)
            {
                xml.Child(Xml.Element("text").Text(description));
            }
            pep.Publish("http://jabber.org/protocol/activity", null, xml);
        }
 private void onActivity(Jid jid, XmlElement item)
 {
     if ((item != null) && (item["activity"] != null))
     {
         string          str;
         XmlElement      element  = item["activity"];
         XmlElement      element2 = null;
         GeneralActivity?nullable = null;
         if (element.IsEmpty)
         {
             nullable = new GeneralActivity?(GeneralActivity.Undefined);
         }
         else
         {
             foreach (object obj2 in Enum.GetValues(typeof(GeneralActivity)))
             {
                 str = this.GeneralActivityToTagName((GeneralActivity)obj2);
                 if (element[str] != null)
                 {
                     nullable = new GeneralActivity?((GeneralActivity)obj2);
                     element2 = element[str];
                 }
             }
         }
         SpecificActivity other = SpecificActivity.Other;
         if (element2 != null)
         {
             foreach (object obj2 in Enum.GetValues(typeof(SpecificActivity)))
             {
                 str = this.SpecificActivityToTagName((SpecificActivity)obj2);
                 if (element2[str] != null)
                 {
                     other = (SpecificActivity)obj2;
                 }
             }
         }
         string description = (element["text"] != null) ? element["text"].InnerText : null;
         if (nullable.HasValue)
         {
             this.ActivityChanged.Raise <ActivityChangedEventArgs>(this, new ActivityChangedEventArgs(jid, nullable.Value, other, description));
         }
     }
 }
Exemple #10
0
 /// <summary>
 /// Sets the user's activity to the specified activity value(s).
 /// </summary>
 /// <param name="activity">A value from the GeneralActivity enumeration to
 /// set the user's general activity to.</param>
 /// <param name="specific">A value from the SpecificActivity enumeration
 /// best describing the user's activity in more detail.</param>
 /// <param name="description">A natural-language description of, or reason
 /// for, the activity.</param>
 /// <exception cref="InvalidOperationException">The XmppClient instance is not
 /// connected to a remote host, or the XmppClient instance has not authenticated with
 /// the XMPP server.</exception>
 /// <exception cref="ObjectDisposedException">The XmppClient object has been
 /// disposed.</exception>
 /// <include file='Examples.xml' path='S22/Xmpp/Client/XmppClient[@name="SetActivity"]/*'/>
 public void SetActivity(GeneralActivity activity, SpecificActivity specific =
     SpecificActivity.Other, string description = null)
 {
     AssertValid();
     userActivity.SetActivity(activity, specific, description);
 }
Exemple #11
0
		/// <summary>
		/// Returns the XMPP element name of the specified specific activity value.
		/// </summary>
		/// <param name="activity">A value from the SpecificActivity enumeration
		/// to convert into an element name.</param>
		/// <returns>The XML element name of the specified activity value.</returns>
		string SpecificActivityToTagName(SpecificActivity activity) {
			StringBuilder b = new StringBuilder();
			string s = activity.ToString();
			for (int i = 0; i < s.Length; i++) {
				if (Char.IsUpper(s, i) && i > 0)
					b.Append('_');
				b.Append(Char.ToLower(s[i]));
			}
			return b.ToString();
		}
Exemple #12
0
 public void SetActivity(GeneralActivity activity, SpecificActivity specific = SpecificActivity.Other, string description = null)
 {
     this.AssertValid();
     this.userActivity.SetActivity(activity, specific, description);
 }