Эх сурвалжийг харах

Remove Superwebsocket dependency

Jessica Tseng 1 жил өмнө
parent
commit
6951a8af06
34 өөрчлөгдсөн 17 нэмэгдсэн , 883 устгасан
  1. 0 3
      EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj
  2. 0 1
      EVCB_OCPP.WSServer/Helper/AddPortalDbContext.cs
  3. 0 1
      EVCB_OCPP.WSServer/HostedProtalServer.cs
  4. 1 2
      EVCB_OCPP.WSServer/Jobs/DenyModelCheckJob.cs
  5. 1 1
      EVCB_OCPP.WSServer/Jobs/HealthCheckTriggerJob.cs
  6. 0 1
      EVCB_OCPP.WSServer/Jobs/HeartBeatCheckJob.cs
  7. 0 1
      EVCB_OCPP.WSServer/Jobs/ServerMessageJob.cs
  8. 1 1
      EVCB_OCPP.WSServer/Jobs/ServerSetFeeJob.cs
  9. 0 1
      EVCB_OCPP.WSServer/Jobs/ServerUpdateJob.cs
  10. 1 1
      EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs
  11. 2 2
      EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs
  12. 1 1
      EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs
  13. 0 1
      EVCB_OCPP.WSServer/Message/LocalAuthListManagementProfileHandler.cs
  14. 1 1
      EVCB_OCPP.WSServer/Message/OCPP16MessageHandler.cs
  15. 0 1
      EVCB_OCPP.WSServer/Message/OCPP20MessageHandler.cs
  16. 1 1
      EVCB_OCPP.WSServer/Message/RemoteTriggerHandler.cs
  17. 1 1
      EVCB_OCPP.WSServer/Message/ReservationProfileHandler.cs
  18. 2 2
      EVCB_OCPP.WSServer/Message/SecurityProfileHandler.cs
  19. 1 1
      EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs
  20. 2 10
      EVCB_OCPP.WSServer/ProtalServer.cs
  21. 1 1
      EVCB_OCPP.WSServer/Service/ConnectionLogdbService.cs
  22. 1 1
      EVCB_OCPP.WSServer/Service/GoogleGetTimePrintService.cs
  23. 0 1
      EVCB_OCPP.WSServer/Service/OuterBusinessService.cs
  24. 0 1
      EVCB_OCPP.WSServer/Service/WsService/OcppWebsocketService.cs
  25. 0 19
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallCmd.cs
  26. 0 19
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallErrorCmd.cs
  27. 0 19
      EVCB_OCPP.WSServer/SuperSocket.Command/ProcessCallResultCmd.cs
  28. 0 128
      EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs
  29. 0 8
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLog.cs
  30. 0 5
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPLogFactory.cs
  31. 0 35
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubCommandConverter.cs
  32. 0 322
      EVCB_OCPP.WSServer/SuperSocket.Protocol/OCPPSubProtocol.cs
  33. 0 251
      EVCB_OCPP.WSServer/SuperSocket/OCPPWSServer.cs
  34. 0 39
      EVCB_OCPP.WSServer/SuperSocket/OCPPWSServerFactory.cs

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

@@ -62,7 +62,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>

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

@@ -4,7 +4,6 @@ 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;

+ 0 - 1
EVCB_OCPP.WSServer/HostedProtalServer.cs

@@ -6,7 +6,6 @@ using EVCB_OCPP.WSServer.Jobs;
 using EVCB_OCPP.WSServer.Message;
 using EVCB_OCPP.WSServer.Service;
 using EVCB_OCPP.WSServer.Service.WsService;
-using EVCB_OCPP.WSServer.SuperSocket;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Caching.Memory;
 using Microsoft.Extensions.Configuration;

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

@@ -1,11 +1,10 @@
 using Dapper;
-using DnsClient.Internal;
+
 using EVCB_OCPP.WSServer.Service;
 using EVCB_OCPP.WSServer.Service.WsService;
 using Microsoft.Data.SqlClient;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using Quartz;
 using System;
 using System.Collections.Generic;

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

@@ -1,7 +1,7 @@
 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;

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

@@ -4,7 +4,6 @@ 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;

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

@@ -8,7 +8,6 @@ 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/ServerSetFeeJob.cs

@@ -13,7 +13,7 @@ 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;

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

@@ -4,7 +4,6 @@ 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

@@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
 using NLog;
-using OCPPServer.Protocol;
+
 
 
 namespace EVCB_OCPP.WSServer.Message

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

@@ -14,11 +14,11 @@ using Microsoft.Extensions.Configuration;
 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.WSServer.Service.WsService;
 
 namespace EVCB_OCPP.WSServer.Message;

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

@@ -4,7 +4,7 @@ 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;

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

@@ -5,7 +5,6 @@ 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 - 1
EVCB_OCPP.WSServer/Message/OCPP16MessageHandler.cs

@@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 
-using OCPPServer.Protocol;
+
 using System;
 using System.Collections.Generic;
 

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

@@ -6,7 +6,6 @@ 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

@@ -5,7 +5,7 @@ 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

@@ -5,7 +5,7 @@ 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,6 +1,6 @@
 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;
@@ -55,7 +55,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

@@ -8,7 +8,7 @@ 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;

+ 2 - 10
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -11,10 +11,7 @@ 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;
@@ -27,7 +24,6 @@ using Microsoft.AspNetCore.Builder;
 using NLog.Extensions.Logging;
 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;
@@ -617,11 +613,7 @@ namespace EVCB_OCPP.WSServer
         //    }
         //}
 
-        private void AppServer_SessionClosed(WsClientData session, CloseReason value)
-        {
-            WriteMachineLog(session, string.Format("CloseReason: {0}", value), "Connection", "");
-            RemoveClient(session);
-        }
+    
 
         private async void AppServer_NewSessionConnected(WsClientData session)
         {

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

@@ -8,7 +8,7 @@ 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;

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

@@ -6,7 +6,7 @@ using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using ZstdSharp.Unsafe;
+
 
 namespace EVCB_OCPP.WSServer.Service
 {

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

@@ -7,7 +7,6 @@ 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;

+ 0 - 1
EVCB_OCPP.WSServer/Service/WsService/OcppWebsocketService.cs

@@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
 using System.Net.WebSockets;
 using System.Text;
 

+ 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 - 128
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -1,128 +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;
-
-namespace OCPPServer.Protocol
-{
-    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 - 251
EVCB_OCPP.WSServer/SuperSocket/OCPPWSServer.cs

@@ -1,251 +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)) break;
-            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 - 39
EVCB_OCPP.WSServer/SuperSocket/OCPPWSServerFactory.cs

@@ -1,39 +0,0 @@
-using EVCB_OCPP.WSServer.Service;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using OCPPServer.Protocol;
-using SuperWebSocket.SubProtocol;
-using System;
-using System.Collections.Generic;
-
-namespace EVCB_OCPP.WSServer.SuperSocket;
-
-public interface IOCPPWSServerFactory
-{
-    OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols);
-}
-
-public class OCPPWSServerFactory : IOCPPWSServerFactory
-{
-
-    public OCPPWSServerFactory(
-        IConfiguration configuration,
-        IMainDbService mainDbService,
-        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;
-}