public async Task <ListMessages> getMessages(string accessToken) { string endpoint = "https://graph.microsoft.com/v1.0/me/messages"; string queryParameter = ""; ListMessages messages = new ListMessages(); using (var client = new HttpClient()) { using (var request = new HttpRequestMessage(HttpMethod.Get, endpoint + queryParameter)) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); using (var response = await client.SendAsync(request)) { if (response.IsSuccessStatusCode) { string stringResult = await response.Content.ReadAsStringAsync(); messages = JsonConvert.DeserializeObject <ListMessages>(stringResult); } return(messages); } } } }
public ActionResult ChatMessages(int id) { GetApplicationCookie(); Debug.WriteLine("MESSAGE/CHATMESSAGES/" + id); //Request data from API controller via http request string request = "MessageData/GetMessagesByChatId/" + id; HttpResponseMessage response = client.GetAsync(request).Result; //The IHTTPActionResult should send an OK response as well as a MessageDto object list if (response.IsSuccessStatusCode) { IEnumerable <MessageDto> MessageDtos = response.Content.ReadAsAsync <IEnumerable <MessageDto> >().Result; ListMessages MessageList = new ListMessages(); MessageList.Messages = MessageDtos; ChatDto thisChat = new ChatDto(); thisChat.ChatId = id; MessageList.Chat = thisChat; return(View(MessageList)); } else { return(RedirectToAction("Error")); } }
public void Send(string Data) { try { var message = new JSMessage { contenu = Data, date = DateTime.Now, id_Groupe = Id_Groupe, id_Expediteur = Settings.ActualUser.id_Employe, Employe = Settings.ActualUser }; var val = JsonConvert.SerializeObject(message); socket.Emit("send", val); Messages.Add(message); ObMessages = ObservableCollectionConvert.ObservableCollectionConvertion(Messages); ListMessages.ItemsSource = ObMessages; ListMessages.ScrollTo(ObMessages.Last(), ScrollToPosition.End, true); } catch (Exception e) { Console.WriteLine(e.Message); socket.Disconnect(); } }
public Task <IEnumerable <UserMessage> > Handle(ListMessages request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } return(ListMessagesInternalAsync(cancellationToken)); }
public void AddMessage(IMessage msg) { if (msg == null) { return; } ListMessages.Clear(); ListMessages.Add(msg); OnMessageAdded?.Invoke(this, new MessageAddedEventArgs(msg)); }
public override void OnNavigatedTo(NavigationParameters parameters) { //Lógica para automaticamente colocar a tela de chat na ultima msg recebida if (ListMessages.Count > 0) { var msg = ListMessages.Last <Message>(); ListMessages.Remove(msg); ListMessages.Add(msg); } }
void AddLine(string line) { string[] items = line.Split(';'); if (items.Length == 0) { return; } int range = items.Count(item => String.IsNullOrEmpty(item)); bool isComment = range == 0 && !char.IsDigit(items[0][0]); bool isSubMasterNode = range == 0 && !isComment; if (isSubMasterNode) // Start of a message { string timeStamp = items[0]; string message = items.Length > 1 ? items[1] : "???"; string masterName = null; int imageId = -1; bool endFlag; int masterRange = GetMasterRange(message, out imageId, out masterName, out endFlag); ListMessages.Add(currentMessageItem = new TreeMessageItem(timeStamp, message, GetImage(items.Length > 2 ? items[3] : "???", isComment), isComment)); MessageCount++; if (masterRange >= 0) // It's a group start or end { if (endFlag) { currentMasterMessageItem.Add(currentMessageItem); } Main.Add(currentMasterMessageItem = new TreeMasterMessageItem(treeView1, timeStamp, masterName, masterRange, imageId)); } if (!endFlag) { currentMasterMessageItem.Add(currentMessageItem); } } else if (isComment) // Just a comment { currentMessageItem = new TreeMessageItem(null, line, GetImage(line, isComment), isComment); ListMessages.Add(currentMessageItem); if (currentMasterMessageItem == null) { Main.Add(currentMasterMessageItem = new TreeMasterMessageItem(treeView1, "", "Start", 0, GetImage(line, isComment))); } currentMasterMessageItem.Add(currentMessageItem); } else // A line within a message if (currentMessageItem != null) { currentMessageItem.Add(new TreeItemLine(range, items[range], (items.Length == range + 2) ? items[range + 1] : null)); } }
private void MessageAdd_MessageAdd(object sender, MessageTable e) { if (e.MsgType == type && type == 0) { ListMessages.Add(e); } else if (e.FromId == fromId) { ListMessages.Add(e); } MoveEnd(); }
public void AddLogMessage(string message, AccountEventArgs numbersArgs, MessageType messageType) { Message = new LoggerMessage { MessageType = messageType, Message = message, Sender = numbersArgs.SenderNumber, Receiver = numbersArgs.ReceiverNumber, DateTime = DateTime.Now }; ListMessages.Add(Message); }
int IComparable.CompareTo(object obj) { position compWith = obj as position; if (compWith != null) { if (tmi == null || compWith.tmi == null) { throw new InvalidOperationException(string.Format("Can't compare two positions that do not define tmi")); } return(ListMessages.IndexOf(tmi).CompareTo(ListMessages.IndexOf(compWith.tmi))); } throw new InvalidOperationException(string.Format("Can't compare a {0} with a position", obj.GetType())); }
public override void OnNavigatingTo(NavigationParameters parameters) { MessagingCenter.Unsubscribe <MensagemRespostaSocket>(this, "NovaMensagemChat"); MessagingCenter.Subscribe <MensagemRespostaSocket>(this, "NovaMensagemChat", (sender) => { var resposta = sender.msg.Split(new string[] { "=>" }, StringSplitOptions.None); var message = new Message { Text = resposta[0], IsTextIn = true, MessageDateTime = DateTime.ParseExact(resposta[1], "dd/MM/yyyy hh:mm", System.Globalization.CultureInfo.InvariantCulture) }; ListMessages.Add(message); GravarMensagem(message, ListMessages); }); }
void MainPageData_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "VKMessage" && this.UID != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { this.Items = App.MainPageData.GetMessage(this.UID); this.NotifyPropertyChanged("Items"); UpdateLayout(); if (ListMessages.Items.Count != 0) { ListMessages.ScrollIntoView(ListMessages.Items.Last()); } }); } }
private async void Loading(byte type, long fromId) { try { var database = DependencyService.Get <ChaTDataBaseManager>(); var msglist = await database.GetMessage(type, fromId); ListMessages.AddRange(msglist); MoveEnd(); } catch (Exception er) { Log.Error(er); } }
public override IResult <Pagination <MessageModel> > Execute ( ListMessages request, IUserContext userContext ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!userContext.IsAuthenticated) { return(ResultFactory .Unauthorized("You must authenticate prior to reading messages.")); } return(_messagePaginator .Paginate(_state.Messages, request)); }
public void WriteLogMessages() { Directory.CreateDirectory(Path.GetDirectoryName(FolderPath + SerializedFileName) ?? throw new InvalidOperationException()); using (var fileStream = new FileStream(FolderPath + CallLoggerFileName, FileMode.Append)) using (var writer = new StreamWriter(fileStream)) { foreach (var message in ListMessages) { writer.WriteLine($"MessageType: {message.MessageType}"); writer.WriteLine($"Message: {message.Message}"); writer.WriteLine($"Sender: {message.Sender}"); writer.WriteLine($"Receiver: {message.Receiver}"); writer.WriteLine($"Date and time: {message.DateTime}"); writer.WriteLine(); } } ListMessages.Clear(); }
public async void EnviarNovaMensagem() { if (!String.IsNullOrWhiteSpace(OutText)) { var message = new Message { Text = OutText, IsTextIn = false, MessageDateTime = DateTime.Now }; GravarMensagem(message); ListMessages.Add(message); await ConectarSocket(); await WebSocketClientClass.SendMessagAsync("MensagemChat=>" + OutText); OutText = ""; } }
public ActionResult <ListMessages> GetMessageList([FromBody] MessageFilter filter) { if (filter.Count < 0 || filter.From < 0) { return(BadRequest()); } if (User.Claims.ToList().Count > 0) { var a = User.Claims.ToList()[0].Value; if (User.Claims.ToList()[0].Value.ToString() != filter.chat.SenderId && User.Claims.ToList()[0].Value.ToString() != filter.chat.RecipientId) { return(BadRequest()); } } if (!ModelState.IsValid) { var errors = CustomValidator.GetErrorsByModel(ModelState); return(BadRequest(errors)); } var array = _context.Messages .Where(x => (x.SenderId == filter.chat.SenderId || x.SenderId == filter.chat.RecipientId) && (x.RecipientId == filter.chat.RecipientId || x.RecipientId == filter.chat.SenderId)).ToList(); array.Reverse(); ListMessages model = new ListMessages(); model.messages = new List <ModelMessage>(); for (int i = filter.From; i < filter.Count + filter.From && i < array.Count; i++) { model.messages.Add(new ModelMessage { SenderId = array[i].SenderId, DateCreate = array[i].DateCreate, RecipientId = array[i].RecipientId, Text = array[i].Text }); } return(Ok(model)); }
void SendMsg() { var message = new Mensagem { CHA_ID = 1, CHA_CVS_TXT = OutText, CHA_CVS_DTA_HOR_LOG = DateTime.Now, CHA_CVS_ID = 1, }; if (ListMessages.Count % 2 == 0) { message.CHA_CVS_OGM = "P"; } else { message.CHA_CVS_OGM = "c"; } ListMessages.Add(message); OutText = string.Empty; }
private async void Log(int id_groupe) { var groupe = await HttpRequest.getRequest(App.Url + "api/Groupes?filter[where][Id_Groupe]=" + id_groupe); var message = await HttpRequest.getRequest(App.Url + "api/Messageries?filter[include][employe]&filter[where][Id_Groupe]=" + id_groupe + "&filter[limit]=10"); Messages = JsonConvert.DeserializeObject <List <JSMessage> >(message); System.Diagnostics.Debug.WriteLine(message); Settings.ActualGroupe = JsonConvert.DeserializeObject <List <JSGroupe> >(groupe).FirstOrDefault(); ObMessages = ObservableCollectionConvert.ObservableCollectionConvertion(Messages); ListMessages.ItemsSource = ObMessages; socket.Connect(); var JSUser = JsonConvert.SerializeObject(Settings.ActualUser); var JSGroupe = JsonConvert.SerializeObject(Settings.ActualGroupe); socket.Emit("nouv_client", JSUser, JSGroupe); socket.On("retour", (data) => { Device.BeginInvokeOnMainThread(() => { System.Diagnostics.Debug.WriteLine(data.ToString()); JSMessage jSMessage = JsonConvert.DeserializeObject <JSMessage>(data.First().ToString()); Messages.Add(jSMessage); ObMessages = ObservableCollectionConvert.ObservableCollectionConvertion(Messages); ListMessages.ItemsSource = ObMessages; ListMessages.ScrollTo(ObMessages.Last(), ScrollToPosition.End, false); }); }); socket.On("Error", (data) => { socket.Emit("nouv_client", JSUser, JSGroupe); Device.BeginInvokeOnMainThread(() => { DisplayAlert("Erreur", "Renvoyer votre message", "ok"); }); }); }