Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MqIp = ToolService.GetConfig("MqIp");

            DevId = ToolService.GetConfig("DevId");

            SDate = ToolService.GetConfig("SDate");

            DevTopic = $"SmartBoard/Device/{DevId}/ToDev";



            var tmp = ReadLog($@"{Directory.GetCurrentDirectory()}\Data\Data.log");

            var closeDev = IOService.ReadTextByLine($@"{Directory.GetCurrentDirectory()}\Data\Data.log").FirstOrDefault().Replace("{{DevId}}", DevId);

            today = Convert.ToDateTime(SDate);

            mqs = new MqttService(MqIp);

            lg = new LogService();



            mqs.MqttPublish(DevTopic, closeDev);
            System.Threading.Thread.Sleep(3000);
            try
            {
                var send = tmp.Where(o => o.Need == true).ToList();

                //send.Count();
                send.ForEach(x =>
                {
                    MqPublish(x);
                    //System.Threading.Thread.Sleep(1000);
                    //if (i > 10)
                    //{
                    //    return;
                    //}

                    //i++;
                });
                Log("測試結束");
            }
            catch (Exception ex)
            {
                Log($"錯誤\n{ex.ToString()}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 讀取文字檔並物件化,儲存的內容必須是Json
        /// </summary>
        /// <typeparam name="T">要轉換的物件</typeparam>
        /// <param name="path">文字檔路徑</param>
        /// <returns></returns>
        public static T ReadJsonFileToObj <T>(string path) where T : class, new()
        {
            T result = new T();

            try
            {
                result = ToolService.JsonToObj <T>(File.ReadAllText(path));
            }
            catch (Exception ex)
            {
                LogService.logger.Error(ex, "讀取Json檔案錯誤");
            }

            return(result);
        }