|
@@ -122,6 +122,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
//ReadTCCSetting();
|
|
|
OpenNetwork();
|
|
|
|
|
|
+ Task fillinChargerDataTask = new Task(FillinChargerData, _ct);
|
|
|
+ fillinChargerDataTask.Start();
|
|
|
+
|
|
|
+
|
|
|
Task serverCommandTask = new Task(ServerMessageTrigger, _ct);
|
|
|
serverCommandTask.Start();
|
|
|
|
|
@@ -435,15 +439,15 @@ namespace EVCB_OCPP.WSServer
|
|
|
// 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();
|
|
|
- }
|
|
|
- }
|
|
|
+ //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();
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -717,10 +721,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
if (action == Actions.BootNotification && replyResult.Message is BootNotificationConfirmation)
|
|
|
{
|
|
|
- session.IsCheckIn = true;
|
|
|
if (((BootNotificationConfirmation)replyResult.Message).status == Packet.Messages.SubTypes.RegistrationStatus.Accepted)
|
|
|
{
|
|
|
+ session.IsCheckIn = true;
|
|
|
+
|
|
|
|
|
|
+ await SetDefaultFee(session);
|
|
|
CheckVersion(session.ChargeBoxId);
|
|
|
CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
if (session.CustomerId == new Guid("298918C0-6BB5-421A-88CC-4922F918E85E") || session.CustomerId == new Guid("9E6BFDCC-09FB-4DAB-A428-43FE507600A3"))
|
|
@@ -847,21 +853,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- using (var db = new MainDBContext())
|
|
|
- {
|
|
|
- var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
- if (machine != null)
|
|
|
- {
|
|
|
- if (machine.ConnectorType.Contains("6") || machine.ConnectorType.Contains("7") || machine.ConnectorType.Contains("8") || machine.ConnectorType.Contains("9"))
|
|
|
- {
|
|
|
- session.IsAC = false;
|
|
|
- }
|
|
|
- machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- await SetDefaultFee(session);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -943,75 +935,75 @@ namespace EVCB_OCPP.WSServer
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
}
|
|
|
|
|
|
- if (action == Actions.StartTransaction)
|
|
|
- {
|
|
|
- var stationId = _loadingBalanceService.GetStationIdByMachineId(session.MachineId);
|
|
|
- var _powerDic = _loadingBalanceService.GetSettingPower(stationId, session.MachineId);
|
|
|
- if (_powerDic != null)
|
|
|
- {
|
|
|
- foreach (var kv in _powerDic)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- string chargeBoxId = string.Empty;
|
|
|
- //set profile
|
|
|
- lock (_lockClientDic)
|
|
|
- {
|
|
|
- chargeBoxId = clientDic.Where(x => x.Value.MachineId == kv.Key).Select(x => x.Value.ChargeBoxId).FirstOrDefault();
|
|
|
- }
|
|
|
-
|
|
|
- if (chargeBoxId != null && kv.Value.HasValue)
|
|
|
- {
|
|
|
- profileHandler.SetChargingProfile(chargeBoxId, kv.Value.Value, Packet.Messages.SubTypes.ChargingRateUnitType.W);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.Error(string.Format("Set Profile Exception: {0}", ex.ToString()));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (action == Actions.StopTransaction)
|
|
|
- {
|
|
|
- var stationId = _loadingBalanceService.GetStationIdByMachineId(session.MachineId);
|
|
|
- if (_loadingBalanceService.IsNeedtoCancelSetting(stationId, session.MachineId, session.ChargeBoxId))
|
|
|
- {
|
|
|
- //Clear current profile
|
|
|
- profileHandler.ClearChargingProfile(session.ChargeBoxId);
|
|
|
-
|
|
|
- var _powerDic = _loadingBalanceService.GetRerangeSettingPower(stationId);
|
|
|
- if (_powerDic != null)
|
|
|
- {
|
|
|
- foreach (var kv in _powerDic)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- string chargeBoxId = string.Empty;
|
|
|
- //set profile
|
|
|
- lock (_lockClientDic)
|
|
|
- {
|
|
|
- chargeBoxId = clientDic.Where(x => x.Value.MachineId == kv.Key).Select(x => x.Value.ChargeBoxId).FirstOrDefault();
|
|
|
- }
|
|
|
-
|
|
|
- if (chargeBoxId != null && kv.Value.HasValue)
|
|
|
- {
|
|
|
- profileHandler.SetChargingProfile(chargeBoxId, kv.Value.Value, Packet.Messages.SubTypes.ChargingRateUnitType.W);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.Error(string.Format("Set Profile Exception: {0}", ex.ToString()));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ //if (action == Actions.StartTransaction)
|
|
|
+ //{
|
|
|
+ // var stationId = _loadingBalanceService.GetStationIdByMachineId(session.MachineId);
|
|
|
+ // var _powerDic = _loadingBalanceService.GetSettingPower(stationId, session.MachineId);
|
|
|
+ // if (_powerDic != null)
|
|
|
+ // {
|
|
|
+ // foreach (var kv in _powerDic)
|
|
|
+ // {
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // string chargeBoxId = string.Empty;
|
|
|
+ // //set profile
|
|
|
+ // lock (_lockClientDic)
|
|
|
+ // {
|
|
|
+ // chargeBoxId = clientDic.Where(x => x.Value.MachineId == kv.Key).Select(x => x.Value.ChargeBoxId).FirstOrDefault();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (chargeBoxId != null && kv.Value.HasValue)
|
|
|
+ // {
|
|
|
+ // profileHandler.SetChargingProfile(chargeBoxId, kv.Value.Value, Packet.Messages.SubTypes.ChargingRateUnitType.W);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // logger.Error(string.Format("Set Profile Exception: {0}", ex.ToString()));
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (action == Actions.StopTransaction)
|
|
|
+ //{
|
|
|
+ // var stationId = _loadingBalanceService.GetStationIdByMachineId(session.MachineId);
|
|
|
+ // if (_loadingBalanceService.IsNeedtoCancelSetting(stationId, session.MachineId, session.ChargeBoxId))
|
|
|
+ // {
|
|
|
+ // //Clear current profile
|
|
|
+ // profileHandler.ClearChargingProfile(session.ChargeBoxId);
|
|
|
+
|
|
|
+ // var _powerDic = _loadingBalanceService.GetRerangeSettingPower(stationId);
|
|
|
+ // if (_powerDic != null)
|
|
|
+ // {
|
|
|
+ // foreach (var kv in _powerDic)
|
|
|
+ // {
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // string chargeBoxId = string.Empty;
|
|
|
+ // //set profile
|
|
|
+ // lock (_lockClientDic)
|
|
|
+ // {
|
|
|
+ // chargeBoxId = clientDic.Where(x => x.Value.MachineId == kv.Key).Select(x => x.Value.ChargeBoxId).FirstOrDefault();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (chargeBoxId != null && kv.Value.HasValue)
|
|
|
+ // {
|
|
|
+ // profileHandler.SetChargingProfile(chargeBoxId, kv.Value.Value, Packet.Messages.SubTypes.ChargingRateUnitType.W);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // logger.Error(string.Format("Set Profile Exception: {0}", ex.ToString()));
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+
|
|
|
+ //}
|
|
|
|
|
|
}
|
|
|
break;
|
|
@@ -1211,6 +1203,61 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
|
|
|
}
|
|
|
+ DateTime fillinDt = DateTime.UtcNow.AddMinutes(-1);
|
|
|
+ async private void FillinChargerData()
|
|
|
+ {
|
|
|
+ for (; ; )
|
|
|
+ {
|
|
|
+ if (_ct.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ var min_Interval = (DateTime.UtcNow - fillinDt).TotalSeconds;
|
|
|
+ if (min_Interval > 3)
|
|
|
+ {
|
|
|
+ BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
|
+ Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
+ lock (_lockClientDic)
|
|
|
+ {
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+
|
|
|
+ }
|
|
|
+ var chargers = _copyClientDic.Values.Where(x => x.CustomerId == Guid.Empty).Take(100).ToList();
|
|
|
+ fillinDt = DateTime.UtcNow;
|
|
|
+ using (var db = new MainDBContext())
|
|
|
+ {
|
|
|
+
|
|
|
+ foreach (var charger in chargers)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ var machine = db.Machine.Where(x => x.ChargeBoxId == charger.ChargeBoxId && x.IsDelete == false).Select(x => new { x.CustomerId, x.Id ,x.ConnectorType }).FirstOrDefault();
|
|
|
+ if (machine == null)
|
|
|
+ {
|
|
|
+ charger.LastActiveTime = DateTime.UtcNow.AddDays(-1);
|
|
|
+ }
|
|
|
+ if (machine.ConnectorType.Contains("6") || machine.ConnectorType.Contains("7") || machine.ConnectorType.Contains("8") || machine.ConnectorType.Contains("9"))
|
|
|
+ {
|
|
|
+ charger.IsAC = false;
|
|
|
+ }
|
|
|
+ charger.CustomerName = machine == null ? "Unknown" : db.Customer.Where(x => x.Id == machine.CustomerId).Select(x => x.Name).FirstOrDefault();
|
|
|
+ charger.CustomerId = machine == null ? Guid.Empty : machine.CustomerId;
|
|
|
+ charger.MachineId = machine == null ? String.Empty : machine.Id;
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error(string.Format("FillinChargerData ChargeBoxId:{0} Ex:{1}", charger.ChargeBoxId, ex.ToString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await Task.Delay(10000);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
async private void ServerUpdateTrigger()
|
|
|
{
|
|
@@ -1510,6 +1557,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
watch.Start();
|
|
|
foreach (var session in clients)
|
|
|
{
|
|
|
+ if (string.IsNullOrEmpty(session.MachineId))
|
|
|
+ continue;
|
|
|
+
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
var machine = new Machine() { Id = session.MachineId };
|
|
@@ -2065,7 +2115,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
try
|
|
|
{
|
|
|
session.m_ReceiveData -= new ClientData.OCPPClientDataEventHandler<ClientData, String>(ReceivedMessage);
|
|
|
- // session.Close(CloseReason.ServerShutdown);
|
|
|
+ session.Close(CloseReason.ServerShutdown);
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -2109,6 +2159,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ //using (var maindb = new MainDBContext())
|
|
|
+ //{
|
|
|
+ // GlobalConfig.Machines = maindb.Machine.ToList();
|
|
|
+ //}
|
|
|
+
|
|
|
using (var log = new ConnectionLogDBContext())
|
|
|
{
|
|
|
log.MachineConnectionLog.ToList();
|