Example #1
0
        public void AddMessage(byte[] bin)
        {
            var xml = DMessenger.MessageEncoder.Decode(bin);
            var msg = new DMessenger.Message(xml);

            AddMessage(msg, bin);
        }
Example #2
0
        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     = "";
        }
Example #3
0
        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();
            }
        }
Example #4
0
        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();
            }
        }
Example #5
0
 public void AddMessage(DMessenger.Message msg)
 {
     AddMessage(msg, DMessenger.MessageEncoder.Encode(msg.ToXml(), rsa));
 }