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<Int32, string> updateState = null;
|
private Action stopTaskUI = null;
|
internal void EnableWriter(Action<string> debugWriter,Action<string> infoWriter, Action<Int64> remainWriter, Func< Int64, bool> cancelConfirm,Action stopTaskUI,Action<Int32,string> updateState)
|
{
|
this.debugWriter = debugWriter;
|
this.infoWriter = infoWriter;
|
this.remainTimeWriter = remainWriter;
|
this.cancelConfirm = cancelConfirm;
|
this.stopTaskUI = stopTaskUI;
|
this.updateState = updateState;
|
}
|
|
/// <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>
|
/// <param name="index"></param>
|
/// <param name="text"></param>
|
public void UpdateState(Int32 index, string text)
|
{
|
this.updateState(index, text);
|
}
|
|
/// <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
|
}
|
}
|