|
@@ -29,6 +29,8 @@ using Microsoft.Data.SqlClient;
|
|
|
using System.Collections.Concurrent;
|
|
|
using EVCB_OCPP.WSServer.SuperSocket;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
+using EVCB_OCPP.WSServer.Service.WsService;
|
|
|
+using System.Net.WebSockets;
|
|
|
|
|
|
namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
@@ -60,12 +62,13 @@ namespace EVCB_OCPP.WSServer
|
|
|
, SqlConnectionFactory<WebDBConetext> webDbConnectionFactory
|
|
|
, SqlConnectionFactory<MainDBContext> mainDbConnectionFactory
|
|
|
, IHostEnvironment environment
|
|
|
- , IOCPPWSServerFactory ocppWSServerFactory
|
|
|
+ //, IOCPPWSServerFactory ocppWSServerFactory
|
|
|
, IConnectionLogdbService connectionLogdbService
|
|
|
, WebDbService webDbService
|
|
|
, ServerMessageService serverMessageService
|
|
|
- , IServiceProvider serviceProvider,
|
|
|
- OuterHttpClient httpClient)
|
|
|
+ , IServiceProvider serviceProvider
|
|
|
+ , OcppWebsocketService websocketService
|
|
|
+ , OuterHttpClient httpClient)
|
|
|
{
|
|
|
_ct = _cts.Token;
|
|
|
this.logger = logger;
|
|
@@ -74,10 +77,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
this.mainDbService = mainDbService;
|
|
|
this.webDbConnectionFactory = webDbConnectionFactory;
|
|
|
//this.connectionLogdbContextFactory = connectionLogdbContextFactory;
|
|
|
- this.ocppWSServerFactory = ocppWSServerFactory;
|
|
|
+ //this.ocppWSServerFactory = ocppWSServerFactory;
|
|
|
this.connectionLogdbService = connectionLogdbService;
|
|
|
this.webDbService = webDbService;
|
|
|
this.messageService = serverMessageService;
|
|
|
+ this.websocketService = websocketService;
|
|
|
this.httpClient = httpClient;
|
|
|
isInDocker = !string.IsNullOrEmpty(configuration["DOTNET_RUNNING_IN_CONTAINER"]);
|
|
|
|
|
@@ -91,7 +95,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
#region private fields
|
|
|
private OuterHttpClient httpClient;
|
|
|
private DateTime lastcheckdt = DateTime.UtcNow.AddSeconds(-20);
|
|
|
- private ConcurrentDictionary<string, ClientData> clientDic = new ConcurrentDictionary<string, ClientData>();
|
|
|
+ private ConcurrentDictionary<string, WsClientData> clientDic = new ConcurrentDictionary<string, WsClientData>();
|
|
|
//private readonly Object _lockClientDic = new object();
|
|
|
private readonly Object _lockConfirmPacketList = new object();
|
|
|
private readonly ILogger<ProtalServer> logger;
|
|
@@ -102,10 +106,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
private readonly SqlConnectionFactory<WebDBConetext> webDbConnectionFactory;
|
|
|
|
|
|
//private readonly IDbContextFactory<ConnectionLogDBContext> connectionLogdbContextFactory;
|
|
|
- private readonly IOCPPWSServerFactory ocppWSServerFactory;
|
|
|
+ //private readonly IOCPPWSServerFactory ocppWSServerFactory;
|
|
|
private readonly IConnectionLogdbService connectionLogdbService;
|
|
|
private readonly WebDbService webDbService;
|
|
|
private readonly ServerMessageService messageService;
|
|
|
+ private readonly OcppWebsocketService websocketService;
|
|
|
private readonly ProfileHandler profileHandler;//= new ProfileHandler();
|
|
|
//private readonly string webConnectionString;// = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
|
|
|
private readonly bool isInDocker;
|
|
@@ -152,31 +157,26 @@ namespace EVCB_OCPP.WSServer
|
|
|
};
|
|
|
private CancellationTokenSource _cts = new CancellationTokenSource();
|
|
|
private CancellationToken _ct;
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
- internal Dictionary<string, ClientData> ClientDic
|
|
|
+ internal Dictionary<string, WsClientData> GetClientDic()
|
|
|
{
|
|
|
- get
|
|
|
- {
|
|
|
- Dictionary<string, ClientData> toReturn = null;
|
|
|
- toReturn = new Dictionary<string, ClientData>(clientDic);
|
|
|
- return toReturn;
|
|
|
- }
|
|
|
+ Dictionary<string, WsClientData> toReturn = null;
|
|
|
+ toReturn = new Dictionary<string, WsClientData>(clientDic);
|
|
|
+ return toReturn;
|
|
|
}
|
|
|
|
|
|
- internal List<NeedConfirmMessage> ResendMessage
|
|
|
+ internal List<NeedConfirmMessage> GetResendMessage()
|
|
|
{
|
|
|
- get
|
|
|
+ List<NeedConfirmMessage> sendMessages = new List<NeedConfirmMessage>();
|
|
|
+ lock (_lockConfirmPacketList)
|
|
|
{
|
|
|
- List<NeedConfirmMessage> sendMessages = new List<NeedConfirmMessage>();
|
|
|
- lock (_lockConfirmPacketList)
|
|
|
- {
|
|
|
- sendMessages = needConfirmPacketList.Where(x => x.SentTimes > 1 && x.CreatedBy == "Server").ToList();
|
|
|
+ sendMessages = needConfirmPacketList.Where(x => x.SentTimes > 1 && x.CreatedBy == "Server").ToList();
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- return sendMessages;
|
|
|
}
|
|
|
+
|
|
|
+ return sendMessages;
|
|
|
}
|
|
|
|
|
|
internal IReadOnlyList<Profile> Profiles => profiles.AsReadOnly();
|
|
@@ -200,7 +200,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
clientDic[key].DisplayPrice = price;
|
|
|
}
|
|
|
|
|
|
- internal void SendMsg(ClientData session, string msg, string messageType, string errorMsg = "")
|
|
|
+ internal void SendMsg(WsClientData session, string msg, string messageType, string errorMsg = "")
|
|
|
{
|
|
|
Send(session,msg,messageType,errorMsg);
|
|
|
}
|
|
@@ -214,11 +214,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
Console.WriteLine("Please check App.Config setting .");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- OpenNetwork();
|
|
|
|
|
|
+ StartWsService();
|
|
|
+ //OpenNetwork();
|
|
|
|
|
|
- RunHttpConsoleService();
|
|
|
+
|
|
|
+ //RunHttpConsoleService();
|
|
|
return;
|
|
|
if (!isInDocker)
|
|
|
{
|
|
@@ -229,6 +230,70 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void StartWsService()
|
|
|
+ {
|
|
|
+ websocketService.NewSessionConnected += AppServer_NewSessionConnected;
|
|
|
+ }
|
|
|
+ private void StopWsService()
|
|
|
+ {
|
|
|
+ websocketService.NewSessionConnected -= AppServer_NewSessionConnected;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void AppServer_NewSessionConnected(object sender, WsClientData session)
|
|
|
+ {
|
|
|
+ logger.LogDebug(string.Format("{0} NewSessionConnected", session.Path));
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ bool isNotSupported = session.SecWebSocketProtocol.Contains("ocpp1.6") ? false : session.SecWebSocketProtocol.Contains("ocpp2.0") ? false : true;
|
|
|
+ if (isNotSupported)
|
|
|
+ {
|
|
|
+ //logger.LogDebug(string.Format("ChargeBoxId:{0} SecWebSocketProtocol:{1} NotSupported", session.ChargeBoxId, session.SecWebSocketProtocol));
|
|
|
+ WriteMachineLog(session, string.Format("SecWebSocketProtocol:{0} NotSupported", session.SecWebSocketProtocol), "Connection", "");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ TryRemoveDuplicatedSession(session);
|
|
|
+ clientDic[session.ChargeBoxId] = session;
|
|
|
+
|
|
|
+ session.SessionClosed += AppServer_SessionClosed;
|
|
|
+ session.m_ReceiveData += ReceivedMessageTimeLimited;
|
|
|
+ // logger.LogDebug("------------New " + (session == null ? "Oops" : session.ChargeBoxId));
|
|
|
+ WriteMachineLog(session, "NewSessionConnected", "Connection", "");
|
|
|
+
|
|
|
+ await mainDbService.UpdateMachineConnectionType(session.ChargeBoxId, session.UriScheme.Contains("wss") ? 2 : 1);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError(string.Format("NewSessionConnected Ex: {0}", ex.ToString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AppServer_SessionClosed(object sender, string closeReason)
|
|
|
+ {
|
|
|
+ if (sender is not WsClientData session)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ session.SessionClosed -= AppServer_SessionClosed;
|
|
|
+ session.m_ReceiveData -= ReceivedMessageTimeLimited;
|
|
|
+
|
|
|
+ WriteMachineLog(session, string.Format("CloseReason: {0}", closeReason), "Connection", "");
|
|
|
+ RemoveClient(session);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TryRemoveDuplicatedSession(WsClientData session)
|
|
|
+ {
|
|
|
+ if (clientDic.ContainsKey(session.ChargeBoxId))
|
|
|
+ {
|
|
|
+ var oldSession = clientDic[session.ChargeBoxId];
|
|
|
+ WriteMachineLog(oldSession, "Duplicate Logins", "Connection", "");
|
|
|
+ RemoveClient(oldSession);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void RunConsoleInteractive()
|
|
|
{
|
|
|
while (true)
|
|
@@ -254,8 +319,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
case "lc":
|
|
|
{
|
|
|
Console.WriteLine("Command List Clients");
|
|
|
- Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+ Dictionary<string, WsClientData> _copyClientDic = null;
|
|
|
+ _copyClientDic = new Dictionary<string, WsClientData>(clientDic);
|
|
|
var list = _copyClientDic.Select(c => c.Value).ToList();
|
|
|
int i = 1;
|
|
|
foreach (var c in list)
|
|
@@ -268,8 +333,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
case "lcn":
|
|
|
{
|
|
|
Console.WriteLine("Command List Customer Name");
|
|
|
- Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+ Dictionary<string, WsClientData> _copyClientDic = null;
|
|
|
+ _copyClientDic = new Dictionary<string, WsClientData>(clientDic);
|
|
|
var lcn = clientDic.Select(c => c.Value.CustomerName).Distinct().ToList();
|
|
|
int iLcn = 1;
|
|
|
foreach (var c in lcn)
|
|
@@ -388,8 +453,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
app.MapPost("/lc", () => {
|
|
|
List<string> toReturn = new List<string>() { "Command List Clients" };
|
|
|
- Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+ Dictionary<string, WsClientData> _copyClientDic = null;
|
|
|
+ _copyClientDic = new Dictionary<string, WsClientData>(clientDic);
|
|
|
var list = _copyClientDic.Select(c => c.Value).ToList();
|
|
|
int i = 1;
|
|
|
foreach (var c in list)
|
|
@@ -402,8 +467,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
app.MapPost("/lcn", () => {
|
|
|
List<string> toReturn = new List<string> { "Command List Customer Name" };
|
|
|
- Dictionary<string, ClientData> _copyClientDic = null;
|
|
|
- _copyClientDic = new Dictionary<string, ClientData>(clientDic);
|
|
|
+ Dictionary<string, WsClientData> _copyClientDic = null;
|
|
|
+ _copyClientDic = new Dictionary<string, WsClientData>(clientDic);
|
|
|
var lcn = clientDic.Select(c => c.Value.CustomerName).Distinct().ToList();
|
|
|
int iLcn = 1;
|
|
|
foreach (var c in lcn)
|
|
@@ -491,74 +556,74 @@ namespace EVCB_OCPP.WSServer
|
|
|
_cts?.Cancel();
|
|
|
}
|
|
|
|
|
|
- private void OpenNetwork()
|
|
|
- {
|
|
|
-
|
|
|
- //載入OCPP Protocol
|
|
|
- OCPPWSServer appServer = ocppWSServerFactory.Create(new List<OCPPSubProtocol>() { new OCPPSubProtocol(), new OCPPSubProtocol(" ocpp1.6"), new OCPPSubProtocol("ocpp2.0") });
|
|
|
- //var appServer = new OCPPWSServer(new List<OCPPSubProtocol>() { new OCPPSubProtocol(), new OCPPSubProtocol(" ocpp1.6"), new OCPPSubProtocol("ocpp2.0") });
|
|
|
-
|
|
|
- List<IListenerConfig> llistener = new List<IListenerConfig>();
|
|
|
-
|
|
|
- if (GlobalConfig.GetWS_Port() != 0)
|
|
|
- {
|
|
|
- llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = GlobalConfig.GetWS_Port(), Backlog = 100, Security = "None" });
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var securityport in GlobalConfig.GetWSS_Ports())
|
|
|
- {
|
|
|
- llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = securityport, Backlog = 100, Security = SslProtocols.Tls12.ToString() });
|
|
|
- }
|
|
|
-
|
|
|
- //var config = ConfigurationManager.GetSection("superSocket") as IConfigurationSource;\
|
|
|
- //var certificate = configuration.GetSection("superSocket").GetSection("Servers:0").GetSection("Certificate").Get<CertificateConfig>();
|
|
|
- var certificate = configuration.GetSection("SuperSocketServerCertificate").Get<CertificateConfig>();
|
|
|
- ICertificateConfig Certificate = certificate;
|
|
|
- IEnumerable<IListenerConfig> listeners = llistener;
|
|
|
-
|
|
|
- //設定server config
|
|
|
- var serverConfig = new ServerConfig
|
|
|
- {
|
|
|
- SendingQueueSize = 10,
|
|
|
- //Port = Convert.ToInt32(2012),
|
|
|
- //Ip = "172.17.40.13",
|
|
|
- MaxRequestLength = 204800,
|
|
|
- //Security = serverSecurity,
|
|
|
- //Certificate = Certificate,
|
|
|
- Listeners = listeners,
|
|
|
- // LogAllSocketException = true,
|
|
|
- KeepAliveTime = 10,
|
|
|
- // LogBasicSessionActivity = true
|
|
|
- //Security = "None"
|
|
|
- };
|
|
|
-
|
|
|
- //Setup with listening port
|
|
|
- if (!appServer.Setup(serverConfig, logFactory: new NLogLoggerFactory()))
|
|
|
- {
|
|
|
- Console.WriteLine("Failed to setup!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- appServer.NewSessionConnected += AppServer_NewSessionConnected;
|
|
|
- appServer.SessionClosed += AppServer_SessionClosed;
|
|
|
-
|
|
|
-
|
|
|
- //Try to start the appServer
|
|
|
- if (!appServer.Start())
|
|
|
- {
|
|
|
- Console.WriteLine("Failed to start!");
|
|
|
- //Console.ReadKey();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void AppServer_SessionClosed(ClientData session, CloseReason value)
|
|
|
+ //private void OpenNetwork()
|
|
|
+ //{
|
|
|
+
|
|
|
+ // //載入OCPP Protocol
|
|
|
+ // OCPPWSServer appServer = ocppWSServerFactory.Create(new List<OCPPSubProtocol>() { new OCPPSubProtocol(), new OCPPSubProtocol(" ocpp1.6"), new OCPPSubProtocol("ocpp2.0") });
|
|
|
+ // //var appServer = new OCPPWSServer(new List<OCPPSubProtocol>() { new OCPPSubProtocol(), new OCPPSubProtocol(" ocpp1.6"), new OCPPSubProtocol("ocpp2.0") });
|
|
|
+
|
|
|
+ // List<IListenerConfig> llistener = new List<IListenerConfig>();
|
|
|
+
|
|
|
+ // if (GlobalConfig.GetWS_Port() != 0)
|
|
|
+ // {
|
|
|
+ // llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = GlobalConfig.GetWS_Port(), Backlog = 100, Security = "None" });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // foreach (var securityport in GlobalConfig.GetWSS_Ports())
|
|
|
+ // {
|
|
|
+ // llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = securityport, Backlog = 100, Security = SslProtocols.Tls12.ToString() });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //var config = ConfigurationManager.GetSection("superSocket") as IConfigurationSource;\
|
|
|
+ // //var certificate = configuration.GetSection("superSocket").GetSection("Servers:0").GetSection("Certificate").Get<CertificateConfig>();
|
|
|
+ // var certificate = configuration.GetSection("SuperSocketServerCertificate").Get<CertificateConfig>();
|
|
|
+ // ICertificateConfig Certificate = certificate;
|
|
|
+ // IEnumerable<IListenerConfig> listeners = llistener;
|
|
|
+
|
|
|
+ // //設定server config
|
|
|
+ // var serverConfig = new ServerConfig
|
|
|
+ // {
|
|
|
+ // SendingQueueSize = 10,
|
|
|
+ // //Port = Convert.ToInt32(2012),
|
|
|
+ // //Ip = "172.17.40.13",
|
|
|
+ // MaxRequestLength = 204800,
|
|
|
+ // //Security = serverSecurity,
|
|
|
+ // //Certificate = Certificate,
|
|
|
+ // Listeners = listeners,
|
|
|
+ // // LogAllSocketException = true,
|
|
|
+ // KeepAliveTime = 10,
|
|
|
+ // // LogBasicSessionActivity = true
|
|
|
+ // //Security = "None"
|
|
|
+ // };
|
|
|
+
|
|
|
+ // //Setup with listening port
|
|
|
+ // if (!appServer.Setup(serverConfig, logFactory: new NLogLoggerFactory()))
|
|
|
+ // {
|
|
|
+ // Console.WriteLine("Failed to setup!");
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // appServer.NewSessionConnected += AppServer_NewSessionConnected;
|
|
|
+ // appServer.SessionClosed += AppServer_SessionClosed;
|
|
|
+
|
|
|
+
|
|
|
+ // //Try to start the appServer
|
|
|
+ // if (!appServer.Start())
|
|
|
+ // {
|
|
|
+ // Console.WriteLine("Failed to start!");
|
|
|
+ // //Console.ReadKey();
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ private void AppServer_SessionClosed(WsClientData session, CloseReason value)
|
|
|
{
|
|
|
WriteMachineLog(session, string.Format("CloseReason: {0}", value), "Connection", "");
|
|
|
RemoveClient(session);
|
|
|
}
|
|
|
|
|
|
- private async void AppServer_NewSessionConnected(ClientData session)
|
|
|
+ private async void AppServer_NewSessionConnected(WsClientData session)
|
|
|
{
|
|
|
logger.LogDebug(string.Format("{0} NewSessionConnected", session.Path));
|
|
|
|
|
@@ -571,14 +636,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
WriteMachineLog(session, string.Format("SecWebSocketProtocol:{0} NotSupported", session.SecWebSocketProtocol), "Connection", "");
|
|
|
return;
|
|
|
}
|
|
|
- //ClientData _removeClient = null;
|
|
|
+ //WsClientData _removeClient = null;
|
|
|
|
|
|
//var addedClient = clientDic.GetOrAdd(session.ChargeBoxId, session);
|
|
|
if (clientDic.ContainsKey(session.ChargeBoxId))
|
|
|
{
|
|
|
var oldSession = clientDic[session.ChargeBoxId];
|
|
|
WriteMachineLog(oldSession, "Duplicate Logins", "Connection", "");
|
|
|
- oldSession.Close(CloseReason.ServerShutdown);
|
|
|
+ //oldSession.Close(CloseReason.ServerShutdown);
|
|
|
RemoveClient(oldSession);
|
|
|
}
|
|
|
clientDic[session.ChargeBoxId] = session;
|
|
@@ -601,7 +666,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
var machine = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefaultAsync();
|
|
|
if (machine != null)
|
|
|
{
|
|
|
- machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
|
|
|
+ machine.ConnectionType = session.UriScheme.Contains("wss") ? 2 : 1;
|
|
|
await db.SaveChangesAsync();
|
|
|
}
|
|
|
|
|
@@ -615,8 +680,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
- async private void ReceivedMessageTimeLimited(ClientData session, string rawdata)
|
|
|
+ async private void ReceivedMessageTimeLimited(object sender, string rawdata)
|
|
|
{
|
|
|
+ if (sender is not WsClientData session)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
CancellationTokenSource tokenSource = new();
|
|
|
var task = ReceivedMessage(session, rawdata);
|
|
|
var completedTask = await Task.WhenAny(task, Task.Delay(90_000, tokenSource.Token));
|
|
@@ -632,7 +701,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- async private Task ReceivedMessage(ClientData session, string rawdata)
|
|
|
+ async private Task ReceivedMessage(WsClientData session, string rawdata)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -875,7 +944,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async Task ProcessRequestMessage(MessageResult analysisResult, ClientData session, Actions action)
|
|
|
+ private async Task ProcessRequestMessage(MessageResult analysisResult, WsClientData session, Actions action)
|
|
|
{
|
|
|
Stopwatch outter_stopwatch = Stopwatch.StartNew();
|
|
|
//BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
@@ -932,7 +1001,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
session.IsAC = false;
|
|
|
}
|
|
|
- machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
|
|
|
+ machine.ConnectionType = session.UriScheme.Contains("wss") ? 2 : 1;
|
|
|
await db.SaveChangesAsync();
|
|
|
}
|
|
|
}
|
|
@@ -1085,7 +1154,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async private void ProcessConfirmationMessage(MessageResult analysisResult, ClientData session, Actions action)
|
|
|
+ async private void ProcessConfirmationMessage(MessageResult analysisResult, WsClientData session, Actions action)
|
|
|
{
|
|
|
|
|
|
BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
@@ -1154,7 +1223,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async void ProcessErrorMessage(MessageResult analysisResult, ClientData session, Actions action)
|
|
|
+ private async void ProcessErrorMessage(MessageResult analysisResult, WsClientData session, Actions action)
|
|
|
{
|
|
|
BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
|
if (await ReConfirmMessage(analysisResult))
|
|
@@ -1212,7 +1281,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void Send(ClientData session, string msg, string messageType, string errorMsg = "")
|
|
|
+ private void Send(WsClientData session, string msg, string messageType, string errorMsg = "")
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -1232,7 +1301,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
- async private Task<string> SetDefaultFee(ClientData client)
|
|
|
+ async private Task<string> SetDefaultFee(WsClientData client)
|
|
|
{
|
|
|
string displayPriceText = string.Empty;
|
|
|
string charingPriceText = string.Empty;
|
|
@@ -1386,7 +1455,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
|
|
|
|
|
|
- internal void RemoveClient(ClientData session)
|
|
|
+ internal async void RemoveClient(WsClientData session)
|
|
|
{
|
|
|
if (session == null)
|
|
|
{
|
|
@@ -1396,13 +1465,17 @@ namespace EVCB_OCPP.WSServer
|
|
|
if (!string.IsNullOrEmpty(session.MachineId))
|
|
|
logger.LogTrace("RemoveClient[" + session.ChargeBoxId + "]");
|
|
|
|
|
|
- if (session.Connected)
|
|
|
- {
|
|
|
- session.Close(CloseReason.ServerShutdown);
|
|
|
- }
|
|
|
+ //if (session.Connected)
|
|
|
+ //{
|
|
|
+ // session.Close(CloseReason.ServerShutdown);
|
|
|
+ //}
|
|
|
RemoveClientDic(session);
|
|
|
try
|
|
|
{
|
|
|
+ if (session.State == WebSocketState.Open)
|
|
|
+ {
|
|
|
+ await session.Close();
|
|
|
+ }
|
|
|
session.m_ReceiveData -= ReceivedMessageTimeLimited;
|
|
|
// session.Close(CloseReason.ServerShutdown);
|
|
|
|
|
@@ -1419,7 +1492,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RemoveClientDic(ClientData session)
|
|
|
+ private void RemoveClientDic(WsClientData session)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(session.ChargeBoxId))
|
|
|
{
|
|
@@ -1444,19 +1517,19 @@ namespace EVCB_OCPP.WSServer
|
|
|
connectionLogdbService.WarmUpLog();
|
|
|
}
|
|
|
|
|
|
- private void WriteMachineLog(ClientData clientData, string data, string messageType, string errorMsg = "", bool isSent = false)
|
|
|
+ private void WriteMachineLog(WsClientData WsClientData, string data, string messageType, string errorMsg = "", bool isSent = false)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
- if (clientData == null || string.IsNullOrEmpty(data)) return;
|
|
|
+ if (WsClientData == null || string.IsNullOrEmpty(data)) return;
|
|
|
|
|
|
- if (clientData.ChargeBoxId == null)
|
|
|
+ if (WsClientData.ChargeBoxId == null)
|
|
|
{
|
|
|
- logger.LogCritical(clientData.Path + "]********************session ChargeBoxId null sessionId=" + clientData.SessionID);
|
|
|
+ logger.LogCritical(WsClientData.Path.ToString() + "]********************session ChargeBoxId null sessionId=" + WsClientData.SessionID);
|
|
|
}
|
|
|
|
|
|
- connectionLogdbService.WriteMachineLog(clientData, data, messageType, errorMsg, isSent);
|
|
|
+ connectionLogdbService.WriteMachineLog(WsClientData, data, messageType, errorMsg, isSent);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|