Esempio n. 1
0
        /// <summary>
        ///   Publishes the avatar.
        /// </summary>
        /// <param name = "mimetype">The mimetype.</param>
        /// <param name = "hash">The hash.</param>
        /// <param name = "avatarImage">The avatar image.</param>
        public IXmppSession PublishAvatar(string mimetype, string hash, Image avatarImage)
        {
            var avatarData = new MemoryStream();

            try
            {
                avatarImage.Save(avatarData, ImageFormat.Png);

                // Publish the avatar
                var iq    = new IQ();
                var vcard = new VCardData();

                iq.ID   = XmppIdentifierGenerator.Generate();
                iq.Type = IQType.Set;
                iq.From = UserId.ToString();

                vcard.Photo.Type  = mimetype;
                vcard.Photo.Photo = avatarData.ToArray();

                iq.Items.Add(vcard);

                Send(iq);

                // Save the avatar
                avatarStorage.SaveAvatar(UserId.BareIdentifier, hash, avatarData);

                // Update session configuration
                avatarStorage.Save();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (avatarData != null)
                {
                    avatarData.Close();
                    avatarData.Dispose();
                    avatarData = null;
                }
            }

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        ///   Closes the Session
        /// </summary>
        public IXmppSession Close()
        {
            if (connection != null &&
                (connection.State == XmppConnectionState.Opening ||
                 connection.State == XmppConnectionState.Open))
            {
                try
                {
                    State = XmppSessionState.LoggingOut;

                    if (connection.State == XmppConnectionState.Open)
                    {
                        // Save session configuration
                        AvatarStorage.Save();

                        // Change presence to unavailable
                        SetUnavailable();

                        // Clear all chats
                        chats.Clear();
                    }

                    // Close connection
                    connection.Close();

                    // Unwire XmppConnection events
                    Unsubscribe();
                }
                catch
                {
                }
                finally
                {
                    State = XmppSessionState.LoggedOut;
                }
            }

            return(this);
        }