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. 134
      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,82 +295,98 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
private async Task<int> ReslutGen(Task<DiaResult> detectTask) private async Task<int> ReslutGen(Task<DiaResult> detectTask)
{ {
bool hasErr = false;
CompleteProgressQuicklyAsync(); try
if (detectTask.Result != null)
{ {
switch (detectTask.Result.Status) CompleteProgressQuicklyAsync();
if (detectTask.Result != null)
{ {
case StatusCodes.AlgorithmFailed: switch (detectTask.Result.Status)
new MessageBox().Show(MultilingualHelper.getString("AlgorithmFailed")); {
return -1; case StatusCodes.AlgorithmFailed:
case StatusCodes.ImageFileReadFailure: new MessageBox().Show(MultilingualHelper.getString("AlgorithmFailed"));
new MessageBox().Show(MultilingualHelper.getString("ImageFileReadFailure")); hasErr = true;
return -1; return -1;
case StatusCodes.JsonParseFailure: case StatusCodes.ImageFileReadFailure:
new MessageBox().Show(MultilingualHelper.getString("ImageFileReadFailure"));
hasErr = true;
return -1;
case StatusCodes.JsonParseFailure:
new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure"));
hasErr = true;
return -1;
case StatusCodes.NoDiamond:
new MessageBox().Show(MultilingualHelper.getString("NoDiamond"));
hasErr = true;
return -1;
}
Progress = (100.00);
string strParam = JsonConvert.SerializeObject(detectTask.Result);
//Logger.Info("序列化字符串:" + strParam);
AlgorithmResultEntity parameter = JsonConvert.DeserializeObject<AlgorithmResultEntity>(strParam);
if (parameter == null && _isCancel == false)
{
new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure")); new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure"));
hasErr = true;
return -1; return -1;
case StatusCodes.NoDiamond: }
new MessageBox().Show(MultilingualHelper.getString("NoDiamond"));
return -1;
}
Progress = (100.00); parameter.DiamondCode = _diamondCode;
parameter.Standard = getStandardName();
parameter.Shape = _diamnondType.Split(" ")[0];
parameter.CrownType = _diamnondType.Split(" ")[1];
parameter.PavType = _diamnondType.Split(" ")[2];
string strParam = JsonConvert.SerializeObject(detectTask.Result); try
//Logger.Info("序列化字符串:" + strParam); {
AlgorithmResultEntity parameter = JsonConvert.DeserializeObject<AlgorithmResultEntity>(strParam); string parameterJson = JsonConvert.SerializeObject(parameter);
if (parameter == null && _isCancel == false) parameterJson = JToken.Parse(parameterJson).ToString();
{ string outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "result");
new MessageBox().Show(MultilingualHelper.getString("JsonParseFailure")); if (!Directory.Exists(outputPath))
return -1; Directory.CreateDirectory(outputPath);
} string outputFilePath = $"{outputPath}/{_diamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json";
using (var file = File.Create(outputFilePath))
using (StreamWriter stream = new StreamWriter(file))
{
stream.Write(parameterJson);
}
}
catch (Exception ex)
{
Logger.Error("output输出失败:" + ex.Message);
}
Parameter = parameter;
if (_isCancel == true)
{
SOCClientService.Service.OpenPump(false);
return -100;
}
parameter.DiamondCode = _diamondCode; ;
parameter.Standard = getStandardName();
parameter.Shape = _diamnondType.Split(" ")[0];
parameter.CrownType = _diamnondType.Split(" ")[1];
parameter.PavType = _diamnondType.Split(" ")[2];
try if (parameter.status == StatusCodes.Recheck)
{
string parameterJson = JsonConvert.SerializeObject(parameter);
parameterJson = JToken.Parse(parameterJson).ToString();
string outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "result");
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
string outputFilePath = $"{outputPath}/{_diamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json";
using (var file = File.Create(outputFilePath))
using (StreamWriter stream = new StreamWriter(file))
{ {
stream.Write(parameterJson); new MessageBox().Show(MultilingualHelper.getString("Recheck"));
} }
}
catch (Exception ex)
{
Logger.Error("output输出失败:" + ex.Message);
}
Parameter = parameter; return 0;
if (_isCancel == true)
{
SOCClientService.Service.OpenPump(false);
return -100;
} }
;
if (parameter.status == StatusCodes.Recheck) return -10;
}
finally
{
string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation");
if (hasErr || "0".Equals(strSafeSpace))
{ {
new MessageBox().Show(MultilingualHelper.getString("Recheck")); DiamondSelectVM.HandleAlgorithmFailure(ImagePaths, _diamondCode);
} }
return 0;
} }
return -10;
} }
private async Task CompleteProgressSlowlyAsync() private async Task CompleteProgressSlowlyAsync()

Loading…
Cancel
Save