From 7cb0a952ac0eeca28dc33422373102000c70e49c Mon Sep 17 00:00:00 2001 From: wenjy Date: Tue, 16 Jan 2024 11:32:21 +0800 Subject: [PATCH] add - SlnMesnac.WPF --- SlnMesnac.Serilog/SerilogExtensions.cs | 2 - SlnMesnac.WPF/App.xaml | 9 +++ SlnMesnac.WPF/App.xaml.cs | 54 +++++++++++++++++ SlnMesnac.WPF/AssemblyInfo.cs | 10 +++ SlnMesnac.WPF/MainWindow.xaml | 12 ++++ SlnMesnac.WPF/MainWindow.xaml.cs | 28 +++++++++ SlnMesnac.WPF/SlnMesnac.WPF.csproj | 30 +++++++++ SlnMesnac.WPF/Startup.cs | 84 ++++++++++++++++++++++++++ SlnMesnac.WPF/appsettings.json | 15 +++++ SlnMesnac.sln | 16 +++-- 10 files changed, 253 insertions(+), 7 deletions(-) create mode 100644 SlnMesnac.WPF/App.xaml create mode 100644 SlnMesnac.WPF/App.xaml.cs create mode 100644 SlnMesnac.WPF/AssemblyInfo.cs create mode 100644 SlnMesnac.WPF/MainWindow.xaml create mode 100644 SlnMesnac.WPF/MainWindow.xaml.cs create mode 100644 SlnMesnac.WPF/SlnMesnac.WPF.csproj create mode 100644 SlnMesnac.WPF/Startup.cs create mode 100644 SlnMesnac.WPF/appsettings.json diff --git a/SlnMesnac.Serilog/SerilogExtensions.cs b/SlnMesnac.Serilog/SerilogExtensions.cs index 559fd0a..b2f1846 100644 --- a/SlnMesnac.Serilog/SerilogExtensions.cs +++ b/SlnMesnac.Serilog/SerilogExtensions.cs @@ -31,8 +31,6 @@ namespace SlnMesnac.Serilog .CreateLogger(); app.UseSerilogRequestLogging(); - Log.Information($"项目初始化完成,日志存放路径:{appConfig.logPath}"); - return app; } } diff --git a/SlnMesnac.WPF/App.xaml b/SlnMesnac.WPF/App.xaml new file mode 100644 index 0000000..e613bdf --- /dev/null +++ b/SlnMesnac.WPF/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs new file mode 100644 index 0000000..7bad7db --- /dev/null +++ b/SlnMesnac.WPF/App.xaml.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using SlnMesnac.Config; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace SlnMesnac.WPF +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public static IServiceProvider ServiceProvider; + + // Startup事件 + protected override async void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + var host = CreateHostBuilder(e.Args).Build();//生成宿主。 + + ServiceProvider = host.Services; + await host.StartAsync(); + + var appConfig = host.Services.GetService(); + var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; + Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}"); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .UseSerilog() + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + + // Exit事件 + protected override void OnExit(ExitEventArgs e) + { + base.OnExit(e); + + // 释放资源 + // ... + } + } +} diff --git a/SlnMesnac.WPF/AssemblyInfo.cs b/SlnMesnac.WPF/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/SlnMesnac.WPF/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml new file mode 100644 index 0000000..1c3a2e8 --- /dev/null +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/SlnMesnac.WPF/MainWindow.xaml.cs b/SlnMesnac.WPF/MainWindow.xaml.cs new file mode 100644 index 0000000..e09e3df --- /dev/null +++ b/SlnMesnac.WPF/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SlnMesnac.WPF +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj new file mode 100644 index 0000000..d3832b7 --- /dev/null +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -0,0 +1,30 @@ + + + + Exe + net6.0-windows + enable + true + + + + + + + + + PreserveNewest + + + + + + + + + + + + + + diff --git a/SlnMesnac.WPF/Startup.cs b/SlnMesnac.WPF/Startup.cs new file mode 100644 index 0000000..9b91b65 --- /dev/null +++ b/SlnMesnac.WPF/Startup.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using SlnMesnac.Config; +using SlnMesnac.Common; +using SlnMesnac.Quartz; +using SlnMesnac.Repository; +using SlnMesnac.Plc; +using SlnMesnac.Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; + +namespace SlnMesnac.WPF +{ + /// + /// + /// + public class Startup + { + /// + /// This method gets called by the runtime. Use this method to add services to the container. + /// + /// + [Obsolete] + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + + //注册配置类 + services.AddSingleton(provider => + { + var configuration = provider.GetService(); + return configuration.GetSection("AppConfig").Get(); + + }); + + //注册通用类 + services.AddCommonSetup(); + + //注册SqlSugar + services.AddSqlSugarSetup(); + + //注册服务 + services.AddServices(); + + //注册任务调度 + services.AddQuartzSetUp(); + + //注册PLC + services.AddPlcSetup(); + } + + /// + /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + /// + /// + /// + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + //启用Serilog中间件 + app.UseSerilogExtensions(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + + } + } +} \ No newline at end of file diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json new file mode 100644 index 0000000..d05c71e --- /dev/null +++ b/SlnMesnac.WPF/appsettings.json @@ -0,0 +1,15 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "AppConfig": { + "logPath": "E:\\桌面\\日常代码\\SlnMesnac\\SlnMesnac\\bin\\Debug\\net6.0", + "mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS", + "mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma" + } +} diff --git a/SlnMesnac.sln b/SlnMesnac.sln index 9f80800..6bd8d16 100644 --- a/SlnMesnac.sln +++ b/SlnMesnac.sln @@ -9,15 +9,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Common", "SlnMesn EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Config", "SlnMesnac.Config\SlnMesnac.Config.csproj", "{6EF7F087-7149-4689-885C-E0D05E1A9AA8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Model", "SlnMesnac.Model\SlnMesnac.Model.csproj", "{9EC081B6-971F-418C-A40C-5B8AD2E27417}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Model", "SlnMesnac.Model\SlnMesnac.Model.csproj", "{9EC081B6-971F-418C-A40C-5B8AD2E27417}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Repository", "SlnMesnac.Repository\SlnMesnac.Repository.csproj", "{C892C06A-496B-43B6-AEC7-AF9D70778C0C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Repository", "SlnMesnac.Repository\SlnMesnac.Repository.csproj", "{C892C06A-496B-43B6-AEC7-AF9D70778C0C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Quartz", "SlnMesnac.Quartz\SlnMesnac.Quartz.csproj", "{12ED397C-951E-411C-9C43-CDABA79CA45B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Quartz", "SlnMesnac.Quartz\SlnMesnac.Quartz.csproj", "{12ED397C-951E-411C-9C43-CDABA79CA45B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Serilog", "SlnMesnac.Serilog\SlnMesnac.Serilog.csproj", "{DEE2F305-733C-47C8-891C-502121ABAD00}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Serilog", "SlnMesnac.Serilog\SlnMesnac.Serilog.csproj", "{DEE2F305-733C-47C8-891C-502121ABAD00}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Plc", "SlnMesnac.Plc\SlnMesnac.Plc.csproj", "{D17E9024-9D25-4CE4-8E98-8A6C859CE436}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Plc", "SlnMesnac.Plc\SlnMesnac.Plc.csproj", "{D17E9024-9D25-4CE4-8E98-8A6C859CE436}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.WPF", "SlnMesnac.WPF\SlnMesnac.WPF.csproj", "{B986555B-86D1-457A-95F5-B9135B9FBC55}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,6 +59,10 @@ Global {D17E9024-9D25-4CE4-8E98-8A6C859CE436}.Debug|Any CPU.Build.0 = Debug|Any CPU {D17E9024-9D25-4CE4-8E98-8A6C859CE436}.Release|Any CPU.ActiveCfg = Release|Any CPU {D17E9024-9D25-4CE4-8E98-8A6C859CE436}.Release|Any CPU.Build.0 = Release|Any CPU + {B986555B-86D1-457A-95F5-B9135B9FBC55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B986555B-86D1-457A-95F5-B9135B9FBC55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B986555B-86D1-457A-95F5-B9135B9FBC55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B986555B-86D1-457A-95F5-B9135B9FBC55}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE