|
@@ -39,6 +39,7 @@ using NLog.Extensions.Logging;
|
|
|
using Microsoft.Data.SqlClient;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Collections.Concurrent;
|
|
|
+using EVCB_OCPP.WSServer.SuperSocket;
|
|
|
|
|
|
namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
@@ -63,21 +64,26 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
public ProtalServer(
|
|
|
IConfiguration configuration
|
|
|
- , IServiceProvider serviceProvider
|
|
|
, IDbContextFactory<MainDBContext> maindbContextFactory
|
|
|
+ , IDbContextFactory<ConnectionLogDBContext> connectionLogdbContextFactory
|
|
|
, IHostEnvironment environment
|
|
|
- , IOCPPWSServerFactory ocppWSServerFactory)
|
|
|
+ , IOCPPWSServerFactory ocppWSServerFactory
|
|
|
+ , IConnectionLogdbService connectionLogdbService
|
|
|
+ , WebDbService webDbService
|
|
|
+ ,IServiceProvider serviceProvider)
|
|
|
{
|
|
|
_ct = _cts.Token;
|
|
|
|
|
|
this.configuration = configuration;
|
|
|
- this.serviceProvider = serviceProvider;
|
|
|
this.maindbContextFactory = maindbContextFactory;
|
|
|
+ //this.connectionLogdbContextFactory = connectionLogdbContextFactory;
|
|
|
this.ocppWSServerFactory = ocppWSServerFactory;
|
|
|
+ this.connectionLogdbService = connectionLogdbService;
|
|
|
+ this.webDbService = webDbService;
|
|
|
isInDocker = !string.IsNullOrEmpty(configuration["DOTNET_RUNNING_IN_CONTAINER"]);
|
|
|
|
|
|
webConnectionString = configuration.GetConnectionString("WebDBContext");
|
|
|
- profileHandler = serviceProvider.GetService<ProfileHandler>();// new ProfileHandler(configuration, serviceProvider);
|
|
|
+ this.profileHandler = serviceProvider.GetService<ProfileHandler>();// new ProfileHandler(configuration, serviceProvider);
|
|
|
_loadingBalanceService = new LoadingBalanceService(configuration);
|
|
|
|
|
|
WarmUpLog();
|
|
@@ -89,9 +95,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
//private readonly Object _lockClientDic = new object();
|
|
|
private readonly Object _lockConfirmPacketList = new object();
|
|
|
private readonly IConfiguration configuration;
|
|
|
- private readonly IServiceProvider serviceProvider;
|
|
|
+ //private readonly IServiceProvider serviceProvider;
|
|
|
private readonly IDbContextFactory<MainDBContext> maindbContextFactory;
|
|
|
+ //private readonly IDbContextFactory<ConnectionLogDBContext> connectionLogdbContextFactory;
|
|
|
private readonly IOCPPWSServerFactory ocppWSServerFactory;
|
|
|
+ private readonly IConnectionLogdbService connectionLogdbService;
|
|
|
+ private readonly WebDbService webDbService;
|
|
|
private readonly ProfileHandler profileHandler;//= new ProfileHandler();
|
|
|
private readonly string webConnectionString;// = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
|
|
|
private readonly bool isInDocker;
|
|
@@ -168,10 +177,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
internal LoadingBalanceService LoadingBalanceService => _loadingBalanceService;
|
|
|
internal ProfileHandler ProfileHandler => profileHandler;
|
|
|
|
|
|
- public Task StartAsync(CancellationToken cancellationToken)
|
|
|
+ public async Task StartAsync(CancellationToken cancellationToken)
|
|
|
{
|
|
|
+ GlobalConfig.DenyModelNames = await webDbService.GetDenyModelNames();
|
|
|
Start();
|
|
|
- return Task.CompletedTask;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
@@ -1419,21 +1429,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async void WarmUpLog()
|
|
|
+ private void WarmUpLog()
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- using (var log = await serviceProvider.GetService<IDbContextFactory<ConnectionLogDBContext>>().CreateDbContextAsync())
|
|
|
- {
|
|
|
- log.MachineConnectionLog.ToList();
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Console.WriteLine(ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ connectionLogdbService.WarmUpLog();
|
|
|
}
|
|
|
|
|
|
private async Task WriteMachineLog(ClientData clientData, string data, string messageType, string errorMsg = "", bool isSent = false)
|
|
@@ -1447,25 +1445,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
logger.Fatal(clientData.Path + "]********************session ChargeBoxId null sessionId=" + clientData.SessionID);
|
|
|
}
|
|
|
- using (var db = await serviceProvider.GetService<IDbContextFactory<ConnectionLogDBContext>>().CreateDbContextAsync())
|
|
|
- {
|
|
|
- string sp = "[dbo].[uspInsertMachineConnectionLog] @CreatedOn," +
|
|
|
- "@ChargeBoxId,@MessageType,@Data,@Msg,@IsSent,@EVSEEndPoint,@Session";
|
|
|
- var dd = DateTime.UtcNow;
|
|
|
- SqlParameter[] parameter =
|
|
|
- {
|
|
|
- new SqlParameter("CreatedOn", SqlDbType.DateTime){ Value = dd },
|
|
|
- new SqlParameter("ChargeBoxId", SqlDbType.NVarChar, 50){ Value= clientData.ChargeBoxId==null?"unknown":clientData.ChargeBoxId.Replace("'","''") },
|
|
|
- new SqlParameter("MessageType", SqlDbType.NVarChar , 50){ Value = messageType.Replace("'","''")},
|
|
|
- new SqlParameter("Data", SqlDbType.NVarChar, -1) { Value = data.Replace("'", "''") },
|
|
|
- new SqlParameter("Msg", SqlDbType.NVarChar, 200) { Value = errorMsg.Replace("'", "''") },
|
|
|
- new SqlParameter("IsSent", SqlDbType.Bit) { Value = isSent },
|
|
|
- new SqlParameter("EVSEEndPoint", SqlDbType.NVarChar, 25) { Value = clientData.RemoteEndPoint == null ? "123" : clientData.RemoteEndPoint.ToString() },
|
|
|
- new SqlParameter("Session", SqlDbType.NVarChar, 36) { Value = clientData.SessionID == null ? "123" : clientData.SessionID }
|
|
|
- };
|
|
|
-
|
|
|
- await db.Database.ExecuteSqlRawAsync(sp, parameter);
|
|
|
- }
|
|
|
+
|
|
|
+ connectionLogdbService.WriteMachineLog(clientData, data, messageType, errorMsg, isSent);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|