默认文件路径保存
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
using Logger;
|
||||
using Prism.Ioc;
|
||||
using TestingModule.ViewModels;
|
||||
using UIShare;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace MainModule.ViewModels
|
||||
@@ -50,6 +53,7 @@ namespace MainModule.ViewModels
|
||||
// 在该作用域内解析 ScopedContext —— 当前作用域唯一
|
||||
_scopedContext = _scope.Resolve<ScopedContext>();
|
||||
_stepRunning = _scope.Resolve<StepRunning>();
|
||||
_systemConfig = _scope.Resolve<SystemConfig>();
|
||||
// 关键:从同一个 _scope 解析 5 个子 VM,DI 会把同一个 ScopedContext 注入它们
|
||||
CommandTreeVM = _scope.Resolve<CommandTreeViewModel>();
|
||||
StepsManagerVM = _scope.Resolve<StepsManagerViewModel>();
|
||||
@@ -71,6 +75,7 @@ namespace MainModule.ViewModels
|
||||
{
|
||||
_globalInfo.ContextDic?.Remove(TestStatus);
|
||||
_globalInfo.StepRunningDic?.Remove(TestStatus);
|
||||
_globalInfo.ConfigDic?.Remove(TestStatus);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -104,10 +109,6 @@ namespace MainModule.ViewModels
|
||||
if (navigationContext.Parameters.ContainsKey("Name"))
|
||||
{
|
||||
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
|
||||
_globalInfo.ContextDic.Add(TestStatus, _scopedContext);
|
||||
_globalInfo.StepRunningDic.Add(TestStatus, _stepRunning);
|
||||
_globalInfo.ScopeDic.Add(TestStatus, _scope);
|
||||
_systemConfig = _scope.Resolve<SystemConfig>();
|
||||
if (ConfigService.IsExit(TestStatus))
|
||||
{
|
||||
string filePath = System.IO.Path.Combine(_systemConfig.SystemPath, $"{TestStatus}.json");
|
||||
@@ -119,6 +120,31 @@ namespace MainModule.ViewModels
|
||||
Newtonsoft.Json.JsonConvert.PopulateObject(json, _systemConfig);
|
||||
}
|
||||
}
|
||||
_globalInfo.ContextDic.Add(TestStatus, _scopedContext);
|
||||
_globalInfo.StepRunningDic.Add(TestStatus, _stepRunning);
|
||||
_globalInfo.ScopeDic.Add(TestStatus, _scope);
|
||||
_globalInfo.ConfigDic.Add(TestStatus, _systemConfig);
|
||||
if(_systemConfig.DefaultProgramFilePath != null&&File.Exists(_systemConfig.DefaultProgramFilePath))
|
||||
{
|
||||
var filePath = _systemConfig.DefaultProgramFilePath;
|
||||
// 读取 JSON 文件
|
||||
string json = File.ReadAllText(filePath);
|
||||
|
||||
// 反序列化为 ProgramModel
|
||||
var program = Newtonsoft.Json.JsonConvert.DeserializeObject<ProgramModel>(json);
|
||||
|
||||
if (program == null)
|
||||
{
|
||||
LoggerHelper.WarnWithNotify($"文件格式不正确或为空: {filePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 💡 2. 严格赋值给快照锁定下的当前工位上下文,实现数据完全隔离
|
||||
_scopedContext.Program.Parameters = program.Parameters;
|
||||
_scopedContext.Program.StepCollection = program.StepCollection;
|
||||
_scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection;
|
||||
_scopedContext.CurrentFilePath = filePath;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user