Ejemplo n.º 1
0
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
     while (!stoppingToken.IsCancellationRequested)
     {
         var         clients = jT808TcpClientFactory.GetAll();
         JT808Report report  = new JT808Report()
         {
             SendTotalCount     = jT808SendAtomicCounterService.MsgSuccessCount,
             ReceiveTotalCount  = jT808ReceiveAtomicCounterService.MsgSuccessCount,
             CurrentDate        = DateTime.Now,
             Connections        = clients.Count,
             OnlineConnections  = clients.Where(w => w.IsOpen).Count(),
             OfflineConnections = clients.Where(w => !w.IsOpen).Count(),
         };
         string json = JsonSerializer.Serialize(report);
         if (logger.IsEnabled(LogLevel.Debug))
         {
             logger.LogDebug(json);
         }
         using (var sw = new StreamWriter(jT808ReportOptions.CurrentValue.FileFullPath, true))
         {
             sw.WriteLine(json);
         }
         await Task.Delay(TimeSpan.FromSeconds(jT808ReportOptions.CurrentValue.Interval), stoppingToken);
     }
 }
Ejemplo n.º 2
0
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
     while (!stoppingToken.IsCancellationRequested)
     {
         try
         {
             var         clients = clientFactory.GetAll();
             JT808Report report  = new JT808Report()
             {
                 SendTotalCount     = SendAtomicCounterService.MsgSuccessCount,
                 ReceiveTotalCount  = ReceiveAtomicCounterService.MsgSuccessCount,
                 CurrentDate        = DateTime.Now,
                 Connections        = clients.Count,
                 OnlineConnections  = clients.Where(w => w.IsOpen).Count(),
                 OfflineConnections = clients.Where(w => !w.IsOpen).Count(),
             };
             await _hubContext.Clients.All.SendAsync("ReceiveMessage", "query", JsonSerializer.Serialize(report));
         }
         catch (Exception ex)
         {
             logger.LogError(ex, "");
         }
         finally
         {
             await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken);
         }
     }
 }
Ejemplo n.º 3
0
        public ActionResult <JT808Report> QueryReport()
        {
            var         clients = clientFactory.GetAll();
            JT808Report report  = new JT808Report()
            {
                SendTotalCount     = SendAtomicCounterService.MsgSuccessCount,
                ReceiveTotalCount  = ReceiveAtomicCounterService.MsgSuccessCount,
                CurrentDate        = DateTime.Now,
                Connections        = clients.Count,
                OnlineConnections  = clients.Where(w => w.IsOpen).Count(),
                OfflineConnections = clients.Where(w => !w.IsOpen).Count(),
            };

            return(report);
        }