using Yw.Vmo;
namespace HStation.WinFrmUI
{
///
/// 监测值辅助类
///
public class SimulationMonitorValueHelper
{
///
///
///
public SimulationMonitorValueHelper(SimulationVisualListHelper visualListHelper, SimulationMonitorHelper monitorHelper)
{
_visualListHelper = visualListHelper;
_monitorHelper = monitorHelper;
}
private SimulationVisualListHelper _visualListHelper = null;//可见列表辅助类
private SimulationMonitorHelper _monitorHelper = null;//监测点辅助类
private List _allMonitorValueList = null;//所有监测值列表
///
/// 获取
///
public async Task> Get()
{
if (_allMonitorValueList == null)
{
_allMonitorValueList = new List();
var allVisualDict = _visualListHelper.GetVisualDict();
if (allVisualDict != null && allVisualDict.Count > 0)
{
var allMonitorList = await _monitorHelper.Get();
if (allMonitorList != null && allMonitorList.Count > 0)
{
foreach (var monitor in allMonitorList)
{
if (allVisualDict.ContainsKey(monitor.Relation))
{
var visual = allVisualDict[monitor.Relation];
var vm = new HydroMonitorValueViewModel(monitor, visual);
_allMonitorValueList.Add(vm);
}
}
}
}
}
return _allMonitorValueList;
}
///
/// 更新
///
public async void Update(string code, List monitorList)
{
var visual = _visualListHelper.GetVisual(code);
if (visual == null)
{
return;
}
var allMonitorValueList = await Get();
var monitorValueList = allMonitorValueList.Where(x => x.Vmo.Relation == code).ToList();
monitorValueList?.ForEach(x =>
{
var result = monitorList?.Exists(t => t.Relation == x.Vmo.Relation && t.PropName == x.Vmo.PropName);
if (!(result.HasValue && result.Value))
{
allMonitorValueList.Remove(x);
}
});
monitorList?.ForEach(x =>
{
var result = monitorValueList?.Exists(t => t.Vmo.Relation == x.Relation && t.Vmo.PropName == x.PropName);
if (!(result.HasValue && result.Value))
{
var vm = new HydroMonitorValueViewModel(x, visual);
allMonitorValueList.Add(vm);
}
});
}
}
}