コード例 #1
0
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                await MQTTContext.getInstance().
                Initialize(txtServer.Text.Trim(), int.Parse(txtPort.Text.Trim()), notification);

                if (_scheduler == null)
                {
                    _scheduler = await StdSchedulerFactory.GetDefaultScheduler();

                    //任务、触发器执行配置
                    XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper());
                    Stream s = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\Quartz.config").BaseStream;
                    await processor.ProcessStream(s, null);

                    await processor.ScheduleJobs(_scheduler);

                    await _scheduler.Start();
                }
                btnStart.Enabled = false;
                btnStop.Enabled  = true;
            }
            catch (Exception ex)
            {
                showMessage(ex.Message);
            }
        }
コード例 #2
0
 public async Task <MqttClientPublishResult> Send(string topic, string payload)
 {
     try
     {
         return(await MQTTContext.getInstance().Publish(topic, payload));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="publishData"></param>
        /// <returns></returns>

        public async Task Send(Dictionary <string, List <byte[]> > publishData)
        {
            try
            {
                await MQTTContext.getInstance().Publish(publishData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     this.BeginInvoke((MethodInvoker) delegate
     {
         if (!btnStart.Enabled)//判断是否在运行中
         {
             if (!MQTTContext.getInstance().Connected.Value)
             {
                 btnStart_Click(null, null);//重试连接
             }
         }
     });
 }
コード例 #5
0
        /// <summary>
        /// 停止
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnStop_Click(object sender, EventArgs e)
        {
            await MQTTContext.getInstance().Close();

            if (_scheduler != null)
            {
                await _scheduler.Shutdown(false);

                _scheduler = null;
            }
            btnStart.Enabled = true;
            btnStop.Enabled  = false;
        }