//using BroCComn.PubSub;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using static Bro.Common.Helper.EnumHelper;
|
|
namespace Bro.Common.Helper
|
{
|
public enum ExceptionLevel
|
{
|
Info = 0,
|
Warning = 1,
|
Fatal = 2,
|
}
|
|
public class ProcessException : Exception
|
{
|
public ExceptionLevel Level { get; set; } = ExceptionLevel.Warning;
|
|
public static Action<DateTime, string, string> OnExceptionNotice;
|
|
//PubSubCenter pubSub = PubSubCenter.GetInstance();
|
|
/// <summary>
|
/// 站点编码
|
/// </summary>
|
public string StationId { get; set; }
|
|
/// <summary>
|
/// 工位索引
|
/// </summary>
|
public int PositionIndex { get; set; }
|
|
/// <summary>
|
/// 原生异常
|
/// </summary>
|
public Exception OriginalException { get; set; }
|
|
/// <summary>
|
/// 异常编码
|
/// </summary>
|
public string ErrorCode { get; set; }
|
|
public ProcessException()
|
{
|
}
|
|
public ProcessException(Exception ex, ExceptionLevel lvl = ExceptionLevel.Warning)
|
{
|
OriginalException = ex;
|
Level = lvl;
|
|
ExceptionNotice();
|
}
|
|
//public ProcessException(string stationCode, int positionIndex)
|
//{
|
// StationId = stationCode;
|
// PositionIndex = positionIndex;
|
//}
|
|
public ProcessException(string error, ExceptionLevel lvl = ExceptionLevel.Warning, Exception ex = null) : base(error, ex)
|
{
|
ErrorCode = error;
|
Level = lvl;
|
OriginalException = ex;
|
|
ExceptionNotice();
|
}
|
|
//public ProcessException(string stationId, int positionIndex, string error, Exception ex)
|
//{
|
// StationId = stationId;
|
// PositionIndex = positionIndex;
|
|
// ErrorCode = error;
|
// OriginalException = ex;
|
|
// ExceptionNotice();
|
//}
|
|
public void ExceptionNotice()
|
{
|
//pubSub.Publish(PubTag.ExceptionUpdate.ToString(), ErrorCode, OriginalException, true);
|
OnExceptionNotice?.Invoke(DateTime.Now, ErrorCode, OriginalException?.GetExceptionMessage());
|
}
|
}
|
}
|