Ver código fonte

remove supersocket , simple test passed

Robert 1 ano atrás
pai
commit
1078d2c276
44 arquivos alterados com 377 adições e 1289 exclusões
  1. 0 24
      EVCB_OCPP.Server.sln
  2. 0 3
      EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj
  3. 1 13
      EVCB_OCPP.WSServer/Helper/AddPortalDbContext.cs
  4. 61 0
      EVCB_OCPP.WSServer/Helper/StringBuilderExtention.cs
  5. 1 5
      EVCB_OCPP.WSServer/HostedProtalServer.cs
  6. 2 12
      EVCB_OCPP.WSServer/Jobs/DenyModelCheckJob.cs
  7. 1 1
      EVCB_OCPP.WSServer/Jobs/HealthCheckTriggerJob.cs
  8. 1 1
      EVCB_OCPP.WSServer/Jobs/HeartBeatCheckJob.cs
  9. 1 1
      EVCB_OCPP.WSServer/Jobs/ServerMessageJob.cs
  10. 1 1
      EVCB_OCPP.WSServer/Jobs/ServerSetFeeJob.cs
  11. 1 1
      EVCB_OCPP.WSServer/Jobs/ServerUpdateJob.cs
  12. 1 1
      EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs
  13. 1 2
      EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs
  14. 1 1
      EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs
  15. 1 1
      EVCB_OCPP.WSServer/Message/LocalAuthListManagementProfileHandler.cs
  16. 1 2
      EVCB_OCPP.WSServer/Message/OCPP16MessageHandler.cs
  17. 1 2
      EVCB_OCPP.WSServer/Message/OCPP20MessageHandler.cs
  18. 1 1
      EVCB_OCPP.WSServer/Message/RemoteTriggerHandler.cs
  19. 1 1
      EVCB_OCPP.WSServer/Message/ReservationProfileHandler.cs
  20. 2 2
      EVCB_OCPP.WSServer/Message/SecurityProfileHandler.cs
  21. 1 1
      EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs
  22. 1 0
      EVCB_OCPP.WSServer/Program.cs
  23. 11 75
      EVCB_OCPP.WSServer/ProtalServer.cs
  24. 1 1
      EVCB_OCPP.WSServer/Service/ConnectionLogdbService.cs
  25. 0 6
      EVCB_OCPP.WSServer/Service/GoogleGetTimePrintService.cs
  26. 2 2
      EVCB_OCPP.WSServer/Service/MapApiServce.cs
  27. 1 1
      EVCB_OCPP.WSServer/Service/OuterBusinessService.cs
  28. 1 9
      EVCB_OCPP.WSServer/Service/WebDbService.cs
  29. 0 170
      EVCB_OCPP.WSServer/Service/WebsocketService.cs
  30. 80 0
      EVCB_OCPP.WSServer/Service/WsService/WebsocketService.cs
  31. 101 0
      EVCB_OCPP.WSServer/Service/WsService/WsClientData.cs
  32. 98 0
      EVCB_OCPP.WSServer/Service/WsService/WsSession.cs
  33. 0 19
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallCmd.cs
  34. 0 19
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallErrorCmd.cs
  35. 0 19
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallResultCmd.cs
  36. 0 225
      EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs
  37. 0 8
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLog.cs
  38. 0 5
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLogFactory.cs
  39. 0 35
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubCommandConverter.cs
  40. 0 322
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubProtocol.cs
  41. 0 255
      EVCB_OCPP.WSServer/SuperSocket/OCPPWSServer.cs
  42. 0 34
      EVCB_OCPP.WSServer/SuperSocket/OCPPWSServerFactory.cs
  43. 0 3
      SocketEngine/SuperSocket.SocketEngine.csproj
  44. 0 5
      SuperWebSocket/SuperWebSocket.csproj

+ 0 - 24
EVCB_OCPP.Server.sln

@@ -7,14 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EVCB_OCPP.WSServer", "EVCB_
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestTool.RemoteTriggerAPP", "TestTool.RemoteTriggerAPP\TestTool.RemoteTriggerAPP.csproj", "{F39A3B1E-2B93-40E1-9C7B-8CEE2529BF52}"
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperWebSocket", "SuperWebSocket\SuperWebSocket.csproj", "{43C5BC98-FA2C-45D1-BF96-A299C05A72AE}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperSocket.SocketBase", "SocketBase\SuperSocket.SocketBase.csproj", "{743510BD-A370-47A9-8264-0F30161EA9D0}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperSocket.SocketEngine", "SocketEngine\SuperSocket.SocketEngine.csproj", "{D4A0E22B-8EAF-4CA5-AE1B-414508D71B62}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperSocket.Common", "SocketCommon\SuperSocket.Common.csproj", "{8241B98B-A7BF-4FBA-BD0B-B1536DDD1A72}"
-EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -29,22 +21,6 @@ Global
 		{F39A3B1E-2B93-40E1-9C7B-8CEE2529BF52}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{F39A3B1E-2B93-40E1-9C7B-8CEE2529BF52}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{F39A3B1E-2B93-40E1-9C7B-8CEE2529BF52}.Release|Any CPU.Build.0 = Release|Any CPU
-		{43C5BC98-FA2C-45D1-BF96-A299C05A72AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{43C5BC98-FA2C-45D1-BF96-A299C05A72AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{43C5BC98-FA2C-45D1-BF96-A299C05A72AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{43C5BC98-FA2C-45D1-BF96-A299C05A72AE}.Release|Any CPU.Build.0 = Release|Any CPU
-		{743510BD-A370-47A9-8264-0F30161EA9D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{743510BD-A370-47A9-8264-0F30161EA9D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{743510BD-A370-47A9-8264-0F30161EA9D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{743510BD-A370-47A9-8264-0F30161EA9D0}.Release|Any CPU.Build.0 = Release|Any CPU
-		{D4A0E22B-8EAF-4CA5-AE1B-414508D71B62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{D4A0E22B-8EAF-4CA5-AE1B-414508D71B62}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{D4A0E22B-8EAF-4CA5-AE1B-414508D71B62}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{D4A0E22B-8EAF-4CA5-AE1B-414508D71B62}.Release|Any CPU.Build.0 = Release|Any CPU
-		{8241B98B-A7BF-4FBA-BD0B-B1536DDD1A72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{8241B98B-A7BF-4FBA-BD0B-B1536DDD1A72}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{8241B98B-A7BF-4FBA-BD0B-B1536DDD1A72}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{8241B98B-A7BF-4FBA-BD0B-B1536DDD1A72}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 0 - 3
EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj

@@ -63,7 +63,4 @@
     <PackageReference Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
     <PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" />
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\SuperWebSocket\SuperWebSocket.csproj" />
-  </ItemGroup>
 </Project>

+ 1 - 13
EVCB_OCPP.WSServer/Helper/AddPortalDbContext.cs

@@ -1,19 +1,7 @@
-using EVCB_OCPP.Domain;
-using EVCB_OCPP.Domain.Extensions;
-using Microsoft.Data.SqlClient;
+using EVCB_OCPP.Domain.Extensions;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using MongoDB.Driver.Core.Configuration;
-using NLog.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Helper;
 

+ 61 - 0
EVCB_OCPP.WSServer/Helper/StringBuilderExtention.cs

@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.WSServer.Helper;
+
+public static class StringBuilderExtention
+{
+    private readonly static char[] m_CrCf;
+
+    static StringBuilderExtention()
+    {
+        m_CrCf = "\r\n".ToArray();
+    }
+
+    /// <summary>
+    /// Appends in the format with CrCf as suffix.
+    /// </summary>
+    /// <param name="builder">The builder.</param>
+    /// <param name="format">The format.</param>
+    /// <param name="arg">The arg.</param>
+    public static void AppendFormatWithCrCf(this StringBuilder builder, string format, object arg)
+    {
+        builder.AppendFormat(format, arg);
+        builder.Append(m_CrCf);
+    }
+
+    /// <summary>
+    /// Appends in the format with CrCf as suffix.
+    /// </summary>
+    /// <param name="builder">The builder.</param>
+    /// <param name="format">The format.</param>
+    /// <param name="args">The args.</param>
+    public static void AppendFormatWithCrCf(this StringBuilder builder, string format, params object[] args)
+    {
+        builder.AppendFormat(format, args);
+        builder.Append(m_CrCf);
+    }
+
+    /// <summary>
+    /// Appends with CrCf as suffix.
+    /// </summary>
+    /// <param name="builder">The builder.</param>
+    /// <param name="content">The content.</param>
+    public static void AppendWithCrCf(this StringBuilder builder, string content)
+    {
+        builder.Append(content);
+        builder.Append(m_CrCf);
+    }
+
+    /// <summary>
+    /// Appends with CrCf as suffix.
+    /// </summary>
+    /// <param name="builder">The builder.</param>
+    public static void AppendWithCrCf(this StringBuilder builder)
+    {
+        builder.Append(m_CrCf);
+    }
+}

+ 1 - 5
EVCB_OCPP.WSServer/HostedProtalServer.cs

@@ -3,10 +3,9 @@ using EVCB_OCPP.WSServer.Helper;
 using EVCB_OCPP.WSServer.Jobs;
 using EVCB_OCPP.WSServer.Message;
 using EVCB_OCPP.WSServer.Service;
-using EVCB_OCPP.WSServer.SuperSocket;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
-using OCPPServer.Protocol;
 using Quartz;
 
 namespace EVCB_OCPP.WSServer
@@ -23,9 +22,6 @@ namespace EVCB_OCPP.WSServer
 
             services.AddSingleton<WebsocketService<WsClientData>>();
 
-            services.AddTransient<OCPPWSServer>();
-            services.AddTransient<IOCPPWSServerFactory, OCPPWSServerFactory>();
-
             services.AddSingleton<ServerMessageService>();
             services.AddSingleton<LoadingBalanceService>();
             services.AddSingleton<MeterValueDbService>();

+ 2 - 12
EVCB_OCPP.WSServer/Jobs/DenyModelCheckJob.cs

@@ -1,17 +1,7 @@
-using Dapper;
-using DnsClient.Internal;
-using EVCB_OCPP.WSServer.Service;
-using Microsoft.Data.SqlClient;
-using Microsoft.Extensions.Configuration;
+using EVCB_OCPP.WSServer.Service;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using Quartz;
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Jobs;
 

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/HealthCheckTriggerJob.cs

@@ -1,6 +1,6 @@
 using EVCB_OCPP.Domain;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using Quartz;
 using System;
 using System.Collections.Generic;

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/HeartBeatCheckJob.cs

@@ -1,9 +1,9 @@
 using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.WSServer.Service;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using Quartz;
 using System;
 using System.Collections.Generic;

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/ServerMessageJob.cs

@@ -3,10 +3,10 @@ using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.WSServer.Message;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
-using OCPPServer.Protocol;
 using Quartz;
 
 namespace EVCB_OCPP.WSServer.Jobs;

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/ServerSetFeeJob.cs

@@ -7,12 +7,12 @@ using EVCB_OCPP.WSServer.Dto;
 using EVCB_OCPP.WSServer.Helper;
 using EVCB_OCPP.WSServer.Message;
 using EVCB_OCPP.WSServer.Service;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Data.SqlClient;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
-using OCPPServer.Protocol;
 using Quartz;
 using System;
 using System.Collections.Generic;

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/ServerUpdateJob.cs

@@ -1,9 +1,9 @@
 using EVCB_OCPP.Domain;
 using EVCB_OCPP.Packet.Messages.RemoteTrigger;
 using EVCB_OCPP.WSServer.Message;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using Quartz;
 using System;
 using System.Collections.Generic;

+ 1 - 1
EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs

@@ -1,10 +1,10 @@
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
 using NLog;
-using OCPPServer.Protocol;
 
 
 namespace EVCB_OCPP.WSServer.Message

+ 1 - 2
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -12,13 +12,12 @@ using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
-using OCPPServer.Protocol;
 using System.Data;
 using System.Diagnostics;
 using System.Globalization;
-using SuperSocket.SocketBase;
 using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.Domain.ConnectionFactory;
+using EVCB_OCPP.WSServer.Service.WsService;
 
 namespace EVCB_OCPP.WSServer.Message;
 

+ 1 - 1
EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs

@@ -3,13 +3,13 @@ using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.FirmwareManagement;
 using Newtonsoft.Json;
-using OCPPServer.Protocol;
 using System;
 using System.Linq;
 using Microsoft.Extensions.Logging;
 using System.Threading.Tasks;
 using Microsoft.EntityFrameworkCore;
 using EVCB_OCPP.Domain.Models.MainDb;
+using EVCB_OCPP.WSServer.Service.WsService;
 
 namespace EVCB_OCPP.WSServer.Message
 {

+ 1 - 1
EVCB_OCPP.WSServer/Message/LocalAuthListManagementProfileHandler.cs

@@ -2,9 +2,9 @@
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.LocalAuthListManagement;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using System;
 using System.Linq;
 using System.Threading.Tasks;

+ 1 - 2
EVCB_OCPP.WSServer/Message/OCPP16MessageHandler.cs

@@ -1,11 +1,10 @@
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
-
-using OCPPServer.Protocol;
 using System;
 using System.Collections.Generic;
 

+ 1 - 2
EVCB_OCPP.WSServer/Message/OCPP20MessageHandler.cs

@@ -1,11 +1,10 @@
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP.WSServer.Service.WsService;
 using EVCB_OCPP20.Packet.Features;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
-
-using OCPPServer.Protocol;
 using System;
 using I20Confirmation = EVCB_OCPP20.Packet.Messages.IConfirmation;
 using I20Request = EVCB_OCPP20.Packet.Messages.IRequest;

+ 1 - 1
EVCB_OCPP.WSServer/Message/RemoteTriggerHandler.cs

@@ -2,9 +2,9 @@
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.RemoteTrigger;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using System;
 using System.Linq;
 using System.Threading.Tasks;

+ 1 - 1
EVCB_OCPP.WSServer/Message/ReservationProfileHandler.cs

@@ -2,9 +2,9 @@
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.Reservation;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using System;
 using System.Linq;
 using System.Threading.Tasks;

+ 2 - 2
EVCB_OCPP.WSServer/Message/SecurityProfileHandler.cs

@@ -1,8 +1,8 @@
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
-using OCPPServer.Protocol;
 using System;
 using Microsoft.Extensions.Logging;
+using EVCB_OCPP.WSServer.Service.WsService;
 
 namespace EVCB_OCPP.WSServer.Message
 {
@@ -54,7 +54,7 @@ namespace EVCB_OCPP.WSServer.Message
         }
 
 
-        internal MessageResult ReceivedSecurityError(Actions action, string errorMsg, ClientData session, string requestId)
+        internal MessageResult ReceivedSecurityError(Actions action, string errorMsg, WsClientData session, string requestId)
         {
             MessageResult result = new MessageResult() { Success = true };
 

+ 1 - 1
EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs

@@ -4,10 +4,10 @@ using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.SmartCharging;
 using EVCB_OCPP.Packet.Messages.SubTypes;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
-using OCPPServer.Protocol;
 using System;
 using System.Collections.Generic;
 using System.Linq;

+ 1 - 0
EVCB_OCPP.WSServer/Program.cs

@@ -5,6 +5,7 @@ using Newtonsoft.Json;
 using EVCB_OCPP.WSServer.Helper;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
+using EVCB_OCPP.WSServer.Service.WsService;
 
 namespace EVCB_OCPP.WSServer
 {

+ 11 - 75
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -8,27 +8,18 @@ using EVCB_OCPP.WSServer.Message;
 using EVCB_OCPP.WSServer.Service;
 using Microsoft.Extensions.Hosting;
 using Newtonsoft.Json;
-
-using OCPPServer.Protocol;
-using OCPPServer.SubProtocol;
-using SuperSocket.SocketBase;
-using SuperSocket.SocketBase.Config;
 using System.Data;
 using System.Diagnostics;
-using System.Security.Authentication;
 using System.Xml.Linq;
 using NLog;
 using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.AspNetCore.Builder;
-using NLog.Extensions.Logging;
 using System.Collections.Concurrent;
-using EVCB_OCPP.WSServer.SuperSocket;
+
 using Microsoft.Extensions.Logging;
 using System.Net.WebSockets;
-using SuperWebSocket;
 using System.Net;
 using System.Text;
+using EVCB_OCPP.WSServer.Service.WsService;
 
 namespace EVCB_OCPP.WSServer
 {
@@ -55,7 +46,6 @@ namespace EVCB_OCPP.WSServer
             ILogger<ProtalServer> logger
             , IConfiguration configuration
             , IMainDbService mainDbService
-            , IOCPPWSServerFactory ocppWSServerFactory
             , IConnectionLogdbService connectionLogdbService
             , LoadingBalanceService loadingBalanceService
             , ServerMessageService serverMessageService
@@ -67,7 +57,6 @@ namespace EVCB_OCPP.WSServer
             this.logger = logger;
             this.configuration = configuration;
             this.mainDbService = mainDbService;
-            this.ocppWSServerFactory = ocppWSServerFactory;
             this.connectionLogdbService = connectionLogdbService;
             this.webDbService = webDbService;
             this.httpClient = httpClient;
@@ -90,7 +79,6 @@ namespace EVCB_OCPP.WSServer
         private readonly IConfiguration configuration;
         private readonly IMainDbService mainDbService;
 
-        private readonly IOCPPWSServerFactory ocppWSServerFactory;
         private readonly IConnectionLogdbService connectionLogdbService;
         private readonly WebDbService webDbService;
         private readonly ProfileHandler profileHandler;
@@ -349,64 +337,8 @@ namespace EVCB_OCPP.WSServer
 
         private void StartWsService()
         {
-
-            //載入OCPP Protocol
-            //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!");
-            //    logger.LogCritical("Failed to setup!");
-            //    return;
-            //}
-
             websocketService.ValidateHandshake = WebsocketServiceValidateHandshake;
             websocketService.NewSessionConnected += AppServer_NewSessionConnected;
-
-
-            //Try to start the appServer
-            //if (!appServer.Start())
-            //{
-            //    logger.LogCritical("Failed to start!");
-            //    //Console.ReadKey();
-            //    return;
-            //}
         }
 
         private void StopWsService()
@@ -451,7 +383,7 @@ namespace EVCB_OCPP.WSServer
                     string sb = responseBuilder.ToString();
                     byte[] data = Encoding.UTF8.GetBytes(sb);
 
-                    ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
+                    session.SendRawData(data, 0, data.Length);
                     logger.LogTrace(sb);
                     return false;
                 }
@@ -487,7 +419,7 @@ namespace EVCB_OCPP.WSServer
                 responseBuilder.AppendWithCrCf();
                 string sb = responseBuilder.ToString();
                 byte[] data = Encoding.UTF8.GetBytes(sb);
-                ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
+                session.SendRawData(data, 0, data.Length);
 
                 logger.LogInformation(sb);
                 return false;
@@ -515,7 +447,7 @@ namespace EVCB_OCPP.WSServer
                 string sb = responseBuilder.ToString();
                 byte[] data = Encoding.UTF8.GetBytes(sb);
 
-                ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
+                session.SendRawData(data, 0, data.Length);
                 logger.LogInformation(sb);
                 return false;
             }
@@ -579,7 +511,7 @@ namespace EVCB_OCPP.WSServer
                     string sb = responseBuilder.ToString();
                     byte[] data = Encoding.UTF8.GetBytes(sb);
 
-                    ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
+                    session.SendRawData(data, 0, data.Length);
                     logger.LogInformation(sb);
                     return false;
                 }
@@ -648,8 +580,12 @@ namespace EVCB_OCPP.WSServer
             }
         }
 
-        async private void ReceivedMessageTimeLimited(WsClientData 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));

+ 1 - 1
EVCB_OCPP.WSServer/Service/ConnectionLogdbService.cs

@@ -2,13 +2,13 @@
 using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.ConnectionFactory;
 using EVCB_OCPP.WSServer.Helper;
+using EVCB_OCPP.WSServer.Service.WsService;
 using log4net;
 using Microsoft.Data.SqlClient;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
 using NLog.Fluent;
-using OCPPServer.Protocol;
 using System;
 using System.Collections.Generic;
 using System.Data;

+ 0 - 6
EVCB_OCPP.WSServer/Service/GoogleGetTimePrintService.cs

@@ -1,12 +1,6 @@
 using Microsoft.Extensions.Logging;
 using RestSharp;
-using System;
-using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using ZstdSharp.Unsafe;
 
 namespace EVCB_OCPP.WSServer.Service
 {

+ 2 - 2
EVCB_OCPP.WSServer/Service/MapApiServce.cs

@@ -1,6 +1,6 @@
-using Microsoft.AspNetCore.Builder;
+using EVCB_OCPP.WSServer.Service.WsService;
+using Microsoft.AspNetCore.Builder;
 using NLog;
-using OCPPServer.Protocol;
 using System;
 using System.Collections.Generic;
 using System.Linq;

+ 1 - 1
EVCB_OCPP.WSServer/Service/OuterBusinessService.cs

@@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using NLog;
-using SuperSocket.SocketBase;
+
 using System;
 using System.Collections.Generic;
 using System.Linq;

+ 1 - 9
EVCB_OCPP.WSServer/Service/WebDbService.cs

@@ -1,19 +1,11 @@
 using Dapper;
-using DnsClient.Internal;
 using EVCB_OCPP.Domain.ConnectionFactory;
 using EVCB_OCPP.WSServer.Dto;
 using EVCB_OCPP.WSServer.Helper;
-using log4net;
+using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Data.SqlClient;
-using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
-using System;
-using System.Collections.Generic;
 using System.Data;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Service;
 

+ 0 - 170
EVCB_OCPP.WSServer/Service/WebsocketService.cs

@@ -1,170 +0,0 @@
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Primitives;
-using OCPPServer.Protocol;
-using SuperSocket.SocketBase;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.WebSockets;
-using System.ServiceModel.Channels;
-using System.Text;
-using System.Threading.Tasks;
-using static OCPPServer.Protocol.ClientData;
-
-namespace EVCB_OCPP.WSServer.Service;
-
-public static class AppExtention
-{
-    public static void MapWsService(this WebApplication webApplication)
-    {
-        var protocals = new List<string>() { "", "ocpp1.6", "ocpp2.0" };
-
-        webApplication.UseWebSockets(new WebSocketOptions()
-        {
-            KeepAliveInterval = TimeSpan.FromSeconds(10)
-        });
-
-        webApplication.Use(async (HttpContext context, RequestDelegate next) => {
-            if (context.WebSockets.IsWebSocketRequest)
-            {
-                var matched = context.WebSockets.WebSocketRequestedProtocols.Intersect(protocals);
-                if (matched is null || !matched.Any())
-                {
-                    await context.Response.WriteAsync("Protocol not matched");
-                    return;
-                }
-                using WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(matched.First());
-                var servcie = context.RequestServices.GetService<WebsocketService<WsClientData>>();
-                await servcie.AddWebSocket(webSocket, context);
-                return;
-            }
-            else
-            {
-                await next(context);
-            }
-        });
-    }
-}
-
-public interface IWebsocketService
-{
-    public Task AddWebSocket(WebSocket webSocket, HttpContext context);
-}
-
-public class WebsocketService<T> : IWebsocketService where T: WsSession
-{
-    public WebsocketService() { }
-
-    public Func<T,  Task<bool>> ValidateHandshake;
-
-    public event EventHandler<T> NewSessionConnected;
-
-    public async Task AddWebSocket(WebSocket webSocket, HttpContext context)
-    {
-        T data = Activator.CreateInstance<T>();
-        data.ClientWebSocket = webSocket;
-        data.Path = context?.Request?.Path;
-        data.UriScheme = context?.Request?.Scheme;
-        data.AuthHeader = context?.Request?.Headers?.Authorization;
-        data.SessionID = context.TraceIdentifier;
-        data.Endpoint = null;
-        data.Origin = context.Request.Headers.Origin;
-
-        var validated = await ValidateHandshake(data);
-
-        if (!validated)
-        {
-            return;
-        }
-
-        NewSessionConnected?.Invoke(this, data);
-        await data.EndConnSemaphore.WaitAsync();
-        return;
-    }
-}
-
-public class WsSession
-{
-    public WsSession()
-    {
-
-    }
-
-    public PathString? Path { get; set; }
-    public string UriScheme { get; set; }
-    public string AuthHeader { get; set; }
-    public string SessionID { get; set; }
-    public Endpoint Endpoint { get; internal set; }
-    public StringValues Origin { get; internal set; }
-    public DateTime LastActiveTime { get; set; }
-
-
-    public WebSocket _WebSocket { get; internal set; }
-    public WebSocket ClientWebSocket {
-        get => _WebSocket;
-        set
-        {
-            Init(value);
-        }
-    }
-
-    public WebSocketState State => ClientWebSocket.State;
-    public string SecWebSocketProtocol => ClientWebSocket.SubProtocol;
-
-    public SemaphoreSlim EndConnSemaphore { get; } = new SemaphoreSlim(0);
-
-    //public event OCPPClientDataEventHandler<WsSession, String> m_ReceiveData;
-
-    public event EventHandler SessionClosed;
-
-    private Task ReceiveLoopTask;
-
-    private void Init(WebSocket webSocket)
-    {
-        _WebSocket = webSocket;
-        ReceiveLoopTask = StartReceivd(webSocket);
-    }
-
-    private async Task StartReceivd(WebSocket webSocket)
-    {
-        while (true)
-        {
-            var buffer = new byte[1024 * 4];
-            var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), default);
-            if (result.CloseStatus.HasValue)
-            {
-                Close(CloseReason.ClientClosing);
-                break;
-            }
-            string received = Encoding.UTF8.GetString(buffer, 0, result.Count);
-            //m_ReceiveData?.Invoke(this, received);
-            this.LastActiveTime = DateTime.UtcNow;
-            HandleReceivedData(received);
-        }
-    }
-
-    internal virtual void HandleReceivedData(string data)
-    {
-
-    }
-
-    internal void Send(string dataString)
-    {
-        var data = Encoding.UTF8.GetBytes(dataString);
-        ClientWebSocket.SendAsync(data, WebSocketMessageType.Text, endOfMessage: true, cancellationToken: default);
-    }
-
-    internal void Send(byte[] data, int offset, int length)
-    {
-        ClientWebSocket.SendAsync(data, WebSocketMessageType.Text, endOfMessage: true, cancellationToken: default);
-    }
-
-    internal void Close(CloseReason closeReason)
-    {
-        SessionClosed?.Invoke(this, null);
-        _WebSocket.Dispose();
-        EndConnSemaphore.Release();
-    }
-}

+ 80 - 0
EVCB_OCPP.WSServer/Service/WsService/WebsocketService.cs

@@ -0,0 +1,80 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Primitives;
+using System.Net.WebSockets;
+using System.Text;
+
+namespace EVCB_OCPP.WSServer.Service.WsService;
+
+public static class AppExtention
+{
+    public static void MapWsService(this WebApplication webApplication)
+    {
+        var protocals = new List<string>() { "", "ocpp1.6", "ocpp2.0" };
+
+        webApplication.UseWebSockets(new WebSocketOptions()
+        {
+            KeepAliveInterval = TimeSpan.FromSeconds(10)
+        });
+
+        webApplication.Use(async (context, next) =>
+        {
+
+            if (!context.WebSockets.IsWebSocketRequest)
+            {
+                await next(context);
+                return;
+            }
+
+            var matched = context.WebSockets.WebSocketRequestedProtocols.Intersect(protocals);
+            if (matched is null || !matched.Any())
+            {
+                await context.Response.WriteAsync("Protocol not matched");
+                return;
+            }
+            using WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(matched.Last());
+            var servcie = context.RequestServices.GetService<WebsocketService<WsClientData>>();
+            await servcie.AddWebSocket(webSocket, context);
+            return;
+        });
+    }
+}
+
+public class WebsocketService<T> where T : WsSession
+{
+    public WebsocketService() { }
+
+    public Func<T, Task<bool>> ValidateHandshake;
+
+    public event EventHandler<T> NewSessionConnected;
+
+    public async Task AddWebSocket(WebSocket webSocket, HttpContext context)
+    {
+        T data = Activator.CreateInstance<T>();
+        data.ClientWebSocket = webSocket;
+        data.Path = context?.Request?.Path;
+        data.UriScheme = context?.Request?.Scheme;
+        data.AuthHeader = context?.Request?.Headers?.Authorization;
+        data.SessionID = context.TraceIdentifier;
+        data.Endpoint = null;
+        data.Origin = context.Request.Headers.Origin;
+
+        var validated = ValidateHandshake == null ? false : await ValidateHandshake(data);
+
+        if (!validated)
+        {
+            return;
+        }
+
+        NewSessionConnected?.Invoke(this, data);
+        await data.EndConnSemaphore.WaitAsync();
+        return;
+    }
+}
+
+public enum CloseReason
+{
+    ClientClosing,
+    ServerShutdown
+}

+ 101 - 0
EVCB_OCPP.WSServer/Service/WsService/WsClientData.cs

@@ -0,0 +1,101 @@
+
+using EVCB_OCPP.Packet.Messages.Basic;
+using EVCB_OCPP.WSServer.Dto;
+
+namespace EVCB_OCPP.WSServer.Service.WsService
+{
+    public class WsClientData : WsSession
+    { /// <summary>
+      /// 根據unique id來儲存.取出OCPP Request
+      /// </summary>
+        public Queue queue = new Queue();
+
+        public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
+
+        public bool? IsPending { set; get; }
+        public bool IsCheckIn { set; get; } = false;
+
+        public string ChargeBoxId { set; get; }
+
+        public Guid CustomerId { get; set; }
+
+        public string MachineId { set; get; }
+
+        public bool ISOCPP20 { set; get; }
+
+        public bool ResetSecurityProfile { set; get; }
+
+
+        public bool IsAC { set; get; } = true;
+
+        #region Billing
+
+        public Dictionary<string, string> UserPrices { set; get; } = new Dictionary<string, string>();
+
+        public Dictionary<string, string> UserDisplayPrices { set; get; } = new Dictionary<string, string>();
+
+        public List<ChargingPrice> ChargingPrices { set; get; }
+
+        /// <summary>
+        /// 電樁顯示費率
+        /// </summary>
+        public string DisplayPrice { set; get; }
+
+        /// <summary>
+        /// 充電費率 以小時計費
+        /// </summary>
+        public decimal ChargingFeebyHour { set; get; }
+
+        /// <summary>
+        /// 停車費率 以小時計費
+        /// </summary>
+        public decimal ParkingFee { set; get; }
+
+        /// <summary>
+        /// 電樁是否計費
+        /// </summary>
+        public bool IsBilling { set; get; }
+
+        /// <summary>
+        /// 收費方式 1: 以度計費 2:以小時計費
+        /// </summary>
+        public int BillingMethod { set; get; }
+
+
+        /// <summary>
+        /// 電樁適用幣別
+        /// </summary>
+        public string Currency { get; internal set; }
+
+        #endregion
+
+        public string CustomerName { get; set; }
+
+        public string StationId { set; get; }
+
+        public event EventHandler<string> m_ReceiveData;
+
+
+        public WsClientData()
+        {
+            ChargeBoxId = SessionID;
+            MachineId = SessionID;
+        }
+
+        /// <summary>
+        /// Sends the raw binary data to client.
+        /// </summary>
+        /// <param name="data">The data.</param>
+        /// <param name="offset">The offset.</param>
+        /// <param name="length">The length.</param>
+        public void SendRawData(byte[] data, int offset, int length)
+        {
+            Send(data, offset, length);
+        }
+
+        internal override void HandleReceivedData(string msg)
+        {
+            m_ReceiveData?.Invoke(this, msg);
+        }
+    }
+}

+ 98 - 0
EVCB_OCPP.WSServer/Service/WsService/WsSession.cs

@@ -0,0 +1,98 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.WebSockets;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.WSServer.Service.WsService
+{
+    public class WsSession
+    {
+        public WsSession()
+        {
+
+        }
+
+        public PathString? Path { get; set; }
+        public string UriScheme { get; set; }
+        public string AuthHeader { get; set; }
+        public string SessionID { get; set; }
+        public Endpoint Endpoint { get; internal set; }
+        public StringValues Origin { get; internal set; }
+        public DateTime LastActiveTime { get; set; }
+
+
+        private WebSocket _WebSocket;
+        public WebSocket ClientWebSocket
+        {
+            get => _WebSocket;
+            set
+            {
+                Init(value);
+            }
+        }
+
+        public WebSocketState State => ClientWebSocket.State;
+        public string SecWebSocketProtocol => ClientWebSocket.SubProtocol;
+
+        public SemaphoreSlim EndConnSemaphore { get; } = new SemaphoreSlim(0);
+
+        //public event OCPPClientDataEventHandler<WsSession, String> m_ReceiveData;
+
+        public event EventHandler SessionClosed;
+
+        private CancellationTokenSource stopReceivCancellationTokenSource = new CancellationTokenSource();
+        private Task ReceiveLoopTask;
+
+        private void Init(WebSocket webSocket)
+        {
+            _WebSocket = webSocket;
+            ReceiveLoopTask = StartReceivd(webSocket, stopReceivCancellationTokenSource.Token);
+        }
+
+        private async Task StartReceivd(WebSocket webSocket, CancellationToken token)
+        {
+            while (!token.IsCancellationRequested)
+            {
+                var buffer = new byte[1024 * 4];
+                var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), token);
+                if (result.CloseStatus.HasValue)
+                {
+                    Close(CloseReason.ClientClosing);
+                    break;
+                }
+                string received = Encoding.UTF8.GetString(buffer, 0, result.Count);
+                //m_ReceiveData?.Invoke(this, received);
+                LastActiveTime = DateTime.UtcNow;
+                HandleReceivedData(received);
+            }
+        }
+
+        internal virtual void HandleReceivedData(string data)
+        {
+
+        }
+
+        internal void Send(string dataString)
+        {
+            var data = Encoding.UTF8.GetBytes(dataString);
+            ClientWebSocket.SendAsync(data, WebSocketMessageType.Text, endOfMessage: true, cancellationToken: default);
+        }
+
+        internal void Send(byte[] data, int offset, int length)
+        {
+            ClientWebSocket.SendAsync(data, WebSocketMessageType.Text, endOfMessage: true, cancellationToken: default);
+        }
+
+        internal void Close(CloseReason closeReason)
+        {
+            SessionClosed?.Invoke(this, null);
+            stopReceivCancellationTokenSource.Cancel();
+            _WebSocket.Dispose();
+            EndConnSemaphore.Release();
+        }
+    }
+}

+ 0 - 19
EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallCmd.cs

@@ -1,19 +0,0 @@
-using OCPPServer.Protocol;
-using SuperWebSocket.SubProtocol;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.WSServer.SuperSocket.Command
-{
-    public class ProcessCallCmd : SubCommandBase<ClientData>
-    {
-        public override void ExecuteCommand(ClientData session, SubRequestInfo requestInfo)
-        {
-            session.ReceiveData(session, requestInfo.Body);
-        }
-
-        public override string Name
-        {
-            get { return "2"; }
-        }
-    }
-}

+ 0 - 19
EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallErrorCmd.cs

@@ -1,19 +0,0 @@
-using OCPPServer.Protocol;
-using SuperWebSocket.SubProtocol;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.WSServer.SuperSocket.Command
-{
-    public class ProcessCallErrorCmd : SubCommandBase<ClientData>
-    {
-        public override void ExecuteCommand(ClientData session, SubRequestInfo requestInfo)
-        {
-            session.ReceiveData(session, requestInfo.Body);
-        }
-
-        public override string Name
-        {
-            get { return "4"; }
-        }
-    }
-}

+ 0 - 19
EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallResultCmd.cs

@@ -1,19 +0,0 @@
-using OCPPServer.Protocol;
-using SuperWebSocket.SubProtocol;
-using System.Threading.Tasks;
-
-namespace EVCB_OCPP.WSServer.SuperSocket.Command
-{
-    public class ProcessCallResultCmd : SubCommandBase<ClientData>
-    {
-        public override void ExecuteCommand(ClientData session, SubRequestInfo requestInfo)
-        {
-            session.ReceiveData(session, requestInfo.Body);
-        }
-
-        public override string Name
-        {
-            get { return "3"; }
-        }
-    }
-}

+ 0 - 225
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -1,225 +0,0 @@
-
-using EVCB_OCPP.Packet.Messages.Basic;
-using EVCB_OCPP.WSServer.Dto;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Threading.Tasks;
-using SuperWebSocket;
-using SuperSocket.SocketBase;
-using EVCB_OCPP.WSServer.Service;
-using System.Net.WebSockets;
-
-namespace OCPPServer.Protocol
-{
-    public class WsClientData : WsSession
-    { /// <summary>
-      /// 根據unique id來儲存.取出OCPP Request
-      /// </summary>
-        public Queue queue = new Queue();
-
-        public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
-
-        public bool? IsPending { set; get; }
-        public bool IsCheckIn { set; get; } = false;
-
-        public string ChargeBoxId { set; get; }
-
-        public Guid CustomerId { get; set; }
-
-        public string MachineId { set; get; }
-
-        public bool ISOCPP20 { set; get; }
-
-        public bool ResetSecurityProfile { set; get; }
-
-
-        public bool IsAC { set; get; } = true;
-
-        #region Billing
-
-        public Dictionary<string, string> UserPrices { set; get; } = new Dictionary<string, string>();
-
-        public Dictionary<string, string> UserDisplayPrices { set; get; } = new Dictionary<string, string>();
-
-        public List<ChargingPrice> ChargingPrices { set; get; }
-
-        /// <summary>
-        /// 電樁顯示費率
-        /// </summary>
-        public string DisplayPrice { set; get; }
-
-        /// <summary>
-        /// 充電費率 以小時計費
-        /// </summary>
-        public decimal ChargingFeebyHour { set; get; }
-
-        /// <summary>
-        /// 停車費率 以小時計費
-        /// </summary>
-        public decimal ParkingFee { set; get; }
-
-        /// <summary>
-        /// 電樁是否計費
-        /// </summary>
-        public bool IsBilling { set; get; }
-
-        /// <summary>
-        /// 收費方式 1: 以度計費 2:以小時計費
-        /// </summary>
-        public int BillingMethod { set; get; }
-
-
-        /// <summary>
-        /// 電樁適用幣別
-        /// </summary>
-        public string Currency { get; internal set; }
-
-        #endregion
-
-        public string CustomerName { get; set; }
-
-        public string StationId { set; get; }
-
-        public event ClientData.OCPPClientDataEventHandler<WsClientData, string> m_ReceiveData;
-
-
-        public WsClientData()
-        {
-            ChargeBoxId = SessionID;
-            MachineId = SessionID;
-        }
-
-        /// <summary>
-        /// Sends the raw binary data to client.
-        /// </summary>
-        /// <param name="data">The data.</param>
-        /// <param name="offset">The offset.</param>
-        /// <param name="length">The length.</param>
-        public void SendRawData(byte[] data, int offset, int length)
-        {
-            base.Send(data, offset, length);
-        }
-
-        internal override void HandleReceivedData(string msg)
-        {
-            m_ReceiveData?.Invoke(this, msg);
-        }
-    }
-
-    public class ClientData : WebSocketSession<ClientData>
-    { /// <summary>
-      /// 根據unique id來儲存.取出OCPP Request
-      /// </summary>
-        public Queue queue = new Queue();
-
-        public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
-
-        public bool? IsPending { set; get; }
-        public bool IsCheckIn { set; get; }
-
-        public string ChargeBoxId { set; get; }
-
-        public Guid CustomerId { get; set; }
-
-        public string MachineId { set; get; }
-
-        public bool ISOCPP20 { set; get; }
-
-        public bool ResetSecurityProfile { set; get; }
-
-
-        public bool IsAC { set; get; }
-
-        #region Billing
-
-        public Dictionary<string,string> UserPrices { set; get; }
-
-        public Dictionary<string, string> UserDisplayPrices { set; get; }
-
-        public List<ChargingPrice> ChargingPrices { set; get; }
-
-        /// <summary>
-        /// 電樁顯示費率
-        /// </summary>
-        public string DisplayPrice { set; get; }
-
-        /// <summary>
-        /// 充電費率 以小時計費
-        /// </summary>
-        public decimal ChargingFeebyHour { set; get; }
-
-        /// <summary>
-        /// 停車費率 以小時計費
-        /// </summary>
-        public decimal ParkingFee { set; get; }
-
-        /// <summary>
-        /// 電樁是否計費
-        /// </summary>
-        public bool IsBilling { set; get; }
-
-        /// <summary>
-        /// 收費方式 1: 以度計費 2:以小時計費
-        /// </summary>
-        public int BillingMethod { set; get; }
-       
-
-        /// <summary>
-        /// 電樁適用幣別
-        /// </summary>
-        public string Currency { get; internal set; }
-
-        #endregion
-
-        public string CustomerName { get; set; }
-
-
-        public string StationId { set; get; }
-
-
-
-        public delegate void OCPPClientDataEventHandler<ClientData, String>(ClientData clientdata, String msg);
-
-        public event OCPPClientDataEventHandler<ClientData, String> m_ReceiveData;
-
-        public ClientData()
-        {
-            IsAC = true;
-            IsCheckIn = false;
-            ChargeBoxId = SessionID;
-            MachineId = SessionID;
-            UserPrices = new Dictionary<string, string>();
-            UserDisplayPrices = new Dictionary<string, string>();
-        }
-
-
-
-        /// <summary>
-        /// Sends the raw binary data to client.
-        /// </summary>
-        /// <param name="data">The data.</param>
-        /// <param name="offset">The offset.</param>
-        /// <param name="length">The length.</param>
-        public void SendRawData(byte[] data, int offset, int length)
-        {
-            base.Send(data, offset, length);
-        }
-
-        //receive data event trigger
-        public void ReceiveData(ClientData clientdata, string msg)
-        {
-            if (m_ReceiveData != null)
-                m_ReceiveData(clientdata, msg);
-        }
-
-        /// <summary>
-        /// Called when [session closed].
-        /// </summary>
-        /// <param name="reason">The reason.</param>
-        protected override void OnSessionClosed(CloseReason reason)
-        {
-        }
-
-    }
-}

+ 0 - 8
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLog.cs

@@ -1,8 +0,0 @@
-
-
-using Microsoft.Extensions.Logging;
-using System;
-
-namespace OCPPServer.SubProtocol
-{
-}

+ 0 - 5
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLogFactory.cs

@@ -1,5 +0,0 @@
-using System.Collections.Generic;
-
-namespace OCPPServer.SubProtocol
-{
-}

+ 0 - 35
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubCommandConverter.cs

@@ -1,35 +0,0 @@
-using SuperSocket.SocketBase.Protocol;
-using SuperWebSocket.SubProtocol;
-
-namespace OCPPServer.SubProtocol
-{
-    public class OCPPSubCommandParser : IRequestInfoParser<SubRequestInfo>
-    {
-        #region ISubProtocolCommandParser Members
-
-        /// <summary>
-        /// Parses the request info.
-        /// </summary>
-        /// <param name="source">The source.</param>
-        /// <returns></returns>
-        public SubRequestInfo ParseRequestInfo(string source)
-        {
-            var cmd = source.Trim();
-            int pos = cmd.IndexOf(',');
-            string name;
-
-            if (pos > 0)
-            {
-                name = cmd.Substring(pos - 1, 1);
-            }
-            else
-            {
-                name = "4";
-            }
-
-            return new SubRequestInfo(name, "", source);
-        }
-
-        #endregion ISubProtocolCommandParser Members
-    }
-}

+ 0 - 322
EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubProtocol.cs

@@ -1,322 +0,0 @@
-using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
-using SuperSocket.Common;
-using SuperSocket.SocketBase;
-using SuperSocket.SocketBase.Protocol;
-using SuperWebSocket;
-using SuperWebSocket.Config;
-using SuperWebSocket.SubProtocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-
-namespace OCPPServer.SubProtocol
-{
-    public class OCPPSubProtocol : OCPPSubProtocol<ClientData>
-    {
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol"/> class.
-        /// </summary>
-        public OCPPSubProtocol()
-            : base(Assembly.GetCallingAssembly())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol"/> class.
-        /// </summary>
-        /// <param name="name">The sub protocol name.</param>
-        public OCPPSubProtocol(string name)
-            : base(name, Assembly.GetCallingAssembly())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol"/> class.
-        /// </summary>
-        /// <param name="commandAssembly">The command assembly.</param>
-        public OCPPSubProtocol(Assembly commandAssembly)
-            : base(commandAssembly)
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="OCPPSubProtocol"/> class.
-        /// </summary>
-        /// <param name="commandAssemblies">The command assemblies.</param>
-        public OCPPSubProtocol(IEnumerable<Assembly> commandAssemblies)
-            : base(commandAssemblies)
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="OCPPSubProtocol"/> class.
-        /// </summary>
-        /// <param name="name">The sub protocol name.</param>
-        /// <param name="commandAssembly">The command assembly.</param>
-        public OCPPSubProtocol(string name, Assembly commandAssembly)
-            : base(name, commandAssembly)
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="OCPPSubProtocol"/> class.
-        /// </summary>
-        /// <param name="name">The sub protocol name.</param>
-        /// <param name="commandAssemblies">The command assemblies.</param>
-        public OCPPSubProtocol(string name, IEnumerable<Assembly> commandAssemblies)
-            : base(name, commandAssemblies)
-        {
-
-        }
-
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="OCPPSubProtocol"/> class.
-        /// </summary>
-        /// <param name="name">The name.</param>
-        /// <param name="commandAssemblies">The command assemblies.</param>
-        /// <param name="requestInfoParser">The request info parser.</param>
-        public OCPPSubProtocol(string name, IEnumerable<Assembly> commandAssemblies, IRequestInfoParser<SubRequestInfo> requestInfoParser)
-            : base(name, commandAssemblies, requestInfoParser)
-        {
-
-        }
-
-        public ILogger Getmlog()
-        {
-            return getlog();
-        }
-
-    }
-
-    public class OCPPSubProtocol<TWebSocketSession> : SubProtocolBase<TWebSocketSession>
-       where TWebSocketSession : WebSocketSession<TWebSocketSession>, new()
-    {
-        /// <summary>
-        /// Default basic sub protocol name
-        /// </summary>
-        public const string DefaultName = "ocpp1.6";//"OCPP1.6";
-
-        private List<Assembly> m_CommandAssemblies = new List<Assembly>();
-
-        private Dictionary<string, ISubCommand<TWebSocketSession>> m_CommandDict;
-
-        private ILogger m_Logger;
-
-        private SubCommandFilterAttribute[] m_GlobalFilters;
-
-        internal static BasicSubProtocol<TWebSocketSession> CreateDefaultSubProtocol()
-        {
-            var commandAssembly = typeof(TWebSocketSession).Assembly;
-
-            if (commandAssembly == Assembly.GetExecutingAssembly())
-                commandAssembly = Assembly.GetEntryAssembly();
-
-            return new BasicSubProtocol<TWebSocketSession>(DefaultName, commandAssembly);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class with the calling aseembly as command assembly
-        /// </summary>
-        public OCPPSubProtocol()
-            : this(DefaultName, Assembly.GetCallingAssembly())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class with the calling aseembly as command assembly
-        /// </summary>
-        /// <param name="name">The sub protocol name.</param>
-        public OCPPSubProtocol(string name)
-            : this(name, Assembly.GetCallingAssembly())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class with command assemblies
-        /// </summary>
-        /// <param name="commandAssemblies">The command assemblies.</param>
-        public OCPPSubProtocol(IEnumerable<Assembly> commandAssemblies)
-            : this(DefaultName, commandAssemblies, new OCPPSubCommandParser())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class with single command assembly.
-        /// </summary>
-        /// <param name="commandAssembly">The command assembly.</param>
-        public OCPPSubProtocol(Assembly commandAssembly)
-            : this(DefaultName, new List<Assembly> { commandAssembly }, new OCPPSubCommandParser())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class with name and single command assembly.
-        /// </summary>
-        /// <param name="name">The sub protocol name.</param>
-        /// <param name="commandAssembly">The command assembly.</param>
-        public OCPPSubProtocol(string name, Assembly commandAssembly)
-            : this(name, new List<Assembly> { commandAssembly }, new OCPPSubCommandParser())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class with name and command assemblies.
-        /// </summary>
-        /// <param name="name">The sub protocol name.</param>
-        /// <param name="commandAssemblies">The command assemblies.</param>
-        public OCPPSubProtocol(string name, IEnumerable<Assembly> commandAssemblies)
-            : this(name, commandAssemblies, new OCPPSubCommandParser())
-        {
-
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="BasicSubProtocol&lt;TWebSocketSession&gt;"/> class.
-        /// </summary>
-        /// <param name="name">The name.</param>
-        /// <param name="commandAssemblies">The command assemblies.</param>
-        /// <param name="requestInfoParser">The request info parser.</param>
-        public OCPPSubProtocol(string name, IEnumerable<Assembly> commandAssemblies, IRequestInfoParser<SubRequestInfo> requestInfoParser)
-            : base(name)
-        {
-            //The items in commandAssemblies may be null, so filter here
-            m_CommandAssemblies.AddRange(commandAssemblies.Where(a => a != null));
-            SubRequestParser = requestInfoParser;
-        }
-
-
-
-        #region ISubProtocol Members
-
-        private void DiscoverCommands()
-        {
-            var subCommands = new List<ISubCommand<TWebSocketSession>>();
-
-            foreach (var assembly in m_CommandAssemblies)
-            {
-                subCommands.AddRange(assembly.GetImplementedObjectsByInterface<ISubCommand<TWebSocketSession>>());
-            }
-
-#if DEBUG
-            var cmdbuilder = new StringBuilder();
-            cmdbuilder.AppendLine(string.Format("SubProtocol {0} found the commands below:", this.Name));
-
-            foreach (var c in subCommands)
-            {
-                cmdbuilder.AppendLine(c.Name);
-            }
-
-
-            m_Logger.LogDebug(cmdbuilder.ToString());
-#endif
-
-            m_CommandDict = new Dictionary<string, ISubCommand<TWebSocketSession>>(subCommands.Count, StringComparer.OrdinalIgnoreCase);
-
-            subCommands.ForEach(c =>
-            {
-                var fc = c as ISubCommandFilterLoader;
-
-                if (fc != null)
-                    fc.LoadSubCommandFilters(m_GlobalFilters);
-
-                m_CommandDict.Add(c.Name, c);
-            }
-                );
-        }
-
-
-        private bool ResolveCommmandAssembly(string definition)
-        {
-            try
-            {
-                var assemblies = AssemblyUtil.GetAssembliesFromString(definition);
-
-                if (assemblies.Any())
-                    m_CommandAssemblies.AddRange(assemblies);
-
-                return true;
-            }
-            catch (Exception e)
-            {
-                m_Logger.LogError(e,e.Message);
-                return false;
-            }
-        }
-
-        public ILogger getlog()
-        {
-            return m_Logger;
-        }
-
-        /// <summary>
-        /// Tries get command from the sub protocol's command inventory.
-        /// </summary>
-        /// <param name="name">The name.</param>
-        /// <param name="command">The command.</param>
-        /// <returns></returns>
-        public override bool TryGetCommand(string name, out ISubCommand<TWebSocketSession> command)
-        {
-            return m_CommandDict.TryGetValue(name, out command);
-        }
-
-
-
-        public override bool Initialize(IAppServer appServer, SubProtocolConfig protocolConfig, ILogger logger)
-        {
-            m_Logger = logger;
-
-            var config = appServer.Config;
-
-            m_GlobalFilters = appServer.GetType()
-                    .GetCustomAttributes(true)
-                    .OfType<SubCommandFilterAttribute>()
-                    .Where(a => string.IsNullOrEmpty(a.SubProtocol) || Name.Equals(a.SubProtocol, StringComparison.OrdinalIgnoreCase)).ToArray();
-
-            if (Name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase))
-            {
-                var commandAssembly = config.Options.GetValue("commandAssembly");
-
-                if (!string.IsNullOrEmpty(commandAssembly))
-                {
-                    if (!ResolveCommmandAssembly(commandAssembly))
-                        return false;
-                }
-            }
-
-            if (protocolConfig != null && protocolConfig.Commands != null)
-            {
-                foreach (var commandConfig in protocolConfig.Commands)
-                {
-                    var assembly = commandConfig.Options.GetValue("assembly");
-
-                    if (!string.IsNullOrEmpty(assembly))
-                    {
-                        if (!ResolveCommmandAssembly(assembly))
-                            return false;
-                    }
-                }
-            }
-
-            //Always discover commands
-            DiscoverCommands();
-
-            return true;
-        }
-
-        #endregion
-    }
-}

+ 0 - 255
EVCB_OCPP.WSServer/SuperSocket/OCPPWSServer.cs

@@ -1,255 +0,0 @@
-using EVCB_OCPP.WSServer.Service;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
-using SuperSocket.SocketBase;
-using SuperWebSocket;
-using SuperWebSocket.SubProtocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Net.Security;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-
-namespace EVCB_OCPP.WSServer.SuperSocket;
-
-public class OCPPWSServer : WebSocketServer<ClientData>
-{
-
-    private readonly ILogger logger;
-    private readonly IConfiguration configuration;
-    private readonly IMainDbService mainDbService;
-
-    /// <summary>
-    /// 可允許連線Clinet數
-    /// </summary>
-    public int connectNum { get; set; }
-
-    /// <summary>
-    /// 是否限制連線Clinet數
-    /// </summary>
-    public bool beConnectLimit { get; set; }
-
-    /// <summary>
-    /// Initializes a new instance of the <see cref="WebSocketServer"/> class.
-    /// </summary>
-    /// <param name="subProtocols">The sub protocols.</param>
-    public OCPPWSServer(
-        IConfiguration configuration,
-        IMainDbService mainDbService,
-        ILogger<OCPPWSServer> logger)
-        : base(new List<ISubProtocol<ClientData>>())
-    {
-        this.configuration = configuration;
-        this.mainDbService = mainDbService;
-        this.logger = logger;
-    }
-
-    /// <summary>
-    /// Initializes a new instance of the <see cref="WebSocketServer"/> class.
-    /// </summary>
-    /// <param name="subProtocol">The sub protocol.</param>
-    //public OCPPWSServer(ISubProtocol<ClientData> subProtocol, IServiceProvider serviceProvider)
-    //    : base(subProtocol)
-    //{
-    //    this.configuration = serviceProvider.GetService<IConfiguration>();
-
-    //    logger = serviceProvider.GetService<ILogger<OCPPWSServer>>();
-    //}
-
-    /// <summary>
-    /// Initializes a new instance of the <see cref="WebSocketServer"/> class.
-    /// </summary>
-    //public OCPPWSServer(IServiceProvider serviceProvider)
-    //    : base(new List<ISubProtocol<ClientData>>())
-    //{
-    //    this.configuration = serviceProvider.GetService<IConfiguration>();
-
-    //    logger = serviceProvider.GetService<ILogger<OCPPWSServer>>();
-    //}
-
-    protected override bool ValidateClientCertificate(ClientData session, object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
-    {
-        //  Console.WriteLine(string.Format("{0} :{1}", session.ChargeBoxId + " ValidateClientCertificate", sslPolicyErrors));
-        return true;
-        // return base.ValidateClientCertificate(session, sender, certificate, chain, sslPolicyErrors);
-    }
-
-    protected override bool ValidateHandshake(ClientData session, string origin)
-    {
-        session.ISOCPP20 = session.SecWebSocketProtocol.ToLower().Contains("ocpp2.0");
-
-        int securityProfile = 0;
-        string authorizationKey = string.Empty;
-        if (string.IsNullOrEmpty(session.Path))
-        {
-            //logger.Log();
-            logger.LogWarning("===========================================");
-            logger.LogWarning("session.Path EMPTY");
-            logger.LogWarning("===========================================");
-        }
-
-        string[] words = session.Path.Split('/');
-        session.ChargeBoxId = words.Last();
-
-        foreach (var denyModel in GlobalConfig.DenyModelNames)
-        {
-            if (string.IsNullOrEmpty(denyModel))
-            {
-                continue;
-            }
-
-            if (session.ChargeBoxId.StartsWith(denyModel))
-            {
-
-                StringBuilder responseBuilder = new StringBuilder();
-
-                responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-                (int)HttpStatusCode.Unauthorized, @"Unauthorized");
-
-                responseBuilder.AppendWithCrCf();
-                string sb = responseBuilder.ToString();
-                byte[] data = Encoding.UTF8.GetBytes(sb);
-
-                ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
-                logger.LogTrace(sb);
-                return false;
-            }
-        }
-
-        if (configuration["MaintainMode"] == "1")
-        {
-            session.ChargeBoxId = session.ChargeBoxId + "_2";
-        }
-
-        logger.LogInformation(string.Format("ValidateHandshake: {0}", session.Path));
-        bool isExistedSN = false;
-        bool authorizated = false;
-
-        var info = mainDbService.GetMachineIdAndCustomerInfo(session.ChargeBoxId).Result;
-        //var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.IsDelete == false).Select(x => new { x.CustomerId, x.Id }).AsNoTracking().FirstOrDefault();
-        //session.CustomerName = machine == null ? "Unknown" : db.Customer.Where(x => x.Id == machine.CustomerId).Select(x => x.Name).FirstOrDefault();
-        //session.CustomerId = machine == null ? Guid.Empty : machine.CustomerId;
-        //session.MachineId = machine == null ? String.Empty : machine.Id;
-        //isExistedSN = machine == null ? false : true;
-        session.CustomerName = info.CustomerName;
-        session.CustomerId = info.CustomerId;
-        session.MachineId = info.MachineId;
-        isExistedSN = !string.IsNullOrEmpty(info.MachineId);// machine == null ? false : true;
-
-        if (!isExistedSN)
-        {
-            StringBuilder responseBuilder = new StringBuilder();
-
-            responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-            (int)HttpStatusCode.NotFound, @"Not Found");
-
-            responseBuilder.AppendWithCrCf();
-            string sb = responseBuilder.ToString();
-            byte[] data = Encoding.UTF8.GetBytes(sb);
-            ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
-
-            logger.LogInformation(sb);
-            return false;
-        }
-
-        //var configVaule = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.SecurityProfile)
-        //                  .Select(x => x.ConfigureSetting).FirstOrDefault();
-        var configVaule = mainDbService.GetMachineSecurityProfile(session.ChargeBoxId).Result;
-        int.TryParse(configVaule, out securityProfile);
-
-        if (session.ISOCPP20)
-        {
-            // 1.6 server only support change server  function
-            securityProfile = 0;
-        }
-
-        if (securityProfile == 3 && session.UriScheme == "ws")
-        {
-            StringBuilder responseBuilder = new StringBuilder();
-
-            responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-            (int)HttpStatusCode.Unauthorized, @"Unauthorized");
-
-            responseBuilder.AppendWithCrCf();
-            string sb = responseBuilder.ToString();
-            byte[] data = Encoding.UTF8.GetBytes(sb);
-
-            ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
-            logger.LogInformation(sb);
-            return false;
-        }
-
-        if (securityProfile == 1 || securityProfile == 2)
-        {
-            if (securityProfile == 2 && session.UriScheme == "ws")
-            {
-                authorizated = false;
-            }
-
-            if (session.Items.ContainsKey("Authorization") || session.Items.ContainsKey("authorization"))
-            {
-                //authorizationKey = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.AuthorizationKey)
-                //                    .Select(x => x.ConfigureSetting).FirstOrDefault();
-                authorizationKey = mainDbService.GetMachineAuthorizationKey(session.ChargeBoxId).Result;
-
-                if (session.ISOCPP20)
-                {
-                    // 1.6 server only support change server  function
-                    securityProfile = 0;
-                }
-
-                logger.LogInformation("***********Authorization   ");
-
-                if (!string.IsNullOrEmpty(authorizationKey))
-                {
-                    string base64Encoded = session.Items.ContainsKey("Authorization") ? session.Items["Authorization"].ToString().Replace("Basic ", "") : session.Items["authorization"].ToString().Replace("Basic ", "");
-                    byte[] data = Convert.FromBase64String(base64Encoded);
-                    string[] base64Decoded = Encoding.ASCII.GetString(data).Split(':');
-                    logger.LogInformation("***********Authorization   " + Encoding.ASCII.GetString(data));
-                    if (base64Decoded.Count() == 2 && base64Decoded[0] == session.ChargeBoxId && base64Decoded[1] == authorizationKey)
-                    {
-                        authorizated = true;
-                    }
-                }
-
-
-
-
-
-            }
-            else
-            {
-                authorizated = true;
-
-            }
-
-
-
-            if (!authorizated)
-            {
-                StringBuilder responseBuilder = new StringBuilder();
-
-                responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-                (int)HttpStatusCode.Unauthorized, @"Unauthorized");
-
-                responseBuilder.AppendWithCrCf();
-                string sb = responseBuilder.ToString();
-                byte[] data = Encoding.UTF8.GetBytes(sb);
-
-                ((IWebSocketSession)session).SendRawData(data, 0, data.Length);
-                logger.LogInformation(sb);
-                return false;
-            }
-        }
-
-
-
-
-
-        logger.LogInformation(string.Format("ValidateHandshake PASS: {0}", session.Path));
-        return true;
-    }
-}

+ 0 - 34
EVCB_OCPP.WSServer/SuperSocket/OCPPWSServerFactory.cs

@@ -1,34 +0,0 @@
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
-using SuperWebSocket.SubProtocol;
-
-namespace EVCB_OCPP.WSServer.SuperSocket;
-
-public interface IOCPPWSServerFactory
-{
-    OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols);
-}
-
-public class OCPPWSServerFactory : IOCPPWSServerFactory
-{
-
-    public OCPPWSServerFactory(
-        ILoggerFactory loggerFactory,
-        IServiceProvider serviceProvider)
-    {
-        this.loggerFactory = loggerFactory;
-        this.serviceProvider = serviceProvider;
-    }
-
-    public OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols)
-    {
-        var logger = loggerFactory.CreateLogger<OCPPWSServer>();
-        var server = serviceProvider.GetRequiredService<OCPPWSServer>();
-        server.RegisterSubProtocol(subProtocols);
-        return server;
-    }
-
-    private readonly ILoggerFactory loggerFactory;
-    private readonly IServiceProvider serviceProvider;
-}

+ 0 - 3
SocketEngine/SuperSocket.SocketEngine.csproj

@@ -81,7 +81,4 @@
     <Compile Remove="Extensions.Net35.cs" />
     <Compile Remove="SocketSession.Net45.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\SocketBase\SuperSocket.SocketBase.csproj" />
-  </ItemGroup>
 </Project>

+ 0 - 5
SuperWebSocket/SuperWebSocket.csproj

@@ -29,11 +29,6 @@
   <ItemGroup>
     <Folder Include="DLL\" />
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\SocketBase\SuperSocket.SocketBase.csproj" />
-    <ProjectReference Include="..\SocketCommon\SuperSocket.Common.csproj" />
-    <ProjectReference Include="..\SocketEngine\SuperSocket.SocketEngine.csproj" />
-  </ItemGroup>
   <ItemGroup>
     <PackageReference Include="DnsClient" Version="1.7.0" />
     <PackageReference Include="MongoDB.Bson" Version="2.18.0" />