Beispiel #1
0
        private async void button3_Click(object sender, EventArgs e)
        {
            hslProgress1.Value = 0;
            hslProgress2.Value = 0;
            DateTime start = DateTime.Now;

            button3.Enabled = false;
            OperateResult <string, byte[]> read = await mqttSyncClient.ReadAsync(
                textBox5.Text, Encoding.UTF8.GetBytes(textBox4.Text),
                new Action <long, long>(SendProgressReport), null,
                new Action <long, long>(ReceiveProgressReport));

            button3.Enabled = true;

            textBox7.Text = (int)(DateTime.Now - start).TotalMilliseconds + " ms";
            if (!read.IsSuccess)
            {
                MessageBox.Show("Read Failed:" + read.ToMessageShowString( )); return;
            }


            // 此处应该修改demo里的RPC接口的默认参数功能
            if (mqttRpcApiInfos != null)
            {
                MqttRpcApiInfo api = mqttRpcApiInfos.FirstOrDefault(m => m.ApiTopic == textBox5.Text);
                if (api != null)
                {
                    api.ExamplePayload = textBox4.Text;
                }
            }

            textBox6.Text = read.Content1;
            string msg = Encoding.UTF8.GetString(read.Content2);

            if (radioButton4.Checked)
            {
                try
                {
                    msg = System.Xml.Linq.XElement.Parse(msg).ToString( );
                }
                catch
                {
                }
            }
            else if (radioButton5.Checked)
            {
                try
                {
                    msg = Newtonsoft.Json.Linq.JObject.Parse(msg).ToString( );
                }
                catch
                {
                }
            }

            textBox8.Text = msg;
        }
Beispiel #2
0
        private async void button3_Click(object sender, EventArgs e)
        {
            hslProgress1.Value = 0;
            hslProgress2.Value = 0;
            DateTime start = DateTime.Now;

            button3.Enabled = false;
            OperateResult <string, byte[]> read = await mqttSyncClient.ReadAsync(
                textBox5.Text, Encoding.UTF8.GetBytes(textBox4.Text),
                new Action <long, long>(SendProgressReport), null,
                new Action <long, long>(ReceiveProgressReport));

            button3.Enabled = true;

            textBox7.Text = (int)(DateTime.Now - start).TotalMilliseconds + " ms";
            if (!read.IsSuccess)
            {
                MessageBox.Show("Rend Failed:" + read.Message); return;
            }

            textBox6.Text = read.Content1;
            string msg = Encoding.UTF8.GetString(read.Content2);

            if (radioButton4.Checked)
            {
                try
                {
                    msg = System.Xml.Linq.XElement.Parse(msg).ToString( );
                }
                catch
                {
                }
            }
            else if (radioButton5.Checked)
            {
                try
                {
                    msg = Newtonsoft.Json.Linq.JObject.Parse(msg).ToString( );
                }
                catch
                {
                }
            }

            textBox8.Text = msg;
        }