Esempio n. 1
0
        public async Task Execute(AuthorizeClientRequestParams requestParams)
        {
            Contract.Requires(requestParams != null);
            if (!JabberID.ValidateJid(_requestParams.AuthorizeCredentials.Jid))
            {
                MessageBox.Show("Введен некорректный идентификатор пользователя.");
                return;
            }

            XmppClientConnection connection = requestParams.Connection;
            ClientVModel         client     = requestParams.Client;
            //ConversationVModel conversation = requestParams.Conversation;
            ConnectionStateVModel connectionState = requestParams.ConnectionState;
            AuthorizationVModel   credentials     = requestParams.AuthorizeCredentials;
            ReadOnlyObservableCollection <RosterContactVModel> contacts = requestParams.Contacts;

            JabberID id = new JabberID(credentials.Jid);

            connection = new XmppClientConnection(id, credentials.Password);

            await connection.LoginAsync();

            if (connection.Connected && connection.Authenticated)
            {
                MessageBox.Show("Вы успешно авторизованы.");
                client.JabberId           = id;
                client.Password           = credentials.Password;
                connectionState.Connected = true;

                //TODO: Всем контактам передать ссылку на текущее соединение
                //conversation.Connection = connection;
                foreach (var contact in contacts)
                {
                    contact.Conversation.InitMessageGrabber(connection, contact.JabberId);
                    //contact.Conversation.Connection = connection;
                    //contact.Conversation.MessageGrabber = new MessageGrabber(connection)
                    //    .Add(new JabberID(PartnerJid), OnMessage);
                }
            }
            else
            {
                MessageBox.Show("Произошла ошибка, попробуйте еще раз");
                return;
            }

            SendMessageCommand       sendMessageCommand = _requestParams.SendMessageCommand;
            SendMessageRequestParams parameters         = new SendMessageRequestParams(connection, client);

            sendMessageCommand.ExecuteParams = parameters;

            connection.Send(new Presence(ShowType.Show));
        }
Esempio n. 2
0
        public async Task TestSendPresenceAndMessageAsync()
        {
            Presence presence = new Presence(ShowType.Show);

            JabberID from    = new JabberID(myJid);
            JabberID to      = new JabberID(partnerJid);
            string   msg     = "Hello";
            Message  message = new Message(from, to, msg);

            XmppClientConnection connection = new XmppClientConnection(
                new JabberID(myJid), password);
            await connection.LoginAsync();

            if (!connection.Connected || !connection.Authenticated)
            {
                throw new Exception("Not authenticate");
            }

            Assert.DoesNotThrow(() => { connection.Send(presence); });
            Assert.DoesNotThrow(() => { connection.Send(message); });
        }