fix: 20250313 add history images config

master
Tongg 4 months ago
parent 94249bf5f3
commit 8ead72772d
  1. 2
      App.config
  2. 14
      ViewModel/Grading/DiamondSelectVM.cs
  3. 18
      ViewModel/Grading/GradingLoadingVM.cs

@ -8,6 +8,8 @@
<add key="ImageFileBasePath" value="D:\diamond_images"/> <add key="ImageFileBasePath" value="D:\diamond_images"/>
<!-- 算法失败时,历史图片保存文件夹路径 --> <!-- 算法失败时,历史图片保存文件夹路径 -->
<add key="ImageHistoryPath" value="D:\ImageHistory"/> <add key="ImageHistoryPath" value="D:\ImageHistory"/>
<!-- 安全空间保留 GB -->
<add key="SafeSpaceReservation" value="10"/>
<!-- 打印机名称 --> <!-- 打印机名称 -->
<add key="PrintName" value="Deli DL-720C"/> <add key="PrintName" value="Deli DL-720C"/>
<!-- 检测结果默认DS --> <!-- 检测结果默认DS -->

@ -536,7 +536,7 @@ public class DiamondSelectVM : BaseViewModel
/// ///
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer)); private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
[Log] [Log]
private void HandleAlgorithmFailure(string image_files, string dCode = "") public static void HandleAlgorithmFailure(string[] image_files, string dCode = "")
{ {
// 从配置文件中读取 imageHistoryPath // 从配置文件中读取 imageHistoryPath
@ -554,8 +554,11 @@ public class DiamondSelectVM : BaseViewModel
string newFolderPath = Path.Combine(imageHistoryPath, string.IsNullOrWhiteSpace(dCode) ? $"image-{timestamp}" : $"image-{dCode}-{timestamp}" ); string newFolderPath = Path.Combine(imageHistoryPath, string.IsNullOrWhiteSpace(dCode) ? $"image-{timestamp}" : $"image-{dCode}-{timestamp}" );
// 检查 D 盘内存空间 // 检查 D 盘内存空间
DriveInfo dDrive = new DriveInfo("D"); string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation");
long requiredSpace = 10L * 1024 * 1024 * 1024; // 10GB long safeSpace = 10L;
long.TryParse(strSafeSpace, out safeSpace);
DriveInfo dDrive = new DriveInfo(imageHistoryPath.Substring(0,1));
long requiredSpace = safeSpace * 1024 * 1024 * 1024;
if (dDrive.TotalFreeSpace < requiredSpace) if (dDrive.TotalFreeSpace < requiredSpace)
{ {
// 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹 // 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹
@ -582,8 +585,9 @@ public class DiamondSelectVM : BaseViewModel
try try
{ {
// 解析 image_files JSON 数组 // 解析 image_files JSON 数组
JArray imageFilesArray = JArray.Parse(image_files); // JArray imageFilesArray = JArray.Parse(image_files);
string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray(); // string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray();
string[] imageFiles = image_files;
string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录 string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录
if (string.IsNullOrEmpty(imageBasePath)) if (string.IsNullOrEmpty(imageBasePath))

@ -295,7 +295,9 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
private async Task<int> ReslutGen(Task<DiaResult> detectTask) private async Task<int> ReslutGen(Task<DiaResult> detectTask)
{ {
bool hasErr = false;
try
{
CompleteProgressQuicklyAsync(); CompleteProgressQuicklyAsync();
if (detectTask.Result != null) if (detectTask.Result != null)
@ -304,15 +306,19 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
{ {
case StatusCodes.AlgorithmFailed: case StatusCodes.AlgorithmFailed:
new MessageBox().Show(MultilingualHelper.getString("AlgorithmFailed")); new MessageBox().Show(MultilingualHelper.getString("AlgorithmFailed"));
hasErr = true;
return -1; return -1;
case StatusCodes.ImageFileReadFailure: case StatusCodes.ImageFileReadFailure:
new MessageBox().Show(MultilingualHelper.getString("ImageFileReadFailure")); new MessageBox().Show(MultilingualHelper.getString("ImageFileReadFailure"));
hasErr = true;
return -1; return -1;
case StatusCodes.JsonParseFailure: case StatusCodes.JsonParseFailure:
new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure")); new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure"));
hasErr = true;
return -1; return -1;
case StatusCodes.NoDiamond: case StatusCodes.NoDiamond:
new MessageBox().Show(MultilingualHelper.getString("NoDiamond")); new MessageBox().Show(MultilingualHelper.getString("NoDiamond"));
hasErr = true;
return -1; return -1;
} }
@ -324,6 +330,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
if (parameter == null && _isCancel == false) if (parameter == null && _isCancel == false)
{ {
new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure")); new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure"));
hasErr = true;
return -1; return -1;
} }
@ -372,6 +379,15 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
return -10; return -10;
} }
finally
{
string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation");
if (hasErr || "0".Equals(strSafeSpace))
{
DiamondSelectVM.HandleAlgorithmFailure(ImagePaths, _diamondCode);
}
}
}
private async Task CompleteProgressSlowlyAsync() private async Task CompleteProgressSlowlyAsync()
{ {

Loading…
Cancel
Save