您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

49 行
1.5 KiB

  1. using DotNetty.Buffers;
  2. using JT808.DotNetty.Abstractions.Dtos;
  3. using JT808.DotNetty.Core;
  4. using JT808.DotNetty.Core.Interfaces;
  5. using JT808.DotNetty.Core.Metadata;
  6. using JT808.DotNetty.Core.Services;
  7. using System;
  8. using System.Linq;
  9. namespace JT808.DotNetty.Internal
  10. {
  11. internal class JT808UnificationTcpSendService : IJT808UnificationTcpSendService
  12. {
  13. private readonly JT808TcpSessionManager jT808SessionManager;
  14. public JT808UnificationTcpSendService(
  15. JT808TcpSessionManager jT808SessionManager)
  16. {
  17. this.jT808SessionManager = jT808SessionManager;
  18. }
  19. public JT808ResultDto<bool> Send(string terminalPhoneNo, byte[] data)
  20. {
  21. JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>();
  22. try
  23. {
  24. if(jT808SessionManager.TrySend(terminalPhoneNo, data, out var message))
  25. {
  26. resultDto.Code = JT808ResultCode.Ok;
  27. resultDto.Data = false;
  28. }
  29. else
  30. {
  31. resultDto.Code = JT808ResultCode.Ok;
  32. resultDto.Data = false;
  33. resultDto.Message = message;
  34. }
  35. }
  36. catch (Exception ex)
  37. {
  38. resultDto.Data = false;
  39. resultDto.Code = JT808ResultCode.Error;
  40. resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex);
  41. }
  42. return resultDto;
  43. }
  44. }
  45. }