patrick
2019-12-10 1c4426810c71eead57084be8a18ade8d314dd8c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//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());
        }
    }
}