Browse Source

add main commit
Commit 36903b02: 1.可 listen 多個 wss port
2.新增可以關閉 ws port 功能

Robert 1 năm trước cách đây
mục cha
commit
6a97620e8c

+ 31 - 8
EVCB_OCPP.WSServer/GlobalConfig.cs

@@ -13,7 +13,9 @@ namespace EVCB_OCPP.WSServer
             "WSPort",
             "WSSPort",
             "OCPP20_WSUrl",
-            "OCPP20_WSSUrl"
+            "OCPP20_WSSUrl",
+            "SecurityProfileLevel",
+            "SecurityPassword"
         };
 
         public static List<string> DenyModelNames = new List<string>();
@@ -28,6 +30,10 @@ namespace EVCB_OCPP.WSServer
 
         public static string OCPP20_WSSUrl = string.Empty;
 
+        public static int SecurityProfileLevel = 0;
+
+        public static string SecurityPassword = string.Empty;
+
         public static JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings()
         {
             NullValueHandling = NullValueHandling.Ignore,
@@ -51,7 +57,7 @@ namespace EVCB_OCPP.WSServer
         /// <summary>
         ///WSS Port
         /// </summary>
-        private static int WSS_Port = 443;
+        private static List<int> WSS_Ports = null;
 
         public static bool LoadAPPConfig(IConfiguration configuration)
         {
@@ -69,14 +75,19 @@ namespace EVCB_OCPP.WSServer
                             {
                                 var value = configuration[key];
 
-                                WS_Port = string.IsNullOrEmpty(value) ? WS_Port : Convert.ToInt32(value);
+                                WS_Port = Int32.TryParse(value, out WS_Port) ? WS_Port : 0;
                             }
                             break;
                         case "WSSPort":
                             {
                                 var value = configuration[key];
 
-                                WSS_Port = string.IsNullOrEmpty(value) ? WS_Port : Convert.ToInt32(value);
+                                var ports = value.Split(',');
+                                WSS_Ports = new List<int>();
+                                foreach (var port in ports)
+                                {
+                                    WSS_Ports.Add(Convert.ToInt32(port));
+                                }
                             }
                             break;
                         case "OCPP20_WSUrl":// convert to int type                       
@@ -93,6 +104,20 @@ namespace EVCB_OCPP.WSServer
                                 OCPP20_WSSUrl = value;
                             }
                             break;
+                        case "SecurityProfileLevel":
+                            {
+                                var value = configuration[key];
+
+                                SecurityProfileLevel = Convert.ToInt32(value);
+                            }
+                            break;
+                        case "SecurityPassword":
+                            {
+                                var value = configuration[key];
+
+                                SecurityPassword = value;
+                            }
+                            break;
                         default://convert to string type                             
                             break;
 
@@ -114,11 +139,9 @@ namespace EVCB_OCPP.WSServer
         {
             return WS_Port;
         }
-
-
-        public static int GetWSS_Port()
+        public static List<int> GetWSS_Ports()
         {
-            return WSS_Port;
+            return WSS_Ports;
         }
 
         public static int GetHEARTBEAT_INTERVAL()

+ 41 - 34
EVCB_OCPP.WSServer/Jobs/ServerSetFeeJob.cs

@@ -138,69 +138,76 @@ public class ServerSetFeeJob : IJob
 
         if (string.IsNullOrEmpty(client.ChargeBoxId)) return displayPriceText;
 
-        using (SqlConnection conn = new SqlConnection(webConnectionString))
+        try
         {
-            var parameters = new DynamicParameters();
-            parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input, 36);
-            string displayPricestrSql = "";
-            string strSql = "";
-
-            if (client.IsAC)
+            using (SqlConnection conn = new SqlConnection(webConnectionString))
             {
-                displayPricestrSql = """
+                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 = """
+                    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 = """
+                }
+                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 = """
+                    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);
-            if (result.Count() == 0)
-            {
-                return string.Empty;
-            }
-            var stationPrice = result.First();
+                }
+                var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
+                if (result.Count() == 0)
+                {
+                    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))
+                if (stationPrice.BillingMethod == 1)
                 {
-                    client.ChargingPrices = new List<ChargingPrice>();
+                    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;
+                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;

+ 9 - 2
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -492,8 +492,15 @@ namespace EVCB_OCPP.WSServer
 
             List<IListenerConfig> llistener = new List<IListenerConfig>();
 
-            llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = Convert.ToInt32(GlobalConfig.GetWS_Port()), Backlog = 100, Security = "None" });
-            llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = Convert.ToInt32(GlobalConfig.GetWSS_Port()), Backlog = 100, Security = SslProtocols.Tls12.ToString() });
+            if (GlobalConfig.GetWS_Port() != 0)
+            {
+                llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = GlobalConfig.GetWS_Port(), Backlog = 100, Security = "None" });
+            }
+
+            foreach (var securityport in GlobalConfig.GetWSS_Ports())
+            {
+                llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = securityport, Backlog = 100, Security = SslProtocols.Tls12.ToString() });
+            }
 
             //var config = ConfigurationManager.GetSection("superSocket") as IConfigurationSource;\
             //var certificate = configuration.GetSection("superSocket").GetSection("Servers:0").GetSection("Certificate").Get<CertificateConfig>();