Robert 11 сар өмнө
parent
commit
78db9fbcd2

+ 4 - 1
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -165,6 +165,7 @@ namespace EVCB_OCPP.WSServer
         };
         private CancellationTokenSource _cts = new CancellationTokenSource();
         private CancellationToken _ct;
+        private Semaphore bootSemaphore = new Semaphore(10, 10);
         #endregion
 
         internal Dictionary<string, WsClientData> GetClientDic()
@@ -721,7 +722,8 @@ namespace EVCB_OCPP.WSServer
                                 {
                                     session.ChargePointVendor = bootNotificationRequest.chargePointVendor;
 
-                                    if (session.BootStatus == BootStatus.Startup)
+                                    if (session.BootStatus == BootStatus.Startup &&
+                                        bootSemaphore.WaitOne(0))
                                     {
                                         session.BootStatus = BootStatus.Initializing;
                                         session.AddTask(StartInitializeEVSE(session));
@@ -1016,6 +1018,7 @@ namespace EVCB_OCPP.WSServer
         {
             await InitializeEVSE(session);
             session.BootStatus = BootStatus.Pending;
+            bootSemaphore.Release();
         }
 
         private async Task InitializeEVSE(WsClientData session)

+ 5 - 0
EVCB_OCPP.WSServer/Service/ConfirmWaitingMessageSerevice.cs

@@ -212,6 +212,11 @@ namespace EVCB_OCPP.WSServer.Service
 
         internal async Task<MessageResult> WaitResultAsync(string msgId, int maxWaitSec = 65000, CancellationToken token = default)
         {
+            if (!asyncWaitingTasks.Keys.Contains(msgId))
+            {
+                return await mainDbService.TryGetResponseFromDb(msgId);
+            }
+
             var waiObj = new MessageResultWaitObject();
             asyncWaitingTasks.Add(msgId, waiObj);
             var task = waiObj.Lock.WaitAsync(token);

+ 1 - 1
EVCB_OCPP.WSServer/Service/DbService/ConnectionLogdbService.cs

@@ -264,7 +264,7 @@ public class ConnectionLogdbService : IConnectionLogdbService
         watch.Stop();
         if (watch.ElapsedMilliseconds > 1000)
         {
-            logger.LogWarning($"MachineLog Bundle Dapper {string.Join("/", times)} coint:{bundleHandlerData.Datas.Count()}");
+            logger.LogWarning($"MachineLog Bundle Dapper {string.Join("/", times)} count:{bundleHandlerData.Datas.Count()}");
         }
 
         return;

+ 5 - 3
EVCB_OCPP.WSServer/Service/DbService/MainDbService.cs

@@ -3,6 +3,7 @@ using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.ConnectionFactory;
 using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.WSServer.Helper;
+using EVCB_OCPP.WSServer.Message;
 using Microsoft.AspNetCore.Connections;
 using Microsoft.Data.SqlClient;
 using Microsoft.EntityFrameworkCore;
@@ -49,6 +50,7 @@ public interface IMainDbService
     Task AddMachineConfiguration(string chargeBoxId, string key, string value, bool isReadOnly, bool isExist = true);
     Task UpdateMachineConfiguration(string chargeBoxId, string item, string empty, bool v, bool isExists = true);
     Task<List<MachineConfigurations>> GetMachineConfiguration(string chargeBoxId);
+    Task<MessageResult> TryGetResponseFromDb(string msgId);
 }
 
 public class MainDbService : IMainDbService
@@ -477,7 +479,7 @@ public class MainDbService : IMainDbService
         updateMachineBasicInfoHandler = new GroupHandler<UpdateMachineBasicInfoParam>(
             handleFunc: BundelUpdateMachineBasicInfo,
             logger: loggerFactory.CreateLogger("UpdateMachineBasicInfoHandler"),
-            workerCnt: 10);
+            workerCnt: 1);
     }
 
     private void InitUpdateServerMessageUpdateOnHandler()
@@ -505,7 +507,7 @@ public class MainDbService : IMainDbService
             logger: loggerFactory.CreateLogger("GetMachineConfigurationHandler"),
             workerCnt: 10);
     }
-    
+
 
     private async Task UpdateMachineBasicInfoEF(string chargeBoxId, Machine machine)
     {
@@ -1125,7 +1127,7 @@ public class MainDbService : IMainDbService
         return machine.ConnectorType;
     }
 
-    public async Task SetMachineConnectionType(string chargeBoxId,int v, CancellationToken token = default)
+    public async Task SetMachineConnectionType(string chargeBoxId, int v, CancellationToken token = default)
     {
         using var db = await contextFactory.CreateDbContextAsync(token);