ServerMessageService.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, string serialNo = "")
  22. {
  23. if (string.IsNullOrEmpty(chargeBoxId)) return null;
  24. return mainDbService.AddServerMessage(
  25. ChargeBoxId: chargeBoxId,
  26. OutAction: Actions.GetConfiguration.ToString(),
  27. OutRequest: new GetConfigurationRequest() { key = new List<string>() },
  28. SerialNo: serialNo
  29. );
  30. }
  31. internal Task<string> SendChangeConfigurationRequest(string chargeBoxId, string key, string value, string serialNo = "")
  32. {
  33. return mainDbService.AddServerMessage(
  34. ChargeBoxId: chargeBoxId,
  35. OutAction: Actions.ChangeConfiguration.ToString(),
  36. OutRequest: new ChangeConfigurationRequest()
  37. {
  38. key = key,
  39. value = value
  40. },
  41. SerialNo: serialNo
  42. );
  43. }
  44. internal Task<string> SendDataTransferRequest(string chargeBoxId, string messageId, string vendorId, string data)
  45. {
  46. return mainDbService.AddServerMessage(
  47. ChargeBoxId: chargeBoxId,
  48. OutAction: Actions.DataTransfer.ToString(),
  49. OutRequest: new DataTransferRequest()
  50. {
  51. messageId = messageId,
  52. vendorId = vendorId,
  53. data = data
  54. }
  55. );
  56. }
  57. }