|
@@ -264,57 +264,76 @@ namespace EVCB_OCPP.WSServer
|
|
|
int takeCount = 8;
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
-
|
|
|
- string maxKeys = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
- if (maxKeys == StandardConfiguration.GetConfigurationMaxKeys)
|
|
|
- {
|
|
|
- var _Configure = db.MachineConfiguration.Where(x => x.ChargeBoxId == chargeBoxId && x.ConfigureName == maxKeys).Select(x => new { ConfigureSetting = x.ConfigureSetting, ConfigureName = x.ConfigureName }).FirstOrDefault();
|
|
|
- if (_Configure != null)
|
|
|
- {
|
|
|
- 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)
|
|
|
+ db.ServerMessage.Add(new ServerMessage()
|
|
|
{
|
|
|
- string _key = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
- var _Configure = db.MachineConfiguration.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(
|
|
|
+ ChargeBoxId = chargeBoxId,
|
|
|
+ CreatedBy = "Server",
|
|
|
+ CreatedOn = DateTime.Now,
|
|
|
+ OutAction = Actions.GetConfiguration.ToString(),
|
|
|
+ OutRequest = JsonConvert.SerializeObject(
|
|
|
new GetConfigurationRequest()
|
|
|
{
|
|
|
- key = _keys
|
|
|
+ key = new List<string>()
|
|
|
|
|
|
},
|
|
|
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();
|
|
|
|
|
|
- }
|
|
|
+ //string maxKeys = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
+ //if (maxKeys == StandardConfiguration.GetConfigurationMaxKeys)
|
|
|
+ //{
|
|
|
+ // var _Configure = db.MachineConfiguration.Where(x => x.ChargeBoxId == chargeBoxId && x.ConfigureName == maxKeys).Select(x => new { ConfigureSetting = x.ConfigureSetting, ConfigureName = x.ConfigureName }).FirstOrDefault();
|
|
|
+ // if (_Configure != null)
|
|
|
+ // {
|
|
|
+ // 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.MachineConfiguration.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 = _keys
|
|
|
+
|
|
|
+ // },
|
|
|
+ // new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ // SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ // InMessage = string.Empty
|
|
|
+
|
|
|
+ // });
|
|
|
+
|
|
|
+ // db.SaveChanges();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // skipCount = skipCount + takeCount;
|
|
|
+
|
|
|
+ //}
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -345,9 +364,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
//Security = serverSecurity,
|
|
|
Certificate = Certificate,
|
|
|
Listeners = listeners,
|
|
|
- LogAllSocketException = true,
|
|
|
+ // LogAllSocketException = true,
|
|
|
KeepAliveTime = 10,
|
|
|
- LogBasicSessionActivity = true
|
|
|
+ // LogBasicSessionActivity = true
|
|
|
|
|
|
|
|
|
};
|
|
@@ -422,8 +441,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- CheckVersion(session.ChargeBoxId);
|
|
|
- CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
+
|
|
|
+ // CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -537,7 +556,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
async private void ProcessRequestMessage(MessageResult analysisResult, ClientData session, Actions action)
|
|
|
{
|
|
@@ -556,32 +575,32 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
|
|
|
|
|
|
- bool oldstatus = session.IsCheckIn;
|
|
|
+
|
|
|
var replyResult = await profileHandler.ExecuteCoreRequest(action, session, (IRequest)analysisResult.Message).ConfigureAwait(false);
|
|
|
if (replyResult.Success)
|
|
|
{
|
|
|
string response = msgAnalyser.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
|
+
|
|
|
+
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Confirmation"), replyResult.Exception == null ? string.Empty : replyResult.Exception.ToString());
|
|
|
+
|
|
|
+
|
|
|
if (action == Actions.BootNotification && replyResult.Message is BootNotificationConfirmation)
|
|
|
{
|
|
|
if (((BootNotificationConfirmation)replyResult.Message).status == Packet.Messages.SubTypes.RegistrationStatus.Accepted)
|
|
|
{
|
|
|
- session.IsCheckIn = true;
|
|
|
- if (!oldstatus)
|
|
|
+ using (var db = new MainDBContext())
|
|
|
{
|
|
|
- using (var db = new MainDBContext())
|
|
|
+ var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
+ if (machine != null)
|
|
|
{
|
|
|
- var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
- if (machine != null)
|
|
|
- {
|
|
|
- machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
+ machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
|
|
|
+ db.SaveChanges();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- // CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
}
|
|
|
+
|
|
|
+ CheckVersion(session.ChargeBoxId);
|
|
|
+ CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -992,7 +1011,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
var cmdMachineList = commandList.Select(c => c.ChargeBoxId).Distinct().ToList();
|
|
|
if (commandList.Count > 0)
|
|
|
{
|
|
|
- Console.WriteLine(string.Format("Now:{0} commandList Count:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), commandList.Count));
|
|
|
+ // Console.WriteLine(string.Format("Now:{0} commandList Count:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), commandList.Count));
|
|
|
}
|
|
|
|
|
|
foreach (var charger_SN in cmdMachineList)
|
|
@@ -1002,6 +1021,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
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)
|
|
|
{
|
|
|
var cmdList = commandList.Where(c => c.ChargeBoxId == charger_SN).ToList();
|
|
@@ -1053,7 +1073,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- db.ChangeTracker.DetectChanges();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
await Task.Delay(1000);
|
|
@@ -1077,9 +1097,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
|
|
|
try
|
|
|
- {
|
|
|
+ {
|
|
|
|
|
|
- if (DateTime.Now.Subtract(lastcheckdt).TotalSeconds > 20)
|
|
|
+ if (DateTime.Now.Subtract(lastcheckdt).TotalSeconds > 10)
|
|
|
{
|
|
|
Stopwatch watch = new Stopwatch();
|
|
|
Dictionary<string, ClientData> _copyClientDic = null;
|
|
@@ -1088,12 +1108,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
_copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
}
|
|
|
|
|
|
- var clients = _copyClientDic.Where(x => x.Value.LastActiveTime > DateTime.Now.AddSeconds(-60)).Select(x => x.Value).ToList();
|
|
|
-
|
|
|
+ var cdt = DateTime.Now;
|
|
|
+ var clients = _copyClientDic.Where(x => x.Value.LastActiveTime > cdt.AddSeconds(-30)).Select(x => x.Value).ToList();
|
|
|
+
|
|
|
watch.Start();
|
|
|
foreach (var session in clients)
|
|
|
{
|
|
|
-
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
var machine = new Machine() { Id = session.MachineId };
|
|
@@ -1112,14 +1132,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
watch.Stop();
|
|
|
- if (watch.ElapsedMilliseconds/1000 > 5)
|
|
|
+ if (watch.ElapsedMilliseconds / 1000 > 5)
|
|
|
{
|
|
|
logger.Fatal("Update HeartBeatCheckTrigger cost " + watch.ElapsedMilliseconds / 1000 + " seconds.");
|
|
|
}
|
|
|
}
|
|
|
lastcheckdt = DateTime.Now;
|
|
|
|
|
|
- await Task.Delay(60000);
|
|
|
+ await Task.Delay(10000);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -1233,7 +1253,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
sc.InMessage = JsonConvert.SerializeObject(analysisResult.Message, Formatting.None);
|
|
|
sc.ReceivedOn = DateTime.Now;
|
|
|
db.SaveChanges();
|
|
|
- Console.WriteLine(string.Format("Now:{0} ServerMessage Id:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), foundRequest.Id));
|
|
|
+ // Console.WriteLine(string.Format("Now:{0} ServerMessage Id:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), foundRequest.Id));
|
|
|
|
|
|
}
|
|
|
confirmed = true;
|