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() { } /// /// 初始化 /// private void Initialize() { this.InputControl = new HardwareInputControl(); } /// /// 释放资料 /// public void Release() { this.InputControl.Close(); this.ApplicationSignal.Close(); } /// /// 输入控制 /// public HardwareInputControl InputControl { get; private set; } #region 日志,剩余时间,属性 private Action debugWriter = null; private Action infoWriter = null; private Action remainTimeWriter = null; private Func cancelConfirm = null; private Action updateState = null; private Action stopTaskUI = null; internal void EnableWriter(Action debugWriter,Action infoWriter, Action remainWriter, Func< Int64, bool> cancelConfirm,Action stopTaskUI,Action updateState) { this.debugWriter = debugWriter; this.infoWriter = infoWriter; this.remainTimeWriter = remainWriter; this.cancelConfirm = cancelConfirm; this.stopTaskUI = stopTaskUI; this.updateState = updateState; } /// /// 显示调试信息 /// /// public void DebugWriter(string msg) { debugWriter(msg); } /// /// 显示关键信息 /// /// public void InfoWriter(string msg) { infoWriter(msg); } /// /// 显示剩余时间 /// /// public void RemainTimeWriter(Int64 remainSecond) { remainTimeWriter(remainSecond); } /// /// 发起取消确认 /// /// /// /// public bool CancelConfirm(string msg, Int64 remainMillSecond) { debugWriter(msg); WindowUtils.SetSelfToTop(); return cancelConfirm( remainMillSecond); } /// /// 更新状态 /// /// /// public void UpdateState(Int32 index, string text) { this.updateState(index, text); } /// /// 停止任务 /// public void StopTaskUI() { this.stopTaskUI(); } #endregion #region 防多次运行 /// /// 应用程序唯一实例 /// private Mutex ApplicationSignal = new Mutex(false, "RichCreator"); /// /// 确定应用程序唯一实例 /// /// public bool ApplicationEntry() { if (ApplicationSignal.WaitOne(100)) { Initialize(); return true; } return false; } /// /// 释放应用锁 /// 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 } }