천호석
2022-12-06 183f2b92b7d5058a8f0d289826d7698b542038fe
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using DIT.SharedMemory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace SHARP_CLAS_UI
{
    public class Alarm_Occurred_Manager:IDisposable
    {
        #region Property
        private static readonly Lazy<Alarm_Occurred_Manager> _instatnce = new Lazy<Alarm_Occurred_Manager>(() => new Alarm_Occurred_Manager());
 
        public static Alarm_Occurred_Manager Instance
        {
            get
            {
                return _instatnce.Value;
            }
        }
 
        public List<AlarmOccurredInfo> Alarm_Occured_List { get; private set; }
 
        public bool Is_Heavy { get; private set; }
        #endregion
 
        #region Filed
        SharedMemory sm;
        byte[] Current_Data;
        bool IsDisposed;
        Thread Data_Update_Th;
        #endregion
 
        #region Construct
        private Alarm_Occurred_Manager()
        {
            IsDisposed = false;
            Is_Heavy = false;
 
            sm = new SharedMemory("SHARP_CLAS", 10000, true);
            sm.Open();
            
            Alarm_Occured_List = new List<AlarmOccurredInfo>();
            Alarm_Occured_List.Clear();
 
            Data_Update_Th = new Thread(Data_Update_Th_Set);
            Data_Update_Th.Start();
        }
        #endregion
 
        #region Function
        public void Dispose()
        {
            IsDisposed = true;
        }
        
        private void Data_Update_Th_Set()
        {
            while (!IsDisposed)
            {
                Thread.Sleep(10);
                DateTime dt = DateTime.Now;
                Data_Update();
                TimeSpan ts = (DateTime.Now - dt);
            }
        }
 
        private void Data_Update()
        {
            try
            {
                DateTime dt = DateTime.Now;
 
                bool heavycheck = false;
 
                SharedmemoryAddressInfo[] Alarm_List = Alarm_Memory_Address.Get_Address_Infos();
 
                for (int i = 0; i < Alarm_List.Length; i++)
                {
                    object value = 0;
                    if (sm.Get_Value(Alarm_List[i], out value))
                    {
                        if ((bool)value)
                        {
                            Alarm info;
                            if (Alarm_Manager.Instance.Get_Alarm_Info(i, out info))
                            {
                                if (info.Use) continue;
 
                                if (info.Heavy)
                                    heavycheck = true;
 
                                if (!Alarm_Occured_List.Exists(x => x.CODE == (int)info.Code))
                                {
                                    Alarm_Occured_List.Add(new AlarmOccurredInfo((int)info.Code, info.Code.ToString(), info.Description, info.Heavy));
                                }
                            }
                        }
                    }
                }
 
                Is_Heavy = heavycheck;
                TimeSpan ts = DateTime.Now - dt;
            }
            catch (Exception)
            {
 
            }
        }
        #endregion
    }
}