|
@@ -2,12 +2,14 @@
|
|
|
using EVCB_OCPP.Domain.Models.MainDb;
|
|
|
using EVCB_OCPP.Packet.Features;
|
|
|
using EVCB_OCPP.Packet.Messages;
|
|
|
+using EVCB_OCPP.Packet.Messages.Core;
|
|
|
using EVCB_OCPP.WSServer.Message;
|
|
|
using EVCB_OCPP.WSServer.Service;
|
|
|
using EVCB_OCPP.WSServer.Service.WsService;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
+using Microsoft.VisualBasic;
|
|
|
using Newtonsoft.Json;
|
|
|
using Quartz;
|
|
|
using System;
|
|
@@ -25,21 +27,21 @@ public class ServerMessageJob : IJob
|
|
|
public ServerMessageJob(
|
|
|
ProtalServer protalServer,
|
|
|
ConfirmWaitingMessageSerevice confirmWaitingMessageSerevice,
|
|
|
- VendorIdReplaceService vendorIdReplaceService,
|
|
|
+ //VendorIdUpdateService vendorIdReplaceService,
|
|
|
IConfiguration configuration,
|
|
|
IDbContextFactory<MainDBContext> maindbContextFactory,
|
|
|
ILogger<ServerMessageJob> logger)
|
|
|
{
|
|
|
this.protalServer = protalServer;
|
|
|
this.confirmWaitingMessageSerevice = confirmWaitingMessageSerevice;
|
|
|
- this.vendorIdReplaceService = vendorIdReplaceService;
|
|
|
+ //this.vendorIdUpdateService = vendorIdReplaceService;
|
|
|
this.maindbContextFactory = maindbContextFactory;
|
|
|
this.logger = logger;
|
|
|
}
|
|
|
|
|
|
private readonly ProtalServer protalServer;
|
|
|
private readonly ConfirmWaitingMessageSerevice confirmWaitingMessageSerevice;
|
|
|
- private readonly VendorIdReplaceService vendorIdReplaceService;
|
|
|
+ //private readonly VendorIdUpdateService vendorIdUpdateService;
|
|
|
private readonly IDbContextFactory<MainDBContext> maindbContextFactory;
|
|
|
private readonly ILogger<ServerMessageJob> logger;
|
|
|
|
|
@@ -73,6 +75,7 @@ public class ServerMessageJob : IJob
|
|
|
DateTime dt = new DateTime(1991, 1, 1);
|
|
|
DateTime currentTime = dateTimeNow;
|
|
|
List<ServerMessage> commandList;
|
|
|
+ List<Task> waitTasks = new List<Task>();
|
|
|
|
|
|
using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
@@ -84,14 +87,16 @@ public class ServerMessageJob : IJob
|
|
|
{
|
|
|
// 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)
|
|
|
+ await Parallel.ForEachAsync(cmdMachineList, async (charger_SN, token) => //{ });
|
|
|
+ //foreach (var charger_SN in cmdMachineList)
|
|
|
{
|
|
|
WsClientData session;
|
|
|
string uuid = string.Empty;
|
|
|
|
|
|
if (!clientDic.TryGetValue(charger_SN, out session))
|
|
|
{
|
|
|
- continue;
|
|
|
+ //continue;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
//logger.LogDebug(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")));
|
|
@@ -99,7 +104,8 @@ public class ServerMessageJob : IJob
|
|
|
//if (session.IsCheckIn && !session.ISOCPP20)
|
|
|
if (session.ISOCPP20)
|
|
|
{
|
|
|
- continue;
|
|
|
+ //continue;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
string rawRequest = string.Empty;
|
|
@@ -129,6 +135,10 @@ public class ServerMessageJob : IJob
|
|
|
if (_RequestType != null && item.CreatedBy != "Destroyer")
|
|
|
{
|
|
|
request = JsonConvert.DeserializeObject(item.OutRequest, _RequestType) as IRequest;
|
|
|
+ if (action == Actions.DataTransfer)
|
|
|
+ {
|
|
|
+ ReplaceVID(session, action, request);
|
|
|
+ }
|
|
|
uuid = session.queue.store(request);
|
|
|
rawRequest = BasicMessageHandler.GenerateRequest(uuid, item.OutAction, request);
|
|
|
protalServer.SendMsg(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
@@ -155,13 +165,16 @@ public class ServerMessageJob : IJob
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await confirmWaitingMessageSerevice.Add(charger_SN, item.Id, item.SerialNo, item.OutAction, uuid, item.CreatedBy, rawRequest);
|
|
|
+ var tmpTask = confirmWaitingMessageSerevice.Add(charger_SN, item.Id, item.SerialNo, item.OutAction, uuid, item.CreatedBy, rawRequest);
|
|
|
+ waitTasks.Add(tmpTask);
|
|
|
//protalServer.AddConfirmMessage(charger_SN, item.Id, item.SerialNo, item.OutAction, uuid, item.CreatedBy, rawRequest);
|
|
|
|
|
|
await Task.Delay(100);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ );
|
|
|
+ await Task.WhenAll(waitTasks);
|
|
|
}
|
|
|
|
|
|
private void ResendServerMessage(Dictionary<string, WsClientData> clientDic)
|
|
@@ -183,4 +196,20 @@ public class ServerMessageJob : IJob
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void ReplaceVID(WsClientData session, Actions action, IRequest request)
|
|
|
+ {
|
|
|
+ if (action != Actions.DataTransfer ||
|
|
|
+ request is not DataTransferRequest dataTransferRequest)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ string vid = session.ChargePointVendor;
|
|
|
+ if (string.IsNullOrEmpty(vid))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dataTransferRequest.vendorId = vid;
|
|
|
+ }
|
|
|
}
|