ServerMessageService.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using EVCB_OCPP.Packet.Features;
  2. using EVCB_OCPP.Packet.Messages.Core;
  3. using Microsoft.Extensions.Logging;
  4. using static System.Runtime.InteropServices.JavaScript.JSType;
  5. using System.ServiceModel.Channels;
  6. using EVCB_OCPP.Packet.Messages.Security;
  7. namespace EVCB_OCPP.WSServer.Service;
  8. public class ServerMessageService
  9. {
  10. public ServerMessageService(
  11. IMainDbService mainDbService
  12. , ILogger<ServerMessageService> logger)
  13. {
  14. this.mainDbService = mainDbService;
  15. this.logger = logger;
  16. }
  17. private readonly IMainDbService mainDbService;
  18. private readonly ILogger<ServerMessageService> logger;
  19. internal async Task SendGetEVSEConfigureRequest(string chargeBoxId)
  20. {
  21. if (string.IsNullOrEmpty(chargeBoxId)) return;
  22. await mainDbService.AddServerMessage(
  23. ChargeBoxId: chargeBoxId,
  24. OutAction: Actions.GetConfiguration.ToString(),
  25. OutRequest: new GetConfigurationRequest() { key = new List<string>() }
  26. );
  27. }
  28. internal Task SendChangeConfigurationRequest(string chargeBoxId, string key, string value)
  29. {
  30. return mainDbService.AddServerMessage(
  31. ChargeBoxId: chargeBoxId,
  32. OutAction: Actions.ChangeConfiguration.ToString(),
  33. OutRequest: new ChangeConfigurationRequest()
  34. {
  35. key = key,
  36. value = value
  37. });
  38. }
  39. internal Task SendDataTransferRequest(string chargeBoxId, string messageId, string vendorId, string data)
  40. {
  41. return mainDbService.AddServerMessage(
  42. ChargeBoxId: chargeBoxId,
  43. OutAction: Actions.DataTransfer.ToString(),
  44. OutRequest: new DataTransferRequest()
  45. {
  46. messageId = messageId,
  47. vendorId = vendorId,
  48. data = data
  49. }
  50. );
  51. }
  52. internal Task SendCertificateSignedRequest(string chargeBoxId, string crt)
  53. {
  54. return mainDbService.AddServerMessage(
  55. ChargeBoxId: chargeBoxId,
  56. OutAction: Actions.SignCertificate.ToString(),
  57. OutRequest: new CertificateSignedRequest()
  58. {
  59. certificateChain = crt
  60. }
  61. );
  62. }
  63. }