Exemplo n.º 1
0
 /// <summary>
 /// Publishes the image data provided by the specified stream as the user's
 /// avatar.
 /// </summary>
 /// <param name="stream">A stream containing the image data to publish as
 /// the user's avatar.</param>
 /// <exception cref="ArgumentNullException">The stream parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The stream does not have a valid
 /// image format.</exception>
 /// <exception cref="NotSupportedException">The server does not support
 /// the 'Personal Eventing Protocol' extension.</exception>
 /// <exception cref="XmppErrorException">The server returned an XMPP error code.
 /// Use the Error property of the XmppErrorException to obtain the specific
 /// error condition.</exception>
 /// <exception cref="XmppException">The server returned invalid data or another
 /// unspecified XMPP error occurred.</exception>
 public void Publish(Stream stream)
 {
     stream.ThrowIfNull("stream");
     using (Image image = Image.FromStream(stream)) {
         string mimeType = GetMimeType(image);
         int    width = image.Width;
         int    height = image.Height;
         long   size = 0;
         string hash = String.Empty, base64Data = String.Empty;
         using (var ms = new MemoryStream()) {
             image.Save(ms, image.RawFormat);
             size = ms.Length;
             // Calculate the SHA-1 hash of the image data.
             byte[] data = ms.ToArray();
             hash = Hash(data);
             // Convert the binary data into a BASE64-string.
             base64Data = Convert.ToBase64String(data);
         }
         // Publish the image- and meta data.
         pep.Publish("urn:xmpp:avatar:data", hash,
                     Xml.Element("data", "urn:xmpp:avatar:data").Text(base64Data));
         pep.Publish("urn:xmpp:avatar:metadata", hash,
                     Xml.Element("metadata", "urn:xmpp:avatar:metadata").Child(
                         Xml.Element("info")
                         .Attr("bytes", size.ToString())
                         .Attr("height", height.ToString())
                         .Attr("width", width.ToString())
                         .Attr("id", hash)
                         .Attr("type", mimeType))
                     );
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the user's mood to the specified mood value.
        /// </summary>
        /// <param name="mood">A value from the Mood enumeration to set the user's
        /// mood to.</param>
        /// <param name="description">A natural-language description of, or reason
        /// for, the mood.</param>
        public void SetMood(Mood mood, string description = null)
        {
            var xml = Xml.Element("mood", "http://jabber.org/protocol/mood")
                      .Child(Xml.Element(MoodToTagName(mood)));

            if (description != null)
            {
                xml.Child(Xml.Element("text").Text(description));
            }
            pep.Publish("http://jabber.org/protocol/mood", null, xml);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Publishes the specified music information to contacts on the user's
        /// roster.
        /// </summary>
        /// <param name="title">The title of the song or piece.</param>
        /// <param name="artist">The artist or performer of the song or piece.</param>
        /// <param name="track">A unique identifier for the tune; e.g., the track number
        /// within a collection or the specific URI for the object (e.g., a
        /// stream or audio file).</param>
        /// <param name="length">The duration of the song or piece in seconds.</param>
        /// <param name="rating">The user's rating of the song or piece, from 1
        /// (lowest) to 10 (highest).</param>
        /// <param name="source">The collection (e.g., album) or other source
        /// (e.g., a band website that hosts streams or audio files).</param>
        /// <param name="uri">A URI or URL pointing to information about the song,
        /// collection, or artist</param>
        /// <exception cref="NotSupportedException">The server does not support the
        /// 'Personal Eventing Protocol' extension.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        /// <remarks>Publishing no information (i.e. calling Publish without any parameters
        /// is considered a "stop command" to disable publishing).</remarks>
        public void Publish(string title = null, string artist = null, string track = null,
                            int length   = 0, int rating       = 0, string source   = null, string uri = null)
        {
            length.ThrowIfOutOfRange(0, Int16.MaxValue);
            rating.ThrowIfOutOfRange(0, 10);
            var tune = Xml.Element("tune", "http://jabber.org/protocol/tune");

            if (!String.IsNullOrEmpty(title))
            {
                tune.Child(Xml.Element("title").Text(title));
            }
            if (!String.IsNullOrEmpty(artist))
            {
                tune.Child(Xml.Element("artist").Text(artist));
            }
            if (!String.IsNullOrEmpty(track))
            {
                tune.Child(Xml.Element("track").Text(track));
            }
            if (length > 0)
            {
                tune.Child(Xml.Element("length").Text(length.ToString()));
            }
            if (rating > 0)
            {
                tune.Child(Xml.Element("rating").Text(rating.ToString()));
            }
            if (!String.IsNullOrEmpty(source))
            {
                tune.Child(Xml.Element("source").Text(source));
            }
            if (!String.IsNullOrEmpty(uri))
            {
                tune.Child(Xml.Element("uri").Text(uri));
            }
            pep.Publish("http://jabber.org/protocol/tune", null, tune);
        }