|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using System.Data; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
using System.Windows.Forms; |
|
|
|
|
using log4net; |
|
|
|
@ -83,6 +84,72 @@ namespace SparkClient.Model.Services |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 算法调用失败时,保存图片到历史记录文件夹 |
|
|
|
|
if (result.status == "P002") |
|
|
|
|
{ |
|
|
|
|
// 定义历史记录文件夹路径 |
|
|
|
|
string imageHistoryPath = "D:\\ImageHistory"; |
|
|
|
|
// 生成时间戳,格式为 yyyyMMddHHmmss |
|
|
|
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); |
|
|
|
|
// 组合新的文件夹路径 |
|
|
|
|
string newFolderPath = Path.Combine(imageHistoryPath, $"image-{timestamp}"); |
|
|
|
|
|
|
|
|
|
// 检查 D 盘内存空间 |
|
|
|
|
DriveInfo dDrive = new DriveInfo("D"); |
|
|
|
|
long requiredSpace = 10L * 1024 * 1024 * 1024; // 10GB |
|
|
|
|
if (dDrive.TotalFreeSpace < requiredSpace) |
|
|
|
|
{ |
|
|
|
|
// 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹 |
|
|
|
|
DirectoryInfo historyDir = new DirectoryInfo(imageHistoryPath);//获取历史记录文件夹的信息 |
|
|
|
|
DirectoryInfo[] subDirs = historyDir.GetDirectories();//获取历史记录文件夹中的所有子文件夹 |
|
|
|
|
if (subDirs.Length > 0) |
|
|
|
|
{ |
|
|
|
|
// 按创建时间排序子文件夹 |
|
|
|
|
var orderedSubDirs = subDirs.OrderBy(d => d.CreationTime).ToList(); |
|
|
|
|
int foldersToDelete = Math.Min(10, orderedSubDirs.Count); |
|
|
|
|
|
|
|
|
|
// 删除最早的 10 个文件夹,如果不够 10 个则全删掉 |
|
|
|
|
for (int i = 0; i < foldersToDelete; i++) |
|
|
|
|
{ |
|
|
|
|
orderedSubDirs[i].Delete(true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 创建新文件夹 |
|
|
|
|
Directory.CreateDirectory(newFolderPath); |
|
|
|
|
|
|
|
|
|
// 保存图片到新文件夹 |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
// 解析 image_files JSON 数组 |
|
|
|
|
JArray imageFilesArray = JArray.Parse(image_files); |
|
|
|
|
string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray(); |
|
|
|
|
|
|
|
|
|
string imageBasePath = "D:\\diamond_images"; // 图片根目录 |
|
|
|
|
|
|
|
|
|
foreach (string imageFile in imageFiles) |
|
|
|
|
{ |
|
|
|
|
// 获取文件名 |
|
|
|
|
string fileName = Path.GetFileName(imageFile); |
|
|
|
|
// 构建完整的源文件路径 |
|
|
|
|
string sourcePath = Path.Combine(imageBasePath, imageFile); |
|
|
|
|
// 组合目标路径 |
|
|
|
|
string destinationPath = Path.Combine(newFolderPath, fileName); |
|
|
|
|
// 复制文件到目标路径,如果目标文件已存在则覆盖 |
|
|
|
|
File.Copy(sourcePath, destinationPath, true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (JsonException ex) |
|
|
|
|
{ |
|
|
|
|
// 记录日志或处理异常 |
|
|
|
|
Console.WriteLine($"Error parsing image_files JSON: {ex.Message}"); |
|
|
|
|
Logger.Error($"Error parsing image_files JSON: {ex.Message}"); |
|
|
|
|
Logger.Error($"Stack Trace: {ex.StackTrace}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|