From 225397b8e7ee6e7e7cae7960df8ac65a89370d95 Mon Sep 17 00:00:00 2001
From: tfarcraw <123211521@163.com>
Date: Mon, 23 Nov 2026 21:37:04 +0800
Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E8=AE=BE=E7=BD=AE=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E9=85=8D=E6=96=B9=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?=
=?UTF-8?q?=EF=BC=9A=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA=E6=8C=89=E9=92=AE?=
=?UTF-8?q?=E6=8E=A5=E9=85=8D=E6=96=B9=E5=8C=85=E8=AF=BB=E5=86=99=EF=BC=8C?=
=?UTF-8?q?=E5=90=8C=E5=90=8D=E9=85=8D=E6=96=B9=E5=BC=B9=E7=AA=97=E9=80=89?=
=?UTF-8?q?=E6=8B=A9=E8=A6=86=E7=9B=96=EF=BC=88=E6=97=A7=E9=85=8D=E6=96=B9?=
=?UTF-8?q?=E5=BD=92=E6=A1=A3=EF=BC=89=E6=88=96=E5=8F=A6=E5=AD=98=E6=96=B0?=
=?UTF-8?q?=E5=90=8D=EF=BC=8C=E5=AF=BC=E5=85=A5=E4=B8=8D=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E5=BA=94=E7=94=A8=E5=B9=B6=E6=8F=90=E7=A4=BA=E5=A4=8D=E6=A0=B8?=
=?UTF-8?q?=E5=8C=BA=E5=9F=9F=EF=BC=9B=E8=A1=A5=E5=85=85=E7=95=8C=E9=9D=A2?=
=?UTF-8?q?=E5=86=92=E7=83=9F=E6=A3=80=E6=9F=A5=E5=B9=B6=E4=BF=AE=E6=AD=A3?=
=?UTF-8?q?=E8=BF=87=E6=9C=9F=E7=9A=84=E4=BE=A7=E6=A0=8F=E4=B8=8E=E4=B8=8B?=
=?UTF-8?q?=E6=8B=89=E6=95=B0=E9=87=8F=E6=96=AD=E8=A8=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Presentation/DesktopPlatform.cs | 27 ++-
.../ImportRecipeConflictDialog.cs | 53 ++++++
.../RuntimeSettings/RuntimeSettings.axaml | 10 +-
.../RuntimeSettings/RuntimeSettings.axaml.cs | 7 +
.../VVMs/SopPage/SopPageViewModel.cs | 158 +++++++++++++++++-
.../Training/RecipePackage.cs | 11 +-
tests/Avalonia.Smoke/Program.cs | 78 ++++++++-
7 files changed, 329 insertions(+), 15 deletions(-)
create mode 100644 src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs
diff --git a/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs b/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs
index 36f88f4..2143b69 100644
--- a/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs
+++ b/src/SopHelper.Avalonia/Presentation/DesktopPlatform.cs
@@ -76,9 +76,32 @@ public sealed class OpenFileDialog
if(files.Count==0)return false; FileName=files[0].TryGetLocalPath()??throw new IOException("请选择本地文件");return true;
}
}
-public sealed class OpenFolderDialog
+/// 保存文件对话框:封装 Avalonia 存储选择器,供导出配方包等写盘入口复用。
+public sealed class SaveFileDialog
{
- public string Title { get; set; } = "选择文件夹";
+ public string Title { get; set; } = "保存文件";
+ public string Filter { get; set; } = "所有文件|*.*";
+ public string DefaultExt { get; set; } = "";
+ public string SuggestedFileName { get; set; } = "";
+ public string InitialDirectory { get; set; } = "";
+
+ /// 用户确认后的本地保存路径;取消时保持为空。
+ public string FileName { get; private set; } = "";
+
+ /// 弹出保存对话框,返回 true 表示已选择本地路径,false 表示用户取消;覆盖确认交给系统对话框处理。
+ public async Task ShowDialogAsync()
+ {
+ var storage=DesktopPlatform.Owner.StorageProvider;
+ var filters=Filter.Split('|');var types=new List();
+ for(var i=0;i+1 ShowDialogAsync()
diff --git a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs
new file mode 100644
index 0000000..5da7af0
--- /dev/null
+++ b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/ImportRecipeConflictDialog.cs
@@ -0,0 +1,53 @@
+// 同名配方导入确认窗口:说明覆盖会把旧配方整目录归档,同时提供改名导入,返回用户选择。
+
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Layout;
+using Avalonia.Media;
+using SopHelper.VVMs.SopPage;
+
+namespace SopHelper.VVMs.RuntimeSettings;
+
+/// 导入包内配方与工作区已有配方同名时的选择窗口。
+public sealed class ImportRecipeConflictDialog : Window
+{
+ public ImportRecipeConflictDialog(SopPageViewModel.ImportConflict conflict)
+ {
+ static string Size(long bytes) => bytes switch
+ {
+ >= 1024L * 1024 => $"{bytes / 1024.0 / 1024:0.0} MB",
+ >= 1024 => $"{bytes / 1024.0:0.0} KB",
+ _ => $"{bytes} B"
+ };
+
+ var name = conflict.Info.RecipeName;
+ Title = "导入配方"; Width = 540; SizeToContent = SizeToContent.Height;
+ CanResize = false; WindowStartupLocation = WindowStartupLocation.CenterOwner;
+ var cancel = new Button { Content = "取消", IsCancel = true, IsDefault = true };
+ var saveAsNew = new Button { Content = $"另存为“{conflict.SuggestedName}”" };
+ var overwrite = new Button { Content = "覆盖现有配方", Foreground = new SolidColorBrush(Color.FromRgb(240, 83, 60)) };
+ cancel.Click += (_, _) => Close(SopPageViewModel.ImportConflictChoice.Cancel);
+ saveAsNew.Click += (_, _) => Close(SopPageViewModel.ImportConflictChoice.SaveAsNew);
+ overwrite.Click += (_, _) => Close(SopPageViewModel.ImportConflictChoice.Overwrite);
+
+ var exportedAt = conflict.Info.ExportedAt is { } time ? time.ToLocalTime().ToString("yyyy-MM-dd HH:mm") : "未知时间";
+ var details = new List
+ {
+ new TextBlock { Text = $"配方“{name}”已存在于本机。", FontSize = 16, FontWeight = FontWeight.Bold, TextWrapping = TextWrapping.Wrap },
+ new TextBlock { Text = $"包内配方导出于 {exportedAt},含 {conflict.Info.FileCount} 个文件,约 {Size(conflict.Info.TotalBytes)}。", TextWrapping = TextWrapping.Wrap },
+ new TextBlock { Text = "覆盖前会把现有配方整目录(含录像、标注和运行图片)移入本地“已删除配方”目录,必要时可以找回。", Foreground = new SolidColorBrush(Color.FromRgb(240, 83, 60)), TextWrapping = TextWrapping.Wrap },
+ new TextBlock { Text = "导入的配方不会自动应用,请在列表中核对区域坐标后手动应用。", Foreground = new SolidColorBrush(Color.FromRgb(150, 150, 150)), TextWrapping = TextWrapping.Wrap }
+ };
+ // 包内提醒(配方缺步骤、缺标准视频、完成图目录被改写等)在确认前公开,避免用户覆盖后才发现条件不足。
+ foreach (var warning in conflict.Info.Warnings.Take(6))
+ details.Add(new TextBlock { Text = "提醒:" + warning, Foreground = new SolidColorBrush(Color.FromRgb(150, 150, 150)), TextWrapping = TextWrapping.Wrap });
+ details.Add(new StackPanel
+ {
+ Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Spacing = 8,
+ Children = { cancel, saveAsNew, overwrite }
+ });
+ var panel = new StackPanel { Margin = new Thickness(20), Spacing = 12 };
+ foreach (var control in details) panel.Children.Add(control);
+ Content = panel;
+ }
+}
diff --git a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml
index 94f19ff..084224c 100644
--- a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml
+++ b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml
@@ -32,14 +32,20 @@
+
+
-
-
+
+
+
+
+
+
diff --git a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml.cs b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml.cs
index 212d56b..125f0e4 100644
--- a/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml.cs
+++ b/src/SopHelper.Avalonia/VVMs/RuntimeSettings/RuntimeSettings.axaml.cs
@@ -18,5 +18,12 @@ public partial class RuntimeSettings : UserControl
if (TopLevel.GetTopLevel(this) is not Window owner) return false;
return await new DeleteRecipeDialog(name).ShowDialog(owner);
};
+ // 同名配方导入的确认挂在这里,与删除确认共用“视图提供模态窗口、视图模型决定业务动作”的分工。
+ // 窗口被直接关闭时 ShowDialog 返回默认值 Cancel,保持不覆盖现场配方。
+ model.ConfirmImportConflictAsync = async conflict =>
+ {
+ if (TopLevel.GetTopLevel(this) is not Window owner) return SopPageViewModel.ImportConflictChoice.Cancel;
+ return await new ImportRecipeConflictDialog(conflict).ShowDialog(owner);
+ };
}
}
diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs
index 8d17ac8..0881b02 100644
--- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs
+++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs
@@ -17,6 +17,7 @@ using SopHelper.Engine.Camera;
using SopHelper.Engine.Common;
using SopHelper.Engine.Pipeline;
using SopHelper.Engine.Sop;
+using SopHelper.Engine.Training;
namespace SopHelper.VVMs.SopPage;
@@ -81,7 +82,24 @@ public class SopPageViewModel : ViewModelBase
private string? _selectedRecipe;
private bool _refreshingRecipes;
private bool _deletingRecipe;
+
+ /// 导入/导出进行中标记:期间锁定配方与相机操作,避免解压时列表、选择或采集同时变化。
+ private bool _transferringRecipe;
+
public Func>? ConfirmDeleteRecipeAsync { get; set; }
+
+ /// 同名配方导入前向设置页请求确认(覆盖 / 另存新名 / 取消);未接上时按取消处理,不擅自覆盖现场配方。
+ public Func>? ConfirmImportConflictAsync { get; set; }
+
+ /// 同名配方导入的确认信息:包路径、包摘要和已算好的可用名称。
+ /// 用户选择的配方包文件路径。
+ /// 包摘要,含配方名、文件数、体积与提醒。
+ /// 改名导入时将使用的可用配方名。
+ public sealed record ImportConflict(string PackagePath, SopHelper.Engine.Training.RecipePackage.PackageInfo Info, string SuggestedName);
+
+ /// 同名配方导入的用户选择。
+ public enum ImportConflictChoice { Cancel, Overwrite, SaveAsNew }
+
private string _activeRecipe = "未应用配方";
private ImageSource? _frame;
private string _statusText = "就绪";
@@ -146,7 +164,9 @@ public class SopPageViewModel : ViewModelBase
SnapshotCommand = ConfigurationCommand(Snapshot, () => _lastFrame is not null);
EditRecipeCommand = ConfigurationCommand(EditRecipe, CanEditRecipe);
NewRecipeCommand = ConfigurationCommand(NewRecipe, () => CanSelectCamera);
- DeleteRecipeCommand = ConfigurationCommand(async () => await DeleteRecipeAsync(), CanDeleteRecipe);
+ DeleteRecipeCommand = ConfigurationCommand(async () => await DeleteRecipeAsync(), CanDeleteRecipe, false, "删除配方");
+ ImportRecipeCommand = ConfigurationCommand(async () => await ImportRecipeAsync(), CanImportRecipe, false, "导入配方");
+ ExportRecipeCommand = ConfigurationCommand(async () => await ExportRecipeAsync(), CanExportRecipe, false, "导出配方");
OpenRecipeFolderCommand = ConfigurationCommand(() =>
{
try { DesktopPlatform.Reveal(DesktopPlatform.Recipes.DirectoryFor(Path.GetFileNameWithoutExtension(SelectedRecipe!))); }
@@ -291,12 +311,14 @@ public class SopPageViewModel : ViewModelBase
// 无权限时保留点击入口用于显示提示;业务忙碌等非权限条件仍按原逻辑禁用。
// 执行委托再次校验角色,保证提示窗口不会替代实际的授权拦截。
- private DelegateCommand ConfigurationCommand(Action action, Func available, bool administrator = false)
+ // operation 只影响提示措辞(如“导入配方”),不改变判定;管理员操作仍按管理员权限判定。
+ private DelegateCommand ConfigurationCommand(Action action, Func available, bool administrator = false, string? operation = null)
{
bool Authorized() => administrator ? Access.IsAdministrator : Access.CanConfigure;
+ var deniedOperation = operation ?? (administrator ? "修改模型配置" : "执行此操作");
return new DelegateCommand(() =>
{
- if (Access.CheckPermission(Authorized(), administrator ? "修改模型配置" : "执行此操作") && available()) action();
+ if (Access.CheckPermission(Authorized(), deniedOperation) && available()) action();
}, () => !Authorized() || available());
}
private void AccessChanged()
@@ -306,8 +328,23 @@ public class SopPageViewModel : ViewModelBase
RaiseCommands();
}
- /// 连接、枚举、采集期间不切换设备。
- public bool CanSelectCamera => !IsRunning && !_isCameraBusy && !_deletingRecipe;
+ /// 连接、枚举、采集、删除和配方包传输期间不切换设备,也不改动配方列表。
+ public bool CanSelectCamera => !IsRunning && !_isCameraBusy && !_deletingRecipe && !_transferringRecipe;
+
+ /// 导入不需要选中配方(全新工作区也要能导入),只需要不在运行和传输中。
+ private bool CanImportRecipe() => CanSelectCamera;
+
+ /// 导出需要一个已存在的选中配方;运行中允许导出,导出只读不改配方。
+ private bool CanExportRecipe() => CanSelectCamera && SelectedRecipe is { Length: > 0 } && File.Exists(RecipePath(SelectedRecipe));
+
+ /// 配方包传输期间统一锁定相机、配方选择和配方命令,结束时无论成败都解锁。
+ private void SetRecipeTransfer(bool busy)
+ {
+ _transferringRecipe = busy;
+ RaisePropertyChanged(nameof(CanSelectCamera)); RaisePropertyChanged(nameof(CanChangeSettings)); RaisePropertyChanged(nameof(CanChangeModels));
+ RaiseCommands();
+ }
+
/// 相机是否已连接
public bool IsConnected
@@ -443,6 +480,12 @@ public class SopPageViewModel : ViewModelBase
public DelegateCommand NewRecipeCommand { get; private set; } = null!;
public DelegateCommand OpenRecipeFolderCommand { get; private set; } = null!;
+ /// 把选中配方导出为单个配方包文件
+ public DelegateCommand ExportRecipeCommand { get; private set; } = null!;
+
+ /// 从配方包导入配方(不自动应用)
+ public DelegateCommand ImportRecipeCommand { get; private set; } = null!;
+
/// 切换选中设备前异步释放当前连接,协调相机忙状态与命令可用性。
private async Task ReleaseCameraForSelectionAsync()
{
@@ -488,6 +531,8 @@ public class SopPageViewModel : ViewModelBase
EditRecipeCommand?.RaiseCanExecuteChanged();
NewRecipeCommand?.RaiseCanExecuteChanged();
DeleteRecipeCommand?.RaiseCanExecuteChanged();
+ ImportRecipeCommand?.RaiseCanExecuteChanged();
+ ExportRecipeCommand?.RaiseCanExecuteChanged();
OpenRecipeFolderCommand?.RaiseCanExecuteChanged();
SaveDjevSelectionCommand?.RaiseCanExecuteChanged();
}
@@ -686,6 +731,109 @@ public class SopPageViewModel : ViewModelBase
RaiseCommands();
}
+ ///
+ /// 导入配方包:选文件 → 检查包 → 同名时确认覆盖或改名 → 落位并刷新列表。
+ ///
+ ///
+ /// 只新增或替换配方,不改当前已应用配方、不自动应用、不启动采集,现场运行节奏不被打断。
+ /// 检查阶段先读出包内配方名、文件数与提醒;同名时由设置页弹窗选择覆盖(旧配方整目录归档)或改名导入,取消时盘上文件不动。
+ /// 只捕获配方包与文件系统的可预期错误并写状态和日志,解压失败不会变成界面崩溃。
+ ///
+ private async Task ImportRecipeAsync()
+ {
+ if (!CanImportRecipe()) return;
+ var picker = new OpenFileDialog
+ {
+ Title = "导入配方包",
+ Filter = "配方包|*.bwsrecipe;*.zip|所有文件|*.*",
+ InitialDirectory = UserFileDirectory
+ };
+ if (await picker.ShowDialogAsync() != true) return;
+ var packagePath = picker.FileName;
+ SetRecipeTransfer(true);
+ try
+ {
+ var info = await Task.Run(() => RecipePackage.Inspect(packagePath));
+ var target = info.RecipeName;
+ var overwrite = false;
+ if (File.Exists(DesktopPlatform.Recipes.ConfigPath(target)))
+ {
+ var suggested = RecipePackage.SuggestName(DesktopPlatform.Recipes, target);
+ var choice = ConfirmImportConflictAsync is null
+ ? ImportConflictChoice.Cancel
+ : await ConfirmImportConflictAsync(new ImportConflict(packagePath, info, suggested));
+ switch (choice)
+ {
+ case ImportConflictChoice.Overwrite: overwrite = true; break;
+ case ImportConflictChoice.SaveAsNew: target = suggested; break;
+ default: StatusText = "已取消导入配方"; return;
+ }
+ }
+ var result = await Task.Run(() => RecipePackage.Import(DesktopPlatform.Recipes, packagePath, target, overwrite));
+ // 只刷新列表并保持当前选择:新配方要由工艺师核对区域坐标后手动应用,区域是按相机分辨率标定的。
+ LoadRecipes(SelectedRecipe);
+ StatusText = $"已导入配方“{result.Name}”({info.FileCount} 个文件,{FormatBytes(info.TotalBytes)}),核对区域后点击“应用”开始使用";
+ Log("info", StatusText);
+ foreach (var warning in result.Warnings) Log("warn", warning);
+ }
+ catch (Exception error) when (error is IOException or InvalidDataException or ArgumentException or NotSupportedException or JsonException)
+ {
+ StatusText = "导入配方失败:" + error.Message;
+ Log("warn", StatusText);
+ }
+ finally { SetRecipeTransfer(false); }
+ }
+
+ /// 导出选中配方为配方包文件,成功后在状态栏给出路径和体积。
+ /// 读配方目录在后台线程执行,不改动配方文件;配方目录之外的完成图目录写进包内说明,导入端同样显示。
+ private async Task ExportRecipeAsync()
+ {
+ if (!CanExportRecipe()) return;
+ var name = Path.GetFileNameWithoutExtension(SelectedRecipe!);
+ var picker = new SaveFileDialog
+ {
+ Title = "导出配方包",
+ Filter = "配方包|*.bwsrecipe|所有文件|*.*",
+ DefaultExt = "bwsrecipe",
+ SuggestedFileName = name,
+ InitialDirectory = UserFileDirectory
+ };
+ if (await picker.ShowDialogAsync() != true) return;
+ SetRecipeTransfer(true);
+ try
+ {
+ var result = await Task.Run(() => RecipePackage.Export(DesktopPlatform.Recipes, name, picker.FileName));
+ StatusText = $"已导出配方“{name}”({result.FileCount} 个文件,{FormatBytes(result.TotalBytes)}):{result.Path}";
+ Log("info", StatusText);
+ foreach (var note in result.Warnings) Log("warn", note);
+ }
+ catch (Exception error) when (error is IOException or UnauthorizedAccessException or ArgumentException)
+ {
+ StatusText = "导出配方失败:" + error.Message;
+ Log("warn", StatusText);
+ }
+ finally { SetRecipeTransfer(false); }
+ }
+
+ /// 按现场习惯显示包体积,便于判断能否用 U 盘或即时消息传递。
+ private static string FormatBytes(long bytes) => bytes switch
+ {
+ >= 1024L * 1024 * 1024 => $"{bytes / 1024.0 / 1024 / 1024:0.0} GB",
+ >= 1024L * 1024 => $"{bytes / 1024.0 / 1024:0.0} MB",
+ >= 1024 => $"{bytes / 1024.0:0.0} KB",
+ _ => $"{bytes} B"
+ };
+
+ /// 配方包默认读写位置:优先下载目录,其次文档目录。
+ private static string UserFileDirectory
+ {
+ get
+ {
+ var downloads = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
+ return Directory.Exists(downloads) ? downloads : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+ }
+ }
+
///
/// 编辑当前选中的配方
///
diff --git a/src/SopHelper.CrossPlatform.Engine/Training/RecipePackage.cs b/src/SopHelper.CrossPlatform.Engine/Training/RecipePackage.cs
index 2c6ca53..7ee599c 100644
--- a/src/SopHelper.CrossPlatform.Engine/Training/RecipePackage.cs
+++ b/src/SopHelper.CrossPlatform.Engine/Training/RecipePackage.cs
@@ -149,7 +149,7 @@ public static class RecipePackage
{
packagePath = Path.GetFullPath(packagePath);
if (!File.Exists(packagePath)) throw new FileNotFoundException("配方包不存在", packagePath);
- using var archive = ZipFile.OpenRead(packagePath);
+ using var archive = OpenRead(packagePath);
var manifest = ReadManifest(archive);
// 导出端记录的处理说明(完成图目录改写等)在导入端原样重现,两边看同一份说明。
var warnings = new List(manifest.Notes ?? []);
@@ -203,7 +203,7 @@ public static class RecipePackage
try
{
PackageManifest manifest;
- using (var archive = ZipFile.OpenRead(Path.GetFullPath(packagePath)))
+ using (var archive = OpenRead(Path.GetFullPath(packagePath)))
{
manifest = ReadManifest(archive);
var declared = manifest.Files.Select(file => file.Path).ToHashSet(StringComparer.Ordinal);
@@ -257,6 +257,13 @@ public static class RecipePackage
return Path.HasExtension(destination) ? destination : destination + Extension;
}
+ /// 读取 zip;非 zip 文件(改名的文档、损坏的下载)给出面向现场的解释,而不是底层术语。
+ private static ZipArchive OpenRead(string path)
+ {
+ try { return ZipFile.OpenRead(path); }
+ catch (InvalidDataException error) { throw new InvalidDataException($"文件不是可读取的配方包(可能不是配方包或已损坏):{error.Message}"); }
+ }
+
private static void WriteManifest(ZipArchive archive, PackageManifest manifest)
{
var entry = archive.CreateEntry(ManifestEntry, CompressionLevel.Optimal);
diff --git a/tests/Avalonia.Smoke/Program.cs b/tests/Avalonia.Smoke/Program.cs
index 89648b3..b5ece13 100644
--- a/tests/Avalonia.Smoke/Program.cs
+++ b/tests/Avalonia.Smoke/Program.cs
@@ -117,6 +117,16 @@ internal static class Smoke
{ await CheckPermissions(app, window); await CheckOwnPasswords(window); _exit = 0; return; }
// 既有业务回归使用显式测试管理员;不改变生产环境默认未登录状态。
UserAccess.Current.Setup("smoke-admin", "SmokePassword123");
+ if (Environment.GetCommandLineArgs().Contains("--recipe-transfer-only"))
+ {
+ // 单独跑配方导入导出入口检查:视图需要真实窗口宿主,确认窗才能以模态方式打开。
+ var transferModel = app.Container.Resolve();
+ var transferView = new SopHelper.VVMs.RuntimeSettings.RuntimeSettings(transferModel);
+ var transferWindow = new Window { Content = transferView, Width = 900, Height = 900 };
+ transferWindow.Show(); await Task.Delay(120);
+ await CheckRecipeTransfer(lifetime, transferView, transferModel);
+ transferWindow.Close(); _exit = 0; return;
+ }
if(Environment.GetCommandLineArgs().Contains("--djev-shutdown-only"))
{
// 注入尚未完成的启动任务,验证关闭必须先取消并等待,且重复点击不会提前销毁窗口。
@@ -317,8 +327,8 @@ internal static class Smoke
CheckCameraPreferences(app);
CheckRecipePreferences(app);
var navigation=app.Container.Resolve();
- Check(navigation.Pages.Count==2&&navigation.Pages[1].DisplayName=="运行设置","Sidebar contains operator and runtime settings pages only");
- Check(navigation.Pages[0].DisplayName=="SOP 辅助"&&!navigation.Pages.Any(p=>p.DisplayName=="零件标注与训练"),"Training no longer has a standalone sidebar entry");
+ Check(navigation.Pages.Count==2&&navigation.Pages[1].DisplayName=="设置","Sidebar contains operator and runtime settings pages only");
+ Check(navigation.Pages[0].DisplayName=="运行"&&!navigation.Pages.Any(p=>p.DisplayName=="零件标注与训练"),"Training no longer has a standalone sidebar entry");
window.WindowState=WindowState.Normal;window.Width=1180;window.Height=820;
await Task.Delay(150);
var sop=app.Container.Resolve();
@@ -330,7 +340,8 @@ internal static class Smoke
navigation.SelectedIndex=1;await Task.Delay(100);
var settings=window.GetVisualDescendants().OfType().Single();
Check(ReferenceEquals(settings.DataContext,sop),"Settings and operator page share runtime state");
- Check(settings.GetVisualDescendants().OfType().Count()==2&&settings.GetVisualDescendants().OfType().Count()==1,"Camera, recipe and stride editors are on settings page");
+ // 相机、配方和 djev 启动档位各有下拉,抽帧是唯一的滑块。
+ Check(settings.GetVisualDescendants().OfType().Count()==3&&settings.GetVisualDescendants().OfType().Count()==1,"Camera, recipe, djev tier and stride editors are on settings page");
await CheckRecipeSelection(window,navigation,sop);
if(_recipeSelectionOnly){_exit=0;return;}
// 后续断言针对 demo 的四步三域,不能依赖新增模板后的文件排序。
@@ -373,6 +384,7 @@ internal static class Smoke
navigation.SelectedIndex=1;await Task.Delay(80);
Check(settings.GetVisualDescendants().Where(c=>c is ComboBox or Slider).Cast().All(c=>c.IsEnabled),"Runtime settings become editable after stopping");
await CheckRecipeDeletion(lifetime,settings,sop);
+ await CheckRecipeTransfer(lifetime,settings,sop);
navigation.SelectedIndex=0;await Task.Delay(80);
Check(window.GetVisualDescendants().OfType().Any(),"SOP page navigates");
sop.EditRecipeCommand.Execute();await Task.Delay(150);
@@ -549,6 +561,61 @@ internal static class Smoke
sop.SelectedRecipe=selected;
}
+ /// 验证配方导入导出入口、同名确认窗的选择回传和说明文案;文件选择器不在无头环境调用。
+ private static async Task CheckRecipeTransfer(IClassicDesktopStyleApplicationLifetime lifetime, Control settings, SopPageViewModel sop)
+ {
+ var store = new RecipeWorkspace(Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT")!);
+ var importButton = settings.GetVisualDescendants().OfType