예제 #1
0
 public IOTDataService(ILogger <IOTDataService> logger)
 {
     this.logger = logger;
     litedb      = new LitedbWapper(DBFile);
     bus         = new BusClient();
     this.bus.Subscribe(BusOption.DATA_OUTPUT);
     this.bus.OnReceived += Bus_OnReceived;
     //每10分钟执行一次数据清理
     this.timer = new Timer(p => this.ClearData(), null, 0, 1000 * 10 * 60);
 }
예제 #2
0
        private void Bus_OnReceived(object sender, BusEventArgs e)
        {
            var data = System.Text.Json.JsonSerializer.Deserialize <IEnumerable <IOTData> >(e.Message);

            lock (Program.lockdb)
            {
                using (var litedb = new LitedbWapper(DBFile))
                {
                    litedb.Insert <IOTData>(data);
                }
            }
        }