|
|
|
@ -145,204 +145,250 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
|
DiamondCode = ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var loadingView = new GradingLoadingVM(param.ToString(), DiamondCode); |
|
|
|
|
BaseControlVM vm = new BaseControlVM(loadingView, MultilingualHelper.getString("DetectionResult")); |
|
|
|
|
vm.WindowTitle = string.IsNullOrWhiteSpace(DiamondCode) ? vm.WindowTitle : $"{vm.WindowTitle} - {DiamondCode}"; |
|
|
|
|
WindowManager.mainViewModel.Content = vm; |
|
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
|
string runModel = ConfigurationHelper.ReadConfigValue("RunModel")??"1"; |
|
|
|
|
|
|
|
|
|
int res = await loadingView.Start(); |
|
|
|
|
|
|
|
|
|
if (res < 0) |
|
|
|
|
if("0".Equals(runModel)) |
|
|
|
|
//json模式 |
|
|
|
|
DoStartGrading(param); |
|
|
|
|
else if ("1".Equals(runModel)) |
|
|
|
|
{ |
|
|
|
|
//返回 |
|
|
|
|
loadingView.Dispose(); |
|
|
|
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
|
|
|
; |
|
|
|
|
return; |
|
|
|
|
//Image模式 |
|
|
|
|
var loadingView = new GradingLoadingVM(param.ToString(), DiamondCode); |
|
|
|
|
BaseControlVM vm = new BaseControlVM(loadingView, MultilingualHelper.getString("wait")); |
|
|
|
|
vm.WindowTitle = string.IsNullOrWhiteSpace(DiamondCode) ? vm.WindowTitle : $"{vm.WindowTitle} - {DiamondCode}"; |
|
|
|
|
WindowManager.mainViewModel.Content = vm; |
|
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
|
|
|
|
|
|
int res = await loadingView.Start(1); |
|
|
|
|
|
|
|
|
|
if (res > -100 && res < 0) |
|
|
|
|
{ |
|
|
|
|
//返回 |
|
|
|
|
loadingView.Dispose(); |
|
|
|
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
|
|
|
; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
else if ( res <= -100) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
GradingResult(loadingView.Parameter); |
|
|
|
|
loadingView.Dispose(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
//获取结果,下一步 |
|
|
|
|
} |
|
|
|
|
#if DEBUG |
|
|
|
|
//DoStartGrading(param); |
|
|
|
|
//#else |
|
|
|
|
LoadingDialog loading = new LoadingDialog(DiamondCode); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
if (param != null) |
|
|
|
|
{ |
|
|
|
|
string progTime = ConfigurationHelper.ReadConfigValue("ProgressTime"); |
|
|
|
|
|
|
|
|
|
int iProgTime = 50000; |
|
|
|
|
int.TryParse(progTime, out iProgTime); |
|
|
|
|
int setpTime = iProgTime / 97; |
|
|
|
|
|
|
|
|
|
var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => loading.ShowDialog())); |
|
|
|
|
await Task.Run(async () => |
|
|
|
|
{ |
|
|
|
|
bool isEnd = false; |
|
|
|
|
int progress = 0; |
|
|
|
|
// 更新进度条的值(需要在UI线程上执行) |
|
|
|
|
loading.Dispatcher.Invoke(async () => |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i <= 97; i++) |
|
|
|
|
{ |
|
|
|
|
if (isEnd) |
|
|
|
|
{ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// 模拟耗时操作 |
|
|
|
|
//System.Threading.Thread.Sleep(50); // 休眠50毫秒 |
|
|
|
|
await Task.Delay(setpTime); |
|
|
|
|
loading.setValue(i); |
|
|
|
|
progress = i; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
SocResultEntity socResolt = new SocResultEntity(); |
|
|
|
|
AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
|
|
string value = param.ToString() ?? ""; |
|
|
|
|
if (value != null && value.Split(" ").Length == 3) |
|
|
|
|
{ |
|
|
|
|
parameter.Shape = value.Split(" ")[0]; |
|
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
|
} |
|
|
|
|
// 初始化SOC客户端服务,传入SOC端的地址和认证Token |
|
|
|
|
_socClientService = new SOCClientService(); |
|
|
|
|
// 启动soc |
|
|
|
|
socResolt = await _socClientService.ProcessImageCollectionAsync(); |
|
|
|
|
switch (socResolt.Status) |
|
|
|
|
{ |
|
|
|
|
case StatusCodes.OpenOfTheHatch: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("OpenOfTheHatch"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.DeviceNotFound: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("DeviceNotFound"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.InProgress: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("InProgress"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.CacheCleared: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CacheCleared"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.CannotSendCommand: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CannotSendCommand"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.MicrocontrollerTimeout: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("MicrocontrollerTimeout"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.MicrocontrollerError: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("MicrocontrollerError"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.CameraNotConnected: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CameraNotConnected"), loading); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
_algorithmServer = new AlgorithmServer(); |
|
|
|
|
// //图片集合 |
|
|
|
|
string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented); |
|
|
|
|
// string image_files =$"[ \"image_0.bmp\", \"image_1.bmp\", \"image_2.bmp\", \"image_3.bmp\", \"image_4.bmp\", \"image_5.bmp\", \"image_6.bmp\", \"image_7.bmp\", \"image_8.bmp\", \"image_9.bmp\", \"image_10.bmp\", \"image_11.bmp\", \"image_12.bmp\", \"image_13.bmp\", \"image_14.bmp\", \"image_15.bmp\", \"image_16.bmp\", \"image_17.bmp\", \"image_18.bmp\", \"image_19.bmp\", \"image_20.bmp\", \"image_21.bmp\", \"image_22.bmp\", \"image_23.bmp\", \"image_24.bmp\", \"image_25.bmp\", \"image_26.bmp\", \"image_27.bmp\", \"image_28.bmp\", \"image_29.bmp\", \"image_30.bmp\", \"image_31.bmp\", \"image_32.bmp\", \"image_33.bmp\", \"image_34.bmp\", \"image_35.bmp\", \"image_36.bmp\", \"image_37.bmp\", \"image_38.bmp\", \"image_39.bmp\", \"image_40.bmp\", \"image_41.bmp\", \"image_42.bmp\", \"image_43.bmp\", \"image_44.bmp\", \"image_45.bmp\", \"image_46.bmp\", \"image_47.bmp\", \"image_48.bmp\", \"image_49.bmp\", \"image_50.bmp\", \"image_51.bmp\", \"image_52.bmp\", \"image_53.bmp\", \"image_54.bmp\", \"image_55.bmp\", \"image_56.bmp\", \"image_57.bmp\", \"image_58.bmp\", \"image_59.bmp\", \"image_60.bmp\", \"image_61.bmp\", \"image_62.bmp\", \"image_63.bmp\", \"image_64.bmp\", \"image_65.bmp\", \"image_66.bmp\", \"image_67.bmp\", \"image_68.bmp\", \"image_69.bmp\", \"image_70.bmp\", \"image_71.bmp\", \"image_72.bmp\", \"image_73.bmp\", \"image_74.bmp\", \"image_75.bmp\", \"image_76.bmp\", \"image_77.bmp\", \"image_78.bmp\", \"image_79.bmp\", \"image_80.bmp\", \"image_81.bmp\", \"image_82.bmp\", \"image_83.bmp\", \"image_84.bmp\", \"image_85.bmp\", \"image_86.bmp\", \"image_87.bmp\", \"image_88.bmp\", \"image_89.bmp\", \"image_90.bmp\", \"image_91.bmp\", \"image_92.bmp\", \"image_93.bmp\", \"image_94.bmp\", \"image_95.bmp\", \"image_96.bmp\", \"image_97.bmp\", \"image_98.bmp\", \"image_99.bmp\"]" ; |
|
|
|
|
|
|
|
|
|
// 保存图片到历史记录文件夹 |
|
|
|
|
HandleAlgorithmFailure(image_files, DiamondCode); |
|
|
|
|
//正常模式 |
|
|
|
|
var loadingView = new GradingLoadingVM(param.ToString(), DiamondCode); |
|
|
|
|
BaseControlVM vm = new BaseControlVM(loadingView, MultilingualHelper.getString("wait")); |
|
|
|
|
vm.WindowTitle = string.IsNullOrWhiteSpace(DiamondCode) ? vm.WindowTitle : $"{vm.WindowTitle} - {DiamondCode}"; |
|
|
|
|
WindowManager.mainViewModel.Content = vm; |
|
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
|
|
|
|
|
|
int res = await loadingView.Start(); |
|
|
|
|
|
|
|
|
|
// 启动算法 |
|
|
|
|
parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files); |
|
|
|
|
//机器号 |
|
|
|
|
parameter.DeviceId = socResolt.DeviceId; |
|
|
|
|
switch (parameter.status) |
|
|
|
|
{ |
|
|
|
|
case StatusCodes.AlgorithmFailed: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("AlgorithmFailed"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.ImageFileReadFailure: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("ImageFileReadFailure"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.JsonParseFailure: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("JsonParseFailure"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.NoDiamond: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("NoDiamond"), loading); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
parameter.Standard = getStandardName(); |
|
|
|
|
parameter.Shape = value.Split(" ")[0]; |
|
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
|
parameter.DiamondCode = DiamondCode; |
|
|
|
|
if (res > -100 && res < 0) |
|
|
|
|
{ |
|
|
|
|
//返回 |
|
|
|
|
loadingView.Dispose(); |
|
|
|
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
|
|
|
; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
else if ( res <= -100) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
GradingResult(loadingView.Parameter); |
|
|
|
|
loadingView.Dispose(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!parameter.status.Equals(StatusCodes.Ok)) |
|
|
|
|
parameter.error_msg = MultilingualHelper.getString(StatusCodes.GetConstantNameByValue(parameter.status)); |
|
|
|
|
//参数实体转json输出 |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Logger.Error("output输出失败:"+ex.Message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isEnd = true; |
|
|
|
|
//GradingResult(parameter); |
|
|
|
|
await loading.Dispatcher.Invoke(async () => |
|
|
|
|
{ |
|
|
|
|
for (int i = progress; progress <= 100; i++) |
|
|
|
|
{ |
|
|
|
|
Random random = new Random(); int minValue = 20; int maxValue = 100; // 生成50到150之间的随机整数 |
|
|
|
|
int randomNumber = random.Next(minValue, maxValue + 1); |
|
|
|
|
await Task.Delay(randomNumber); |
|
|
|
|
loading.setValue(i); |
|
|
|
|
if (loading.ProgressBar.Value == 98) |
|
|
|
|
{ |
|
|
|
|
GradingResult(parameter); |
|
|
|
|
} |
|
|
|
|
if(loading.ProgressBar.Value >= 100) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
loading.Close(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 检测到钻石需进行清洁 |
|
|
|
|
if (parameter.status == StatusCodes.Recheck) |
|
|
|
|
{ |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("Recheck"), loading); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (DirectoryNotFoundException ex) |
|
|
|
|
{ |
|
|
|
|
loading.Close(); |
|
|
|
|
new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists")); |
|
|
|
|
} |
|
|
|
|
catch (IOException ex) |
|
|
|
|
{ |
|
|
|
|
loading.Close(); |
|
|
|
|
new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}"); |
|
|
|
|
} |
|
|
|
|
finally { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
/** |
|
|
|
|
|
|
|
|
|
LoadingDialog loading = new LoadingDialog(DiamondCode); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
if (param != null) |
|
|
|
|
{ |
|
|
|
|
string progTime = ConfigurationHelper.ReadConfigValue("ProgressTime"); |
|
|
|
|
|
|
|
|
|
int iProgTime = 50000; |
|
|
|
|
int.TryParse(progTime, out iProgTime); |
|
|
|
|
int setpTime = iProgTime / 97; |
|
|
|
|
|
|
|
|
|
var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => loading.ShowDialog())); |
|
|
|
|
await Task.Run(async () => |
|
|
|
|
{ |
|
|
|
|
bool isEnd = false; |
|
|
|
|
int progress = 0; |
|
|
|
|
// 更新进度条的值(需要在UI线程上执行) |
|
|
|
|
loading.Dispatcher.Invoke(async () => |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i <= 97; i++) |
|
|
|
|
{ |
|
|
|
|
if (isEnd) |
|
|
|
|
{ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// 模拟耗时操作 |
|
|
|
|
//System.Threading.Thread.Sleep(50); // 休眠50毫秒 |
|
|
|
|
await Task.Delay(setpTime); |
|
|
|
|
loading.setValue(i); |
|
|
|
|
progress = i; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
SocResultEntity socResolt = new SocResultEntity(); |
|
|
|
|
AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
|
|
string value = param.ToString() ?? ""; |
|
|
|
|
if (value != null && value.Split(" ").Length == 3) |
|
|
|
|
{ |
|
|
|
|
parameter.Shape = value.Split(" ")[0]; |
|
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
|
} |
|
|
|
|
// 初始化SOC客户端服务,传入SOC端的地址和认证Token |
|
|
|
|
_socClientService = new SOCClientService(); |
|
|
|
|
// 启动soc |
|
|
|
|
socResolt = await _socClientService.ProcessImageCollectionAsync(); |
|
|
|
|
switch (socResolt.Status) |
|
|
|
|
{ |
|
|
|
|
case StatusCodes.OpenOfTheHatch: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("OpenOfTheHatch"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.DeviceNotFound: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("DeviceNotFound"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.InProgress: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("InProgress"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.CacheCleared: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CacheCleared"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.CannotSendCommand: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CannotSendCommand"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.MicrocontrollerTimeout: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("MicrocontrollerTimeout"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.MicrocontrollerError: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("MicrocontrollerError"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.CameraNotConnected: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CameraNotConnected"), loading); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
_algorithmServer = new AlgorithmServer(); |
|
|
|
|
// //图片集合 |
|
|
|
|
string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented); |
|
|
|
|
// string image_files =$"[ \"image_0.bmp\", \"image_1.bmp\", \"image_2.bmp\", \"image_3.bmp\", \"image_4.bmp\", \"image_5.bmp\", \"image_6.bmp\", \"image_7.bmp\", \"image_8.bmp\", \"image_9.bmp\", \"image_10.bmp\", \"image_11.bmp\", \"image_12.bmp\", \"image_13.bmp\", \"image_14.bmp\", \"image_15.bmp\", \"image_16.bmp\", \"image_17.bmp\", \"image_18.bmp\", \"image_19.bmp\", \"image_20.bmp\", \"image_21.bmp\", \"image_22.bmp\", \"image_23.bmp\", \"image_24.bmp\", \"image_25.bmp\", \"image_26.bmp\", \"image_27.bmp\", \"image_28.bmp\", \"image_29.bmp\", \"image_30.bmp\", \"image_31.bmp\", \"image_32.bmp\", \"image_33.bmp\", \"image_34.bmp\", \"image_35.bmp\", \"image_36.bmp\", \"image_37.bmp\", \"image_38.bmp\", \"image_39.bmp\", \"image_40.bmp\", \"image_41.bmp\", \"image_42.bmp\", \"image_43.bmp\", \"image_44.bmp\", \"image_45.bmp\", \"image_46.bmp\", \"image_47.bmp\", \"image_48.bmp\", \"image_49.bmp\", \"image_50.bmp\", \"image_51.bmp\", \"image_52.bmp\", \"image_53.bmp\", \"image_54.bmp\", \"image_55.bmp\", \"image_56.bmp\", \"image_57.bmp\", \"image_58.bmp\", \"image_59.bmp\", \"image_60.bmp\", \"image_61.bmp\", \"image_62.bmp\", \"image_63.bmp\", \"image_64.bmp\", \"image_65.bmp\", \"image_66.bmp\", \"image_67.bmp\", \"image_68.bmp\", \"image_69.bmp\", \"image_70.bmp\", \"image_71.bmp\", \"image_72.bmp\", \"image_73.bmp\", \"image_74.bmp\", \"image_75.bmp\", \"image_76.bmp\", \"image_77.bmp\", \"image_78.bmp\", \"image_79.bmp\", \"image_80.bmp\", \"image_81.bmp\", \"image_82.bmp\", \"image_83.bmp\", \"image_84.bmp\", \"image_85.bmp\", \"image_86.bmp\", \"image_87.bmp\", \"image_88.bmp\", \"image_89.bmp\", \"image_90.bmp\", \"image_91.bmp\", \"image_92.bmp\", \"image_93.bmp\", \"image_94.bmp\", \"image_95.bmp\", \"image_96.bmp\", \"image_97.bmp\", \"image_98.bmp\", \"image_99.bmp\"]" ; |
|
|
|
|
|
|
|
|
|
// 保存图片到历史记录文件夹 |
|
|
|
|
HandleAlgorithmFailure(image_files, DiamondCode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 启动算法 |
|
|
|
|
parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files); |
|
|
|
|
//机器号 |
|
|
|
|
parameter.DeviceId = socResolt.DeviceId; |
|
|
|
|
switch (parameter.status) |
|
|
|
|
{ |
|
|
|
|
case StatusCodes.AlgorithmFailed: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("AlgorithmFailed"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.ImageFileReadFailure: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("ImageFileReadFailure"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.JsonParseFailure: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("JsonParseFailure"), loading); |
|
|
|
|
return; |
|
|
|
|
case StatusCodes.NoDiamond: |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("NoDiamond"), loading); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
parameter.Standard = getStandardName(); |
|
|
|
|
parameter.Shape = value.Split(" ")[0]; |
|
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
|
parameter.DiamondCode = DiamondCode; |
|
|
|
|
|
|
|
|
|
if (!parameter.status.Equals(StatusCodes.Ok)) |
|
|
|
|
parameter.error_msg = MultilingualHelper.getString(StatusCodes.GetConstantNameByValue(parameter.status)); |
|
|
|
|
//参数实体转json输出 |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Logger.Error("output输出失败:"+ex.Message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isEnd = true; |
|
|
|
|
//GradingResult(parameter); |
|
|
|
|
await loading.Dispatcher.Invoke(async () => |
|
|
|
|
{ |
|
|
|
|
for (int i = progress; progress <= 100; i++) |
|
|
|
|
{ |
|
|
|
|
Random random = new Random(); int minValue = 20; int maxValue = 100; // 生成50到150之间的随机整数 |
|
|
|
|
int randomNumber = random.Next(minValue, maxValue + 1); |
|
|
|
|
await Task.Delay(randomNumber); |
|
|
|
|
loading.setValue(i); |
|
|
|
|
if (loading.ProgressBar.Value == 98) |
|
|
|
|
{ |
|
|
|
|
GradingResult(parameter); |
|
|
|
|
} |
|
|
|
|
if(loading.ProgressBar.Value >= 100) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
loading.Close(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 检测到钻石需进行清洁 |
|
|
|
|
if (parameter.status == StatusCodes.Recheck) |
|
|
|
|
{ |
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("Recheck"), loading); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (DirectoryNotFoundException ex) |
|
|
|
|
{ |
|
|
|
|
loading.Close(); |
|
|
|
|
new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists")); |
|
|
|
|
} |
|
|
|
|
catch (IOException ex) |
|
|
|
|
{ |
|
|
|
|
loading.Close(); |
|
|
|
|
new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}"); |
|
|
|
|
} |
|
|
|
|
finally { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
**/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|