Browse Source

1.Update MachineError schema from Domain Dll commitId:e90c45d5
2. Fixed the content received from the charger in connectionlog
3. Response with an invalid IdToken if transactionId=0 is received.
4.Added the stop time of error status to the record.
5. updated non-safety packages

Jessica Tseng 10 months ago
parent
commit
26917898e8

BIN
EVCB_OCPP.WSServer/DLL/EVCB_OCPP.Domain.dll


+ 2 - 1
EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj

@@ -40,7 +40,7 @@
     </BootstrapperPackage>
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Azure.Identity" Version="1.10.4" />
+    <PackageReference Include="Azure.Identity" Version="1.11.2" />
     <PackageReference Include="Dapper" Version="2.0.143" />
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.12" />
@@ -57,6 +57,7 @@
     <PackageReference Include="Polly" Version="7.2.4" />
     <PackageReference Include="Quartz.Extensions.Hosting" Version="3.7.0" />
     <PackageReference Include="RestSharp" Version="110.2.0" />
+    <PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
     <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
     <PackageReference Include="System.Security.Cryptography.Pkcs" Version="6.0.3" />
     <PackageReference Include="System.ServiceModel.Federation" Version="6.0.0" />

+ 21 - 5
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -21,6 +21,7 @@ using System.Globalization;
 using EVCB_OCPP.WSServer.Service.WsService;
 using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.Domain.ConnectionFactory;
+using Microsoft.AspNetCore.Mvc.Diagnostics;
 
 namespace EVCB_OCPP.WSServer.Message;
 
@@ -300,6 +301,21 @@ internal partial class ProfileHandler
 								VendorId = string.IsNullOrEmpty(_request.vendorId) ? string.Empty : _request.vendorId,
 								VendorErrorCode = string.IsNullOrEmpty(_request.vendorErrorCode) ? string.Empty : _request.vendorErrorCode
 							});
+
+							if (preStatus == (int)ChargePointStatus.Faulted)
+							{
+								if (_request.status != ChargePointStatus.Faulted ||
+									(_oldStatus.ChargePointErrorCodeId != (int)_request.errorCode && _oldStatus.VendorErrorCode != _request.vendorErrorCode))
+								{									
+									await mainDbService.FillupFinishedTimetoMachineError(
+										ConnectorId: (byte)_request.connectorId,
+										FinishedOn: _request.timestamp.HasValue ? _request.timestamp.Value : DateTime.UtcNow,									
+										ChargeBoxId: session.ChargeBoxId,
+										PreviousErrorOn: _oldStatus.CreatedOn
+										);
+								}
+
+							}
 						}
 
 						s2 = statusNotificationTimer.ElapsedMilliseconds;
@@ -354,7 +370,7 @@ internal partial class ProfileHandler
 						result.Message = confirm;
 						result.Success = true;
 
-						statusNotificationTimer.Stop();
+						statusNotificationTimer.Stop();						
 						if (statusNotificationTimer.ElapsedMilliseconds / 1000 > 1)
 						{
 							logger.LogCritical(string.Format("StatusNotification took {0}/{1}/{2}/{3}/{4}", s1, s2, s3, s4, s5));
@@ -421,9 +437,9 @@ internal partial class ProfileHandler
 							{
 								foreach (var sampleVaule in item.sampledValue)
 								{
-                                    if (sampleVaule.format == ValueFormat.SignedData) continue;
+									if (sampleVaule.format == ValueFormat.SignedData) continue;
 
-                                    decimal value = Convert.ToDecimal(sampleVaule.value);
+									decimal value = Convert.ToDecimal(sampleVaule.value);
 									datas.Add(new InsertMeterValueParam(
 										chargeBoxId: session.ChargeBoxId
 										, connectorId: (byte)_request.connectorId
@@ -633,8 +649,8 @@ internal partial class ProfileHandler
 					{
 						StopTransactionRequest _request = request as StopTransactionRequest;
 
-						//遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
-						if (_request.timestamp < new DateTime(2021, 11, 1))
+						//遠傳太久以前的停止充電 或 電樁上傳TransactionId=0 直接拒絕 避免電樁持續重送~~~~~~~
+						if (_request.timestamp < new DateTime(2021, 11, 1) || _request.transactionId == 0)
 						{
 							var confirm = new StopTransactionConfirmation()
 							{

+ 26 - 3
EVCB_OCPP.WSServer/Service/MainDbService.cs

@@ -3,6 +3,7 @@ using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.ConnectionFactory;
 using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.WSServer.Helper;
+using Microsoft.AspNetCore.Http.HttpResults;
 using Microsoft.Data.SqlClient;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Caching.Memory;
@@ -31,7 +32,9 @@ public interface IMainDbService
     Task AddServerMessage(ServerMessage message);
     Task AddServerMessage(string ChargeBoxId, string OutAction, object OutRequest, string CreatedBy = "", DateTime? CreatedOn = null, string SerialNo = "", string InMessage = "");
     ValueTask AddMachineError(byte ConnectorId, DateTime CreatedOn, int Status, string ChargeBoxId, int ErrorCodeId, string ErrorInfo, int PreStatus, string VendorErrorCode, string VendorId);
-    ValueTask<Customer> GetCustomer(string id, CancellationToken token = default);
+	ValueTask FillupFinishedTimetoMachineError(byte ConnectorId, DateTime FinishedOn, string ChargeBoxId, DateTime PreviousErrorOn);
+
+	ValueTask<Customer> GetCustomer(string id, CancellationToken token = default);
     ValueTask<Customer> GetCustomer(Guid id, CancellationToken token = default);
     Task<Guid> GetCustomerIdByChargeBoxId(string chargeboxId);
     Task<int?> TryGetDuplicatedTransactionId(string chargeBoxId, Guid customerId, int connectorId, DateTime timestamp);
@@ -213,7 +216,12 @@ public class MainDbService : IMainDbService
         return AddMachineErrorDapper(ConnectorId, CreatedOn, Status, ChargeBoxId, ErrorCodeId, ErrorInfo, PreStatus, VendorErrorCode, VendorId);
     }
 
-    public Task AddServerMessage(string ChargeBoxId, string OutAction, object OutRequest, string CreatedBy, DateTime? CreatedOn = null, string SerialNo = "", string InMessage = "")
+	public ValueTask FillupFinishedTimetoMachineError(byte ConnectorId, DateTime FinishedOn, string ChargeBoxId, DateTime PreviousErrorOn)
+	{
+		
+		return AddFinishedTimetoMachineErrorDapper(ConnectorId, FinishedOn, ChargeBoxId, PreviousErrorOn);
+	}
+	public Task AddServerMessage(string ChargeBoxId, string OutAction, object OutRequest, string CreatedBy, DateTime? CreatedOn = null, string SerialNo = "", string InMessage = "")
     {
         if (string.IsNullOrEmpty(CreatedBy))
         {
@@ -621,7 +629,22 @@ public class MainDbService : IMainDbService
             """, parameters);
     }
 
-    private async Task BundleUpdateConnectorStatus(IEnumerable<StatusNotificationParam> statusNotifications)
+	private async ValueTask AddFinishedTimetoMachineErrorDapper(byte connectorId, DateTime finishedTime, string chargeBoxId, DateTime previousErrorOn)
+	{
+		var parameters = new DynamicParameters();
+		parameters.Add("@FinishedOn", finishedTime, DbType.DateTime, ParameterDirection.Input,50);
+		parameters.Add("@ConnectorId", connectorId, DbType.Int16, ParameterDirection.Input);	
+		parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
+		parameters.Add("@CreatedOn", previousErrorOn, DbType.DateTime, ParameterDirection.Input, 50);
+
+		using var conn = await sqlConnectionFactory.CreateAsync();
+		await conn.ExecuteAsync("""
+            Update MachineError set FinishedOn=@FinishedOn where
+            ChargeBoxId=@ChargeBoxId and ConnectorId=@ConnectorId and CreatedOn=@CreatedOn
+            """, parameters);
+	}
+
+	private async Task BundleUpdateConnectorStatus(IEnumerable<StatusNotificationParam> statusNotifications)
     {
         using var db = await contextFactory.CreateDbContextAsync();
         using var trans = await db.Database.BeginTransactionAsync();

+ 1 - 1
EVCB_OCPP.WSServer/Service/WsService/WsClientData.cs

@@ -129,7 +129,7 @@ public class WsClientData : WsSession
 
         if (startIndex is not null && stopIndex is not null)
         {
-            msg = buffer.Substring(startIndex.Value, stopIndex.Value - startIndex.Value);
+            msg = buffer.Substring(startIndex.Value, (stopIndex.Value - startIndex.Value)+1);
             buffer = buffer.Substring(stopIndex.Value + 1);
             return true;
         }

+ 4 - 4
EVCB_OCPP.WSServer/appsettings.json

@@ -132,9 +132,9 @@
     }
   },
   "ConnectionStrings": {
-    "ConnectionLogDBContext": "data source=zerova-ev-dev.database.windows.net;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=azdevsoftware;password=1h52dev#az;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=200;Connection Lifetime=0;Pooling=true;",
-    "MainDBContext": "data source=zerova-ev-dev.database.windows.net;initial catalog=StandardOCPP_Main;;persist security info=True;user id=azdevsoftware;password=1h52dev#az;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=1024;Connection Lifetime=0;Pooling=true;Min Pool Size=150;",
-    "MeterValueDBContext": "data source=zerova-ev-dev.database.windows.net;initial catalog=StandardOCPP_MeterValue;;persist security info=True;user id=azdevsoftware;password=1h52dev#az;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=200;Connection Lifetime=0;Pooling=true;",
-    "WebDBContext": "data source=zerova-ev-dev.database.windows.net;initial catalog=StandardOCPP_Web;;persist security info=True;user id=azdevsoftware;password=1h52dev#az;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=200;Connection Lifetime=0;Pooling=true;"
+    "ConnectionLogDBContext": "Server=tcp:zerova-evbackend.database.windows.net,1433;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=ev_user;password=Thw2DEa2hZPdg;MultipleActiveResultSets=False;App=EntityFramework;TrustServerCertificate=false;Max Pool Size=500;Min Pool Size=50;Pooling=true;",
+    "MainDBContext": "Server=tcp:zerova-evbackend.database.windows.net,1433;Initial Catalog=StandardOCPP_Main;Persist Security Info=False;User ID=ev_user;Password=Thw2DEa2hZPdg;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=false;ConnectRetryCount=10;ConnectRetryInterval=1;Max Pool Size=4096;Min Pool Size=50;",
+    "MeterValueDBContext": "data source=tcp:zerova-evbackend.database.windows.net,1433;initial catalog=StandardOCPP_MeterValue;;persist security info=True;User ID=ev_user;Password=Thw2DEa2hZPdg;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=200;Connection Lifetime=0;Pooling=true;",
+    "WebDBContext": "data source=tcp:zerova-evbackend.database.windows.net,1433;initial catalog=StandardOCPP_Web;;persist security info=True;User ID=ev_user;Password=Thw2DEa2hZPdg;MultipleActiveResultSets=True;App=EntityFramework;TrustServerCertificate=true;Max Pool Size=200;Connection Lifetime=0;Pooling=true;"
   }
 }

+ 1 - 1
version.txt

@@ -1 +1 @@
-Docker_v1.1.22
+Docker_v1.1.23