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)); }
public void Execute(RosterContactVModel contact, SendMessageRequestParams requestParams) { XmppClientConnection connection = requestParams.Connection; ClientVModel client = requestParams.Client; ConversationVModel conversation = contact.Conversation; Message message = new Message( client.JabberId, contact.JabberId, conversation.MessageToSend); conversation.ChatField += "[" + DateTime.Now.ToLongTimeString() + "]" + "<" + client.JabberId.Username + "> " + conversation.MessageToSend + Environment.NewLine; conversation.MessageToSend = string.Empty; connection.Send(message); }
public SendMessageCommand(SendMessageRequestParams requestParams) { _requestParams = requestParams; }