Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

47 linhas
1.4 KiB

  1. using JT808.Gateway.Abstractions;
  2. using JT808.Gateway.MsgIdHandler;
  3. using JT808.Gateway.SimpleQueueNotification.Hubs;
  4. using JT808.Protocol.Extensions;
  5. using Microsoft.AspNetCore.SignalR;
  6. using Microsoft.Extensions.Logging;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text.Json;
  11. using System.Threading.Tasks;
  12. namespace JT808.Gateway.SimpleQueueNotification.Impl
  13. {
  14. public class JT808MsgIdHandlerImpl: IJT808UpMessageHandler
  15. {
  16. private readonly ILogger<JT808MsgIdHandlerImpl> logger;
  17. private readonly IHubContext<JT808MsgHub> _hubContext;
  18. public JT808MsgIdHandlerImpl(
  19. ILoggerFactory loggerFactory,
  20. IHubContext<JT808MsgHub> hubContext
  21. )
  22. {
  23. this._hubContext = hubContext;
  24. logger = loggerFactory.CreateLogger<JT808MsgIdHandlerImpl>();
  25. }
  26. public void Processor(string TerminalNo, byte[] Data)
  27. {
  28. try
  29. {
  30. if (logger.IsEnabled(LogLevel.Trace))
  31. {
  32. logger.LogTrace($"{TerminalNo}-{Data.ToHexString()}");
  33. }
  34. _hubContext.Clients.All.SendAsync("ReceiveMessage", TerminalNo, Data.ToHexString());
  35. }
  36. catch (Exception ex)
  37. {
  38. logger.LogError(ex, "");
  39. }
  40. }
  41. }
  42. }