using SKMC.Api.Common;
using SKMC.Api.Common.Logger;
using System;
namespace SKMC.Api.Motion.Model
{
///
/// 电机运行条件, 可作为触发动作的条件, 也可以作为告警状态的条件
///
public class AxisCnd
{
protected static readonly ILogger log = LogFactory.Get();
private readonly MotionCacher motionCacher = ObjectFactory.Resolve();
public Func CndExpress { get; set; }
public MotionAxis DataModel { get; set; }
// Type: Trigger 0, Validate 1
public short Type { get; set; } = 0;
public static AxisCnd Make(string code) => new AxisCnd
{
Code = code
};
public static AxisCnd Make(string code, Func cndExpress) => new AxisCnd
{
Code = code,
CndExpress = cndExpress
};
public bool Match() => CndExpress.Invoke(DataModel);
public bool Match(Func cndExpress) => cndExpress.Invoke(DataModel);
private string _code;
public string Code
{
get { return _code; }
set
{
_code = value;
DataModel = motionCacher.GetMotionAxis(_code);
}
}
}
}