Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/RT/IOCore/Interlock/Limits/DiLimit.cs

36 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using Aitex.Core.RT.IOCore.Interlock.DataProvider;
namespace Aitex.Core.RT.IOCore.Interlock.Limits;
/// <summary>
/// 基于DI判断的互锁限制条件。
/// </summary>
internal class DiLimit : InterlockLimitBase<DiValueProvider, bool>
{
public override bool CurrentValue => (bool)DataProvider.GetValue();
public override string LimitReason =>
$"{DataProvider.Name} = [{(CurrentValue ? "ON" : "OFF")}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}";
public override string DaemonReason =>
$"{DataProvider.Name} = [{(LimitValue ? "ON" : "OFF")}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}";
public DiLimit(DiValueProvider dataProvider, string value, string tip, Dictionary<string, string> cultureTip,bool ignoreReverse)
: base(dataProvider, value, tip, cultureTip,ignoreReverse)
{
if (bool.TryParse(value, out var limitValue))
LimitValue = limitValue;
else
throw new InvalidCastException($"unable to convert {value} to boolean.");
}
protected override bool CheckInRange()
{
return CurrentValue == LimitValue;
}
}