|
@@ -113,8 +113,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
serverUpdateTask.Start();
|
|
|
|
|
|
|
|
|
- // Task serverHealthTask = new Task(HealthAlarmTrigger, _ct);
|
|
|
- // serverHealthTask.Start();
|
|
|
+ Task serverHealthTask = new Task(HealthAlarmTrigger, _ct);
|
|
|
+ serverHealthTask.Start();
|
|
|
|
|
|
while (true)
|
|
|
{
|
|
@@ -327,6 +327,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
appServer.NewSessionConnected += AppServer_NewSessionConnected;
|
|
|
appServer.SessionClosed += AppServer_SessionClosed;
|
|
|
|
|
|
+
|
|
|
//Try to start the appServer
|
|
|
if (!appServer.Start())
|
|
|
{
|
|
@@ -371,7 +372,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
clientDic.Add(session.ChargeBoxId, session);
|
|
|
session.m_ReceiveData += new ClientData.OCPPClientDataEventHandler<ClientData, String>(ReceivedMessage);
|
|
|
- // logger.Debug("------------New " + (session == null ? "Oops" : session.ChargeBoxId));
|
|
|
+ // logger.Debug("------------New " + (session == null ? "Oops" : session.ChargeBoxId));
|
|
|
WriteMachineLog(session, "NewSessionConnected", "Connection", "");
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
@@ -999,7 +1000,38 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
async private void HealthAlarmTrigger()
|
|
|
{
|
|
|
+ for (; ; )
|
|
|
+ {
|
|
|
+ if (_ct.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
+ lock (_lockClientDic)
|
|
|
+ {
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+ }
|
|
|
+
|
|
|
+ var removeClients= _copyClientDic.Where(x => x.Value.LastActiveTime < DateTime.Now.AddSeconds(-120)).Select(x => x.Value).ToList();
|
|
|
+
|
|
|
+ foreach(var session in removeClients)
|
|
|
+ {
|
|
|
+
|
|
|
+ Console.WriteLine(string.Format("Server forced to shut down ChargeBox ({0}: LastActiveTime{1})", session.ChargeBoxId, session.LastActiveTime));
|
|
|
+ RemoveClient(session);
|
|
|
+ }
|
|
|
+
|
|
|
+ await Task.Delay(60000);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error(string.Format("HealthAlarmTrigger Ex:{0}", ex.ToString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1101,6 +1133,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
|
|
|
logger.Trace("RemoveClient[" + session.ChargeBoxId + "]");
|
|
|
+ if(session.Connected)
|
|
|
+ {
|
|
|
+ session.Close(CloseReason.ServerShutdown);
|
|
|
+ }
|
|
|
RemoveClientDic(session);
|
|
|
try
|
|
|
{
|