|
@@ -57,9 +57,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
public ProtalServer(
|
|
|
ILogger<ProtalServer> logger
|
|
|
, IConfiguration configuration
|
|
|
- , IDbContextFactory<MainDBContext> maindbContextFactory
|
|
|
+ //, IDbContextFactory<MainDBContext> maindbContextFactory
|
|
|
, IMainDbService mainDbService
|
|
|
- , IDbContextFactory<ConnectionLogDBContext> connectionLogdbContextFactory
|
|
|
+ //, IDbContextFactory<ConnectionLogDBContext> connectionLogdbContextFactory
|
|
|
, ISqlConnectionFactory<WebDBConetext> webDbConnectionFactory
|
|
|
, ISqlConnectionFactory<MainDBContext> mainDbConnectionFactory
|
|
|
, IHostEnvironment environment
|
|
@@ -75,9 +75,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
_ct = _cts.Token;
|
|
|
this.logger = logger;
|
|
|
this.configuration = configuration;
|
|
|
- this.maindbContextFactory = maindbContextFactory;
|
|
|
+ //this.maindbContextFactory = maindbContextFactory;
|
|
|
this.mainDbService = mainDbService;
|
|
|
- this.webDbConnectionFactory = webDbConnectionFactory;
|
|
|
+ //this.webDbConnectionFactory = webDbConnectionFactory;
|
|
|
//this.connectionLogdbContextFactory = connectionLogdbContextFactory;
|
|
|
//this.ocppWSServerFactory = ocppWSServerFactory;
|
|
|
this.connectionLogdbService = connectionLogdbService;
|
|
@@ -104,9 +104,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
private readonly ILogger<ProtalServer> logger;
|
|
|
private readonly IConfiguration configuration;
|
|
|
//private readonly IServiceProvider serviceProvider;
|
|
|
- private readonly IDbContextFactory<MainDBContext> maindbContextFactory;
|
|
|
+ //private readonly IDbContextFactory<MainDBContext> maindbContextFactory;
|
|
|
private readonly IMainDbService mainDbService;
|
|
|
- private readonly ISqlConnectionFactory<WebDBConetext> webDbConnectionFactory;
|
|
|
+ //private readonly ISqlConnectionFactory<WebDBConetext> webDbConnectionFactory;
|
|
|
|
|
|
//private readonly IDbContextFactory<ConnectionLogDBContext> connectionLogdbContextFactory;
|
|
|
//private readonly IOCPPWSServerFactory ocppWSServerFactory;
|
|
@@ -714,8 +714,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
if (session.BootStatus == BootStatus.Startup)
|
|
|
{
|
|
|
- session.AddTask(InitializeEVSE(session));
|
|
|
session.BootStatus = BootStatus.Initializing;
|
|
|
+ session.AddTask(StartInitializeEVSE(session));
|
|
|
}
|
|
|
|
|
|
if (bootNotificationConfirmation.status == Packet.Messages.SubTypes.RegistrationStatus.Accepted)
|
|
@@ -995,22 +995,23 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private async Task StartInitializeEVSE(WsClientData session)
|
|
|
+ {
|
|
|
+ await InitializeEVSE(session);
|
|
|
+ session.BootStatus = BootStatus.Pending;
|
|
|
+ }
|
|
|
+
|
|
|
private async Task InitializeEVSE(WsClientData session)
|
|
|
{
|
|
|
// Pending mode 下發設定
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ string connectorType = await mainDbService.GetMachineConnectorType(session.ChargeBoxId);
|
|
|
+ if (!string.IsNullOrEmpty(connectorType) &&
|
|
|
+ (connectorType.Contains("6") || connectorType.Contains("7") || connectorType.Contains("8") || connectorType.Contains("9")))
|
|
|
{
|
|
|
- var machine = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefaultAsync();
|
|
|
- if (machine != null)
|
|
|
- {
|
|
|
- if (machine.ConnectorType.Contains("6") || machine.ConnectorType.Contains("7") || machine.ConnectorType.Contains("8") || machine.ConnectorType.Contains("9"))
|
|
|
- {
|
|
|
- session.IsAC = false;
|
|
|
- }
|
|
|
- machine.ConnectionType = session.UriScheme.Contains("wss") ? 2 : 1;
|
|
|
- await db.SaveChangesAsync();
|
|
|
- }
|
|
|
+ session.IsAC = false;
|
|
|
}
|
|
|
+ await mainDbService.SetMachineConnectionType(session.ChargeBoxId, session.UriScheme.Contains("wss") ? 2 : 1);
|
|
|
+
|
|
|
string requestId = string.Empty;
|
|
|
MessageResult response = null;
|
|
|
Func<Task<string>> sendTask = null;
|
|
@@ -1020,7 +1021,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
sendTask = async () => await messageService.SendChangeConfigurationRequest(
|
|
|
session.ChargeBoxId, key: "DefaultPrice", value: displayPriceText);
|
|
|
- await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
|
|
|
+ await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
|
|
|
|
|
|
if (session.CustomerId == new Guid("298918C0-6BB5-421A-88CC-4922F918E85E") || session.CustomerId == new Guid("9E6BFDCC-09FB-4DAB-A428-43FE507600A3"))
|
|
|
{
|
|
@@ -1035,7 +1036,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
|
|
|
sendTask = async () => await messageService.SendGetEVSEConfigureRequest(session.ChargeBoxId);
|
|
|
- response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
|
|
|
+ response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
|
|
|
if (response.Success && response.Message is GetConfigurationConfirmation confirmation)
|
|
|
{
|
|
|
await CheckandUpdateConfig(session.ChargeBoxId, confirmation.configurationKey.ToDictionary(x => x.key, x => x.value));
|
|
@@ -1046,15 +1047,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
messageId: "ID_FirmwareVersion",
|
|
|
vendorId: "Phihong Technology",
|
|
|
data: string.Empty);
|
|
|
- await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
|
|
|
-
|
|
|
- if (session.BootStatus == BootStatus.Initializing)
|
|
|
- {
|
|
|
- session.BootStatus = BootStatus.Pending;
|
|
|
- }
|
|
|
+ await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
|
|
|
}
|
|
|
|
|
|
- private async Task CheckandUpdateConfig(string chargeBoxId, Dictionary<string,string> currentConfigs)
|
|
|
+ internal async Task CheckandUpdateConfig(string chargeBoxId, Dictionary<string,string> currentConfigs, CancellationToken token = default)
|
|
|
{
|
|
|
List<KeyValuePair<string, string>> configs = await webDbService.GetCustomerStationEvseConfig(chargeBoxId);
|
|
|
if (configs == null)
|
|
@@ -1073,7 +1069,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
MessageResult response = null;
|
|
|
var sendTask = async () => await messageService.SendChangeConfigurationRequest(chargeBoxId, config.Key, config.Value);
|
|
|
- response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
|
|
|
+ response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, token);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1097,76 +1093,6 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
- async private Task<string> SetDefaultFee(WsClientData client)
|
|
|
- {
|
|
|
- string displayPriceText = string.Empty;
|
|
|
- string charingPriceText = string.Empty;
|
|
|
-
|
|
|
- if (string.IsNullOrEmpty(client.ChargeBoxId)) return displayPriceText;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
-
|
|
|
- using (SqlConnection conn = await webDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input, 36);
|
|
|
- string displayPricestrSql = "";
|
|
|
- string strSql = "";
|
|
|
-
|
|
|
- if (client.IsAC)
|
|
|
- {
|
|
|
- displayPricestrSql = " SELECT [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour" +
|
|
|
- " ,[AC_ParkingFee] as ParkingFee, [Currency] FROM[StationMachine] left join[dbo].[Station]" +
|
|
|
- " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
-
|
|
|
- strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee] FROM[StationMachine] left join [dbo].[StationFee]" +
|
|
|
- " on[StationMachine].StationId = StationFee.StationId where StationMachine.MachineId =@MachineId and StationFee.IsAC=1; ";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- displayPricestrSql = " SELECT [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour" +
|
|
|
- " ,[DC_ParkingFee] as ParkingFee, [Currency] FROM[StationMachine] left join[dbo].[Station]" +
|
|
|
- " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
-
|
|
|
- strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee] FROM[StationMachine] left join [dbo].[StationFee]" +
|
|
|
- " on[StationMachine].StationId = StationFee.StationId where StationMachine.MachineId =@MachineId and StationFee.IsAC=0; ";
|
|
|
-
|
|
|
- }
|
|
|
- //var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
|
|
|
- var result = await conn.QueryFirstOrDefaultAsync<StationFee>(displayPricestrSql, parameters);
|
|
|
- if (result == default)
|
|
|
- {
|
|
|
- return string.Empty;
|
|
|
- }
|
|
|
- var stationPrice = result;//.First();
|
|
|
-
|
|
|
- if (stationPrice.BillingMethod == 1)
|
|
|
- {
|
|
|
- var chargingPriceResult = await conn.QueryAsync<ChargingPrice>(strSql, parameters);
|
|
|
- client.ChargingPrices = chargingPriceResult.ToList();
|
|
|
- if (string.IsNullOrEmpty(client.ChargingPrices[0].StartTime))
|
|
|
- {
|
|
|
- client.ChargingPrices = new List<ChargingPrice>();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- displayPriceText = stationPrice.FeeName;
|
|
|
- client.BillingMethod = stationPrice.BillingMethod;
|
|
|
- client.Currency = stationPrice.Currency;
|
|
|
- client.ChargingFeebyHour = stationPrice.ChargingFeebyHour;
|
|
|
- client.ParkingFee = stationPrice.ParkingFee;
|
|
|
- client.IsBilling = true;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("SetDefaultFee", ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
- return displayPriceText;
|
|
|
- }
|
|
|
-
|
|
|
internal async void RemoveClient(WsClientData session, string reason)
|
|
|
{
|
|
|
if (session == null)
|