using DataCollection.Tools;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;

namespace DataCollection
{
    internal class Program
    {
        static void Main(string[] args)
        {
            bool createnew = false;
            Mutex mutex = new Mutex(true, typeof(DataCollection.Service).FullName, out createnew);
            if (!createnew) return;
            LogTool.Init();
            Service service = new Service();
            try
            {
                service.Init();
                LogTool.WriteLog($"初始化成功");
            }
            catch (Exception ex)
            {
                LogTool.WriteLog($"初始化失败:{Newtonsoft.Json.JsonConvert.SerializeObject(ex)}");
            }
            try
            {
                service.Start();
                LogTool.WriteLog($"启动成功");
            }
            catch (Exception ex)
            {
                LogTool.WriteLog($"启动失败:{ex.Message}");
            }
            Thread.Sleep(-1);
            service.Stop();
            LogTool.WriteLog($"程序退出");
        }
    }
}
