using Yw.Vmo;
using Yw.WinFrmUI.Bimface;
namespace HStation.WinFrmUI
{
///
/// 监测标记辅助类
///
public class SimulationMonitorMarkerHelper
{
///
///
///
public SimulationMonitorMarkerHelper(SimulationMonitorHelper monitorHelper, ISimulationMonitorMarkerView view)
{
_monitorHelper = monitorHelper;
_views = new List() { view };
}
private SimulationMonitorHelper _monitorHelper = null;//监测点辅助类
private List _views = null;//视图列表
private List _allMarkerList = null;//所有标记列表
///
/// 是否可见
///
public bool Visible
{
get { return _visible; }
set { _visible = value; }
}
private bool _visible = false;
///
/// 获取
///
public async Task> Get()
{
var allMonitorList = await _monitorHelper.Get();
_allMarkerList = allMonitorList?.Select(x => new LogicMonitorMarker()
{
Id = x.Relation,
PropName = x.PropName,
Description = x.Description
}).ToList();
return _allMarkerList;
}
///
/// 更新
///
public async void Update(string code, List monitorList)
{
var allMarkerList = await Get();
var markerList = allMarkerList.Where(x => x.Id == code).ToList();
markerList?.ForEach(x =>
{
var result = monitorList?.Exists(t => t.Relation == x.Id && t.PropName == x.PropName);
if (!(result.HasValue && result.Value))
{
allMarkerList.Remove(x);
}
});
monitorList?.ForEach(x =>
{
var result = markerList?.Exists(t => t.Id == x.Relation && t.PropName == x.PropName);
if (!(result.HasValue && result.Value))
{
var vm = new LogicMonitorMarker()
{
Id = x.Relation,
PropName = x.PropName,
Description = x.Description
};
allMarkerList.Add(vm);
}
});
}
///
/// 设置
///
public async void Set()
{
if (this.Visible)
{
var allMarkerList = await Get();
_views.ForEach(x => x.SetLogicMonitors(allMarkerList));
}
else
{
_views.ForEach(x => x.ClearLogicMonitors());
}
}
}
}