|
@@ -104,10 +104,6 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
_ct = _cts.Token;
|
|
|
WarmUpLog();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -296,7 +292,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
SerialNo = Guid.NewGuid().ToString(),
|
|
|
InMessage = string.Empty
|
|
|
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
db.SaveChanges();
|
|
|
}
|
|
@@ -756,9 +752,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
if (((BootNotificationConfirmation)replyResult.Message).status == Packet.Messages.SubTypes.RegistrationStatus.Accepted)
|
|
|
{
|
|
|
- session.IsCheckIn = true;
|
|
|
-
|
|
|
-
|
|
|
+ session.IsCheckIn = true;
|
|
|
CheckVersion(session.ChargeBoxId);
|
|
|
CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
|
|
@@ -1330,8 +1324,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- RemoveConfirmMessage();
|
|
|
-
|
|
|
+ RemoveConfirmMessage();
|
|
|
BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
@@ -1347,7 +1340,22 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
// Console.WriteLine(string.Format("Now:{0} commandList Count:{1} ", DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"), commandList.Count));
|
|
|
}
|
|
|
+ var resendList = GetResendMessage();
|
|
|
+ foreach (var resendItem in resendList)
|
|
|
+ {
|
|
|
+ ClientData session;
|
|
|
+ if (clientDic.TryGetValue(resendItem.ChargePointSerialNumber, out session))
|
|
|
+ {
|
|
|
+ if (DateTime.UtcNow.Subtract(resendItem.SentOn).TotalSeconds > 1)
|
|
|
+ {
|
|
|
+ resendItem.SentTimes--;
|
|
|
+ resendItem.SentOn = DateTime.UtcNow;
|
|
|
+ Send(session, resendItem.SentMessage, string.Format("{0} {1}", resendItem.SentAction, "Request"), "");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
foreach (var charger_SN in cmdMachineList)
|
|
|
{
|
|
|
ClientData session;
|
|
@@ -1358,8 +1366,10 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
if (session.IsCheckIn && !session.ISOCPP20)
|
|
|
{
|
|
|
+ string rawRequest = string.Empty;
|
|
|
+
|
|
|
var cmdList = commandList.Where(c => c.ChargeBoxId == charger_SN).ToList();
|
|
|
-
|
|
|
+
|
|
|
foreach (var item in cmdList)
|
|
|
{
|
|
|
IRequest request = null;
|
|
@@ -1382,7 +1392,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
request = JsonConvert.DeserializeObject(item.OutRequest, _RequestType) as IRequest;
|
|
|
uuid = session.queue.store(request);
|
|
|
- string rawRequest = BasicMessageHandler.GenerateRequest(uuid, item.OutAction, request);
|
|
|
+ rawRequest = BasicMessageHandler.GenerateRequest(uuid, item.OutAction, request);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
|
}
|
|
|
|
|
@@ -1394,20 +1404,20 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
request = Activator.CreateInstance(_RequestType) as IRequest;
|
|
|
uuid = session.queue.store(request);
|
|
|
- string rawRequest = BasicMessageHandler.GenerateDestroyRequest(uuid, item.OutAction, item.OutRequest);
|
|
|
+ rawRequest = BasicMessageHandler.GenerateDestroyRequest(uuid, item.OutAction, item.OutRequest);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- string rawRequest = BasicMessageHandler.GenerateDestroyRequest(Guid.NewGuid().ToString(), item.OutAction, item.OutRequest);
|
|
|
+ rawRequest = BasicMessageHandler.GenerateDestroyRequest(Guid.NewGuid().ToString(), item.OutAction, item.OutRequest);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- AddConfirmMessage(charger_SN, item.Id, item.SerialNo, item.OutAction, uuid);
|
|
|
+ AddConfirmMessage(charger_SN, item.Id, item.SerialNo, item.OutAction, uuid, item.CreatedBy, rawRequest);
|
|
|
|
|
|
#region 更新資料表單一欄位
|
|
|
var _UpdatedItem = new ServerMessage() { Id = item.Id, UpdatedOn = DateTime.UtcNow };
|
|
@@ -1419,12 +1429,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
db.Entry(_UpdatedItem).Property(x => x.UpdatedOn).IsModified = true;// 可以直接使用這方式強制某欄位要更新,只是查詢集合耗效能而己
|
|
|
|
|
|
db.SaveChanges();
|
|
|
- await Task.Delay(100);
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
+ await Task.Delay(100);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1821,53 +1831,62 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
{
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input);
|
|
|
- string displayPricestrSql = "";
|
|
|
- string strSql = "";
|
|
|
-
|
|
|
- if (client.IsAC)
|
|
|
+ try
|
|
|
{
|
|
|
- displayPricestrSql = " SELECT [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour" +
|
|
|
- " ,[AC_ParkingFee] as ParkingFee, [Currency] FROM[StationMachine] left join[dbo].[Station]" +
|
|
|
- " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
|
|
|
- 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 and StationFee.IsAC=1; ";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- displayPricestrSql = " SELECT [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour" +
|
|
|
- " ,[DC_ParkingFee] as ParkingFee, [Currency] FROM[StationMachine] left join[dbo].[Station]" +
|
|
|
- " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
|
|
|
- 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 and StationFee.IsAC=0; ";
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input);
|
|
|
+ string displayPricestrSql = "";
|
|
|
+ string strSql = "";
|
|
|
+
|
|
|
+ if (client.IsAC)
|
|
|
+ {
|
|
|
+ displayPricestrSql = " SELECT [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour" +
|
|
|
+ " ,[AC_ParkingFee] as ParkingFee, [Currency] FROM[StationMachine] left join[dbo].[Station]" +
|
|
|
+ " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
+
|
|
|
+ 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 and StationFee.IsAC=1; ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ displayPricestrSql = " SELECT [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour" +
|
|
|
+ " ,[DC_ParkingFee] as ParkingFee, [Currency] FROM[StationMachine] left join[dbo].[Station]" +
|
|
|
+ " on[StationMachine].StationId = Station.[Id] where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
|
|
|
+
|
|
|
+ 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 and StationFee.IsAC=0; ";
|
|
|
+
|
|
|
+ }
|
|
|
+ var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
|
|
|
+ if (result.Count() == 0)
|
|
|
+ {
|
|
|
+ return string.Empty;
|
|
|
+ }
|
|
|
+ var stationPrice = result.First();
|
|
|
+
|
|
|
+ if (stationPrice.BillingMethod == 1)
|
|
|
+ {
|
|
|
+ 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.BillingMethod = stationPrice.BillingMethod;
|
|
|
+ client.Currency = stationPrice.Currency;
|
|
|
+ client.ChargingFeebyHour = stationPrice.ChargingFeebyHour;
|
|
|
+ client.ParkingFee = stationPrice.ParkingFee;
|
|
|
+ client.IsBilling = true;
|
|
|
}
|
|
|
- var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
|
|
|
- if (result.Count() == 0)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- return string.Empty;
|
|
|
+ logger.Error(ex.ToString());
|
|
|
}
|
|
|
- var stationPrice = result.First();
|
|
|
-
|
|
|
- if (stationPrice.BillingMethod == 1)
|
|
|
- {
|
|
|
- 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.BillingMethod = stationPrice.BillingMethod;
|
|
|
- client.Currency = stationPrice.Currency;
|
|
|
- client.ChargingFeebyHour = stationPrice.ChargingFeebyHour;
|
|
|
- client.ParkingFee = stationPrice.ParkingFee;
|
|
|
- client.IsBilling = true;
|
|
|
}
|
|
|
|
|
|
return displayPriceText;
|
|
@@ -1910,16 +1929,30 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void AddConfirmMessage(string chargePointSerialNumber, int table_id, string requestId, string action, string msg_id)
|
|
|
+ private List<NeedConfirmMessage> GetResendMessage()
|
|
|
+ {
|
|
|
+ List<NeedConfirmMessage> sendMessages = new List<NeedConfirmMessage>();
|
|
|
+ lock (_lockConfirmPacketList)
|
|
|
+ {
|
|
|
+ sendMessages = needConfirmPacketList.Where(x => x.SentTimes > 0 && x.CreatedBy == "Server").ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return sendMessages;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AddConfirmMessage(string chargePointSerialNumber, int table_id, string requestId, string action, string msg_id, string createdBy,string sendMessage)
|
|
|
{
|
|
|
NeedConfirmMessage _needConfirmMsg = new NeedConfirmMessage();
|
|
|
_needConfirmMsg.Id = table_id;
|
|
|
_needConfirmMsg.SentAction = action;
|
|
|
_needConfirmMsg.SentOn = DateTime.UtcNow;
|
|
|
- _needConfirmMsg.SentTimes = 1;
|
|
|
+ _needConfirmMsg.SentTimes = 3;
|
|
|
_needConfirmMsg.ChargePointSerialNumber = chargePointSerialNumber;
|
|
|
_needConfirmMsg.RequestId = requestId;
|
|
|
_needConfirmMsg.SentUniqueId = msg_id;
|
|
|
+ _needConfirmMsg.CreatedBy = createdBy;
|
|
|
+ _needConfirmMsg.SentMessage = sendMessage;
|
|
|
|
|
|
if (needConfirmActions.Contains(action))
|
|
|
{
|