void sendEnqueuedMessage() { String test = messagesToSend.First(); poster = new MessagePoster(localUser, new MessagePoster.MessagePostDelegate(postMessageResponseHandler)); poster.post(conversation, messagesToSend.First()); }
void sendEnqueuedMessage() // Siųst iš eilės { if (poster == null && Queue.Count > 0) { messageBeingSent = Queue.Dequeue(); poster = new MessagePoster(PrivateKey, MessagePosterDelegate); poster.post(messageBeingSent.Conversation, messageBeingSent.Text); } }
private void MessagePosterDelegate(MessagePoster.MessageStatus status, Conversation conversation, string message) { //Console.Write(status + " " + message + "\n"); if (status == MessagePoster.MessageStatus.Success || status == MessagePoster.MessageStatus.ConversationNotFound || status == MessagePoster.MessageStatus.MessageEmpty) { //Success poster = null; Result?.Invoke(EnumConverter.Convert <MessageSendStatus>(status), messageBeingSent); if (Sending) { sendEnqueuedMessage(); } } else if (RetryOnFail) // Jei nepavyko { Thread.Sleep(RetryInterval); // Palaukiam ir bandom išnaujo poster = new MessagePoster(PrivateKey, MessagePosterDelegate); poster.post(messageBeingSent.Conversation, messageBeingSent.Text); return; } }
public void MessagingFullTest() { LocalUser user = Login(username: "******", password: "******"); var statusGetterConversation = ConversationGetter.GetStatus.UnknownError; var statusStarter = ConversationStarter.ConversationStatus.UnknownError; var statusPoster = MessagePoster.MessageStatus.UnknownError; var statusGetterMessages = MessageGetter.MessageStatus.UnknownError; bool done = false; Conversation conversation = null; string message = null; List <Message> messages = null; List <Conversation> conversations = null; Dictionary <String, User> users = null; var getterConv = new ConversationGetter(user, (_status, _conversations, _users) => { statusGetterConversation = _status; conversations = _conversations; users = _users; done = true; }); var conversationStarter = new ConversationStarter(user, (_status, _conversation, _users) => { statusStarter = _status; conversation = _conversation; users = _users; done = true; }); var messagePoster = new MessagePoster(user, (_status, _conversation, _message) => { statusPoster = _status; conversation = _conversation; message = _message; done = true; }); var messageGetter = new MessageGetter(user, (_status, _messages) => { statusGetterMessages = _status; messages = _messages; done = true; }); ///Pradedam Conversation done = false; conversationStarter.start("test4"); while (!done) { } Assert.AreEqual(statusStarter, ConversationStarter.ConversationStatus.Success); Assert.AreNotEqual(conversation, null); /// ///Gaunam messages done = false; messageGetter.get(conversation, 0, false); while (!done) { } Assert.AreEqual(statusGetterMessages, MessageGetter.MessageStatus.Success); Assert.AreNotEqual(messages, null); var timestamp = (messages.Count == 0 ? 0 : messages[messages.Count - 1].Timestamp); /// ///Siunčiam message var random = new Random(); done = false; messagePoster.post(conversation, random.Next().ToString()); while (!done) { } Assert.AreEqual(statusPoster, MessagePoster.MessageStatus.Success); Assert.AreNotEqual(message, null); /// ///Gaunam messages done = false; messageGetter.get(conversation, timestamp, false); while (!done) { } Assert.AreEqual(statusGetterMessages, MessageGetter.MessageStatus.Success); Assert.AreNotEqual(messages, null); ///Tikrinam ar nusisiuntė var myMessage = messages.Find((_message) => { return(_message.Text == message && _message.Username == user.Username); }); Assert.AreNotEqual(myMessage, null); /// ///Gaunam conversations done = false; getterConv.get(true); while (!done) { } Assert.AreEqual(statusGetterConversation, ConversationGetter.GetStatus.Success); Assert.AreNotEqual(users, null); Assert.AreNotEqual(conversations, null); var myConversation = conversations.Find((_conversation) => { return(_conversation.Id == conversation.Id); }); Assert.AreNotEqual(myConversation, null); /// }