2025-06-23 17:01:06 +08:00
|
|
|
|
using System.Windows;
|
2025-06-24 20:48:38 +08:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using iNKORE.UI.WPF.Modern.Common.IconKeys;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-06-23 13:42:02 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using NLog;
|
|
|
|
|
|
using NLog.Extensions.Logging;
|
|
|
|
|
|
using PMSWPF.Data;
|
|
|
|
|
|
using PMSWPF.Data.Entities;
|
2025-06-12 18:41:46 +08:00
|
|
|
|
using PMSWPF.Data.Repositories;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
using PMSWPF.Services;
|
|
|
|
|
|
using PMSWPF.ViewModels;
|
|
|
|
|
|
using PMSWPF.Views;
|
2025-06-23 17:01:06 +08:00
|
|
|
|
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
namespace PMSWPF;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class App : Application
|
2025-05-29 08:58:58 +08:00
|
|
|
|
{
|
2025-06-23 17:01:06 +08:00
|
|
|
|
public App()
|
2025-05-29 08:58:58 +08:00
|
|
|
|
{
|
2025-06-23 17:01:06 +08:00
|
|
|
|
var container = new ServiceCollection();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
var nlog = LogManager.Setup().LoadConfigurationFromFile("Config/nlog.config").GetCurrentClassLogger();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
container.AddLogging(loggingBuilder =>
|
|
|
|
|
|
{
|
|
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
|
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
|
|
|
|
|
|
loggingBuilder.AddNLog();
|
|
|
|
|
|
});
|
2025-06-23 13:42:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
container.AddSingleton<NavgatorServices>();
|
|
|
|
|
|
container.AddSingleton<DevicesRepositories>();
|
|
|
|
|
|
container.AddSingleton<IDeviceDialogService, DeviceDialogService>();
|
|
|
|
|
|
container.AddSingleton<GrowlNotificationService>();
|
|
|
|
|
|
container.AddSingleton<MainViewModel>();
|
|
|
|
|
|
container.AddSingleton<HomeViewModel>();
|
|
|
|
|
|
container.AddSingleton<DevicesViewModel>();
|
|
|
|
|
|
container.AddSingleton<DataTransformViewModel>();
|
|
|
|
|
|
container.AddSingleton<SettingViewModel>();
|
|
|
|
|
|
container.AddSingleton<SettingView>();
|
|
|
|
|
|
container.AddSingleton<MainView>();
|
|
|
|
|
|
container.AddSingleton<HomeView>();
|
|
|
|
|
|
container.AddSingleton<DevicesView>();
|
|
|
|
|
|
container.AddSingleton<DataTransformViewModel>();
|
|
|
|
|
|
container.AddSingleton<VariableTableViewModel>();
|
|
|
|
|
|
container.AddSingleton<VariableTableView>();
|
|
|
|
|
|
Services = container.BuildServiceProvider();
|
|
|
|
|
|
// 启动服务
|
|
|
|
|
|
Services.GetRequiredService<GrowlNotificationService>();
|
|
|
|
|
|
}
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
public new static App Current => (App)Application.Current;
|
|
|
|
|
|
public IServiceProvider Services { get; }
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnStartup(e);
|
|
|
|
|
|
InitDB();
|
2025-06-24 20:48:38 +08:00
|
|
|
|
// InitMenu();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
MainWindow = Services.GetRequiredService<MainView>();
|
|
|
|
|
|
MainWindow.Show();
|
|
|
|
|
|
}
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-24 20:48:38 +08:00
|
|
|
|
private void InitMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var db = DbContext.GetInstance())
|
|
|
|
|
|
{
|
|
|
|
|
|
List<DbMenu> items = new List<DbMenu>();
|
|
|
|
|
|
items.Add(new DbMenu() { Id = 1, Name = "主页", Icon = SegoeFluentIcons.Home.Glyph, ParentId = 0});
|
|
|
|
|
|
items.Add(new DbMenu() { Id = 1, Name = "设备", Icon = SegoeFluentIcons.Devices.Glyph, ParentId = 0});
|
|
|
|
|
|
items.Add(new DbMenu() { Id = 1, Name = "数据转换", Icon = SegoeFluentIcons.Move.Glyph, ParentId = 0});
|
|
|
|
|
|
items.Add(new DbMenu() { Id = 1, Name = "设置", Icon = SegoeFluentIcons.Settings.Glyph, ParentId = 0});
|
|
|
|
|
|
items.Add(new DbMenu() { Id = 1, Name = "关于", Icon = SegoeFluentIcons.Info.Glyph, ParentId = 0});
|
|
|
|
|
|
db.Insertable<DbMenu>(items).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
|
private void InitDB()
|
|
|
|
|
|
{
|
|
|
|
|
|
var _db = DbContext.GetInstance();
|
|
|
|
|
|
_db.DbMaintenance.CreateDatabase();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbNlog>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbNlog>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbDevice>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbVariableTable>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbDataVariable>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbS7DataVariable>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbUser>();
|
|
|
|
|
|
_db.CodeFirst.InitTables<DbMqtt>();
|
2025-06-24 20:48:38 +08:00
|
|
|
|
_db.CodeFirst.InitTables<DbMenu>();
|
2025-06-10 20:55:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|