|
@@ -37,13 +37,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
- private Dictionary<string, ClientData> ClientDic = new Dictionary<string, ClientData>();
|
|
|
+
|
|
|
+ private Dictionary<string, ClientData> clientDic = new Dictionary<string, ClientData>();
|
|
|
private readonly Object _lockClientDic = new object();
|
|
|
private readonly Object _lockConfirmPacketList = new object();
|
|
|
- private ProfileHandler _profileHandler = new ProfileHandler();
|
|
|
- private List<NeedConfirmMessage> NeedConfirmPacketList = new List<NeedConfirmMessage>();
|
|
|
+ private ProfileHandler profileHandler = new ProfileHandler();
|
|
|
+ private List<NeedConfirmMessage> needConfirmPacketList = new List<NeedConfirmMessage>();
|
|
|
private DateTime checkUpdateDt = DateTime.Now;
|
|
|
- private List<string> _needConfirmActions = new List<string>()
|
|
|
+ private List<string> needConfirmActions = new List<string>()
|
|
|
{
|
|
|
"GetConfiguration",
|
|
|
"ChangeConfiguration",
|
|
@@ -108,6 +109,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
Task serverUpdateTask = new Task(ServerUpdateTrigger, _ct);
|
|
|
serverUpdateTask.Start();
|
|
|
|
|
|
+
|
|
|
+ Task serverHealthTask = new Task(HealthAlarmTrigger, _ct);
|
|
|
+ // serverHealthTask.Start();
|
|
|
+
|
|
|
while (true)
|
|
|
{
|
|
|
var input = Console.ReadLine();
|
|
@@ -130,14 +135,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
lock (_lockClientDic)
|
|
|
{
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(ClientDic);
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
|
|
|
}
|
|
|
var list = _copyClientDic.Select(c => c.Value).ToList();
|
|
|
int i = 1;
|
|
|
foreach (var c in list)
|
|
|
{
|
|
|
- logger.Info(i + ":" + c.ChargeBoxId);
|
|
|
+ logger.Info(i + ":" + c.ChargeBoxId + " " + c.SessionID);
|
|
|
i++;
|
|
|
}
|
|
|
|
|
@@ -149,14 +154,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
lock (_lockClientDic)
|
|
|
{
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(ClientDic);
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
|
|
|
}
|
|
|
- var lcn = ClientDic.Select(c => c.Value.CustomerName).Distinct().ToList();
|
|
|
+ var lcn = clientDic.Select(c => c.Value.CustomerName).Distinct().ToList();
|
|
|
int iLcn = 1;
|
|
|
foreach (var c in lcn)
|
|
|
{
|
|
|
- logger.Info(iLcn + ":" + c + ":" + ClientDic.Where(z => z.Value.CustomerName == c).Count().ToString());
|
|
|
+ logger.Info(iLcn + ":" + c + ":" + clientDic.Where(z => z.Value.CustomerName == c).Count().ToString());
|
|
|
iLcn++;
|
|
|
}
|
|
|
|
|
@@ -209,6 +214,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
internal void Stop()
|
|
|
{
|
|
|
if (_cts != null)
|
|
@@ -219,38 +226,65 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
private void CheckEVSEConfigure(string chargeBoxId)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
+ int skipCount = 0;
|
|
|
+ int takeCount = 8;
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
|
|
|
- var _sn = db.MachineConfigure.Where(x => x.ChargeBoxId == chargeBoxId).Select(x => x.ChargeBoxId).FirstOrDefault();
|
|
|
- if (string.IsNullOrEmpty(_sn))
|
|
|
+ string maxKeys = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
+ if (maxKeys == StandardConfiguration.GetConfigurationMaxKeys)
|
|
|
{
|
|
|
- db.ServerMessage.Add(new ServerMessage()
|
|
|
+ var _Configure = db.MachineConfigure.Where(x => x.ChargeBoxId == chargeBoxId && x.ConfigureName == maxKeys).Select(x => new { ConfigureSetting = x.ConfigureSetting, ConfigureName = x.ConfigureName }).FirstOrDefault();
|
|
|
+ if (_Configure != null)
|
|
|
{
|
|
|
- ChargeBoxId = chargeBoxId,
|
|
|
- CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.Now,
|
|
|
- OutAction = Actions.GetConfiguration.ToString(),
|
|
|
- OutRequest = JsonConvert.SerializeObject(
|
|
|
+ int cp_ConfiureCount = 0;
|
|
|
+ int.TryParse(_Configure.ConfigureSetting, out cp_ConfiureCount);
|
|
|
+ takeCount = takeCount > cp_ConfiureCount ? cp_ConfiureCount : takeCount;
|
|
|
+ skipCount = 1;
|
|
|
+ if (string.IsNullOrEmpty(_Configure.ConfigureSetting)) return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ while (StandardConfiguration.AllConfigs.Count > skipCount)
|
|
|
+ {
|
|
|
+ string _key = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
+ var _Configure = db.MachineConfigure.Where(x => x.ChargeBoxId == chargeBoxId && x.ConfigureName == _key).Select(x => new { ConfigureSetting = x.ConfigureSetting, ConfigureName = x.ConfigureName }).FirstOrDefault();
|
|
|
+ takeCount = StandardConfiguration.AllConfigs.Count - skipCount > takeCount ? takeCount : StandardConfiguration.AllConfigs.Count - skipCount;
|
|
|
+
|
|
|
+ var _keys = StandardConfiguration.AllConfigs.Skip(skipCount).Take(takeCount).ToList();
|
|
|
+ Console.WriteLine("===============Skip:" + skipCount);
|
|
|
+ if (_Configure == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("_Configure == null===============Skip:" + skipCount);
|
|
|
+ db.ServerMessage.Add(new ServerMessage()
|
|
|
+ {
|
|
|
+ ChargeBoxId = chargeBoxId,
|
|
|
+ CreatedBy = "Server",
|
|
|
+ CreatedOn = DateTime.Now,
|
|
|
+ OutAction = Actions.GetConfiguration.ToString(),
|
|
|
+ OutRequest = JsonConvert.SerializeObject(
|
|
|
new GetConfigurationRequest()
|
|
|
{
|
|
|
- key = new List<string>()
|
|
|
+ key = _keys
|
|
|
|
|
|
},
|
|
|
new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- SerialNo = Guid.NewGuid().ToString(),
|
|
|
- InMessage = string.Empty
|
|
|
+ SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ InMessage = string.Empty
|
|
|
|
|
|
- });
|
|
|
+ });
|
|
|
+
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+ skipCount = skipCount + takeCount;
|
|
|
|
|
|
- db.SaveChanges();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void OpenNetwork()
|
|
|
{
|
|
|
|
|
@@ -269,6 +303,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
//設定server config
|
|
|
var serverConfig = new ServerConfig
|
|
|
{
|
|
|
+
|
|
|
//Port = Convert.ToInt32(2012),
|
|
|
//Ip = "172.17.40.13",
|
|
|
MaxRequestLength = 4096,
|
|
@@ -300,31 +335,54 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
private void AppServer_SessionClosed(ClientData session, CloseReason value)
|
|
|
{
|
|
|
- Console.WriteLine(session.RemoteEndPoint.Address);
|
|
|
- WriteMachineLog(session.ChargeBoxId, string.Format("CloseReason: {0}", value), "Connection", "");
|
|
|
+ // Console.WriteLine(session.RemoteEndPoint.Address);
|
|
|
+ WriteMachineLog(session, string.Format("CloseReason: {0}", value), "Connection", "");
|
|
|
RemoveClient(session);
|
|
|
// close Connection
|
|
|
}
|
|
|
|
|
|
private void AppServer_NewSessionConnected(ClientData session)
|
|
|
{
|
|
|
- Console.WriteLine("------------New");
|
|
|
- session.m_ReceiveData += new ClientData.OCPPClientDataEventHandler<ClientData, String>(ReceivedMessage);
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
lock (_lockClientDic)
|
|
|
{
|
|
|
+ bool isNotSupported = session.SecWebSocketProtocol.Contains("ocpp1.6") ? false : true;
|
|
|
+ if (isNotSupported)
|
|
|
+ {
|
|
|
+ logger.Debug(string.Format("ChargeBoxId:{0} SecWebSocketProtocol:{1} NotSupported", session.ChargeBoxId, session.SecWebSocketProtocol));
|
|
|
+ WriteMachineLog(session, string.Format("SecWebSocketProtocol:{0} NotSupported", session.SecWebSocketProtocol), "Connection", "");
|
|
|
+ return;
|
|
|
+ }
|
|
|
ClientData _removeClient = null;
|
|
|
-
|
|
|
- ClientDic.TryGetValue(session.ChargeBoxId, out _removeClient);
|
|
|
+ clientDic.TryGetValue(session.ChargeBoxId, out _removeClient);
|
|
|
if (_removeClient != null)
|
|
|
{
|
|
|
+ WriteMachineLog(_removeClient, "Duplicate Logins", "Connection", "");
|
|
|
+ _removeClient.Close(CloseReason.ServerShutdown);
|
|
|
RemoveClient(_removeClient);
|
|
|
}
|
|
|
- ClientDic.Add(session.ChargeBoxId, session);
|
|
|
-
|
|
|
- Console.WriteLine("------------New" + (session == null ? "Oops" : session.ChargeBoxId));
|
|
|
- WriteMachineLog(session.ChargeBoxId, "", "Connection", "");
|
|
|
+
|
|
|
+ session.IsCheckIn = true;
|
|
|
+
|
|
|
+ clientDic.Add(session.ChargeBoxId, session);
|
|
|
+ session.m_ReceiveData += new ClientData.OCPPClientDataEventHandler<ClientData, String>(ReceivedMessage);
|
|
|
+ logger.Debug("------------New " + (session == null ? "Oops" : session.ChargeBoxId));
|
|
|
+ WriteMachineLog(session, "NewSessionConnected", "Connection", "");
|
|
|
+
|
|
|
+ using (var db = new MainDBContext())
|
|
|
+ {
|
|
|
+ var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
+ if (machine != null)
|
|
|
+ {
|
|
|
+ machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -342,7 +400,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
MessageResult analysisResult = msgAnalyser.AnalysisReceiveData(session, rawdata);
|
|
|
|
|
|
|
|
|
- WriteMachineLog(session.ChargeBoxId, rawdata,
|
|
|
+ WriteMachineLog(session, rawdata,
|
|
|
string.Format("{0} {1}", string.IsNullOrEmpty(analysisResult.Action) ? "unknown" : analysisResult.Action, analysisResult.Id == 2 ? "Request" : (analysisResult.Id == 3 ? "Confirmation" : "Error")));
|
|
|
|
|
|
if (analysisResult.Success == false)
|
|
@@ -422,7 +480,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
|
|
|
bool oldstatus = session.IsCheckIn;
|
|
|
- var replyResult = _profileHandler.ExecuteCoreRequest(action, session, (IRequest)analysisResult.Message);
|
|
|
+ var replyResult = profileHandler.ExecuteCoreRequest(action, session, (IRequest)analysisResult.Message);
|
|
|
if (replyResult.Success)
|
|
|
{
|
|
|
string response = msgAnalyser.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
@@ -445,7 +503,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
|
|
|
|
|
|
- CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
+ // CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -463,7 +521,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
break;
|
|
|
case "FirmwareManagement":
|
|
|
{
|
|
|
- var replyResult = _profileHandler.ExecuteFirmwareManagementRequest(action, session, (IRequest)analysisResult.Message);
|
|
|
+ var replyResult = profileHandler.ExecuteFirmwareManagementRequest(action, session, (IRequest)analysisResult.Message);
|
|
|
if (replyResult.Success)
|
|
|
{
|
|
|
string response = msgAnalyser.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
@@ -503,32 +561,32 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
case "Core":
|
|
|
{
|
|
|
- confirmResult = _profileHandler.ExecuteCoreConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ confirmResult = profileHandler.ExecuteCoreConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "FirmwareManagement":
|
|
|
{
|
|
|
- confirmResult = _profileHandler.ExecuteFirmwareManagementConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ confirmResult = profileHandler.ExecuteFirmwareManagementConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "RemoteTrigger":
|
|
|
{
|
|
|
- confirmResult = _profileHandler.ExecuteRemoteTriggerConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ confirmResult = profileHandler.ExecuteRemoteTriggerConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "Reservation":
|
|
|
{
|
|
|
- confirmResult = _profileHandler.ExecuteReservationConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ confirmResult = profileHandler.ExecuteReservationConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "LocalAuthListManagement":
|
|
|
{
|
|
|
- confirmResult = _profileHandler.ExecuteLocalAuthListManagementConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ confirmResult = profileHandler.ExecuteLocalAuthListManagementConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "SmartCharging":
|
|
|
{
|
|
|
- confirmResult = _profileHandler.ExecuteSmartChargingConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ confirmResult = profileHandler.ExecuteSmartChargingConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -565,32 +623,32 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
case "Core":
|
|
|
{
|
|
|
- _profileHandler.ReceivedCoreError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
+ profileHandler.ReceivedCoreError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "FirmwareManagement":
|
|
|
{
|
|
|
- _profileHandler.ReceivedFirmwareManagementError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
+ profileHandler.ReceivedFirmwareManagementError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "RemoteTrigger":
|
|
|
{
|
|
|
- _profileHandler.ReceivedRemoteTriggerError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
+ profileHandler.ReceivedRemoteTriggerError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "Reservation":
|
|
|
{
|
|
|
- _profileHandler.ExecuteReservationError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
+ profileHandler.ExecuteReservationError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "LocalAuthListManagement":
|
|
|
{
|
|
|
- _profileHandler.ReceivedLocalAuthListManagementError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
+ profileHandler.ReceivedLocalAuthListManagementError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
case "SmartCharging":
|
|
|
{
|
|
|
- _profileHandler.ReceivedSmartChargingError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
+ profileHandler.ReceivedSmartChargingError(action, analysisResult.ReceivedErrorCode, session, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -621,7 +679,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
if (session != null)
|
|
|
{
|
|
|
- WriteMachineLog(session.ChargeBoxId, msg, messageType, errorMsg, true);
|
|
|
+ WriteMachineLog(session, msg, messageType, errorMsg, true);
|
|
|
session.Send(msg);
|
|
|
}
|
|
|
|
|
@@ -650,7 +708,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
lock (_lockClientDic)
|
|
|
{
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(ClientDic);
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
|
|
|
}
|
|
|
checkUpdateDt = DateTime.Now;
|
|
@@ -668,15 +726,15 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
|
|
|
ClientData session;
|
|
|
if (_copyClientDic.TryGetValue(chargeBoxId, out session))
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
string requestId = Guid.NewGuid().ToString();
|
|
|
- // using (var db = new MainDBContext())
|
|
|
-
|
|
|
+ // using (var db = new MainDBContext())
|
|
|
+
|
|
|
if (session.IsCheckIn)
|
|
|
{
|
|
|
|
|
@@ -794,7 +852,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
ClientData session;
|
|
|
string uuid = string.Empty;
|
|
|
- if (ClientDic.TryGetValue(charger_SN, out session))
|
|
|
+ if (clientDic.TryGetValue(charger_SN, out session))
|
|
|
{
|
|
|
Console.WriteLine(string.Format("charger_SN:{0} startDt:{1} CreatedOn:{2}", charger_SN, startDt.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
|
|
if (session.IsCheckIn)
|
|
@@ -862,6 +920,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
|
|
|
|
|
|
+ async private void HealthAlarmTrigger()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void AddConfirmMessage(string chargePointSerialNumber, int table_id, string requestId, string action, string msg_id)
|
|
|
{
|
|
|
NeedConfirmMessage _needConfirmMsg = new NeedConfirmMessage();
|
|
@@ -873,12 +937,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
_needConfirmMsg.RequestId = requestId;
|
|
|
_needConfirmMsg.SentUniqueId = msg_id;
|
|
|
|
|
|
- if (_needConfirmActions.Contains(action))
|
|
|
+ if (needConfirmActions.Contains(action))
|
|
|
{
|
|
|
|
|
|
lock (_lockConfirmPacketList)
|
|
|
{
|
|
|
- NeedConfirmPacketList.Add(_needConfirmMsg);
|
|
|
+ needConfirmPacketList.Add(_needConfirmMsg);
|
|
|
if (action == "GetConfiguration")
|
|
|
{
|
|
|
Console.WriteLine("AddConfirmMessage: " + msg_id);
|
|
@@ -893,10 +957,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
var before_3mins = DateTime.Now.AddMinutes(-3);
|
|
|
lock (_lockConfirmPacketList)
|
|
|
{
|
|
|
- var removeList = NeedConfirmPacketList.Where(x => x.SentTimes == 0 || x.SentOn < before_3mins).ToList();
|
|
|
+ var removeList = needConfirmPacketList.Where(x => x.SentTimes == 0 || x.SentOn < before_3mins).ToList();
|
|
|
foreach (var item in removeList)
|
|
|
{
|
|
|
- NeedConfirmPacketList.Remove(item);
|
|
|
+ needConfirmPacketList.Remove(item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -904,7 +968,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
private bool ReConfirmMessage(MessageResult analysisResult)
|
|
|
{
|
|
|
bool confirmed = false;
|
|
|
- if (_needConfirmActions.Contains(analysisResult.Action))
|
|
|
+ if (needConfirmActions.Contains(analysisResult.Action))
|
|
|
{
|
|
|
if (analysisResult.Action == "GetConfiguration")
|
|
|
{
|
|
@@ -913,7 +977,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
NeedConfirmMessage foundRequest = null;
|
|
|
lock (_lockConfirmPacketList)
|
|
|
{
|
|
|
- foundRequest = NeedConfirmPacketList.Where(x => x.SentUniqueId == analysisResult.UUID).FirstOrDefault();
|
|
|
+ foundRequest = needConfirmPacketList.Where(x => x.SentUniqueId == analysisResult.UUID).FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
if (foundRequest != null && foundRequest.Id > 0)
|
|
@@ -964,7 +1028,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
try
|
|
|
{
|
|
|
session.m_ReceiveData -= new ClientData.OCPPClientDataEventHandler<ClientData, String>(ReceivedMessage);
|
|
|
- session.Close(CloseReason.ServerClosing);
|
|
|
+ // session.Close(CloseReason.ServerShutdown);
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -987,9 +1052,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
lock (_lockClientDic)
|
|
|
{
|
|
|
|
|
|
- if (ClientDic.ContainsKey(session.ChargeBoxId))
|
|
|
+ if (clientDic.ContainsKey(session.ChargeBoxId))
|
|
|
{
|
|
|
- ClientDic.Remove(session.ChargeBoxId);
|
|
|
+ logger.Debug(String.Format("ChargeBoxId:{0} Remove SessionId:{1} Removed SessionId:{2}", session.ChargeBoxId, session.SessionID, clientDic[session.ChargeBoxId].SessionID));
|
|
|
+
|
|
|
+ clientDic.Remove(session.ChargeBoxId);
|
|
|
logger.Trace("RemoveClient ContainsKey " + session.ChargeBoxId);
|
|
|
}
|
|
|
}
|
|
@@ -1006,24 +1073,26 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void WriteMachineLog(string sn, string data, string messageType, string errorMsg = "", bool isSent = false)
|
|
|
+ private void WriteMachineLog(ClientData evse, string data, string messageType, string errorMsg = "", bool isSent = false)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (string.IsNullOrEmpty(sn) || string.IsNullOrEmpty(data)) return;
|
|
|
+ if (evse == null || string.IsNullOrEmpty(data)) return;
|
|
|
using (var db = new ConnectionLogDBContext())
|
|
|
{
|
|
|
string sp = "[dbo].[uspInsertMachineConnectionLog] @CreatedOn," +
|
|
|
- "@ChargeBoxId,@MessageType,@Data,@Msg,@IsSent";
|
|
|
+ "@ChargeBoxId,@MessageType,@Data,@Msg,@IsSent,@EVSEEndPoint,@Session";
|
|
|
var dd = DateTime.Now;
|
|
|
SqlParameter[] parameter =
|
|
|
{
|
|
|
new SqlParameter("CreatedOn",dd),
|
|
|
- new SqlParameter("ChargeBoxId",sn.Replace("'","''")),
|
|
|
+ new SqlParameter("ChargeBoxId",evse.ChargeBoxId.Replace("'","''")),
|
|
|
new SqlParameter("MessageType",messageType.Replace("'","''")),
|
|
|
new SqlParameter("Data",data.Replace("'","''")),
|
|
|
new SqlParameter("Msg",errorMsg.Replace("'","''")),
|
|
|
- new SqlParameter("IsSent",isSent)
|
|
|
+ new SqlParameter("IsSent",isSent),
|
|
|
+ new SqlParameter("EVSEEndPoint",evse.RemoteEndPoint.ToString()),
|
|
|
+ new SqlParameter("Session",evse.SessionID)
|
|
|
};
|
|
|
|
|
|
db.Database.ExecuteSqlCommand(sp, parameter);
|