You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.4 KiB

  1. using JT808.Gateway.Traffic;
  2. using JT808.Protocol.Enums;
  3. using JT808.Protocol.Extensions;
  4. using JT808.Protocol.MessageBody;
  5. using Microsoft.Extensions.Hosting;
  6. using Microsoft.Extensions.Logging;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace JT808.Gateway.SimpleServer.Jobs
  13. {
  14. public class TrafficJob : IHostedService
  15. {
  16. private readonly IJT808Traffic jT808Traffic;
  17. private readonly ILogger Logger;
  18. public TrafficJob(
  19. ILoggerFactory loggerFactory,
  20. IJT808Traffic jT808Traffic)
  21. {
  22. Logger = loggerFactory.CreateLogger("TrafficJob");
  23. this.jT808Traffic = jT808Traffic;
  24. }
  25. public Task StartAsync(CancellationToken cancellationToken)
  26. {
  27. Task.Run(async () =>
  28. {
  29. while (!cancellationToken.IsCancellationRequested)
  30. {
  31. await Task.Delay(2 * 1000);
  32. foreach (var item in jT808Traffic.GetAll())
  33. {
  34. Logger.LogDebug($"{item.Item1}-{item.Item2}");
  35. }
  36. }
  37. }, cancellationToken);
  38. return Task.CompletedTask;
  39. }
  40. public Task StopAsync(CancellationToken cancellationToken)
  41. {
  42. return Task.CompletedTask;
  43. }
  44. }
  45. }