Bläddra i källkod

1. 幫支援 2.0.1 電樁進行轉址
2.心跳 改成60秒間隔 & 強制剔除時間延長到5分鐘

Jessica Tseng 4 år sedan
förälder
incheckning
62f62a2cd2
32 ändrade filer med 158 tillägg och 273 borttagningar
  1. 6 12
      EVCB_OCPP.WSServer/Dto/ConnectorErrorStauts.cs
  2. 0 4
      EVCB_OCPP.WSServer/Dto/ErrorDetails.cs
  3. 8 11
      EVCB_OCPP.WSServer/GlobalConfig.cs
  4. 2 6
      EVCB_OCPP.WSServer/Helper/Convertor.cs
  5. 6 14
      EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs
  6. 14 17
      EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs
  7. 3 6
      EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs
  8. 0 3
      EVCB_OCPP.WSServer/Message/LocalAuthListManagementProfileHandler.cs
  9. 2 6
      EVCB_OCPP.WSServer/Message/MessageResult.cs
  10. 0 4
      EVCB_OCPP.WSServer/Message/NeedConfirmMessage.cs
  11. 13 17
      EVCB_OCPP.WSServer/Message/OCPP20MessageHandler.cs
  12. 3 6
      EVCB_OCPP.WSServer/Message/RemoteTriggerHandler.cs
  13. 1 4
      EVCB_OCPP.WSServer/Message/ReservationProfileHandler.cs
  14. 8 16
      EVCB_OCPP.WSServer/Message/SecurityProfileHandler.cs
  15. 1 3
      EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs
  16. 2 11
      EVCB_OCPP.WSServer/Program.cs
  17. 39 44
      EVCB_OCPP.WSServer/ProtalServer.cs
  18. 2 4
      EVCB_OCPP.WSServer/Service/BusinessServiceFactory.cs
  19. 2 3
      EVCB_OCPP.WSServer/Service/HttpClientService.cs
  20. 1 3
      EVCB_OCPP.WSServer/Service/LoadingBalanceService.cs
  21. 8 10
      EVCB_OCPP.WSServer/Service/LocalBusinessService.cs
  22. 7 8
      EVCB_OCPP.WSServer/Service/OuterBusinessService.cs
  23. 1 2
      EVCB_OCPP.WSServer/Service/OuterHttpClient.cs
  24. 1 6
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallCmd.cs
  25. 0 5
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallErrorCmd.cs
  26. 0 5
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallResultCmd.cs
  27. 0 1
      EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs
  28. 25 29
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLog.cs
  29. 1 8
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLogFactory.cs
  30. 1 1
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubCommandParser.cs
  31. 1 3
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubProtocol.cs
  32. 0 1
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPWSServer.cs

+ 6 - 12
EVCB_OCPP.WSServer/Dto/ConnectorErrorStauts.cs

@@ -1,26 +1,20 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.WSServer.Dto
+namespace EVCB_OCPP.WSServer.Dto
 {
     public class ConnectorErrorStauts
     {
-        
+
         public byte ConnectorId { get; set; }
 
         public int Status { get; set; }
 
         public int ChargePointErrorCodeId { get; set; }
-    
+
         public string ErrorInfo { get; set; }
-      
+
         public string VendorId { get; set; }
-      
+
         public string VendorErrorCode { get; set; }
 
-       
+
     }
 }

+ 0 - 4
EVCB_OCPP.WSServer/Dto/ErrorDetails.cs

@@ -1,9 +1,5 @@
 using EVCB_OCPP.Packet.Messages.SubTypes;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Dto
 {

+ 8 - 11
EVCB_OCPP.WSServer/GlobalConfig.cs

@@ -2,9 +2,6 @@
 using System;
 using System.Collections.Generic;
 using System.Configuration;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer
 {
@@ -21,9 +18,9 @@ namespace EVCB_OCPP.WSServer
         /// <summary>
         /// 預設心跳間隔時間 單位:秒
         /// </summary>
-        private static int DEFAULT_HEARTBEAT_INTERVAL = 15;
+        private static int DEFAULT_HEARTBEAT_INTERVAL = 60;
+
 
-   
 
         /// <summary>
         ///WS Port
@@ -39,17 +36,17 @@ namespace EVCB_OCPP.WSServer
         /// <summary>
         /// Load setting from app.config 
         /// </summary>
-        public static bool  LoadAPPConfig()
+        public static bool LoadAPPConfig()
         {
             bool result = false;
             string key = string.Empty;
             try
             {
-               
+
                 for (int i = 0; i < ConfigKeys.Count; i++)
                 {
                     key = ConfigKeys[i];
-                    switch(key)
+                    switch (key)
                     {
                         case "WSPort":// convert to int type                       
                             {
@@ -75,10 +72,10 @@ namespace EVCB_OCPP.WSServer
             }
             catch (Exception ex)
             {
-                Console.WriteLine(key + " Load from APPConfig "+ ex.ToString()); 
-              
+                Console.WriteLine(key + " Load from APPConfig " + ex.ToString());
+
             }
-            
+
             return result;
         }
 

+ 2 - 6
EVCB_OCPP.WSServer/Helper/Convertor.cs

@@ -1,13 +1,9 @@
 using EVCB_OCPP.Packet.Features;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Helper
 {
-    public  static class Convertor
+    public static class Convertor
     {
         public static Actions GetAction(string action)
         {
@@ -23,6 +19,6 @@ namespace EVCB_OCPP.WSServer.Helper
             return result;
         }
 
-        
+
     }
 }

+ 6 - 14
EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs

@@ -1,16 +1,8 @@
-using EVCB_OCPP.Packet.Features;
-using EVCB_OCPP.Packet.Messages;
-using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP.Packet.Messages;
 using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
 using Newtonsoft.Json.Serialization;
 using NLog;
 using OCPPServer.Protocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 
 namespace EVCB_OCPP.WSServer.Message
@@ -45,7 +37,7 @@ namespace EVCB_OCPP.WSServer.Message
         private const string DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
         private const string DATE_FORMAT_WITH_MS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
         #endregion
-        
+
         private OCPP16MessageHandler _ocpp16Handler = new OCPP16MessageHandler();
         private OCPP20MessageHandler _ocpp20Handler = new OCPP20MessageHandler();
 
@@ -78,8 +70,8 @@ namespace EVCB_OCPP.WSServer.Message
             return msg;
 
         }
-        
-        static internal string GenerateConfirmation(string uniqueId,IConfirmation confirmation)
+
+        static internal string GenerateConfirmation(string uniqueId, IConfirmation confirmation)
         {
             string msg = string.Empty;
             if (confirmation != null && confirmation.Validate())
@@ -108,7 +100,7 @@ namespace EVCB_OCPP.WSServer.Message
             return msg;
         }
 
-        static internal string GenerateRequest(string uniqueId, string action,IRequest request)
+        static internal string GenerateRequest(string uniqueId, string action, IRequest request)
         {
             string msg = string.Empty;
             if (request != null && request.Validate())
@@ -129,7 +121,7 @@ namespace EVCB_OCPP.WSServer.Message
             if (request != null && request.Validate())
             {
 
-                msg = string.Format(CALL_FORMAT, uniqueId, action, JsonConvert.SerializeObject(request, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }));
+                msg = string.Format(CALL_FORMAT, uniqueId, action, JsonConvert.SerializeObject(request, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }));
             }
             else
             {

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

@@ -1,27 +1,22 @@
-using System;
-using System.Collections.Generic;
-using System.Data.Entity;
-using System.Data.SqlClient;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using EVCB_OCPP.Domain;
+using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.Models.Database;
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.Core;
 using EVCB_OCPP.Packet.Messages.SubTypes;
-using EVCB_OCPP.WSServer.Service;
 using EVCB_OCPP.WSServer.Dto;
+using EVCB_OCPP.WSServer.Service;
 using Newtonsoft.Json;
+using NLog;
 using OCPPPackage.Profiles;
 using OCPPServer.Protocol;
-using System.Configuration;
-using System.Transactions;
-using System.Data.Entity.Core;
-using System.Data.Entity.Validation;
-using NLog;
+using System;
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Data.SqlClient;
 using System.Diagnostics;
+using System.Linq;
+using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
@@ -267,7 +262,9 @@ namespace EVCB_OCPP.WSServer.Message
                             int _transactionId = -1;
 
                             var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
-                            var _idTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };                        
+                            //var _idTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };                        
+                            var _idTagInfo = _request.idTag == "Backend" ? new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : await businessService.Authorize(session.ChargeBoxId, _request.idTag);
+
 
                             using (var db = new MainDBContext())
                             {
@@ -330,7 +327,7 @@ namespace EVCB_OCPP.WSServer.Message
                             int _ConnectorId = 0;
 
                             var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
-                            var _idTagInfo =  new IdTagInfo() {  status = AuthorizationStatus.Accepted };
+                            var _idTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
 
 
                             using (var db = new MainDBContext())
@@ -653,7 +650,7 @@ namespace EVCB_OCPP.WSServer.Message
                             if (_confirm.configurationKey != null)
                             {
                                 foreach (var item in _confirm.configurationKey)
-                                {                                    
+                                {
                                     string oldValue = string.Empty;
                                     var foundConfig = configure.Find(x => x.ConfigureName == item.key);
 

+ 3 - 6
EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs

@@ -6,11 +6,8 @@ using EVCB_OCPP.Packet.Messages.FirmwareManagement;
 using Newtonsoft.Json;
 using OCPPServer.Protocol;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Data.Entity;
+using System.Linq;
 
 namespace EVCB_OCPP.WSServer.Message
 {
@@ -94,7 +91,7 @@ namespace EVCB_OCPP.WSServer.Message
                                     {
                                         item.EVSE_Status = (int)_request.status;
                                         item.FinishedOn = DateTime.Now;
-                                         if(string.IsNullOrEmpty(item.EVSE_Value))
+                                        if (string.IsNullOrEmpty(item.EVSE_Value))
                                         {
                                             Console.WriteLine("怎麼悾悾的");
                                         }
@@ -173,7 +170,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)1;//OK
-                                operation.EVSE_Value = string.IsNullOrEmpty(evse_rep)?operation.EVSE_Value: evse_rep;
+                                operation.EVSE_Value = string.IsNullOrEmpty(evse_rep) ? operation.EVSE_Value : evse_rep;
                                 db.SaveChanges();
                             }
 

+ 0 - 3
EVCB_OCPP.WSServer/Message/LocalAuthListManagementProfileHandler.cs

@@ -4,10 +4,7 @@ using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.LocalAuthListManagement;
 using OCPPServer.Protocol;
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {

+ 2 - 6
EVCB_OCPP.WSServer/Message/MessageResult.cs

@@ -1,9 +1,5 @@
 using EVCB_OCPP.Packet.Messages;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
@@ -11,7 +7,7 @@ namespace EVCB_OCPP.WSServer.Message
     {
 
         internal MessageResult()
-        {          
+        {
             Success = true;
         }
 
@@ -42,7 +38,7 @@ namespace EVCB_OCPP.WSServer.Message
     }
 
 
-    internal class  BasicMessageResult
+    internal class BasicMessageResult
     {
         internal IRequest Request { set; get; }
 

+ 0 - 4
EVCB_OCPP.WSServer/Message/NeedConfirmMessage.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {

+ 13 - 17
EVCB_OCPP.WSServer/Message/OCPP20MessageHandler.cs

@@ -1,17 +1,13 @@
-using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP.Packet.Messages;
+using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP20.Packet.Features;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using NLog;
 using OCPPServer.Protocol;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using I20Request = EVCB_OCPP20.Packet.Messages.IRequest;
 using I20Confirmation = EVCB_OCPP20.Packet.Messages.IConfirmation;
-using EVCB_OCPP.Packet.Messages;
-using EVCB_OCPP20.Packet.Features;
+using I20Request = EVCB_OCPP20.Packet.Messages.IRequest;
 
 namespace EVCB_OCPP.WSServer.Message
 {
@@ -46,7 +42,7 @@ namespace EVCB_OCPP.WSServer.Message
         private const string DATE_FORMAT_WITH_MS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
         #endregion
 
-       
+
 
 
         /// <summary>
@@ -113,14 +109,14 @@ namespace EVCB_OCPP.WSServer.Message
                             {
                                 BasicMessageResult baseResult = UnPackPayloadbyCallResult(client.queue20, msg.Id, msg.Payload.ToString());
 
-                                if (baseResult.Confirmation != null)
+                                if (baseResult.Confirmation20 != null)
                                 {
 
-                                    if (baseResult.Confirmation.Validate())
+                                    if (baseResult.Confirmation20.Validate())
                                     {
                                         result.Id = TYPENUMBER_CALLRESULT;
-                                        result.Message = baseResult.Confirmation;
-                                        result.Action = baseResult.Confirmation.GetRequest().Action;
+                                        result.Message = baseResult.Confirmation20;
+                                        result.Action = baseResult.Confirmation20.GetRequest().Action;
                                         //return data
                                     }
                                     else
@@ -128,7 +124,7 @@ namespace EVCB_OCPP.WSServer.Message
                                         string replyMsg = BasicMessageHandler.GenerateCallError(msg.Id, OCPPErrorCodes.OccurenceConstraintViolation.ToString(),
                                       OCPPErrorDescription.OccurenceConstraintViolation);
                                         result.Id = TYPENUMBER_CALLRESULT;
-                                        result.Message = baseResult.Confirmation;
+                                        result.Message = baseResult.Confirmation20;
                                         result.Success = false;
                                         result.CallErrorMsg = replyMsg;
                                         result.Exception = new Exception("Validate Failed");
@@ -139,7 +135,7 @@ namespace EVCB_OCPP.WSServer.Message
                                     string replyMsg = BasicMessageHandler.GenerateCallError(msg.Id, OCPPErrorCodes.OccurenceConstraintViolation.ToString(),
                                    OCPPErrorDescription.OccurenceConstraintViolation);
                                     result.Id = TYPENUMBER_CALLRESULT;
-                                    result.Message = baseResult.Confirmation;
+                                    result.Message = baseResult.Confirmation20;
                                     result.Success = false;
                                     result.CallErrorMsg = replyMsg;
                                     result.Exception = baseResult.Exception;
@@ -250,7 +246,7 @@ namespace EVCB_OCPP.WSServer.Message
 
         private BasicMessageResult UnPackPayloadbyCall(string action, string payload)
         {
-           
+
             BasicMessageResult result = new BasicMessageResult();
             try
             {
@@ -267,7 +263,7 @@ namespace EVCB_OCPP.WSServer.Message
 
             return result;
 
-           
+
         }
 
         private BasicMessageResult UnPackPayloadbyCallResult(EVCB_OCPP20.Packet.Messages.Basic.Queue requestQueue, string uniqueId, string payload)

+ 3 - 6
EVCB_OCPP.WSServer/Message/RemoteTriggerHandler.cs

@@ -4,16 +4,13 @@ using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.RemoteTrigger;
 using OCPPServer.Protocol;
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
     internal partial class ProfileHandler
     {
-      
+
 
         internal MessageResult ExecuteRemoteTriggerConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
         {
@@ -21,7 +18,7 @@ namespace EVCB_OCPP.WSServer.Message
 
             switch (action)
             {
-                case Actions.TriggerMessage:               
+                case Actions.TriggerMessage:
                     {
                         TriggerMessageConfirmation _confirm = confirm as TriggerMessageConfirmation;
                         TriggerMessageRequest _request = _confirm.GetRequest() as TriggerMessageRequest;
@@ -57,7 +54,7 @@ namespace EVCB_OCPP.WSServer.Message
 
             switch (action)
             {
-                case Actions.TriggerMessage:               
+                case Actions.TriggerMessage:
                     {
                         using (var db = new MainDBContext())
                         {

+ 1 - 4
EVCB_OCPP.WSServer/Message/ReservationProfileHandler.cs

@@ -4,16 +4,13 @@ using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.Reservation;
 using OCPPServer.Protocol;
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
     internal partial class ProfileHandler
     {
-        
+
 
         internal MessageResult ExecuteReservationConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
         {

+ 8 - 16
EVCB_OCPP.WSServer/Message/SecurityProfileHandler.cs

@@ -1,30 +1,22 @@
-using EVCB_OCPP.Domain;
-using EVCB_OCPP.Packet.Features;
+using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
-using EVCB_OCPP.Packet.Messages.Security;
 using OCPPServer.Protocol;
 using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
     internal partial class ProfileHandler
     {
         internal MessageResult ExecuteSecurityRequest(Actions action, ClientData session, IRequest request)
-        {            
+        {
             MessageResult result = new MessageResult() { Success = false };
 
             try
             {
                 switch (action)
                 {
-                 
-                                  
+
+
                     default:
                         {
                             Console.WriteLine(string.Format("Not Implement {0} Logic(ExecuteCoreRequest)", request.GetType().ToString().Replace("OCPPPackage.Messages.Core.", "")));
@@ -41,7 +33,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
 
 
-           
+
             return result;
         }
         internal MessageResult ExecuteSecurityConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
@@ -49,8 +41,8 @@ namespace EVCB_OCPP.WSServer.Message
             MessageResult result = new MessageResult() { Success = false };
 
             switch (action)
-            {               
-               
+            {
+
                 default:
                     {
                         Console.WriteLine(string.Format("Not Implement {0} Logic", confirm.GetType().ToString().Replace("OCPPPackage.Messages.RemoteTrigger.", "")));
@@ -67,7 +59,7 @@ namespace EVCB_OCPP.WSServer.Message
 
             switch (action)
             {
-                
+
                 default:
                     {
                         Console.WriteLine(string.Format("Not Implement {0} Logic", action));

+ 1 - 3
EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs

@@ -9,8 +9,6 @@ using OCPPServer.Protocol;
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Message
 {
@@ -69,7 +67,7 @@ namespace EVCB_OCPP.WSServer.Message
                 var _clearProfileRequest = new ClearChargingProfileRequest()
                 {
                     connectorId = 0,
-                    chargingProfilePurpose = ChargingProfilePurposeType.ChargePointMaxProfile,              
+                    chargingProfilePurpose = ChargingProfilePurposeType.ChargePointMaxProfile,
 
                 };
 

+ 2 - 11
EVCB_OCPP.WSServer/Program.cs

@@ -1,14 +1,5 @@
-using EVCB_OCPP.Packet.Features;
-using EVCB_OCPP.Packet.Messages.Basic;
-
-using EVCB_OCPP.WSServer.Message;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
+using Newtonsoft.Json;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer
 {
@@ -16,7 +7,7 @@ namespace EVCB_OCPP.WSServer
     {
         static void Main(string[] args)
         {
-           
+
 
             ProtalServer s = new ProtalServer();
             Console.WriteLine("Starting Server...");

+ 39 - 44
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1,40 +1,30 @@
-using NLog;
+using EVCB_OCPP.Domain;
+using EVCB_OCPP.Domain.Models.Database;
+using EVCB_OCPP.Packet.Features;
+using EVCB_OCPP.Packet.Messages;
+using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP.Packet.Messages.Core;
+using EVCB_OCPP.Packet.Messages.RemoteTrigger;
+using EVCB_OCPP.WSServer.Helper;
+using EVCB_OCPP.WSServer.Message;
+using EVCB_OCPP.WSServer.Service;
+using Newtonsoft.Json;
+using NLog;
 using OCPPServer.Protocol;
 using OCPPServer.SubProtocol;
 using SuperSocket.SocketBase;
 using SuperSocket.SocketBase.Config;
 using System;
 using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Xml.Linq;
-using EVCB_OCPP.Packet.Messages.Basic;
-using EVCB_OCPP.Packet.Messages.Core;
-using EVCB_OCPP.WSServer.Message;
-using EVCB_OCPP.Packet.Messages;
-using EVCB_OCPP.Domain;
-using EVCB_OCPP.Domain.Models.Database;
-using System.Threading;
+using System.Configuration;
 using System.Data.Entity;
-using EVCB_OCPP.Packet.Features;
-using EVCB_OCPP.Packet.Features.Core;
-using Newtonsoft.Json;
-using OCPPPackage.Profiles;
-using System.Threading.Tasks;
-using EVCB_OCPP.WSServer.Helper;
 using System.Data.SqlClient;
-using EVCB_OCPP.Packet.Messages.FirmwareManagement;
-using EVCB_OCPP.Packet.Messages.RemoteTrigger;
-using System.Configuration;
-using System.Net;
-using System.Net.Security;
-using System.Security.Cryptography.X509Certificates;
-using EVCB_OCPP.WSServer.Service;
-using EVCB_OCPP.Packet.Messages.SmartCharging;
-using System.Security.Authentication;
-using NLog.Fluent;
 using System.Diagnostics;
+using System.Linq;
+using System.Security.Authentication;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Xml.Linq;
 
 
 namespace EVCB_OCPP.WSServer
@@ -57,7 +47,7 @@ namespace EVCB_OCPP.WSServer
     {
         static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
 
-
+        private DateTime lastcheckdt = DateTime.Now.AddSeconds(-20);
         private Dictionary<string, ClientData> clientDic = new Dictionary<string, ClientData>();
         private readonly Object _lockClientDic = new object();
         private readonly Object _lockConfirmPacketList = new object();
@@ -531,9 +521,9 @@ namespace EVCB_OCPP.WSServer
                                                 Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Response"), result.Exception == null ? string.Empty : result.Exception.ToString());
 
 
-                                                string changeServerRequest = BasicMessageHandler.GenerateRequestofOCPP20(Guid.NewGuid().ToString(), "SetNetworkProfile", new EVCB_OCPP20.Packet.Messages.SetNetworkProfileRequest()
+                                                var request = new EVCB_OCPP20.Packet.Messages.SetNetworkProfileRequest()
                                                 {
-                                                    ConfigurationSlot = 0,
+                                                    ConfigurationSlot = 1,
                                                     ConnectionData = new EVCB_OCPP20.Packet.DataTypes.NetworkConnectionProfileType()
                                                     {
                                                         OcppVersion = EVCB_OCPP20.Packet.DataTypes.EnumTypes.OCPPVersionEnumType.OCPP20,
@@ -543,10 +533,11 @@ namespace EVCB_OCPP.WSServer
                                                         OcppInterface = EVCB_OCPP20.Packet.DataTypes.EnumTypes.OCPPInterfaceEnumType.Wired0
                                                     }
 
-                                                }
-                                                 );
+                                                };
+                                                var uuid = session.queue20.store(request);
+                                                string requestText = BasicMessageHandler.GenerateRequestofOCPP20(uuid, "SetNetworkProfile", request);
+                                                Send(session, requestText, "SetNetworkProfile");
 
-                                                Send(session, changeServerRequest, "SetNetworkProfile");
                                             }
                                             break;
                                         default:
@@ -594,7 +585,7 @@ namespace EVCB_OCPP.WSServer
 
                                                                     },
                                                                      AttributeType= EVCB_OCPP20.Packet.DataTypes.EnumTypes.AttributeEnumType.Actual,
-                                                                     AttributeValue= _ocpp20NetworkSetting,
+                                                                     AttributeValue= JsonConvert.SerializeObject(new List<int>(){ 1 }),
                                                                      Variable=new EVCB_OCPP20.Packet.DataTypes.VariableType()
                                                                     {
                                                                             Name="NetworkConfigurationPriority",
@@ -607,7 +598,7 @@ namespace EVCB_OCPP.WSServer
 
                                                     };
                                                     var uuid = session.queue20.store(request);
-                                                    string requestText = BasicMessageHandler.GenerateRequestofOCPP20(uuid, "SetVariables", request);                                         
+                                                    string requestText = BasicMessageHandler.GenerateRequestofOCPP20(uuid, "SetVariables", request);
                                                     Send(session, requestText, "SetVariables");
                                                 }
 
@@ -617,7 +608,7 @@ namespace EVCB_OCPP.WSServer
                                             {
                                                 EVCB_OCPP20.Packet.Messages.SetVariablesResponse response = (EVCB_OCPP20.Packet.Messages.IConfirmation)analysisResult.Message as EVCB_OCPP20.Packet.Messages.SetVariablesResponse;
 
-                                                if (response.SetVariableResult[0].AttributeStatus ==  EVCB_OCPP20.Packet.DataTypes.EnumTypes.SetVariableStatusEnumType.RebootRequired )
+                                                if (response.SetVariableResult[0].AttributeStatus == EVCB_OCPP20.Packet.DataTypes.EnumTypes.SetVariableStatusEnumType.RebootRequired)
                                                 {
                                                     var request = new EVCB_OCPP20.Packet.Messages.ResetRequest()
                                                     {
@@ -627,7 +618,7 @@ namespace EVCB_OCPP.WSServer
                                                     var uuid = session.queue20.store(request);
                                                     string requestText = BasicMessageHandler.GenerateRequestofOCPP20(uuid, "Reset", request);
                                                     Send(session, requestText, "Reset");
-                                                 
+
                                                 }
                                             }
                                             break;
@@ -1245,21 +1236,24 @@ namespace EVCB_OCPP.WSServer
             }
         }
 
-        DateTime lastcheckdt = new DateTime();
+      
         async private void HeartBeatCheckTrigger()
         {
             for (; ; )
             {
                 if (_ct.IsCancellationRequested)
                 {
+                    Console.WriteLine("----------********************************************************");
                     break;
                 }
 
                 try
                 {
 
-                    if (DateTime.Now.Subtract(lastcheckdt).TotalSeconds > 10)
+                    if (DateTime.Now.Subtract(lastcheckdt).TotalSeconds > 30)
                     {
+                        lastcheckdt = DateTime.Now;
+                        Console.WriteLine("===========================");
                         Stopwatch watch = new Stopwatch();
                         Dictionary<string, ClientData> _copyClientDic = null;
                         lock (_lockClientDic)
@@ -1268,7 +1262,7 @@ namespace EVCB_OCPP.WSServer
                         }
 
                         var cdt = DateTime.Now;
-                        var clients = _copyClientDic.Where(x => x.Value.LastActiveTime > cdt.AddSeconds(-30)).Select(x => x.Value).ToList();
+                        var clients = _copyClientDic.Where(x => x.Value.LastActiveTime > cdt.AddSeconds(-120)).Select(x => x.Value).ToList();
 
                         watch.Start();
                         foreach (var session in clients)
@@ -1296,13 +1290,14 @@ namespace EVCB_OCPP.WSServer
                             logger.Fatal("Update HeartBeatCheckTrigger cost " + watch.ElapsedMilliseconds / 1000 + " seconds.");
                         }
                     }
-                    lastcheckdt = DateTime.Now;
+                  
 
                     await Task.Delay(10000);
                 }
                 catch (Exception ex)
                 {
-                    logger.Error(string.Format("HealthAlarmTrigger  Ex:{0}", ex.ToString()));
+                    Console.WriteLine("***********************************************************");
+                    logger.Error(string.Format("HeartBeatCheckTrigger  Ex:{0}", ex.ToString()));
                 }
 
             }
@@ -1326,7 +1321,7 @@ namespace EVCB_OCPP.WSServer
                         _copyClientDic = new Dictionary<string, ClientData>(clientDic);
                     }
 
-                    var removeClients = _copyClientDic.Where(x => x.Value.LastActiveTime < DateTime.Now.AddSeconds(-120)).Select(x => x.Value).ToList();
+                    var removeClients = _copyClientDic.Where(x => x.Value.LastActiveTime < DateTime.Now.AddSeconds(-300)).Select(x => x.Value).ToList();
 
                     foreach (var session in removeClients)
                     {

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

@@ -2,9 +2,7 @@
 using EVCB_OCPP.Packet.Messages.SubTypes;
 using EVCB_OCPP.WSServer.Dto;
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
 using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Service
@@ -22,13 +20,13 @@ namespace EVCB_OCPP.WSServer.Service
     {
 
         static public IBusinessService CreateBusinessService(string customerId)
-        {          
+        {
             bool isCallOut = false;
             using (var db = new MainDBContext())
             {
                 isCallOut = db.Customer.Where(x => x.Id == new Guid(customerId)).Select(x => x.CallPartnerApiOnSchedule).SingleOrDefault();
             }
-           
+
             return isCallOut ? new OuterBusinessService(customerId) : (IBusinessService)new LocalBusinessService(customerId);
         }
 

+ 2 - 3
EVCB_OCPP.WSServer/Service/HttpClientService.cs

@@ -5,7 +5,6 @@ using System.Linq;
 using System.Net;
 using System.Net.Http;
 using System.Net.Http.Headers;
-using System.Text;
 using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Service
@@ -59,7 +58,7 @@ namespace EVCB_OCPP.WSServer.Service
           {
               return new HttpClientHandler
               {
-                  
+
                   MaxConnectionsPerServer = _maxConnectionsPerServer
 
               };
@@ -74,7 +73,7 @@ namespace EVCB_OCPP.WSServer.Service
             _clientFactory = _services.BuildServiceProvider()
                      .GetRequiredService<IHttpClientFactory>();
 
-        
+
         }
 
 

+ 1 - 3
EVCB_OCPP.WSServer/Service/LoadingBalanceService.cs

@@ -6,8 +6,6 @@ using System.Configuration;
 using System.Data;
 using System.Data.SqlClient;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Service
 {
@@ -81,7 +79,7 @@ namespace EVCB_OCPP.WSServer.Service
             {
                 _lockDic.TryAdd(stationId, new object());
             }
-           
+
             return _lockDic[stationId];
 
         }

+ 8 - 10
EVCB_OCPP.WSServer/Service/LocalBusinessService.cs

@@ -1,13 +1,11 @@
-using System;
+using EVCB_OCPP.Packet.Messages.SubTypes;
+using EVCB_OCPP.WSServer.Dto;
+using Newtonsoft.Json.Linq;
+using System;
 using System.Collections.Generic;
 using System.Configuration;
-using System.Linq;
 using System.Net;
-using System.Text;
 using System.Threading.Tasks;
-using EVCB_OCPP.Packet.Messages.SubTypes;
-using EVCB_OCPP.WSServer.Dto;
-using Newtonsoft.Json.Linq;
 
 namespace EVCB_OCPP.WSServer.Service
 {
@@ -55,16 +53,16 @@ namespace EVCB_OCPP.WSServer.Service
                         {
                             info.status = (AuthorizationStatus)Enum.Parse(typeof(AuthorizationStatus), jo["message"].ToString());
                         }
-                        catch(Exception)
+                        catch (Exception)
                         {
                             ;
                         }
 
-                     
+
                     }
-                 
+
                 }
-              
+
             }
             catch (Exception ex)
             {

+ 7 - 8
EVCB_OCPP.WSServer/Service/OuterBusinessService.cs

@@ -1,14 +1,13 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using EVCB_OCPP.Domain;
+using EVCB_OCPP.Domain;
 using EVCB_OCPP.Packet.Messages.SubTypes;
 using EVCB_OCPP.WSServer.Dto;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Service
 {
@@ -56,7 +55,7 @@ namespace EVCB_OCPP.WSServer.Service
             signMaterial = GetSign(customerId);
         }
 
-      
+
         async public Task<IdTagInfo> Authorize(string chargeBoxId, string idTag)
         {
             IdTagInfo result = new IdTagInfo() { status = AuthorizationStatus.Invalid };
@@ -68,7 +67,7 @@ namespace EVCB_OCPP.WSServer.Service
                             {
                                 { "PartnerId",signMaterial.Id}
 
-                            }, null, signMaterial.SaltKey).ConfigureAwait(false); 
+                            }, null, signMaterial.SaltKey).ConfigureAwait(false);
 
                 if (response.Success)
                 {

+ 1 - 2
EVCB_OCPP.WSServer/Service/OuterHttpClient.cs

@@ -1,7 +1,6 @@
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using System.Net;
 using System.Security.Cryptography;
 using System.Text;
@@ -44,7 +43,7 @@ namespace EVCB_OCPP.WSServer.Service
 
             try
             {
-               
+
                 var _response = await httpClient.PostFormDataAsync(url, bodyData, null);
 
                 result.Response = _response.Response;

+ 1 - 6
EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallCmd.cs

@@ -1,10 +1,5 @@
-using OCPPServer;
-using OCPPServer.Protocol;
+using OCPPServer.Protocol;
 using SuperWebSocket.SubProtocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 
 namespace EVCB_OCPP.WSServer.SuperSocket.Command
 {

+ 0 - 5
EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallErrorCmd.cs

@@ -1,10 +1,5 @@
 using OCPPServer.Protocol;
 using SuperWebSocket.SubProtocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.SuperSocket.Command
 {

+ 0 - 5
EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallResultCmd.cs

@@ -1,10 +1,5 @@
 using OCPPServer.Protocol;
 using SuperWebSocket.SubProtocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.SuperSocket.Command
 {

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

@@ -3,7 +3,6 @@ using EVCB_OCPP.Packet.Messages.Basic;
 using SuperSocket.SocketBase;
 using SuperWebSocket;
 using System;
-using System.Collections.Generic;
 
 namespace OCPPServer.Protocol
 {

+ 25 - 29
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLog.cs

@@ -2,10 +2,6 @@
 
 using SuperSocket.SocketBase.Logging;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace OCPPServer.SubProtocol
 {
@@ -100,7 +96,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg0">The arg0.</param>
         public void DebugFormat(string format, object arg0)
         {
-            
+
         }
 
         /// <summary>
@@ -110,7 +106,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void DebugFormat(string format, params object[] args)
         {
-            
+
         }
 
         /// <summary>
@@ -121,7 +117,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void DebugFormat(IFormatProvider provider, string format, params object[] args)
         {
-           
+
         }
 
         /// <summary>
@@ -132,7 +128,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg1">The arg1.</param>
         public void DebugFormat(string format, object arg0, object arg1)
         {
-           
+
         }
 
         /// <summary>
@@ -144,7 +140,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg2">The arg2.</param>
         public void DebugFormat(string format, object arg0, object arg1, object arg2)
         {
-           
+
         }
 
         /// <summary>
@@ -174,7 +170,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg0">The arg0.</param>
         public void ErrorFormat(string format, object arg0)
         {
-            
+
         }
 
         /// <summary>
@@ -184,7 +180,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void ErrorFormat(string format, params object[] args)
         {
-           
+
         }
 
         /// <summary>
@@ -195,7 +191,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
         {
-            
+
         }
 
         /// <summary>
@@ -206,7 +202,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg1">The arg1.</param>
         public void ErrorFormat(string format, object arg0, object arg1)
         {
-            
+
         }
 
         /// <summary>
@@ -218,7 +214,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg2">The arg2.</param>
         public void ErrorFormat(string format, object arg0, object arg1, object arg2)
         {
-           
+
         }
 
         /// <summary>
@@ -247,7 +243,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg0">The arg0.</param>
         public void FatalFormat(string format, object arg0)
         {
-            
+
         }
 
         /// <summary>
@@ -257,7 +253,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void FatalFormat(string format, params object[] args)
         {
-           
+
         }
 
         /// <summary>
@@ -268,7 +264,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void FatalFormat(IFormatProvider provider, string format, params object[] args)
         {
-          
+
         }
 
         /// <summary>
@@ -279,7 +275,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg1">The arg1.</param>
         public void FatalFormat(string format, object arg0, object arg1)
         {
-           
+
         }
 
         /// <summary>
@@ -291,7 +287,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg2">The arg2.</param>
         public void FatalFormat(string format, object arg0, object arg1, object arg2)
         {
-           
+
         }
 
         /// <summary>
@@ -321,7 +317,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg0">The arg0.</param>
         public void InfoFormat(string format, object arg0)
         {
-           
+
         }
 
         /// <summary>
@@ -331,7 +327,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void InfoFormat(string format, params object[] args)
         {
-            
+
         }
 
         /// <summary>
@@ -342,7 +338,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void InfoFormat(IFormatProvider provider, string format, params object[] args)
         {
-            
+
         }
 
         /// <summary>
@@ -353,7 +349,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg1">The arg1.</param>
         public void InfoFormat(string format, object arg0, object arg1)
         {
-            
+
         }
 
         /// <summary>
@@ -365,7 +361,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg2">The arg2.</param>
         public void InfoFormat(string format, object arg0, object arg1, object arg2)
         {
-            
+
         }
 
         /// <summary>
@@ -395,7 +391,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg0">The arg0.</param>
         public void WarnFormat(string format, object arg0)
         {
-           
+
         }
 
         /// <summary>
@@ -405,7 +401,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void WarnFormat(string format, params object[] args)
         {
-           
+
         }
 
         /// <summary>
@@ -416,7 +412,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="args">The args.</param>
         public void WarnFormat(IFormatProvider provider, string format, params object[] args)
         {
-           
+
         }
 
         /// <summary>
@@ -427,7 +423,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg1">The arg1.</param>
         public void WarnFormat(string format, object arg0, object arg1)
         {
-           
+
         }
 
         /// <summary>
@@ -439,7 +435,7 @@ namespace OCPPServer.SubProtocol
         /// <param name="arg2">The arg2.</param>
         public void WarnFormat(string format, object arg0, object arg1, object arg2)
         {
-            
+
         }
     }
 }

+ 1 - 8
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLogFactory.cs

@@ -1,12 +1,5 @@
-
-using SuperSocket.SocketBase;
-using SuperSocket.SocketBase.Logging;
-using System;
+using SuperSocket.SocketBase.Logging;
 using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace OCPPServer.SubProtocol
 {

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

@@ -23,7 +23,7 @@ namespace OCPPServer.SubProtocol
 
             if (pos > 0)
             {
-                name = cmd.Substring(pos - 1,1);
+                name = cmd.Substring(pos - 1, 1);
             }
             else
             {

+ 1 - 3
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubProtocol.cs

@@ -10,8 +10,6 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace OCPPServer.SubProtocol
 {
@@ -195,7 +193,7 @@ namespace OCPPServer.SubProtocol
             : base(name)
         {
             //The items in commandAssemblies may be null, so filter here
-            m_CommandAssemblies.AddRange(commandAssemblies.Where(a => a != null));         
+            m_CommandAssemblies.AddRange(commandAssemblies.Where(a => a != null));
             SubRequestParser = requestInfoParser;
         }
 

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

@@ -1,7 +1,6 @@
 
 using EVCB_OCPP.Domain;
 using OCPPPackage.Profiles;
-using SuperSocket.Common;
 using SuperWebSocket;
 using SuperWebSocket.SubProtocol;
 using System;