同步操作将从 Nevermore阳/SprayProcess-System 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using LiveChartsCore;using LiveChartsCore.SkiaSharpView;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using NLog;using NLog.Extensions.Logging;using SkiaSharp;using SprayProcessSystem.UI.Views;using SprayProcessSystem.DAL;using SqlSugar;using SprayProcessSystem.Model.Entities;using SprayProcessSystem.UI.UserControls.Modals;using SprayProcessSystem.BLL.Managers;using SprayProcessSystem.DAL.Services;using SprayProcessSystem.Helper;using static SprayProcessSystem.Model.Constants;using Masuit.Tools;namespace SprayProcessSystem.UI{internal static class Program{public static IServiceProvider ServiceProvider { get; private set; } = null!;[STAThread]static void Main(){Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);AntdUI.Localization.DefaultLanguage = "zh-CN";AntdUI.Config.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;AntdUI.Style.SetPrimary(Color.FromArgb(64, 158, 255));Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.SetHighDpiMode(HighDpiMode.SystemAware);// 解决 liveCharts 中文乱码问题LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('汉')));ConfigureServices();InitDatabase();// 提前加载总控界面,赋值委托 AppendLogServiceProvider.GetRequiredService<ViewTotalControl>();var mainForm = ServiceProvider.GetRequiredService<MainForm>();Application.Run(mainForm);}private static void InitDatabase(){var db = ServiceProvider.GetRequiredService<ISqlSugarClient>();#if DEBUGdb.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(AuthEntity), typeof(DataEntity), typeof(RecipeEntity), typeof(UserEntity));#endif// 如果 Data 目录下不存在 SprayProcessSystem.db 文件,则创建if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "SprayProcessSystem.db"))){db.DbMaintenance.CreateDatabase();db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(AuthEntity), typeof(DataEntity), typeof(RecipeEntity), typeof(UserEntity));}var list = EnumHelper.GetAllEnumDescriptionArray<NavigationType>();var allAuthList = list.Select(x => x.Description).ToArray();var engineerAuthList = list.Where(x => x.Value != NavigationType.UserManage).Select(x => x.Description).ToArray();var operatorAuthList = new[] { "生产看板", "产线总控" };var visitorAuthList = new[] { "生产看板" };// Auth 表初始化if (!db.Queryable<AuthEntity>().Any()){db.Insertable(new AuthEntity(){Role = "开发者",Auths = AESHelper.Encrypt(string.Join(",", allAuthList), AESHelper.EncryptKey)}).ExecuteCommand();db.Insertable(new AuthEntity(){Role = "管理员",Auths = AESHelper.Encrypt(string.Join(",", allAuthList), AESHelper.EncryptKey)}).ExecuteCommand();db.Insertable(new AuthEntity(){Role = "工程师",Auths = AESHelper.Encrypt(string.Join(",", engineerAuthList), AESHelper.EncryptKey)}).ExecuteCommand();db.Insertable(new AuthEntity(){Role = "操作员",Auths = AESHelper.Encrypt(string.Join(",", operatorAuthList), AESHelper.EncryptKey)}).ExecuteCommand();db.Insertable(new AuthEntity(){Role = "访客",Auths = AESHelper.Encrypt(string.Join(",", visitorAuthList), AESHelper.EncryptKey)}).ExecuteCommand();}// 如果 User 表里没有 Admin,则添加if (!db.Queryable<UserEntity>().Any(x => x.UserName.ToLower() == "admin")){db.Insertable(new UserEntity(){UserName = "admin",Password = Database.HashValue("admin"),Role = "管理员",NickName = "默认管理员",IsEnabled = true}).ExecuteCommand();}if (!db.Queryable<UserEntity>().Any(x => x.UserName.ToLower() == "dev")){db.Insertable(new UserEntity(){UserName = "dev",Password = Database.HashValue("dev"),Role = "开发者",NickName = "开发者模式",IsEnabled = true}).ExecuteCommand();}}private static void ConfigureServices(){var services = new ServiceCollection();var config = new ConfigurationBuilder().SetBasePath(Path.Combine(Environment.CurrentDirectory, "Configs")).AddJsonFile("appsettings.json").Build();services.AddSingleton<IConfiguration>(config).AddLogging(loggerBuilder =>{loggerBuilder.ClearProviders(); //清除其他日志的提供者loggerBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); //设置等级loggerBuilder.AddNLog(config);});//获取存储在 appsettings.json 中的 NLog 配置信息var nlogConfig = config.GetSection("NLog");//设置 NLog 配置LogManager.Configuration = new NLogLoggingConfiguration(nlogConfig);var sqlSugarConfig = config.GetSection("SqlSugar");var dbType = Enum.Parse<DbType>(sqlSugarConfig["DbType"]);var connectionString = sqlSugarConfig[$"{dbType}:ConnectionString"];services.AddSingleton<UserService>();services.AddSingleton<UserManager>(sp => new UserManager(sp.GetService<UserService>()));services.AddSingleton<AuthService>();services.AddSingleton<AuthManager>(sp => new AuthManager(sp.GetService<AuthService>()));services.AddSingleton<RecipeService>();services.AddSingleton<RecipeManager>(sp => new RecipeManager(sp.GetService<RecipeService>()));services.AddSingleton<DataService>();services.AddSingleton<DataManager>(sp => new DataManager(sp.GetService<DataService>()));services.AddSqlSugarSetup(dbType, connectionString);services.AddSingleton<MainForm>();services.AddSingleton<ViewProductionBoard>();services.AddSingleton<ViewTotalControl>();services.AddTransient<ViewRecipeManage>();services.AddSingleton<ViewChartManage>();services.AddSingleton<ViewReportManage>();services.AddTransient<ViewLogManage>();services.AddTransient<ViewUserManage>();services.AddTransient<ViewSettings>();services.AddTransient<ModalUserEdit>();services.AddTransient<ModalLogin>();ServiceProvider = services.BuildServiceProvider();foreach (var item in services){if (item.ServiceType.Name.StartsWith("View")){Global.ViewToLifetimeDict.Add(item.ServiceType.Name, item.Lifetime);}}}// 捕获UI线程中的未处理异常static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e){LogManager.GetCurrentClassLogger().Warn(e.Exception.Message, "未处理的UI线程异常");}// 捕获非UI线程中的未处理异常static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e){var ex = (Exception)e.ExceptionObject;LogManager.GetCurrentClassLogger().Warn(ex.Message, "未处理的非UI线程异常");}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。