using CFX;
using CFX.ResourcePerformance;
using CFX.Structures;
using Sln.Iot.Serilog;

namespace Sln.Iot.CFX.Event
{
    /// <summary>
    /// 错误发生事件
    /// </summary>
    public class FaultOccurredEvent
    {
        /// <summary>
        /// 数据封装处理
        /// </summary>
        /// <returns></returns>
        public CFXMessage Handle(string faultCode, FaultSeverity level, Guid faultguid, string description, Guid tranguid)
        {
            CFXMessage eve = null;
            try
            {
                eve = new FaultOccurred()
                {
                    Fault = new Fault()
                    {
                        Cause = FaultCause.MechanicalFailure,
                        Severity = level,
                        FaultCode = faultCode,
                        FaultOccurrenceId = faultguid,
                        Lane = 1,
                        AccessType = AccessType.Local,
                        Description = description,
                        OccurredAt = DateTime.Now,
                        TransactionID = tranguid,
                    }
                };
            }
            catch (Exception e)
            {
                SerilogHelper.Instance.Error("终端节点连接事件数据封装异常", e);
            }
            return eve;
        }
    }
}
