Robert 1 year ago
parent
commit
cbdd87ba9d

+ 1 - 0
EVCB_OCPP.WSServer/Helper/QueueSemaphore.cs

@@ -59,6 +59,7 @@ public class QueueSemaphore
             semaphore.Release();
             return true;
         }
+        _semaphore.Release();
         return false;
     }
 }

+ 8 - 8
EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs

@@ -3,7 +3,7 @@ using EVCB_OCPP.Packet.Messages;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
-
+using NLog;
 using OCPPServer.Protocol;
 
 
@@ -16,7 +16,7 @@ namespace EVCB_OCPP.WSServer.Message
     /// </summary>
     internal class BasicMessageHandler
     {
-        static protected ILogger logger;
+        static internal Logger logger = NLog.LogManager.GetCurrentClassLogger();
 
         #region 傳送 or 解析訊息需要欄位
         private const int INDEX_MESSAGEID = 0;
@@ -83,7 +83,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
             else
             {
-                logger.LogError(string.Format("confirmation is null  or InVaild in GenerateConfirmation Method"), "Warning");
+                logger.Error(string.Format("confirmation is null  or InVaild in GenerateConfirmation Method"), "Warning");
             }
             return msg;
         }
@@ -97,7 +97,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
             else
             {
-                logger.LogError(string.Format("confirmation is null  or InVaild in GenerateConfirmation Method"), "Warning");
+                logger.Error(string.Format("confirmation is null  or InVaild in GenerateConfirmation Method"), "Warning");
             }
             return msg;
         }
@@ -116,17 +116,17 @@ namespace EVCB_OCPP.WSServer.Message
                 {
                     if(!request.Validate())
                     {
-                        logger.LogError("!Validate", "Warning");
+                        logger.Error("!Validate", "Warning");
                     }
 
                     if (request == null)
                     {
-                        logger.LogError("!NULL", "Warning");
+                        logger.Error("!NULL", "Warning");
                     }
 
                 }
 
-                logger.LogError(string.Format("confirmation is null  or InVaild in GenerateRequest Method "+ action), "Warning");
+                logger.Error(string.Format("confirmation is null  or InVaild in GenerateRequest Method "+ action), "Warning");
             }
             return msg;
         }
@@ -141,7 +141,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
             else
             {
-                logger.LogError(string.Format("confirmation is null  or InVaild in GenerateRequest Method"), "Warning");
+                logger.Error(string.Format("confirmation is null  or InVaild in GenerateRequest Method"), "Warning");
             }
             return msg;
         }

+ 14 - 11
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -236,16 +236,12 @@ internal partial class ProfileHandler
                             int.TryParse(configValue, out heartbeat_interval);
                         }
 
-                        if (session.IsPending == true)
-                        {
-                            session.IsPending = false;
-                        }
-                        if (session.IsPending is null)
-                        {
-                            session.IsPending = true;
-                        }
+                        session.IsPending = false;
 
-                        var confirm = new BootNotificationConfirmation() { currentTime = DateTime.UtcNow, interval = session.IsPending.Value ? 5 : heartbeat_interval, status = session.IsPending.Value ? RegistrationStatus.Pending : RegistrationStatus.Accepted };
+                        var confirm = new BootNotificationConfirmation() {
+                            currentTime = DateTime.UtcNow, 
+                            interval = session.IsPending ? 5 : heartbeat_interval,
+                            status = session.IsPending ? RegistrationStatus.Pending : RegistrationStatus.Accepted };
 
                         result.Message = confirm;
                         result.Success = true;
@@ -617,8 +613,15 @@ internal partial class ProfileHandler
                         var businessService = await businessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
                         getServiceTime = stopTrasactionTimer.ElapsedMilliseconds;
 
-                        var _idTagInfo = string.IsNullOrEmpty(_request.idTag) ? null : (_request.idTag == "Backend" ?
-                            new IdTagInfo() { expiryDate = utcNow.AddDays(1), status = AuthorizationStatus.Accepted } : (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo);
+
+                        var _idTagInfo = string.IsNullOrEmpty(_request.idTag) ? null :  (
+                            _request.idTag == "Backend" ? 
+                                new IdTagInfo() { 
+                                    expiryDate = utcNow.AddDays(1), 
+                                    status = AuthorizationStatus.Accepted 
+                                } :
+                                (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo
+                            );
                         getTagInfoTime = stopTrasactionTimer.ElapsedMilliseconds;
 
                         //特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電

+ 2 - 2
EVCB_OCPP.WSServer/Service/BusinessServiceFactory.cs

@@ -24,8 +24,8 @@ public static class BusinessServiceFactoryRegistration
 {
     public static void AddBusinessServiceFactory(this IServiceCollection services)
     {
-        services.AddScoped<OuterBusinessService>();
-        services.AddScoped<LocalBusinessService>();
+        services.AddSingleton<OuterBusinessService>();
+        services.AddSingleton<LocalBusinessService>();
         services.AddSingleton<IBusinessServiceFactory, BusinessServiceFactory>();
     }
 }

+ 1 - 1
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -18,7 +18,7 @@ namespace OCPPServer.Protocol
 
         public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
 
-        public bool? IsPending { set; get; }
+        public bool IsPending { set; get; } = true;
         public bool IsCheckIn { set; get; }
 
         public string ChargeBoxId { set; get; }

+ 1 - 1
EVCB_OCPP.WSServer/SuperSocket/OCPPWSServer.cs

@@ -245,7 +245,7 @@ public class OCPPWSServer : WebSocketServer<ClientData>
 
 
 
-
+        logger.LogInformation(string.Format("ValidateHandshake PASS: {0}", session.Path));
         return true;
     }
 }