示例#1
0
        public InfoNotifyModel getInfoNotify(string message)
        {
            InfoNotifyModel result = new InfoNotifyModel();

            JObject jMessage     = JObject.Parse(message);
            string  textMessage  = jMessage.SelectToken("text").ToString();
            JObject jDataMessage = JObject.Parse(textMessage);
            string  Data         = jDataMessage.SelectToken("data").ToString();

            JObject jData = JObject.Parse(Data);

            result.receiver           = jData.SelectToken("receiver").ToString();
            result.descriptionMessage = jData.SelectToken("description").ToString();
            result.typeMessage        = jData.SelectToken("type").ToString();

            return(result);
        }
示例#2
0
        public void ReceiveNotifyRabbitMQ()
        {
            try
            {
                ConnectionFactory factory = new ConnectionFactory();
                factory.UserName    = "******";
                factory.Password    = "******";
                factory.VirtualHost = "xarzdlrm";
                factory.HostName    = "baboon.rmq.cloudamqp.com";
                IConnection conn = factory.CreateConnection();

                var channel = conn.CreateModel();

                var consumer = new EventingBasicConsumer(channel);
                //exchange test
                //var queueName = channel.QueueDeclare("khanhs").QueueName;
                //channel.QueueBind(queue: queueName, exchange: "directExchange", routingKey: "COOK1");


                consumer.Received += (model, ea) =>
                {
                    var body    = ea.Body;
                    var message = Encoding.UTF8.GetString(body);

                    if (message != null)
                    {
                        try
                        {
                            SoundPlayer sound = new SoundPlayer("../../Resources/musics/when.wav");
                            sound.Play();
                        }
                        catch (Exception e)
                        {
                            // MessageBox.Show("beep sound error!!");
                        }

                        InfoNotifyModel infoNotify = getInfoNotify(message);

                        if (infoNotify.typeMessage != null && infoNotify.descriptionMessage != null && infoNotify.descriptionMessage.Contains("Thanh toán")) // them hinh thuc thanh toan o day
                        {
                            // MessageBox.Show(infoNotify.descriptionMessage);
                            //GotoMomopayment(infoNotify);
                        }
                        else
                        {
                            MessageBox.Show(infoNotify.descriptionMessage);
                        }

                        if (BreadCrumbViewModel.Instance.BreadCrumb.Last() == "Bàn")
                        {
                            Application.Current.Dispatcher.Invoke((Action) delegate {
                                Switcher.Switch(new TablePage());
                            });
                        }
                    }
                };
                channel.BasicConsume(queue: "cashier_queue",
                                     autoAck: true,
                                     consumer: consumer);



                //channel.BasicConsume(queue: queueName,
                //                     autoAck: true,
                //                     consumer: consumer);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Lỗi kết nối Rabbitmq");
            }
        }