asmrobot
2019-10-14 730fe7ea65bcadbe235e40bb54b2410d14495267
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using RichCreator.Utility.InputControl;
using RichCreator.Utility.Utilitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZTImage.Configuration;
 
namespace RichCreator
{
    public class G
    {
        private G()
        { }
 
        /// <summary>
        /// 初始化
        /// </summary>
        private void Initialize()
        {
            this.InputControl = new HardwareInputControl();
        }
 
        /// <summary>
        /// 释放资料
        /// </summary>
        public void Release()
        {
            this.InputControl.Close();
            this.ApplicationSignal.Close();
        }
 
        /// <summary>
        /// 输入控制
        /// </summary>
        public HardwareInputControl InputControl
        {
            get;
            private set;
        }
 
 
        #region 日志,剩余时间,属性
        private Action<string> debugWriter = null;
        private Action<string> infoWriter = null;
        private Action<Int64> remainTimeWriter = null;
        private Func<Int64,bool> cancelConfirm = null;
        private Action stopTaskUI = null;
        internal void EnableWriter(Action<string> debugWriter,Action<string> infoWriter, Action<Int64> remainWriter, Func< Int64, bool> cancelConfirm,Action stopTaskUI)
        {
            this.debugWriter = debugWriter;
            this.infoWriter = infoWriter;
            this.remainTimeWriter = remainWriter;
            this.cancelConfirm = cancelConfirm;
            this.stopTaskUI = stopTaskUI;
        }
        
        /// <summary>
        /// 显示调试信息
        /// </summary>
        /// <param name="msg"></param>
        public void DebugWriter(string msg)
        {
            debugWriter(msg);
        }
 
        /// <summary>
        /// 显示关键信息
        /// </summary>
        /// <param name="msg"></param>
        public void InfoWriter(string msg)
        {
            infoWriter(msg);
        }
 
 
        
 
        /// <summary>
        /// 显示剩余时间
        /// </summary>
        /// <param name="remainSecond"></param>
        public void RemainTimeWriter(Int64 remainSecond)
        {
            remainTimeWriter(remainSecond);
        }
 
        /// <summary>
        /// 发起取消确认
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="remainMillSecond"></param>
        /// <returns></returns>
        public bool CancelConfirm(string msg, Int64 remainMillSecond)
        {
            debugWriter(msg);
            WindowUtils.SetSelfToTop();
            return cancelConfirm( remainMillSecond);
        }
 
        /// <summary>
        /// 停止任务
        /// </summary>
        public void StopTaskUI()
        {
            this.stopTaskUI();
        }
        #endregion
 
        #region 防多次运行
        /// <summary>
        /// 应用程序唯一实例
        /// </summary>
        private Mutex ApplicationSignal = new Mutex(false, "RichCreator");
        
        
 
        /// <summary>
        /// 确定应用程序唯一实例
        /// </summary>
        /// <returns></returns>
        public bool ApplicationEntry()
        {
            if (ApplicationSignal.WaitOne(100))
            {
                Initialize();
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 释放应用锁
        /// </summary>
        public void ReleaseApplicationSignal()
        {
            ApplicationSignal.ReleaseMutex();
        }
        #endregion
 
        
        #region sigleton
        private static G instance;
        private static object lockHelper = new object();
 
        public static G Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (lockHelper)
                    {
                        if (instance == null)
                        {
                            instance = new G();
                        }
                    }
                }
                return instance;
            }
        }
        #endregion
    }
}