2025-05-29 08:58:58 +08:00
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PMSWPF
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
|
{
|
2025-06-10 20:55:39 +08:00
|
|
|
|
public new static App Current => (App)Application.Current;
|
|
|
|
|
|
public IServiceProvider Services { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public App()
|
2025-05-29 08:58:58 +08:00
|
|
|
|
{
|
2025-06-10 20:55:39 +08:00
|
|
|
|
var container = new ServiceCollection();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
|
|
|
|
|
|
var nlog = LogManager.Setup().LoadConfigurationFromFile("Config/nlog.config").GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
|
|
container.AddLogging(loggingBuilder =>
|
|
|
|
|
|
{
|
|
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
|
loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
|
|
|
|
|
loggingBuilder.AddNLog();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-06-10 20:55:39 +08:00
|
|
|
|
container.AddSingleton<NavgatorServices>();
|
2025-06-12 18:41:46 +08:00
|
|
|
|
container.AddSingleton<DevicesRepositories>();
|
2025-06-12 13:15:55 +08:00
|
|
|
|
container.AddSingleton<IDeviceDialogService, DeviceDialogService>();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
container.AddSingleton<GrowlNotificationService>();
|
2025-06-10 20:55:39 +08:00
|
|
|
|
container.AddSingleton<MainViewModel>();
|
|
|
|
|
|
container.AddSingleton<HomeViewModel>();
|
|
|
|
|
|
container.AddSingleton<DevicesViewModel>();
|
|
|
|
|
|
container.AddSingleton<DataTransformViewModel>();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
container.AddSingleton<SettingViewModel>();
|
|
|
|
|
|
container.AddSingleton<SettingView>();
|
|
|
|
|
|
container.AddSingleton<MainView>();
|
2025-06-10 20:55:39 +08:00
|
|
|
|
container.AddSingleton<HomeView>();
|
|
|
|
|
|
container.AddSingleton<DevicesView>();
|
|
|
|
|
|
container.AddSingleton<DataTransformViewModel>();
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
2025-06-10 20:55:39 +08:00
|
|
|
|
Services = container.BuildServiceProvider();
|
2025-06-23 13:42:02 +08:00
|
|
|
|
// 启动服务
|
|
|
|
|
|
Services.GetRequiredService<GrowlNotificationService>();
|
2025-05-29 08:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-10 20:55:39 +08:00
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
2025-05-29 08:58:58 +08:00
|
|
|
|
{
|
2025-06-10 20:55:39 +08:00
|
|
|
|
base.OnStartup(e);
|
2025-06-23 13:42:02 +08:00
|
|
|
|
InitDB();
|
|
|
|
|
|
|
2025-06-10 20:55:39 +08:00
|
|
|
|
MainWindow = Services.GetRequiredService<MainView>();
|
|
|
|
|
|
MainWindow.Show();
|
2025-05-29 08:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-23 13:42:02 +08:00
|
|
|
|
private void InitDB()
|
2025-06-20 18:53:29 +08:00
|
|
|
|
{
|
2025-06-23 13:42:02 +08:00
|
|
|
|
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-20 18:53:29 +08:00
|
|
|
|
}
|
2025-06-10 20:55:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|