84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using DeviceCommand.Base;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Prism.Mvvm;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
using UIShare.UIViewModel;
|
|
|
|
namespace UIShare.GlobalVariable
|
|
{
|
|
public class ScopedContext : BindableBase
|
|
{
|
|
private static readonly Random _randomSeed = new Random();
|
|
|
|
#region 子程序导航(主程序 / 错误程序各自独立)
|
|
|
|
/// <summary>主程序 Tab 的导航状态</summary>
|
|
public ProgramNavigationState MainNav { get; } = new();
|
|
|
|
/// <summary>错误程序 Tab 的导航状态</summary>
|
|
public ProgramNavigationState ErrorNav { get; } = new();
|
|
|
|
/// <summary>
|
|
/// 根据当前选中的 Tab 返回对应的导航状态
|
|
/// </summary>
|
|
public ProgramNavigationState ActiveNav =>
|
|
SelectedStepList == "错误程序" ? ErrorNav : MainNav;
|
|
|
|
/// <summary>
|
|
/// 重置两个 Tab 的导航栈,回到根程序
|
|
/// </summary>
|
|
public void ResetNavigation()
|
|
{
|
|
MainNav.Reset(Program, "主程序");
|
|
ErrorNav.Reset(Program, "错误程序");
|
|
}
|
|
|
|
#endregion
|
|
|
|
public ProgramVM Program { get; set; } = new();
|
|
public String SelectedStepList { get; set; } = "主程序";
|
|
public string CurrentFilePath { get; set; }
|
|
public bool? IsStop { get; set; }
|
|
public bool SingleStep { get; set; }
|
|
public string RunState { get; set; } = "运行";
|
|
public TimeSpan RunningTime { get; set; } = TimeSpan.Zero;
|
|
public Stopwatch SW { get; set; } = new();
|
|
public bool IsTerminate { get; set; } = false;
|
|
public ObservableCollection<Assembly> Assemblies { get; set; } = new();
|
|
public PackIconKind RunIcon { get; set; } = PackIconKind.Play;
|
|
public StepVM SelectedStep { get; set; }
|
|
public ParameterVM SelectedParameter { get; set; }
|
|
|
|
public List<IBaseInterface> DeviceList { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// 日志缓冲队列:后台线程(ScopeLogDispatcher)直接入队,
|
|
/// UI 线程(DispatcherTimer)定时出队并刷新到 ObservableCollection。
|
|
/// 不走 Progress<T> / SynchronizationContext,避免 Post 淹没 UI 消息队列。
|
|
/// </summary>
|
|
public ConcurrentQueue<(string Message, Brush Color, int Depth)> LogBuffer { get; } = new();
|
|
|
|
// 【新增测试属性】:每个实例被 new 出来时独一无二的随机身份
|
|
// 证 ID
|
|
public int DebugRandomId { get; private set; }
|
|
public ScopedContext()
|
|
{
|
|
ErrorNav.IsErrorTab = true;
|
|
lock (_randomSeed)
|
|
{
|
|
// 每次诞生一个新上下文,就在 10000 到 99999 之间随机摇一个数
|
|
DebugRandomId = _randomSeed.Next(10000, 100000);
|
|
}
|
|
}
|
|
}
|
|
}
|