临时提交
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
using System.Windows;
|
||||
using DMS.Infrastructure;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using DMS.Enums;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Helper;
|
||||
using DMS.Services;
|
||||
using DMS.Services.Processors;
|
||||
@@ -16,6 +15,11 @@ using NLog.Extensions.Logging;
|
||||
using DMS.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using DMS.Config;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.WPF.Helper;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.Services.Processors;
|
||||
using DMS.WPF.ViewModels.DMS.ViewModels;
|
||||
using SqlSugar;
|
||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||
|
||||
@@ -24,7 +28,7 @@ namespace DMS;
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
public partial class App : System.Windows.Application
|
||||
{
|
||||
public IServiceProvider Services { get; }
|
||||
|
||||
@@ -43,7 +47,7 @@ public partial class App : Application
|
||||
Services = Host.Services;
|
||||
}
|
||||
|
||||
public new static App Current => (App)Application.Current;
|
||||
public new static App Current => (App)System.Windows.Application.Current;
|
||||
public IHost Host { get; }
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
@@ -55,8 +59,9 @@ public partial class App : Application
|
||||
|
||||
try
|
||||
{
|
||||
InitializeDataBase();
|
||||
InitializeMenu()
|
||||
var databaseInitializer = Host.Services.GetRequiredService<DMS.Infrastructure.Services.DatabaseInitializerService>();
|
||||
databaseInitializer.InitializeDataBase();
|
||||
await databaseInitializer.InitializeMenu()
|
||||
.Await((e) => { NotificationHelper.ShowError($"初始化主菜单失败:{e.Message}", e); },
|
||||
() => { MessageHelper.SendLoadMessage(LoadTypes.Menu); });
|
||||
Host.Services.GetRequiredService<GrowlNotificationService>();
|
||||
@@ -67,7 +72,7 @@ public partial class App : Application
|
||||
dataProcessingService.AddProcessor(Host.Services.GetRequiredService<LoggingProcessor>());
|
||||
dataProcessingService.AddProcessor(Host.Services.GetRequiredService<MqttPublishProcessor>());
|
||||
dataProcessingService.AddProcessor(Host.Services.GetRequiredService<UpdateDbVariableProcessor>());
|
||||
dataProcessingService.AddProcessor(Host.Services.GetRequiredService<HistoryProcessor>());
|
||||
//dataProcessingService.AddProcessor(Host.Services.GetRequiredService<HistoryProcessor>());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -100,9 +105,22 @@ public partial class App : Application
|
||||
|
||||
private void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Register ConnectionSettings
|
||||
services.AddSingleton(ConnectionSettings.Load());
|
||||
|
||||
// Register SqlSugarDbContext (concrete type, used by DatabaseInitializerService)
|
||||
// SqlSugarDbContext now internally creates SqlSugarClient using ConnectionSettings
|
||||
services.AddScoped<DMS.Infrastructure.Data.SqlSugarDbContext>();
|
||||
|
||||
// Register IUnitOfWork (abstract interface for transaction management)
|
||||
services.AddScoped<DMS.Core.Interfaces.IUnitOfWork, DMS.Infrastructure.Data.SqlSugarDbContext>();
|
||||
|
||||
// Register IDatabaseService (abstract interface for database initialization)
|
||||
services.AddSingleton<DMS.Core.Interfaces.IDatabaseService, DMS.Infrastructure.Services.DatabaseInitializerService>();
|
||||
|
||||
services.AddSingleton<DataServices>();
|
||||
services.AddSingleton<NavgatorServices>();
|
||||
services.AddSingleton<IDialogService, DialogService>();
|
||||
//services.AddSingleton<IDialogService, DialogService>();
|
||||
services.AddSingleton<GrowlNotificationService>();
|
||||
services.AddHostedService<S7BackgroundService>();
|
||||
services.AddHostedService<OpcUaBackgroundService>();
|
||||
@@ -189,72 +207,5 @@ public partial class App : Application
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化菜单
|
||||
/// </summary>
|
||||
private async Task InitializeMenu()
|
||||
{
|
||||
using (var db = DbContext.GetInstance())
|
||||
{
|
||||
var homeMenu = new DbMenu()
|
||||
{ Name = "主页", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Home.Glyph, ParentId = 0 };
|
||||
|
||||
var deviceMenu = new DbMenu()
|
||||
{
|
||||
Name = "设备", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Devices3.Glyph,
|
||||
ParentId = 0
|
||||
};
|
||||
var dataTransfromMenu = new DbMenu()
|
||||
{
|
||||
Name = "数据转换", Type = MenuType.MainMenu,
|
||||
Icon = SegoeFluentIcons.ChromeSwitch.Glyph, ParentId = 0
|
||||
};
|
||||
var mqttMenu = new DbMenu()
|
||||
{
|
||||
Name = "Mqtt服务器", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Cloud.Glyph,
|
||||
ParentId = 0
|
||||
};
|
||||
|
||||
var settingMenu = new DbMenu()
|
||||
{
|
||||
Name = "设置", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Settings.Glyph,
|
||||
ParentId = 0
|
||||
};
|
||||
var aboutMenu = new DbMenu()
|
||||
{ Name = "关于", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Info.Glyph, ParentId = 0 };
|
||||
await CheckMainMenuExist(db, homeMenu);
|
||||
await CheckMainMenuExist(db, deviceMenu);
|
||||
await CheckMainMenuExist(db, dataTransfromMenu);
|
||||
await CheckMainMenuExist(db, mqttMenu);
|
||||
await CheckMainMenuExist(db, settingMenu);
|
||||
await CheckMainMenuExist(db, aboutMenu);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task CheckMainMenuExist(SqlSugarClient db, DbMenu menu)
|
||||
{
|
||||
var homeMenuExist = await db.Queryable<DbMenu>()
|
||||
.FirstAsync(dm => dm.Name == menu.Name);
|
||||
if (homeMenuExist == null)
|
||||
{
|
||||
await db.Insertable<DbMenu>(menu)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeDataBase()
|
||||
{
|
||||
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<DbVariable>();
|
||||
_db.CodeFirst.InitTables<DbVariableHistory>();
|
||||
_db.CodeFirst.InitTables<DbUser>();
|
||||
_db.CodeFirst.InitTables<DbMqtt>();
|
||||
_db.CodeFirst.InitTables<DbVariableMqtt>();
|
||||
_db.CodeFirst.InitTables<DbMenu>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -149,4 +149,9 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DMS.Application\DMS.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using DMS.Data.Entities;
|
||||
using DMS.Models;
|
||||
using DMS.Helper;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.WPF.Models;
|
||||
|
||||
namespace DMS.Extensions;
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Models;
|
||||
using DMS.ViewModels;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.WPF.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DMS.Helper;
|
||||
namespace DMS.WPF.Helper;
|
||||
|
||||
public class DataServicesHelper
|
||||
{
|
||||
@@ -122,4 +125,4 @@ public class DataServicesHelper
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Message;
|
||||
using DMS.ViewModels;
|
||||
using DMS.WPF.Message;
|
||||
using DMS.WPF.ViewModels;
|
||||
|
||||
namespace DMS.Helper;
|
||||
namespace DMS.WPF.Helper;
|
||||
|
||||
public class MessageHelper
|
||||
{
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using DMS.Config;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using iNKORE.UI.WPF.Modern;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace DMS.Helper;
|
||||
namespace DMS.WPF.Helper;
|
||||
|
||||
public static class ThemeHelper
|
||||
{
|
||||
@@ -93,4 +94,4 @@ public static class ThemeHelper
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
using S7.Net; // AddAsync this using directive
|
||||
|
||||
namespace DMS.Models;
|
||||
namespace DMS.WPF.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示设备信息。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
namespace DMS.WPF.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示MQTT配置信息。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
namespace DMS.WPF.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示变量数据信息。
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Concurrent;
|
||||
using AutoMapper;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using DMS.Data.Repositories;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.WPF.Message;
|
||||
using DMS.WPF.ViewModels;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Helper;
|
||||
using DMS.Message;
|
||||
using DMS.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DMS.ViewModels;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Services;
|
||||
namespace DMS.WPF.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 数据服务类,负责从数据库加载和管理各种数据,并提供数据变更通知。
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Models;
|
||||
using DMS.ViewModels.Dialogs;
|
||||
using DMS.Views.Dialogs;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.Views.Dialogs;
|
||||
using HandyControl.Tools.Extension;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using DMS.Data.Repositories;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
|
||||
namespace DMS.Services;
|
||||
namespace DMS.WPF.Services;
|
||||
|
||||
public class DialogService :IDialogService
|
||||
{
|
||||
|
||||
@@ -4,14 +4,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DMS.Data;
|
||||
using DMS.Data.Entities;
|
||||
using DMS.Helper;
|
||||
using DMS.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.WPF.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DMS.Services;
|
||||
|
||||
namespace DMS.Services.Processors;
|
||||
namespace DMS.WPF.Services.Processors;
|
||||
|
||||
public class HistoryProcessor : IVariableProcessor, IDisposable
|
||||
{
|
||||
@@ -91,4 +90,4 @@ public class HistoryProcessor : IVariableProcessor, IDisposable
|
||||
// 在 Dispose 时,尝试将剩余数据写入数据库
|
||||
FlushQueueToDatabase().Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Data;
|
||||
using DMS.Data.Repositories;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Helper;
|
||||
using DMS.Models;
|
||||
using DMS.Services;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
|
||||
namespace DMS.WPF.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DMS.ViewModels;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Models;
|
||||
using S7.Net; // AddAsync this using directive
|
||||
using DMS.WPF.Models;
|
||||
using S7.Net;
|
||||
|
||||
namespace DMS.ViewModels.Dialogs;
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class DeviceDialogViewModel : ObservableObject
|
||||
{
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Data;
|
||||
using DMS.Data.Repositories;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Helper;
|
||||
using DMS.Models;
|
||||
using DMS.Services;
|
||||
using DMS.Views;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.Views;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
|
||||
namespace DMS.WPF.ViewModels;
|
||||
using iNKORE.UI.WPF.Modern.Common.IconKeys;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
using DMS.ViewModels;
|
||||
using System.Windows.Controls;
|
||||
using DMS.WPF.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DMS.Views;
|
||||
namespace DMS.WPF.Views;
|
||||
|
||||
public partial class DeviceDetailView : UserControl
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Windows;
|
||||
using DMS.Helper;
|
||||
using DMS.ViewModels.Dialogs;
|
||||
using System.Windows;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using DMS.Models;
|
||||
using DMS.WPF.Models;
|
||||
|
||||
namespace DMS.Views.Dialogs;
|
||||
namespace DMS.WPF.Views.Dialogs;
|
||||
|
||||
public partial class DeviceDialog
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System.Windows;
|
||||
using DMS.Helper;
|
||||
using DMS.Models;
|
||||
using DMS.Services;
|
||||
using DMS.ViewModels;
|
||||
using System.Windows;
|
||||
using DMS.Core.Helper;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.ViewModels;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Views;
|
||||
namespace DMS.WPF.Views;
|
||||
|
||||
/// <summary>
|
||||
/// MainView.xaml 的交互逻辑
|
||||
|
||||
Reference in New Issue
Block a user