|
@@ -70,6 +70,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
, IServiceProvider serviceProvider
|
|
|
, OcppWebsocketService websocketService
|
|
|
, ConfirmWaitingMessageSerevice confirmWaitingMessageSerevice
|
|
|
+ , StationConfigService stationConfigService
|
|
|
, OuterHttpClient httpClient)
|
|
|
{
|
|
|
_ct = _cts.Token;
|
|
@@ -85,6 +86,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
this.messageService = serverMessageService;
|
|
|
this.websocketService = websocketService;
|
|
|
this.confirmWaitingMessageSerevice = confirmWaitingMessageSerevice;
|
|
|
+ this.stationConfigService = stationConfigService;
|
|
|
this.httpClient = httpClient;
|
|
|
isInDocker = !string.IsNullOrEmpty(configuration["DOTNET_RUNNING_IN_CONTAINER"]);
|
|
|
|
|
@@ -115,6 +117,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
private readonly ServerMessageService messageService;
|
|
|
private readonly OcppWebsocketService websocketService;
|
|
|
private readonly ConfirmWaitingMessageSerevice confirmWaitingMessageSerevice;
|
|
|
+ private readonly StationConfigService stationConfigService;
|
|
|
private readonly ProfileHandler profileHandler;//= new ProfileHandler();
|
|
|
//private readonly string webConnectionString;// = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
|
|
|
private readonly bool isInDocker;
|
|
@@ -1038,7 +1041,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
session.ChargeBoxId, key: "StopTransactionOnInvalidId", value: "True");
|
|
|
}
|
|
|
|
|
|
- await GetnChecknUpdateConfig(session.ChargeBoxId, session.DisconnetCancellationToken);
|
|
|
+ await stationConfigService.CheckAndUpdateEvseConfig(session.ChargeBoxId, session.DisconnetCancellationToken);
|
|
|
|
|
|
sendTask = async () => await messageService.SendDataTransferRequest(
|
|
|
session.ChargeBoxId,
|
|
@@ -1048,58 +1051,6 @@ namespace EVCB_OCPP.WSServer
|
|
|
await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
|
|
|
}
|
|
|
|
|
|
- internal async Task GetnChecknUpdateConfig(string chargeBoxId, CancellationToken token = default)
|
|
|
- {
|
|
|
- MessageResult response = await GetEvseCurrentConfig(chargeBoxId, token);
|
|
|
- if (!response.Success || response.Message is not GetConfigurationConfirmation confirmation)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Dictionary<string,string> configs = await GetEvseDBCurrentConfig(chargeBoxId, token);
|
|
|
- if (configs == null)
|
|
|
- {
|
|
|
- logger.LogInformation("{0} get station config failed", chargeBoxId);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- await ComparenUpdateConfig(chargeBoxId,
|
|
|
- evseCurrentConfigs: confirmation.configurationKey.ToDictionary(x => x.key, x => x.value),
|
|
|
- evseDbConfigs: configs,
|
|
|
- token);
|
|
|
- }
|
|
|
-
|
|
|
- private async Task<MessageResult> GetEvseCurrentConfig(string chargeBoxId, CancellationToken token = default)
|
|
|
- {
|
|
|
- var sendTask = async () => await messageService.SendGetEVSEConfigureRequest(chargeBoxId);
|
|
|
- var response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, token);
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- private Task<Dictionary<string, string>> GetEvseDBCurrentConfig(string chargeBoxId, CancellationToken token = default)
|
|
|
- {
|
|
|
- return webDbService.GetCustomerStationEvseConfig(chargeBoxId, token);
|
|
|
- }
|
|
|
-
|
|
|
- internal async Task ComparenUpdateConfig(string chargeBoxId,
|
|
|
- Dictionary<string,string> evseCurrentConfigs,
|
|
|
- Dictionary<string, string> evseDbConfigs,
|
|
|
- CancellationToken token = default)
|
|
|
- {
|
|
|
- foreach(var config in evseDbConfigs)
|
|
|
- {
|
|
|
- if (evseCurrentConfigs.Keys.Contains(config.Key) &&
|
|
|
- evseCurrentConfigs[config.Key] == config.Value)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- MessageResult response = null;
|
|
|
- var sendTask = async () => await messageService.SendChangeConfigurationRequest(chargeBoxId, config.Key, config.Value);
|
|
|
- response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, token);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void Send(WsClientData session, string msg, string messageType, string errorMsg = "")
|
|
|
{
|
|
|
try
|