|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using System; |
|
|
|
|
using System.Configuration; |
|
|
|
|
using System.Data; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Net.Http; |
|
|
|
@ -27,7 +28,7 @@ namespace SparkClient.Model.Services |
|
|
|
|
/// <summary> |
|
|
|
|
/// 基础URL,用于构建完整的API请求地址。 |
|
|
|
|
/// </summary> |
|
|
|
|
private readonly string _baseUrl; |
|
|
|
|
private readonly string? _baseUrl; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 认证令牌,用于HTTP请求的认证。 |
|
|
|
@ -40,7 +41,7 @@ namespace SparkClient.Model.Services |
|
|
|
|
public SOCClientService() |
|
|
|
|
{ |
|
|
|
|
//_baseUrl = "http://192.168.3.100:8080"; |
|
|
|
|
_baseUrl = "http://localhost:5000/api/SoC"; |
|
|
|
|
_baseUrl = ConfigurationManager.AppSettings["BaseUrl"]; |
|
|
|
|
_authToken = "your_basic_auth_token"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -127,7 +128,7 @@ namespace SparkClient.Model.Services |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="savePath">保存图片路径</param> |
|
|
|
|
/// <returns>图片的字节数组</returns> |
|
|
|
|
public async Task<List<string>> RetrieveImageAsync(string savePath) |
|
|
|
|
public async Task<List<string>> RetrieveImageAsync(string? savePath) |
|
|
|
|
{ |
|
|
|
|
List<string> imageNames = new List<string>(); |
|
|
|
|
// 读取图片接口 |
|
|
|
@ -170,7 +171,6 @@ namespace SparkClient.Model.Services |
|
|
|
|
return imageNames; |
|
|
|
|
default: |
|
|
|
|
// 其他状态码,记录警告并继续 |
|
|
|
|
Console.WriteLine($"Unexpected status code: {status} for URL: {url}"); |
|
|
|
|
Logger.Warn($"Unexpected status code: {status} for URL: {url}"); |
|
|
|
|
imageIndex++; |
|
|
|
|
break; |
|
|
|
@ -179,7 +179,6 @@ namespace SparkClient.Model.Services |
|
|
|
|
catch (HttpRequestException ex) |
|
|
|
|
{ |
|
|
|
|
// 捕获HTTP请求异常并记录错误信息 |
|
|
|
|
Console.WriteLine($"HTTP request failed for URL: {url}, Exception: {ex.Message}"); |
|
|
|
|
Logger.Error($"HTTP request failed for URL: {url}, Exception: {ex.Message}"); |
|
|
|
|
imageNames.Clear(); |
|
|
|
|
return imageNames; |
|
|
|
@ -187,7 +186,6 @@ namespace SparkClient.Model.Services |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
// 捕获其他异常并记录错误信息,结束循环 |
|
|
|
|
Console.WriteLine($"An unexpected error occurred for URL: {url}, Exception: {ex.Message}"); |
|
|
|
|
Logger.Error($"An unexpected error occurred for URL: {url}, Exception: {ex.Message}"); |
|
|
|
|
imageNames.Clear(); |
|
|
|
|
return imageNames; |
|
|
|
@ -239,7 +237,7 @@ namespace SparkClient.Model.Services |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
// SOC接口 |
|
|
|
|
string savePath = @"d:\diamond_images"; |
|
|
|
|
string? savePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; |
|
|
|
|
// 清理 savePath 文件夹 |
|
|
|
|
if (Directory.Exists(savePath)) |
|
|
|
|
{ |
|
|
|
|