ServerMessageService.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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)
  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. );
  29. }
  30. internal Task<string> SendChangeConfigurationRequest(string chargeBoxId, string key, string value)
  31. {
  32. return mainDbService.AddServerMessage(
  33. ChargeBoxId: chargeBoxId,
  34. OutAction: Actions.ChangeConfiguration.ToString(),
  35. OutRequest: new ChangeConfigurationRequest()
  36. {
  37. key = key,
  38. value = value
  39. });
  40. }
  41. internal Task<string> SendDataTransferRequest(string chargeBoxId, string messageId, string vendorId, string data)
  42. {
  43. return mainDbService.AddServerMessage(
  44. ChargeBoxId: chargeBoxId,
  45. OutAction: Actions.DataTransfer.ToString(),
  46. OutRequest: new DataTransferRequest()
  47. {
  48. messageId = messageId,
  49. vendorId = vendorId,
  50. data = data
  51. }
  52. );
  53. }
  54. }