作用域配置
This commit is contained in:
@@ -21,15 +21,53 @@ namespace MonitorModule.ViewModels
|
||||
/// </summary>
|
||||
public class MonitorViewModel : NavigateViewModelBase, IRegionMemberLifetime, IDisposable
|
||||
{
|
||||
#region 属性
|
||||
public bool KeepAlive => true;
|
||||
public ScopedContext _scopedContext { get; set; }
|
||||
public GlobalInfo _globalInfo { get; set; }
|
||||
|
||||
public string TestStatus
|
||||
{
|
||||
get => _testStatus;
|
||||
set => SetProperty(ref _testStatus, value);
|
||||
}
|
||||
|
||||
/// <summary>PlotView 直接绑这个 PlotModel</summary>
|
||||
public PlotModel Plot { get; }
|
||||
|
||||
/// <summary>当前已添加的信号集合(左侧列表展示)</summary>
|
||||
public ObservableCollection<SignalItem> Signals { get; } = new();
|
||||
|
||||
public SignalItem? SelectedSignal
|
||||
{
|
||||
get => _selectedSignal;
|
||||
set => SetProperty(ref _selectedSignal, value);
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => SetProperty(ref _statusMessage, value);
|
||||
}
|
||||
#endregion
|
||||
#region 命令
|
||||
public ICommand AddSignalCommand { get; }
|
||||
public ICommand DeleteSignalCommand { get; }
|
||||
public ICommand ResetViewCommand { get; }
|
||||
public ICommand RefreshDataCommand { get; }
|
||||
// 双击展开/折叠:与 RecordView/AutomatedTestingView 共用同一套 ExpandViewEvent
|
||||
public ICommand RefreshCommand { get; }
|
||||
#endregion
|
||||
#region 私有字段
|
||||
private readonly IScopedProvider _scope;
|
||||
private bool IsInitiated = false;
|
||||
private IScopedProvider _scope;
|
||||
// 颜色轮转池,给新加的信号自动分配区分色
|
||||
private static readonly OxyColor[] _palette =
|
||||
{
|
||||
OxyColors.SteelBlue, OxyColors.IndianRed, OxyColors.SeaGreen,
|
||||
OxyColors.DarkOrange, OxyColors.MediumPurple, OxyColors.Goldenrod,
|
||||
OxyColors.Teal, OxyColors.Crimson, OxyColors.OliveDrab
|
||||
};
|
||||
OxyColors.SteelBlue, OxyColors.IndianRed, OxyColors.SeaGreen,
|
||||
OxyColors.DarkOrange, OxyColors.MediumPurple, OxyColors.Goldenrod,
|
||||
OxyColors.Teal, OxyColors.Crimson, OxyColors.OliveDrab
|
||||
};
|
||||
private int _signalCounter;
|
||||
|
||||
// ===== 模拟数据相关 =====
|
||||
@@ -43,60 +81,15 @@ namespace MonitorModule.ViewModels
|
||||
private const int _maxPoints = 200;
|
||||
// 用于 random walk 的随机源
|
||||
private static readonly Random _rng = new();
|
||||
#endregion
|
||||
|
||||
#region 隔离 / 标题
|
||||
public bool KeepAlive => true;
|
||||
public ScopedContext _scopedContext { get; }
|
||||
public GlobalInfo GlobalInfoRef { get; }
|
||||
|
||||
private string _testStatus = string.Empty;
|
||||
public string TestStatus
|
||||
{
|
||||
get => _testStatus;
|
||||
set => SetProperty(ref _testStatus, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region OxyPlot
|
||||
/// <summary>PlotView 直接绑这个 PlotModel</summary>
|
||||
public PlotModel Plot { get; }
|
||||
|
||||
/// <summary>当前已添加的信号集合(左侧列表展示)</summary>
|
||||
public ObservableCollection<SignalItem> Signals { get; } = new();
|
||||
|
||||
private SignalItem? _selectedSignal;
|
||||
public SignalItem? SelectedSignal
|
||||
{
|
||||
get => _selectedSignal;
|
||||
set => SetProperty(ref _selectedSignal, value);
|
||||
}
|
||||
|
||||
private string _statusMessage = "图表已就绪,暂无信号";
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => SetProperty(ref _statusMessage, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
public ICommand AddSignalCommand { get; }
|
||||
public ICommand DeleteSignalCommand { get; }
|
||||
public ICommand ResetViewCommand { get; }
|
||||
public ICommand RefreshDataCommand { get; }
|
||||
// 双击展开/折叠:与 RecordView/AutomatedTestingView 共用同一套 ExpandViewEvent
|
||||
public ICommand RefreshCommand { get; }
|
||||
#endregion
|
||||
|
||||
public MonitorViewModel(IContainerExtension container) : base(container)
|
||||
{
|
||||
_scope = container.CreateScope();
|
||||
GlobalInfoRef = container.Resolve<GlobalInfo>();
|
||||
_scopedContext = _scope.Resolve<ScopedContext>();
|
||||
|
||||
_globalInfo = container.Resolve<GlobalInfo>();
|
||||
Plot = BuildEmptyPlot();
|
||||
|
||||
AddSignalCommand = new DelegateCommand(OnAddSignal);
|
||||
DeleteSignalCommand = new DelegateCommand(OnDeleteSignal);
|
||||
ResetViewCommand = new DelegateCommand(OnResetView);
|
||||
@@ -257,8 +250,9 @@ namespace MonitorModule.ViewModels
|
||||
private void OnExpand()
|
||||
{
|
||||
if (string.IsNullOrEmpty(TestStatus)) return;
|
||||
_globalInfo.CurrentScope = TestStatus;
|
||||
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
|
||||
GlobalInfoRef.CurrentScope = TestStatus;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -297,15 +291,18 @@ namespace MonitorModule.ViewModels
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 导航
|
||||
#region 重写
|
||||
public override void OnNavigatedTo(NavigationContext navigationContext)
|
||||
{
|
||||
base.OnNavigatedTo(navigationContext);
|
||||
if (navigationContext.Parameters.ContainsKey("Name"))
|
||||
if (!IsInitiated && navigationContext.Parameters.ContainsKey("Name"))
|
||||
{
|
||||
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
|
||||
Plot.Title = $"监控 - {TestStatus}";
|
||||
Plot.InvalidatePlot(false);
|
||||
_scope = _globalInfo.ScopeDic[TestStatus];
|
||||
_scopedContext = _globalInfo.ContextDic[TestStatus];
|
||||
IsInitiated = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user