add:check

master
handefeng 1 year ago
parent d3c0676a2d
commit ebfe68ca80
  1. 1
      Model/Services/AlgorithmServer.cs
  2. 43
      Model/Services/SOCClientService.cs
  3. 18
      Resource/Document/log.txt
  4. 9
      SparkClient.csproj
  5. 85
      ViewModel/Grading/DiamondSelectVM.cs
  6. 45
      Views/Dialog/MsgDialog.xaml
  7. 62
      Views/Dialog/MsgDialog.xaml.cs

@ -44,7 +44,6 @@ namespace SparkClient.Model.Services
string resultJson = Marshal.PtrToStringAnsi(resultPtr);
// 释放 DLL 分配的内存
FreeString(resultPtr);
Console.WriteLine("log999999999999999999"+resultJson);
// 检查返回的 JSON 字符串是否为空或无效
if (string.IsNullOrEmpty(resultJson))

@ -19,18 +19,6 @@ namespace SparkClient.Model.Services
// Log地址
private const string LogFilePath = @"..\..\..\Resource\Document\log.txt";
private static readonly Dictionary<string, string> StatusDescriptions = new Dictionary<string, string>
{
{ "S000", "成功" },
{ "S001", "采图正在进行中" },
{ "S002", "缓存图片被清理(读取不够及时)" },
{ "S003", "无法向单片机发送指令" },
{ "S004", "单片机访问超时" },
{ "S005", "单片机返回错误码" },
{ "P001", "未找到切工仪" },
{ "P002", "算法调用失败" }
};
/// <summary>
/// 基础URL,用于构建完整的API请求地址。
/// </summary>
@ -107,7 +95,13 @@ namespace SparkClient.Model.Services
if (status == 200)
{
byte[] imageBytes = await response.Content.ReadAsByteArrayAsync();
string fileName = Path.Combine(savePath, $"image_{imageIndex}.bmp");
// 获取 Content-Type 头以确定图片格式
string contentType = response.Content.Headers.ContentType.MediaType;
string fileExtension = GetFileExtension(contentType);
//string fileName = Path.Combine(savePath, $"image_{imageIndex}.bmp");
string fileName = Path.Combine(savePath, $"image_{imageIndex}{fileExtension}");
// 图片名称List
imageNames.Add(Path.GetFileName(fileName));
// 保存图片
@ -203,19 +197,24 @@ namespace SparkClient.Model.Services
}
/// <summary>
/// 根据状态码获取相应的描述信息。
/// 如果状态码在预定义的状态字典中存在,则返回对应的描述信息;
/// 否则返回“未知状态: [状态码]”。
/// 根据给定的 MIME 类型获取对应的文件扩展名。
/// </summary>
/// <param name="status">状态码。</param>
/// <returns>状态描述信息。</returns>
private string GetDescription(string status)
/// <param name="contentType">HTTP 响应中的 Content-Type 头字段,表示内容的 MIME 类型。</param>
/// <returns>与 MIME 类型对应的文件扩展名。</returns>
/// <exception cref="InvalidOperationException">当传入的 MIME 类型不受支持时抛出此异常。</exception>
private string GetFileExtension(string contentType)
{
if (StatusDescriptions.TryGetValue(status, out string description))
switch (contentType.ToLower())
{
return description;
case "image/bmp":
return ".bmp";
case "image/jpg":
return ".jpg";
case "image/png":
return ".png";
default:
throw new InvalidOperationException($"Unsupported content type: {contentType}");
}
return "未知状态: " + status;
}
}

@ -6,3 +6,21 @@
[2024-12-05 16:51:04.013] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-05 16:58:31.184] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-12 13:27:06.264] 发生异常: The process cannot access the file 'image_39.bmp' because it is being used by another process.
[2024-12-18 08:56:09.327] 发生异常: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
[2024-12-18 15:58:22.476] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:12:57.999] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:13:12.680] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:13:20.632] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:13:29.227] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:13:44.433] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:13:59.933] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 16:14:09.063] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:03:24.758] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:03:50.352] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:06:16.074] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:06:53.906] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:11:04.161] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:13:26.174] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-18 17:25:38.182] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-19 08:50:34.643] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)
[2024-12-19 08:54:45.576] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000)

@ -135,10 +135,19 @@
<SubType>Designer</SubType>
</Page>
<Page Remove="Resource\Images\Temp\**" />
<Page Update="Views\Dialog\MsgDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Remove="Resource\Images\Temp\**" />
<Compile Update="Views\Dialog\MsgDialog.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>MsgDialog.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>

@ -115,9 +115,9 @@ public class DiamondSelectVM : BaseViewModel
/// <param name="param"></param>
public async void StartGrading(object param)
{
#if DEBUG
DoStartGrading(param);
#else
// #if DEBUG
// DoStartGrading(param);
// #else
LoadingDialog loading = new LoadingDialog();
try
{
@ -158,8 +158,30 @@ public class DiamondSelectVM : BaseViewModel
// 启动soc
socResolt = await DoSoc();
if (socResolt.Status == "P001")
{
// 使用 Dispatcher 将 UI 操作调度到主线程
Application.Current.Dispatcher.Invoke(() =>
{
MsgDialog msgDialog = new MsgDialog();
msgDialog.ShowDialog();
});
loading.Dispatcher.Invoke(() => loading.Close());
return;
}
// 启动算法
parameter = await DoAlgorithm(socResolt, parameter.Shape, parameter.CrownType);
if (parameter.status == "P002" || parameter.status == "P003" || parameter.status == "P004")
{
// 使用 Dispatcher 将 UI 操作调度到主线程
Application.Current.Dispatcher.Invoke(() =>
{
MsgDialog msgDialog = new MsgDialog();
msgDialog.ShowDialog();
});
loading.Dispatcher.Invoke(() => loading.Close());
return;
}
parameter.Standard = "IGI 2024";
parameter.Shape = value.Split(" ")[0];
@ -195,7 +217,7 @@ public class DiamondSelectVM : BaseViewModel
finally {
}
#endif
// #endif
}
/// <summary>
@ -287,35 +309,28 @@ public class DiamondSelectVM : BaseViewModel
/// <summary>
/// 启动切工仪接口。
/// </summary>
/// <param name="index">图片索引</param>
/// <param name="index">图片索引</param>
/// <param name="index">图片索引</param>
/// <returns>图片的字节数组</returns>
private async Task<SocResultEntity> DoSoc()
{
// // 光照度
// string sql = new CutterConfigEntity
// {
// ItemName = null,
// Key = null,
// Value = null
// }.GenerateSelectSQL(new List<string> { "Value" }, new Dictionary<string, object> { { "Key", "light_level" } });
// SqliteParameter[] sqliteParameters = [new("@Key", "light_level")];
// DataTable table = DataBaseHelper.ExecuteQuery(sql,sqliteParameters);
// object lightLevelValue = table.Rows[0][0];
// if (!int.TryParse(lightLevelValue.ToString(), out int lightLevel))
// {
// throw new InvalidOperationException("Light level value is not a valid integer.");
// }
// // 初始化SOC客户端服务,传入SOC端的地址和认证Token
// _socClientService = new SOCClientService();
// // SOC接口
// string savePath = @"d:\\diamond_images";
// SocResultEntity resultEntity = await _socClientService.ProcessImageCollectionAsync(lightLevel, savePath);
// // 转换成json
// string jsonResult = JsonConvert.SerializeObject(resultEntity, Formatting.Indented);
SocResultEntity resultEntity = new SocResultEntity();
// 光照度
string sql = new CutterConfigEntity
{
ItemName = null,
Key = null,
Value = null
}.GenerateSelectSQL(new List<string> { "Value" }, new Dictionary<string, object> { { "Key", "light_level" } });
SqliteParameter[] sqliteParameters = [new("@Key", "light_level")];
DataTable table = DataBaseHelper.ExecuteQuery(sql,sqliteParameters);
object lightLevelValue = table.Rows[0][0];
if (!int.TryParse(lightLevelValue.ToString(), out int lightLevel))
{
throw new InvalidOperationException("Light level value is not a valid integer.");
}
// 初始化SOC客户端服务,传入SOC端的地址和认证Token
_socClientService = new SOCClientService();
// SOC接口
string savePath = @"d:\\diamond_images";
SocResultEntity resultEntity = await _socClientService.ProcessImageCollectionAsync(lightLevel, savePath);
return resultEntity;
}
@ -346,19 +361,9 @@ public class DiamondSelectVM : BaseViewModel
AlgorithmResultEntity algoResult = _algorithmServer.CallParseJsonAndReturnActions(shape, shape_mode, image_file_base_path, image_files, algo_config);
// 将 algoResult 序列化为格式化的 JSON 字符串
string algoJsonResult = JsonConvert.SerializeObject(algoResult, Formatting.Indented);
ShowMessage(algoJsonResult);
return Task.FromResult(algoResult);
}
private void ShowMessage(string message)
{
MessageBox.Show(message);
}
}
public class ButtonInfo
{

@ -0,0 +1,45 @@
<Window x:Class="SparkClient.Views.Dialog.MsgDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" AllowsTransparency="True"
Background="Transparent" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
MouseLeftButtonDown="Window_MouseLeftButtonDown">
<!-- 窗口圆角和背景 -->
<Border CornerRadius="20" Background="White" Width="400" Height="250">
<Grid Margin="20">
<!-- 布局定义 -->
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 右上角关闭按钮 -->
<Button Background="Transparent" BorderBrush="Transparent" Click="CloseButton_Click">
<Viewbox Stretch="Uniform"/>
</Button>
<!-- 标题 -->
<TextBlock Grid.Row="0" Text="XXXXXXXXXXXXXX"
FontSize="16" FontWeight="Bold" Foreground="Black"
HorizontalAlignment="Center" Margin="0,70" />
<!-- 按钮区域 -->
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
<!-- 确定按钮 -->
<Button Content="{DynamicResource ok}" HorizontalAlignment="Center" Width="80" Height="35" Margin="10,0"
Background="#4DA3FF" Foreground="White" FontSize="14"
BorderBrush="Transparent" Click="Skip_Click" />
</StackPanel>
<Path Data="{StaticResource CloseGeometry}"
Fill="Azure"
Stroke="Black"
StrokeThickness="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="335,7,0,0"
Width="30" />
</Grid>
</Border>
</Window>

@ -0,0 +1,62 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SparkClient.Views.Dialog
{
/// <summary>
/// MsgDialog.xaml 的交互逻辑
/// </summary>
public partial class MsgDialog : Window
{
public MsgDialog()
{
InitializeComponent();
this.Loaded += (s, e) => ApplyCornerRadiusClip();
this.SizeChanged += (s, e) => ApplyCornerRadiusClip();
}
/// <summary>
/// 关闭按钮点击事件
/// </summary>
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 跳过按钮点击事件
/// </summary>
private void Skip_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 窗口圆角裁剪
/// </summary>
private void ApplyCornerRadiusClip()
{
if (this.ActualWidth > 0 && this.ActualHeight > 0)
{
this.Clip = new RectangleGeometry
{
Rect = new Rect(0, 0, this.ActualWidth, this.ActualHeight),
RadiusX = 20,
RadiusY = 20
};
}
}
/// <summary>
/// 支持窗口拖动
/// </summary>
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
}
}
Loading…
Cancel
Save