Robert 1 سال پیش
والد
کامیت
d1ed77a08d

+ 10 - 22
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1013,18 +1013,14 @@ namespace EVCB_OCPP.WSServer
             }
             string requestId = string.Empty;
             MessageResult response = null;
+            Func<Task<string>> sendTask = null;
 
             var displayPriceText = await webDbService.SetDefaultFee(session);
             UpdateClientDisplayPrice(session.ChargeBoxId, displayPriceText);
 
-            do
-            {
-                requestId = await messageService.SendChangeConfigurationRequest(
-                    session.ChargeBoxId, key: "DefaultPrice", value: displayPriceText);
-                response = await confirmWaitingMessageSerevice.WaitResultAsync(requestId);
-            }
-            while (response == null);
-            //await SetDefaultFee(session);
+            sendTask = async () => await messageService.SendChangeConfigurationRequest(
+                session.ChargeBoxId, key: "DefaultPrice", value: displayPriceText);
+            await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
 
             if (session.CustomerId == new Guid("298918C0-6BB5-421A-88CC-4922F918E85E") || session.CustomerId == new Guid("9E6BFDCC-09FB-4DAB-A428-43FE507600A3"))
             {
@@ -1038,23 +1034,19 @@ namespace EVCB_OCPP.WSServer
                     session.ChargeBoxId, key: "StopTransactionOnInvalidId", value: "True");
             }
 
-            do
-            {
-                requestId = await messageService.SendGetEVSEConfigureRequest(session.ChargeBoxId);
-                response = await confirmWaitingMessageSerevice.WaitResultAsync(requestId);
-            }
-            while (response == null);
-            //GetConfigurationConfirmation
+            sendTask = async () => await messageService.SendGetEVSEConfigureRequest(session.ChargeBoxId);
+            response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
             if (response.Success && response.Message is GetConfigurationConfirmation confirmation)
             {
                 await CheckandUpdateConfig(session.ChargeBoxId, confirmation.configurationKey.ToDictionary(x => x.key, x => x.value));
             }
 
-            await messageService.SendDataTransferRequest(
+            sendTask = async () => await messageService.SendDataTransferRequest(
                 session.ChargeBoxId,
                 messageId: "ID_FirmwareVersion",
                 vendorId: "Phihong Technology",
                 data: string.Empty);
+            await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
 
             if (session.BootStatus == BootStatus.Initializing)
             {
@@ -1080,12 +1072,8 @@ namespace EVCB_OCPP.WSServer
                 }
 
                 MessageResult response = null;
-                do
-                {
-                    var requestId = await messageService.SendChangeConfigurationRequest(chargeBoxId, config.Key, config.Value);
-                    response = await confirmWaitingMessageSerevice.WaitResultAsync(requestId);
-                }
-                while (response == null);
+                var sendTask = async () => await messageService.SendChangeConfigurationRequest(chargeBoxId, config.Key, config.Value);
+                response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask);
             }
         }
 

+ 15 - 1
EVCB_OCPP.WSServer/Service/ConfirmWaitingMessageSerevice.cs

@@ -1,4 +1,6 @@
-using EVCB_OCPP.Domain;
+using Azure.Core;
+using Azure;
+using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.Models.MainDb;
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.WSServer.Message;
@@ -188,6 +190,18 @@ namespace EVCB_OCPP.WSServer.Service
             }
         }
 
+        internal async Task<MessageResult> SendAndWaitUntilResultAsync(Func<Task<string>> sendTask)
+        {
+            MessageResult response;
+            do
+            {
+                var requestId = await sendTask();
+                response = await WaitResultAsync(requestId);
+            }
+            while (response == null);
+            return response;
+        }
+
         internal async Task<MessageResult> WaitResultAsync(string msgId, int maxWaitSec = 65000)
         {
             var waiObj = new MessageResultWaitObject();

+ 3 - 1
EVCB_OCPP.WSServer/Service/ServerMessageService.cs

@@ -4,6 +4,8 @@ using Microsoft.Extensions.Logging;
 using static System.Runtime.InteropServices.JavaScript.JSType;
 using System.ServiceModel.Channels;
 using EVCB_OCPP.WSServer.Service.DbService;
+using Azure;
+using EVCB_OCPP.WSServer.Message;
 
 namespace EVCB_OCPP.WSServer.Service;
 
@@ -42,7 +44,7 @@ public class ServerMessageService
             });
     }
 
-    internal Task SendDataTransferRequest(string chargeBoxId, string messageId, string vendorId, string data)
+    internal Task<string> SendDataTransferRequest(string chargeBoxId, string messageId, string vendorId, string data)
     {
         return mainDbService.AddServerMessage(
             ChargeBoxId: chargeBoxId,