예제 #1
0
        static void Main(string[] args)
        {
            PurVar.PurStatic.WriteToStatus("2s后开始");
            Thread.Sleep(2000);
            try
            {
                PurVar.PurStatic.WriteToStatus(System.AppDomain.CurrentDomain.BaseDirectory);
                _dbHelperMySQL = new DBUtility.DbHelperMySQL("Local");
                string  strSql             = "select * from system_infomation";
                DataSet dsSystemInfomation = _dbHelperMySQL.Quene(strSql);
                if (dsSystemInfomation != null)
                {
                    if (dsSystemInfomation.Tables.Count == 1)
                    {
                        if (dsSystemInfomation.Tables[0].Rows.Count == 1)
                        {
                            PurVar.Repeater.repeaterId      = Convert.ToInt32(dsSystemInfomation.Tables[0].Rows[0]["repeater_id"]);
                            PurVar.Repeater.projectCode     = Convert.ToInt32(dsSystemInfomation.Tables[0].Rows[0]["projectcode"]);
                            PurVar.Repeater.repeaterType    = dsSystemInfomation.Tables[0].Rows[0]["repeater_type"].ToString();
                            PurVar.Repeater.firmwareVersion = dsSystemInfomation.Tables[0].Rows[0]["firmware_version"].ToString();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(System.AppDomain.CurrentDomain.BaseDirectory + "BasicConfig.xml");
                XmlNode xnMQTTUrl  = xmlDoc.SelectSingleNode("/root/MQTT/url");
                XmlNode xnMQTTPort = xmlDoc.SelectSingleNode("/root/MQTT/port");
                _myMqtt = new Model.MyMqtt()
                {
                    AllTopics      = InitTopics(),
                    SelectedTopics = new List <TopicFilter>(),
                    ServerUri      = xnMQTTUrl.InnerText,
                    UserName       = "******",
                    Password       = "******",
                    CurrentTopic   = null,
                    ServerPort     = Convert.ToInt32(xnMQTTPort.InnerText),
                    ClientID       = PurVar.Repeater.repeaterId.ToString()
                };
                if (_myMqtt.ServerUri != null && _myMqtt.ServerPort > 0)
                {
                    InitClient(_myMqtt.ClientID, _myMqtt.ServerUri, _myMqtt.ServerPort);
                }
                else
                {
                    PurVar.PurStatic.WriteToStatus("提示,服务端地址或端口号不能为空!");
                    return;
                }
            }
            catch (Exception ex)
            { PurVar.PurStatic.WriteToStatus("初始化错误:" + ex.Message); }
            Thread tConnect = new Thread(WhilePublish);//上报数据方法

            tConnect.Start();
            Thread tHeartBeat = new Thread(HeartBeat);//心跳线程

            tHeartBeat.Start();
            Thread tReflashSub = new Thread(ReflashSub);//刷新订阅

            tReflashSub.Start();
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                _dbHelperMySQL = new DBUtility.DbHelperMySQL("Local");
                //得到repeater信息
                string  strSql             = "select * from system_infomation";
                DataSet dsSystemInfomation = _dbHelperMySQL.Quene(strSql);
                if (dsSystemInfomation != null)
                {
                    if (dsSystemInfomation.Tables.Count == 1)
                    {
                        if (dsSystemInfomation.Tables[0].Rows.Count == 1)
                        {
                            PurVar.Repeater.repeaterId      = Convert.ToInt32(dsSystemInfomation.Tables[0].Rows[0]["repeater_id"]);
                            PurVar.Repeater.projectCode     = Convert.ToInt32(dsSystemInfomation.Tables[0].Rows[0]["projectcode"]);
                            PurVar.Repeater.repeaterType    = dsSystemInfomation.Tables[0].Rows[0]["repeater_type"].ToString();
                            PurVar.Repeater.firmwareVersion = dsSystemInfomation.Tables[0].Rows[0]["firmware_version"].ToString();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
                //得到MQTT连接信息改原来的xml读取直接读取配置文件

                /*
                 * XmlDocument xmlDoc = new XmlDocument();
                 * //xmlDoc.Load("BasicConfig.xml");
                 * xmlDoc.Load("MQTTRepeater.dll.config");
                 * XmlNode xnMQTTUrl = xmlDoc.SelectSingleNode("/configuration/MQTT/url");
                 * XmlNode xnMQTTPort = xmlDoc.SelectSingleNode("/configuration/MQTT/port");
                 */
                string MQTTrul  = System.Configuration.ConfigurationManager.AppSettings["url"];
                string MQTTport = System.Configuration.ConfigurationManager.AppSettings["port"];

                _myMqtt = new Model.MyMqtt()
                {
                    //  AllTopics = InitTopics(),
                    SelectedTopics = new List <TopicFilter>(),
                    ServerUri      = MQTTrul,                                                           // xnMQTTUrl.InnerText,
                    UserName       = System.Configuration.ConfigurationManager.AppSettings["UserName"], //"user",
                    Password       = System.Configuration.ConfigurationManager.AppSettings["Password"], // "123",
                    CurrentTopic   = null,
                    ServerPort     = int.Parse(MQTTport),                                               //Convert.ToInt32(xnMQTTPort.InnerText),
                    ClientID       = PurVar.Repeater.repeaterId.ToString()
                };
                if (_myMqtt.ServerUri != null && _myMqtt.ServerPort > 0)
                {
                    InitClient(_myMqtt.ClientID, _myMqtt.ServerUri, _myMqtt.ServerPort);
                }
                else
                {
                    PurVar.PurStatic.WriteToStatus("提示,服务端地址或端口号不能为空!请重新配置正确的服务器信息");
                    return;
                }
            }
            catch (Exception ex)
            { PurVar.PurStatic.WriteToStatus("初始化错误:" + ex.Message); }
            Thread tConnect = new Thread(WhilePublish);//上报数据方法

            tConnect.Start();
            Thread tHeartBeat = new Thread(HeartBeat);//心跳线程

            tHeartBeat.Start();
            Thread tReflashSub = new Thread(ReflashSub);//刷新订阅

            tReflashSub.Start();
            Thread tReflashWork = new Thread(APworking);//刷新硬件采集存储

            tReflashWork.Start();
        }