|
|
|
|
|
using Masuit.Tools.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using SharpCompress.Common;
|
|
|
|
|
|
using System.Timers;
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
|
using Khd.Core.Wcs.Global;
|
|
|
|
|
|
using Khd.Core.Wcs;
|
|
|
|
|
|
|
|
|
|
|
|
internal class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
public static IHost _host;
|
|
|
|
|
|
private static void Main(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
init(); //初始化加载配置文件
|
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler; //全局异常捕获
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
bool ret;
|
|
|
|
|
|
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "服务端", out ret);
|
|
|
|
|
|
if (ret)
|
|
|
|
|
|
{
|
|
|
|
|
|
IHost host = CreateHostBuilder(args).Build();
|
|
|
|
|
|
_host = host;
|
|
|
|
|
|
Console.WriteLine("系统启动开始 :" + DateTime.Now);
|
|
|
|
|
|
|
|
|
|
|
|
MainCentralControl main = new MainCentralControl(host);
|
|
|
|
|
|
main.Start();
|
|
|
|
|
|
//while (true)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Console.ReadLine();
|
|
|
|
|
|
//}
|
|
|
|
|
|
mutex.ReleaseMutex(); // 释放 Mutex
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Write("系统重复开启,请先关闭之前窗口");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Write("系统启动异常:" + ex.Message + "\n" + ex.StackTrace);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Exception exception = e.ExceptionObject as Exception;
|
|
|
|
|
|
if (exception != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("全局异常捕获:");
|
|
|
|
|
|
Console.WriteLine(exception.Message);
|
|
|
|
|
|
Console.WriteLine(exception.StackTrace);
|
|
|
|
|
|
LogManager.Info("全局异常捕获:" + exception.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("未知异常捕获:");
|
|
|
|
|
|
Console.WriteLine(e.ExceptionObject);
|
|
|
|
|
|
LogManager.Info("未知异常捕获:" + e.ExceptionObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化加载配置文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void init()
|
|
|
|
|
|
{
|
|
|
|
|
|
IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
|
|
|
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
|
|
|
|
.AddJsonFile("appsettings.json")
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
PlcConfig.CpuType = configuration["PlcConfig:CpuType"].ToInt32(40);
|
|
|
|
|
|
PlcConfig.IP = configuration["PlcConfig:IP"].ToString();
|
|
|
|
|
|
PlcConfig.Port = configuration["PlcConfig:Port"].ToInt32(102);
|
|
|
|
|
|
PlcConfig.Rack = (short)(configuration["PlcConfig:Rack"].ToInt32(0));
|
|
|
|
|
|
PlcConfig.Slot = (short)(configuration["PlcConfig:Slot"].ToInt32(0));
|
|
|
|
|
|
ConnectionStrings.ConnectionString = configuration["ConnectionStrings:DefaultConnection"].ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
|
|
.ConfigureServices((_, services) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
//services.AddDbContext<DefaultDbContext>(options =>
|
|
|
|
|
|
// options.UseSqlServer(ConnectionStrings.ConnectionString));
|
|
|
|
|
|
services.AddDbContext<DefaultDbContext>(options =>
|
|
|
|
|
|
options.UseMySql(ConnectionStrings.ConnectionString, new MySqlServerVersion(new Version(8, 0, 31))));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|