From 1a199f8d856877d364af4cfa697d407de430c589 Mon Sep 17 00:00:00 2001 From: Tongg Date: Fri, 7 Mar 2025 17:55:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=B7=E6=B1=82=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Services/SOCClientService.cs | 23 +++++++++++++++++++---- ViewModel/Grading/GradingLoadingVM.cs | 22 ++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Model/Services/SOCClientService.cs b/Model/Services/SOCClientService.cs index fa87ed4..f9e6142 100644 --- a/Model/Services/SOCClientService.cs +++ b/Model/Services/SOCClientService.cs @@ -74,15 +74,30 @@ namespace SparkClient.Model.Services // 提前读取内容并存储 string responseBody = await result.Content.ReadAsStringAsync(); int statusCode = (int)result.StatusCode; - // 记录日志 Logger.Info($"Response: Status={statusCode}, Body={responseBody}"); - + var tempEntity = JsonConvert.DeserializeObject(responseBody); + if ("S007".Equals(tempEntity.Status)) + { + Logger.Info($"S007 请求重试"); + await Task.Delay(50); + return await SendGetRequestAsync(url); + } result.Content = new StringContent(responseBody); - return result; } } + private async Task SendGetRequestImageAsync(string url) + { + using (var client = new HttpClient()) + { + Logger.Info($"Request sent to URL: {url}"); + client.DefaultRequestHeaders.Add("Authorization", "Basic " + _authToken); + + return await client.GetAsync(url); + + } + } /// /// 启动图片收集任务。 @@ -172,7 +187,7 @@ namespace SparkClient.Model.Services string url = $"{_baseUrl}/retrieve_image/{imageIndex}"; try { - var response = await SendGetRequestAsync(url); + var response = await SendGetRequestImageAsync(url); int status = (int)response.StatusCode; switch (status) diff --git a/ViewModel/Grading/GradingLoadingVM.cs b/ViewModel/Grading/GradingLoadingVM.cs index a5933d8..0a844e4 100644 --- a/ViewModel/Grading/GradingLoadingVM.cs +++ b/ViewModel/Grading/GradingLoadingVM.cs @@ -24,7 +24,6 @@ namespace SparkClient.ViewModel.Grading; public class GradingLoadingVM : BaseViewModel,IDisposable { private double _progress; - private SOCClientService _socClientService; public AlgorithmResultEntity Parameter; /// /// 进度 @@ -134,12 +133,13 @@ public class GradingLoadingVM : BaseViewModel,IDisposable /// /// 开始检测 /// + //[Log] public async Task Start(int type = 0) { try { - + var progress = RunProgressAsync(_progressCts.Token); if (type == 11) @@ -168,15 +168,17 @@ public class GradingLoadingVM : BaseViewModel,IDisposable if(type == 0) { - string openpupmStatus = await SOCClientService.Service.OpenPump(true); - if (!StatusCodes.Success.Equals(openpupmStatus)) - { - new MessageBox().Show("气泵开启失败!"); - return -1; - } - - var processImage = _socClientService.ProcessImageCollectionAsync(); + + await SOCClientService.Service.OpenPump(true); + // if (!StatusCodes.Success.Equals(openpupmStatus)) + // { + // new MessageBox().Show("气泵开启失败!"); + // return -1; + // } + + var processImage = SOCClientService.Service.ProcessImageCollectionAsync(); //通知页面可以播放图片 + await processImage; if (!("ok".Equals(processImage.Result.Status) || "S000".Equals(processImage.Result.Status)))