209 lines
5.3 KiB
C#
209 lines
5.3 KiB
C#
|
using Aitex.Core.RT.Event;
|
|||
|
using Aitex.Core.RT.SCCore;
|
|||
|
using Aitex.Core.Util;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Reflection;
|
|||
|
using System.Runtime.Serialization;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows;
|
|||
|
|
|||
|
namespace MECF.Framework.Common.Aitex.Core.RT.EMS
|
|||
|
{
|
|||
|
[DataContract]
|
|||
|
public class TimeObserver : IObserver
|
|||
|
{
|
|||
|
#region Variables
|
|||
|
|
|||
|
protected DateTime _startDate = DateTime.Now;
|
|||
|
protected DateTime? _trigDate = null;
|
|||
|
protected double _value = 0;
|
|||
|
protected bool _isTimeOut = false;
|
|||
|
protected double _timeExceeded = 0;
|
|||
|
protected readonly R_TRIG _trigTimeOut = new();
|
|||
|
protected double _threshold = 1000000;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Properties
|
|||
|
|
|||
|
[DataMember]
|
|||
|
public string Name { get; set; }
|
|||
|
|
|||
|
[DataMember]
|
|||
|
public string Module { get; set; }
|
|||
|
|
|||
|
[DataMember]
|
|||
|
public int Index { get; set; }
|
|||
|
|
|||
|
[DataMember]
|
|||
|
public string Description { get; set; }
|
|||
|
|
|||
|
[DataMember]
|
|||
|
public bool Enable { get; set; }
|
|||
|
|
|||
|
[DataMember]
|
|||
|
public TimeUnit TimeDisplayUnit { get; set; }
|
|||
|
|
|||
|
#region OutputOnly
|
|||
|
|
|||
|
[Subscription("IsTrigger")]
|
|||
|
public bool IsTrigger => _isTimeOut;
|
|||
|
|
|||
|
[Subscription("StartDate")]
|
|||
|
public DateTime StartDate => _startDate;
|
|||
|
|
|||
|
[Subscription("Value")]
|
|||
|
/// <summary>
|
|||
|
/// 单位s
|
|||
|
/// </summary>
|
|||
|
public double Value => _value;
|
|||
|
|
|||
|
[Subscription("Threshold")]
|
|||
|
/// <summary>
|
|||
|
/// 单位s
|
|||
|
/// </summary>
|
|||
|
public double Threshold => _threshold;
|
|||
|
|
|||
|
[Subscription("TrigDate")]
|
|||
|
public DateTime? TrigDate => _trigDate;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 超出时间,单位TimeDisplayUnit
|
|||
|
/// </summary>
|
|||
|
[Subscription("TimeExceeded")]
|
|||
|
public double TimeExceeded => _timeExceeded;
|
|||
|
|
|||
|
[Subscription("ValueExceeded")]
|
|||
|
public virtual double ValueExceeded => _timeExceeded;
|
|||
|
|
|||
|
[Subscription("IsProcessing")]
|
|||
|
public virtual bool IsProcessing => true;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Constructors
|
|||
|
public TimeObserver()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public TimeObserver(string name,string module ,int index,string description, bool enabled,DateTime startdate, double threshold, TimeUnit timedisplayunit)
|
|||
|
{
|
|||
|
Name = name;
|
|||
|
Module = module;
|
|||
|
Index = index;
|
|||
|
Description = description;
|
|||
|
Enable = enabled;
|
|||
|
TimeDisplayUnit = timedisplayunit;
|
|||
|
|
|||
|
_threshold = threshold;
|
|||
|
|
|||
|
_startDate = startdate;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
#region Methods
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 计算剩余时间和超时时间,不同类算法不同,需要重载
|
|||
|
/// </summary>
|
|||
|
public virtual void Monitor()
|
|||
|
{
|
|||
|
_trigTimeOut.CLK = _isTimeOut;
|
|||
|
|
|||
|
if (_trigTimeOut.Q)
|
|||
|
{
|
|||
|
bool iswarning = true;
|
|||
|
if (SC.ContainsItem("System.IgnoreMaintainTimeOutWarning"))
|
|||
|
{
|
|||
|
iswarning = !SC.GetValue<bool>("System.IgnoreMaintainTimeOutWarning");
|
|||
|
}
|
|||
|
if (iswarning)
|
|||
|
EV.PostWarningLog("Maintainance", $"Plan {Name} reach the deadline, please check as soon as possible.");
|
|||
|
else
|
|||
|
EV.PostInfoLog("Maintainance", $"Plan {Name} reach the deadline, please check as soon as possible.");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 重新开始计时,未使能时或不满足条件无法复位
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public virtual bool Reset()
|
|||
|
{
|
|||
|
if (!Enable)
|
|||
|
{
|
|||
|
EV.PostWarningLog("Maintainance", $"Plan {Name} is disable,can not be reset");
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (CanReset())
|
|||
|
return true;
|
|||
|
else return false;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 阈值设置
|
|||
|
/// </summary>
|
|||
|
/// <param name="threshold">必须大于0</param>
|
|||
|
/// <returns></returns>
|
|||
|
public virtual bool SetThreshold(double threshold)
|
|||
|
{
|
|||
|
if (threshold <= 0)
|
|||
|
{
|
|||
|
EV.PostWarningLog("Maintainance", $"threshold must be greater than zero");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool SetStartDate(DateTime t)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool CanReset()
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool SetMaintain(string parentname, string name, int itemid, DateTime date)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual Dictionary<string, List<MaintainerItem>> GetAllMaintainerItemsDic()
|
|||
|
{
|
|||
|
return new();
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool SetMaintainerItemEnable(string parentname, string name, int itemid, bool enable)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual void AddMaintainerItem(string parentname, MaintainerItem item)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public virtual void RemoveMaintainerItem(string parentname, string itemname, int id)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|