|
@@ -6,6 +6,7 @@ using EVCB_OCPP.Packet.Messages;
|
|
|
using EVCB_OCPP.Packet.Messages.Basic;
|
|
|
using EVCB_OCPP.Packet.Messages.Core;
|
|
|
using EVCB_OCPP.Packet.Messages.RemoteTrigger;
|
|
|
+using EVCB_OCPP.WSServer.Dto;
|
|
|
using EVCB_OCPP.WSServer.Helper;
|
|
|
using EVCB_OCPP.WSServer.Message;
|
|
|
using EVCB_OCPP.WSServer.Service;
|
|
@@ -49,13 +50,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
- private DateTime lastcheckdt = DateTime.Now.AddSeconds(-20);
|
|
|
+ private DateTime lastcheckdt = DateTime.UtcNow.AddSeconds(-20);
|
|
|
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 DateTime checkUpdateDt = DateTime.Now;
|
|
|
+ private DateTime checkUpdateDt = DateTime.UtcNow;
|
|
|
+ private DateTime _CheckFeeDt = DateTime.UtcNow;
|
|
|
private LoadingBalanceService _loadingBalanceService = new LoadingBalanceService();
|
|
|
private List<string> needConfirmActions = new List<string>()
|
|
|
{
|
|
@@ -119,6 +121,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
Task serverUpdateTask = new Task(ServerUpdateTrigger, _ct);
|
|
|
serverUpdateTask.Start();
|
|
|
|
|
|
+ Task serverSetFeeTask = new Task(ServerSetFeeTrigger, _ct);
|
|
|
+ serverSetFeeTask.Start();
|
|
|
|
|
|
Task serverBeatTask = new Task(HeartBeatCheckTrigger, _ct);
|
|
|
serverBeatTask.Start();
|
|
@@ -219,7 +223,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
.Where(c => c.Attribute("writeTo").Value.Equals("console")).Attributes("minlevel").FirstOrDefault();
|
|
|
if (minlevelattr != null)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
minlevelattr.Value = "Warn";
|
|
|
}
|
|
|
xe.Save("NLog.config");
|
|
@@ -232,7 +236,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
.Where(c => c.Attribute("writeTo").Value.Equals("console")).Attributes("minlevel").FirstOrDefault();
|
|
|
if (minlevelattr1 != null)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
minlevelattr1.Value = "trace";
|
|
|
}
|
|
|
xe1.Save("NLog.config");
|
|
@@ -262,7 +266,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
ChargeBoxId = chargeBoxId,
|
|
|
CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.Now,
|
|
|
+ CreatedOn = DateTime.UtcNow,
|
|
|
OutAction = Actions.DataTransfer.ToString(),
|
|
|
OutRequest = JsonConvert.SerializeObject(
|
|
|
new DataTransferRequest()
|
|
@@ -282,53 +286,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
- private string SetDefaultFee(string chargeBoxId, string machineId)
|
|
|
- {
|
|
|
-
|
|
|
- string feeText = "0.00";
|
|
|
- string currencyText = "USD";
|
|
|
- if (string.IsNullOrEmpty(chargeBoxId)) return feeText;
|
|
|
-
|
|
|
- using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@MachineId", machineId, DbType.String, ParameterDirection.Input);
|
|
|
- string strSql = "SELECT CAST( [Fee] as varchar(5))+' '+ [Currency] FROM[StationMachine] left join[StandardOCPP_Web].[dbo].[Station]" +
|
|
|
- " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId ; ";
|
|
|
- feeText = conn.ExecuteScalar<string>(strSql, parameters);
|
|
|
- currencyText = feeText.Split(' ')[1];
|
|
|
- feeText = feeText.Split(' ')[0];
|
|
|
- feeText = string.Format("Connection Fee: $0.00 {0}/time; Current Rate: ${1} {0}/kWh; Occupancy Fee: $0.00 {0}/hr",currencyText, string.IsNullOrEmpty(feeText) ? "0.00" : feeText);
|
|
|
- }
|
|
|
-
|
|
|
- using (var db = new MainDBContext())
|
|
|
- {
|
|
|
- db.ServerMessage.Add(new ServerMessage()
|
|
|
- {
|
|
|
- ChargeBoxId = chargeBoxId,
|
|
|
- CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.Now,
|
|
|
- OutAction = Actions.ChangeConfiguration.ToString(),
|
|
|
- OutRequest = JsonConvert.SerializeObject(
|
|
|
- new ChangeConfigurationRequest()
|
|
|
- {
|
|
|
- key = "DefaultPrice",
|
|
|
- // value= "Connection Fee: $0.00 USD/time; Current Rate: $1.02 USD/kWh; Occupancy Fee: $0.00 USD/hr"
|
|
|
- value = feeText
|
|
|
- },
|
|
|
- new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- SerialNo = Guid.NewGuid().ToString(),
|
|
|
- InMessage = string.Empty
|
|
|
-
|
|
|
- }); ;
|
|
|
-
|
|
|
- db.SaveChanges();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return feeText;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
private void CheckEVSEConfigure(string chargeBoxId)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(chargeBoxId)) return;
|
|
@@ -338,7 +296,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
ChargeBoxId = chargeBoxId,
|
|
|
CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.Now,
|
|
|
+ CreatedOn = DateTime.UtcNow,
|
|
|
OutAction = Actions.GetConfiguration.ToString(),
|
|
|
OutRequest = JsonConvert.SerializeObject(
|
|
|
new GetConfigurationRequest()
|
|
@@ -380,7 +338,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
//Port = Convert.ToInt32(2012),
|
|
|
//Ip = "172.17.40.13",
|
|
|
- MaxRequestLength = 4096,
|
|
|
+ MaxRequestLength = 204800,
|
|
|
//Security = serverSecurity,
|
|
|
Certificate = Certificate,
|
|
|
Listeners = listeners,
|
|
@@ -421,7 +379,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
private void AppServer_NewSessionConnected(ClientData session)
|
|
|
{
|
|
|
-
|
|
|
+ Console.WriteLine("++++++++++++++++");
|
|
|
try
|
|
|
{
|
|
|
lock (_lockClientDic)
|
|
@@ -485,7 +443,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
if (session.ResetSecurityProfile)
|
|
|
{
|
|
|
- logger.Error(string.Format("[{0}] ChargeBoxId:{1} ResetSecurityProfile", DateTime.Now, session.ChargeBoxId));
|
|
|
+ logger.Error(string.Format("[{0}] ChargeBoxId:{1} ResetSecurityProfile", DateTime.UtcNow, session.ChargeBoxId));
|
|
|
RemoveClient(session);
|
|
|
return;
|
|
|
}
|
|
@@ -559,7 +517,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
EVCB_OCPP20.Packet.Messages.BootNotificationRequest _request = (EVCB_OCPP20.Packet.Messages.IRequest)analysisResult.Message as EVCB_OCPP20.Packet.Messages.BootNotificationRequest;
|
|
|
|
|
|
- var confirm = new EVCB_OCPP20.Packet.Messages.BootNotificationResponse() { CurrentTime = DateTime.Now, Interval = 180, Status = EVCB_OCPP20.Packet.DataTypes.EnumTypes.RegistrationStatusEnumType.Pending };
|
|
|
+ var confirm = new EVCB_OCPP20.Packet.Messages.BootNotificationResponse() { CurrentTime = DateTime.UtcNow, Interval = 180, Status = EVCB_OCPP20.Packet.DataTypes.EnumTypes.RegistrationStatusEnumType.Pending };
|
|
|
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
@@ -746,7 +704,6 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
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)
|
|
@@ -761,14 +718,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- session.FeeDescription = SetDefaultFee(session.ChargeBoxId, session.MachineId);
|
|
|
- session.Currency = session.FeeDescription.Substring(session.FeeDescription.Length-6, 3);
|
|
|
- // Console.WriteLine("*"+session.Currency+"*");
|
|
|
-
|
|
|
CheckVersion(session.ChargeBoxId);
|
|
|
CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await SetDefaultFee(session);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -1058,7 +1015,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- var min_Interval = (DateTime.Now - checkUpdateDt).TotalMinutes;
|
|
|
+ var min_Interval = (DateTime.UtcNow - checkUpdateDt).TotalMinutes;
|
|
|
if (min_Interval > 3)
|
|
|
{
|
|
|
BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
@@ -1068,7 +1025,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
_copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
|
|
|
}
|
|
|
- checkUpdateDt = DateTime.Now;
|
|
|
+ checkUpdateDt = DateTime.UtcNow;
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
//var needUpdateChargers = db.Machine.Where(x => x.FW_AssignedMachineVersionId.HasValue == true &&
|
|
@@ -1124,12 +1081,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
// {
|
|
|
// location = new Uri(downloadUrl),
|
|
|
// retries = 3,
|
|
|
- // retrieveDate = DateTime.Now,
|
|
|
+ // retrieveDate = DateTime.UtcNow,
|
|
|
// retryInterval = 10
|
|
|
// };
|
|
|
// db.MachineOperateRecord.Add(new MachineOperateRecord()
|
|
|
// {
|
|
|
- // CreatedOn = DateTime.Now,
|
|
|
+ // CreatedOn = DateTime.UtcNow,
|
|
|
// ChargeBoxId = session.ChargeBoxId,
|
|
|
// SerialNo = requestId,
|
|
|
// RequestContent = JsonConvert.SerializeObject(_updateFWrequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
@@ -1144,7 +1101,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
// {
|
|
|
// ChargeBoxId = session.ChargeBoxId,
|
|
|
// CreatedBy = "Server",
|
|
|
- // CreatedOn = DateTime.Now,
|
|
|
+ // CreatedOn = DateTime.UtcNow,
|
|
|
// OutAction = _updateFWrequest.Action.ToString(),
|
|
|
// OutRequest = JsonConvert.SerializeObject(_updateFWrequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
// SerialNo = requestId,
|
|
@@ -1195,9 +1152,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
- DateTime startDt = DateTime.Now.AddSeconds(-30);
|
|
|
+ DateTime startDt = DateTime.UtcNow.AddSeconds(-30);
|
|
|
DateTime dt = new DateTime(1991, 1, 1);
|
|
|
- DateTime currentTime = DateTime.Now;
|
|
|
+ DateTime currentTime = DateTime.UtcNow;
|
|
|
var commandList = db.ServerMessage.Where(c => c.ReceivedOn == dt && c.UpdatedOn == dt && c.CreatedOn >= startDt && c.CreatedOn <= currentTime).AsNoTracking().ToList();
|
|
|
|
|
|
|
|
@@ -1205,7 +1162,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.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"), commandList.Count));
|
|
|
}
|
|
|
|
|
|
foreach (var charger_SN in cmdMachineList)
|
|
@@ -1214,7 +1171,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
string uuid = string.Empty;
|
|
|
if (clientDic.TryGetValue(charger_SN, out session))
|
|
|
{
|
|
|
- logger.Debug(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")));
|
|
|
+ //logger.Debug(string.Format("charger_SN:{0} startDt:{1} CreatedOn:{2}", charger_SN, startDt.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss")));
|
|
|
|
|
|
if (session.IsCheckIn && !session.ISOCPP20)
|
|
|
{
|
|
@@ -1249,10 +1206,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
if (item.CreatedBy == "Destroyer")
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if (_RequestType != null)
|
|
|
{
|
|
|
- request = Activator.CreateInstance(_RequestType) as IRequest;
|
|
|
+ request = Activator.CreateInstance(_RequestType) as IRequest;
|
|
|
uuid = session.queue.store(request);
|
|
|
string rawRequest = BasicMessageHandler.GenerateDestroyRequest(uuid, item.OutAction, item.OutRequest);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
@@ -1270,16 +1227,16 @@ namespace EVCB_OCPP.WSServer
|
|
|
AddConfirmMessage(charger_SN, item.Id, item.SerialNo, item.OutAction, uuid);
|
|
|
|
|
|
#region 更新資料表單一欄位
|
|
|
- var _UpdatedItem = new ServerMessage() { Id = item.Id, UpdatedOn = DateTime.Now };
|
|
|
+ var _UpdatedItem = new ServerMessage() { Id = item.Id, UpdatedOn = DateTime.UtcNow };
|
|
|
db.Configuration.AutoDetectChangesEnabled = false;//自動呼叫DetectChanges()比對所有的entry集合的每一個屬性Properties的新舊值
|
|
|
db.Configuration.ValidateOnSaveEnabled = false;// 因為Entity有些欄位必填,若不避開會有Validate錯誤
|
|
|
// var _UpdatedItem = db.ServerMessage.Where(x => x.Id == item.Id).FirstOrDefault();
|
|
|
db.ServerMessage.Attach(_UpdatedItem);
|
|
|
- _UpdatedItem.UpdatedOn = DateTime.Now;
|
|
|
+ _UpdatedItem.UpdatedOn = DateTime.UtcNow;
|
|
|
db.Entry(_UpdatedItem).Property(x => x.UpdatedOn).IsModified = true;// 可以直接使用這方式強制某欄位要更新,只是查詢集合耗效能而己
|
|
|
|
|
|
db.SaveChanges();
|
|
|
- await Task.Delay(10);
|
|
|
+ await Task.Delay(100);
|
|
|
#endregion
|
|
|
|
|
|
|
|
@@ -1292,7 +1249,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
|
|
|
await Task.Delay(1000);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -1314,9 +1271,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
try
|
|
|
{
|
|
|
|
|
|
- if (DateTime.Now.Subtract(lastcheckdt).TotalSeconds > 30)
|
|
|
+ if (DateTime.UtcNow.Subtract(lastcheckdt).TotalSeconds > 30)
|
|
|
{
|
|
|
- lastcheckdt = DateTime.Now;
|
|
|
+ lastcheckdt = DateTime.UtcNow;
|
|
|
Stopwatch watch = new Stopwatch();
|
|
|
Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
lock (_lockClientDic)
|
|
@@ -1324,7 +1281,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
_copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
}
|
|
|
|
|
|
- var cdt = DateTime.Now;
|
|
|
+ var cdt = DateTime.UtcNow;
|
|
|
var clients = _copyClientDic.Where(x => x.Value.LastActiveTime > cdt.AddSeconds(-120)).Select(x => x.Value).ToList();
|
|
|
|
|
|
watch.Start();
|
|
@@ -1338,7 +1295,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
db.Configuration.AutoDetectChangesEnabled = false;
|
|
|
db.Configuration.ValidateOnSaveEnabled = false;
|
|
|
db.Machine.Attach(machine);
|
|
|
- machine.HeartbeatUpdatedOn = DateTime.Now;
|
|
|
+ machine.HeartbeatUpdatedOn = DateTime.UtcNow;
|
|
|
machine.ConnectionType = session.UriScheme.Equals("wss") ? 2 : 1;
|
|
|
db.Entry(machine).Property(x => x.HeartbeatUpdatedOn).IsModified = true;
|
|
|
db.Entry(machine).Property(x => x.ConnectionType).IsModified = true;
|
|
@@ -1366,6 +1323,112 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async private void ServerSetFeeTrigger()
|
|
|
+ {
|
|
|
+ for (; ; )
|
|
|
+ {
|
|
|
+ if (_ct.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ var min_Interval = (DateTime.UtcNow - _CheckFeeDt).TotalMinutes;
|
|
|
+ if (min_Interval > 1)
|
|
|
+ {
|
|
|
+ BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
|
+ Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
+ lock (_lockClientDic)
|
|
|
+ {
|
|
|
+ _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+
|
|
|
+ }
|
|
|
+ _CheckFeeDt = DateTime.UtcNow;
|
|
|
+ foreach (var item in _copyClientDic)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ClientData session = item.Value;
|
|
|
+ if (session.IsCheckIn)
|
|
|
+ {
|
|
|
+
|
|
|
+ string displayPriceText = await SetDefaultFee(session);
|
|
|
+ if (!string.IsNullOrEmpty(displayPriceText) && displayPriceText != session.DisplayPrice)
|
|
|
+ {
|
|
|
+ clientDic[item.Key].DisplayPrice = displayPriceText;
|
|
|
+
|
|
|
+ using (var db = new MainDBContext())
|
|
|
+ {
|
|
|
+ db.ServerMessage.Add(new ServerMessage()
|
|
|
+ {
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ CreatedBy = "Server",
|
|
|
+ CreatedOn = DateTime.UtcNow,
|
|
|
+ OutAction = Actions.ChangeConfiguration.ToString(),
|
|
|
+ OutRequest = JsonConvert.SerializeObject(
|
|
|
+ new ChangeConfigurationRequest()
|
|
|
+ {
|
|
|
+ key = "DefaultPrice",
|
|
|
+ value = clientDic[item.Key].DisplayPrice
|
|
|
+ },
|
|
|
+ new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ InMessage = string.Empty
|
|
|
+
|
|
|
+ }); ;
|
|
|
+
|
|
|
+ await db.SaveChangesAsync();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error(string.Format("ServerSetFeeTrigger ChargeBoxId:{0} Ex:{1}", item.Key, ex.ToString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await Task.Delay(1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async private Task<string> SetDefaultFee(ClientData client)
|
|
|
+ {
|
|
|
+ string displayPriceText = string.Empty;
|
|
|
+ string charingPriceText = string.Empty;
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(client.ChargeBoxId)) return displayPriceText;
|
|
|
+
|
|
|
+ using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
+ {
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input);
|
|
|
+ string displayPricestrSql = " SELECT [FeeName],[Currency],[Fee],[BillingMethod] FROM[StationMachine] left join [dbo].[Station]" +
|
|
|
+ " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
+ string strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee] FROM[StationMachine] left join [dbo].[StationFee]" +
|
|
|
+ " on[StationMachine].StationId = StationFee.StationId where StationMachine.MachineId =@MachineId ; ";
|
|
|
+ var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
|
|
|
+ var stationPrice = result.FirstOrDefault();
|
|
|
+ if (stationPrice == null)
|
|
|
+ {
|
|
|
+ return string.Empty;
|
|
|
+ }
|
|
|
+ client.BillingMethod = stationPrice.BillingMethod;
|
|
|
+ var chargingPriceResult = await conn.QueryAsync<ChargingPrice>(strSql, parameters);
|
|
|
+ client.ChargingPrices = chargingPriceResult.ToList();
|
|
|
+ if (string.IsNullOrEmpty(client.ChargingPrices[0].StartTime))
|
|
|
+ {
|
|
|
+ client.ChargingPrices = new List<ChargingPrice>();
|
|
|
+ }
|
|
|
+ displayPriceText = stationPrice.FeeName;
|
|
|
+ client.Currency = stationPrice.Currency;
|
|
|
+ client.HRPrice = stationPrice.Fee;
|
|
|
+ client.IsBilling = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return displayPriceText;
|
|
|
+ }
|
|
|
|
|
|
async private void HealthCheckTrigger()
|
|
|
{
|
|
@@ -1384,7 +1447,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
_copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
}
|
|
|
|
|
|
- var removeClients = _copyClientDic.Where(x => x.Value.LastActiveTime < DateTime.Now.AddSeconds(-300)).Select(x => x.Value).ToList();
|
|
|
+ var removeClients = _copyClientDic.Where(x => x.Value.LastActiveTime < DateTime.UtcNow.AddSeconds(-300)).Select(x => x.Value).ToList();
|
|
|
|
|
|
foreach (var session in removeClients)
|
|
|
{
|
|
@@ -1409,7 +1472,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
NeedConfirmMessage _needConfirmMsg = new NeedConfirmMessage();
|
|
|
_needConfirmMsg.Id = table_id;
|
|
|
_needConfirmMsg.SentAction = action;
|
|
|
- _needConfirmMsg.SentOn = DateTime.Now;
|
|
|
+ _needConfirmMsg.SentOn = DateTime.UtcNow;
|
|
|
_needConfirmMsg.SentTimes = 1;
|
|
|
_needConfirmMsg.ChargePointSerialNumber = chargePointSerialNumber;
|
|
|
_needConfirmMsg.RequestId = requestId;
|
|
@@ -1420,7 +1483,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
lock (_lockConfirmPacketList)
|
|
|
{
|
|
|
- needConfirmPacketList.Add(_needConfirmMsg);
|
|
|
+ needConfirmPacketList.Add(_needConfirmMsg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1428,7 +1491,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
private void RemoveConfirmMessage()
|
|
|
{
|
|
|
|
|
|
- var before_3mins = DateTime.Now.AddMinutes(-3);
|
|
|
+ var before_3mins = DateTime.UtcNow.AddMinutes(-3);
|
|
|
lock (_lockConfirmPacketList)
|
|
|
{
|
|
|
var removeList = needConfirmPacketList.Where(x => x.SentTimes == 0 || x.SentOn < before_3mins).ToList();
|
|
@@ -1444,7 +1507,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
bool confirmed = false;
|
|
|
if (needConfirmActions.Contains(analysisResult.Action))
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
NeedConfirmMessage foundRequest = null;
|
|
|
lock (_lockConfirmPacketList)
|
|
|
{
|
|
@@ -1461,9 +1524,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
var sc = db.ServerMessage.Where(x => x.Id == foundRequest.Id).FirstOrDefault();
|
|
|
sc.InMessage = JsonConvert.SerializeObject(analysisResult.Message, Formatting.None);
|
|
|
- sc.ReceivedOn = DateTime.Now;
|
|
|
+ sc.ReceivedOn = DateTime.UtcNow;
|
|
|
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.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"), foundRequest.Id));
|
|
|
|
|
|
}
|
|
|
confirmed = true;
|
|
@@ -1489,7 +1552,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
private void RemoveClient(ClientData session)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
|
|
|
if (session != null)
|
|
|
{
|