ServerMessageService.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.WSServer.Service.DbService;
  7. using Azure;
  8. using EVCB_OCPP.WSServer.Message;
  9. namespace EVCB_OCPP.WSServer.Service;
  10. public class ServerMessageService
  11. {
  12. public ServerMessageService(
  13. IMainDbService mainDbService
  14. , ILogger<ServerMessageService> logger)
  15. {
  16. this.mainDbService = mainDbService;
  17. this.logger = logger;
  18. }
  19. private readonly IMainDbService mainDbService;
  20. private readonly ILogger<ServerMessageService> logger;
  21. internal Task<string> SendGetEVSEConfigureRequest(string chargeBoxId, List<string> configKeys = default , string serialNo = "")
  22. {
  23. if (string.IsNullOrEmpty(chargeBoxId)) return null;
  24. List<string> toPassConfig = configKeys == default ? new List<string>() : configKeys;
  25. return mainDbService.AddServerMessage(
  26. ChargeBoxId: chargeBoxId,
  27. OutAction: Actions.GetConfiguration.ToString(),
  28. OutRequest: new GetConfigurationRequest() { key = toPassConfig },
  29. SerialNo: serialNo
  30. );
  31. }
  32. internal Task<string> SendChangeConfigurationRequest(string chargeBoxId, string key, string value, string serialNo = "")
  33. {
  34. return mainDbService.AddServerMessage(
  35. ChargeBoxId: chargeBoxId,
  36. OutAction: Actions.ChangeConfiguration.ToString(),
  37. OutRequest: new ChangeConfigurationRequest()
  38. {
  39. key = key,
  40. value = value
  41. },
  42. SerialNo: serialNo
  43. );
  44. }
  45. internal Task<string> SendDataTransferRequest(string chargeBoxId, string messageId, string vendorId, string data)
  46. {
  47. return mainDbService.AddServerMessage(
  48. ChargeBoxId: chargeBoxId,
  49. OutAction: Actions.DataTransfer.ToString(),
  50. OutRequest: new DataTransferRequest()
  51. {
  52. messageId = messageId,
  53. vendorId = vendorId,
  54. data = data
  55. }
  56. );
  57. }
  58. }