public void AddMessage(byte[] bin) { var xml = DMessenger.MessageEncoder.Decode(bin); var msg = new DMessenger.Message(xml); AddMessage(msg, bin); }
private void Button_Click(object sender, RoutedEventArgs e) { var message = textBox.Text; var msg = new DMessenger.Message() { Value = new XElement("value", new XText(message)), UpdateTime = DateTime.UtcNow }; switch (priority.SelectedIndex) { case 1: msg.Priority = DMessenger.MessagePriority.Talk; break; case 2: msg.Priority = DMessenger.MessagePriority.Emergency; break; } DMessenger.MessageThread.Get(thread.Item2.Id, thread.Item2.Title).AddOrUpdate(msg); thread.Item1.AddMessage(msg); toke.ItemsSource = null; toke.ItemsSource = thread.Item1.GetMessages(thread.Item2.Id); textBox.Text = ""; }
private async void OnWriteMessage(GattLocalCharacteristic sender, GattWriteRequestedEventArgs args) { var deferral = args.GetDeferral(); try { var req = await args.GetRequestAsync(); var reader = DataReader.FromBuffer(req.Value); var buf = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(buf); var xml = DMessenger.MessageEncoder.Decode(buf); var msg = new DMessenger.Message(xml); if (req.Option == GattWriteOption.WriteWithResponse) { req.Respond(); } } finally { deferral.Complete(); } }
public void AddMessage(DMessenger.Message msg, byte[] bin) { var msgid = msg.MessageId; if (GetMessages().All(it => it.Id != msgid)) { db.Insert(new DB.MessageItem(msgid, msg.Thread.ThreadId, bin)); if (!db.Table <DB.ThreadItem>().Any(th => th.Id == msg.Thread.ThreadId)) { db.Insert(new DB.ThreadItem() { Id = msg.Thread.ThreadId, Title = msg.Thread.Title }); } db.Commit(); } }
public void AddMessage(DMessenger.Message msg) { AddMessage(msg, DMessenger.MessageEncoder.Encode(msg.ToXml(), rsa)); }