|
@@ -62,6 +62,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
private DateTime checkUpdateDt = DateTime.UtcNow;
|
|
|
private DateTime _CheckFeeDt = DateTime.UtcNow;
|
|
|
private DateTime _CheckLBDt = DateTime.UtcNow;
|
|
|
+ private DateTime _CheckDenyListDt = DateTime.UtcNow.AddDays(-1);
|
|
|
private LoadingBalanceService _loadingBalanceService = new LoadingBalanceService();
|
|
|
private List<StationInfoDto> _StationInfo = new List<StationInfoDto>();
|
|
|
private List<string> needConfirmActions = new List<string>()
|
|
@@ -108,6 +109,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
_ct = _cts.Token;
|
|
|
WarmUpLog();
|
|
|
+ DenyModelCheckTrigger(true);
|
|
|
}
|
|
|
|
|
|
internal void Start()
|
|
@@ -137,6 +139,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
Task smartChargingTask = new Task(SmartChargingTrigger, _ct);
|
|
|
smartChargingTask.Start();
|
|
|
|
|
|
+
|
|
|
+ Task denyModelCheckTask = new Task(()=>DenyModelCheckTrigger(false), _ct);
|
|
|
+ denyModelCheckTask.Start();
|
|
|
+
|
|
|
while (true)
|
|
|
{
|
|
|
var input = Console.ReadLine();
|
|
@@ -290,7 +296,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
//設定server config
|
|
|
var serverConfig = new ServerConfig
|
|
|
{
|
|
|
- SendingQueueSize=10,
|
|
|
+ SendingQueueSize = 10,
|
|
|
//Port = Convert.ToInt32(2012),
|
|
|
//Ip = "172.17.40.13",
|
|
|
MaxRequestLength = 204800,
|
|
@@ -990,6 +996,70 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
+ async private void DenyModelCheckTrigger(bool warmup)
|
|
|
+ {
|
|
|
+ Console.WriteLine("DenyModelCheckTrigger " + warmup);
|
|
|
+ for (; ; )
|
|
|
+ {
|
|
|
+ if (_ct.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var min_Interval = (DateTime.UtcNow - _CheckDenyListDt).TotalMinutes;
|
|
|
+
|
|
|
+ if (min_Interval > 5)
|
|
|
+ {
|
|
|
+ using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
+ {
|
|
|
+ string strSql = "SELECT [Value] FROM[StandardOCPP_Web].[dbo].[KernelConfig]" +
|
|
|
+ "where SystemKey = 'DenyModelNames'; ";
|
|
|
+ var result = await conn.QueryAsync<string>(strSql);
|
|
|
+
|
|
|
+ GlobalConfig.DenyModelNames = result.FirstOrDefault().Split(',').ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ _CheckDenyListDt = DateTime.UtcNow;
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(GlobalConfig.DenyModelNames[0]))
|
|
|
+ {
|
|
|
+ Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
+ lock (_lockClientDic)
|
|
|
+ {
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+ }
|
|
|
+ foreach (var denyName in GlobalConfig.DenyModelNames)
|
|
|
+ {
|
|
|
+ var removeClients = _copyClientDic.Where(x => x.Key.StartsWith(denyName)).Select(x => x.Value).ToList();
|
|
|
+ foreach (var session in removeClients)
|
|
|
+ {
|
|
|
+
|
|
|
+ Console.WriteLine(string.Format("Server forced to shut down ChargeBox ({0}: Reason: DenyModelName-{1}", session.ChargeBoxId, denyName));
|
|
|
+ RemoveClient(session);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ await Task.Delay(500);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error(string.Format("DenyModelCheckTrigger Ex:{0}", ex.ToString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (warmup) break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async private void ServerUpdateTrigger()
|
|
|
{
|
|
|
for (; ; )
|
|
@@ -1441,8 +1511,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
foreach (var station in stations)
|
|
|
{
|
|
|
var compareStation = _StationInfo.Where(x => x.Id == station.Id).FirstOrDefault();
|
|
|
-
|
|
|
- if (compareStation == null ||(station.Id == compareStation.Id && station.Availability != compareStation.Availability))
|
|
|
+
|
|
|
+ if (compareStation == null || (station.Id == compareStation.Id && station.Availability != compareStation.Availability))
|
|
|
{
|
|
|
var _powerDic = await _loadingBalanceService.GetSettingPower(station.Id);
|
|
|
if (_powerDic != null)
|
|
@@ -1450,7 +1520,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
foreach (var kv in _powerDic)
|
|
|
{
|
|
|
try
|
|
|
- {
|
|
|
+ {
|
|
|
|
|
|
if (kv.Value.HasValue)
|
|
|
{
|