private async Task DisplayNewMessage(TextMessage message) { if (message == null) { MessageBox.Show("empty message"); return; } var settings = UserSettings.Load(); if (settings.LanguageCode != null) { var http = new HttpClient(); var response = await http.GetStringAsync($"myapi"); response = response.Substring(17, response.Length - 19); //removes response information causing error converting to JObject var translatedMsg = JObject.Parse(response); var output = translatedMsg["text"]?.ToString(); MessagesLB.Invoke((MethodInvoker)delegate { MessagesLB.Items.Add($"{_db.GetClient(message.FromUser).UserName}: {output}"); }); return; } MessagesLB.Invoke((MethodInvoker)delegate { MessagesLB.Items.Add($"{_db.GetClient(message.FromUser).UserName}: {message.Content}"); }); }
private async Task<List<TextMessage>> TranslateMessages(Stack<TextMessage> messages) { var orderedMsgs = new List<TextMessage>(); var settings = UserSettings.Load(); while (messages.Count > 0) { var message = messages.Pop(); var http = new HttpClient(); var response = await http.GetStringAsync($"myapi"); response = response.Substring(17, response.Length - 19); //removes response information causing error converting to JObject var translatedMsg = JObject.Parse(response); message.Content translatedMsg["text"]?.ToString(); orderedMsgs.Add(message); } return orderedMsgs; }
async