初步完成Log的增删改查

This commit is contained in:
2025-09-07 19:01:58 +08:00
parent 1f9c0a1111
commit 0e4a306fa7
12 changed files with 596 additions and 34 deletions

View File

@@ -0,0 +1,72 @@
namespace DMS.Application.DTOs;
/// <summary>
/// 用于在UI上显示NLog日志条目的DTO。
/// </summary>
public class NlogDto
{
/// <summary>
/// 日志ID。
/// </summary>
public int Id { get; set; }
/// <summary>
/// 日志记录时间。
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
/// 日志级别 (如 INFO, ERROR 等)。
/// </summary>
public string Level { get; set; }
/// <summary>
/// 线程ID。
/// </summary>
public int ThreadId { get; set; }
/// <summary>
/// 线程名称。
/// </summary>
public string ThreadName { get; set; }
/// <summary>
/// 调用点(通常是记录日志的方法名)。
/// </summary>
public string Callsite { get; set; }
/// <summary>
/// 调用点所在的行号。
/// </summary>
public int CallsiteLineNumber { get; set; }
/// <summary>
/// 日志消息内容。
/// </summary>
public string Message { get; set; }
/// <summary>
/// 记录日志的记录器名称。
/// </summary>
public string Logger { get; set; }
/// <summary>
/// 异常信息(如果有的话)。
/// </summary>
public string Exception { get; set; }
/// <summary>
/// 调用方文件路径。
/// </summary>
public string CallerFilePath { get; set; }
/// <summary>
/// 调用方行号。
/// </summary>
public int CallerLineNumber { get; set; }
/// <summary>
/// 调用方成员(方法名)。
/// </summary>
public string CallerMember { get; set; }
}

View File

@@ -0,0 +1,30 @@
using DMS.Application.DTOs;
namespace DMS.Application.Interfaces;
/// <summary>
/// 定义Nlog日志管理相关的应用服务操作。
/// </summary>
public interface INlogAppService
{
/// <summary>
/// 异步根据ID获取Nlog日志DTO。
/// </summary>
Task<NlogDto> GetLogByIdAsync(int id);
/// <summary>
/// 异步获取所有Nlog日志DTO列表。
/// </summary>
Task<List<NlogDto>> GetAllLogsAsync();
/// <summary>
/// 异步获取指定数量的最新Nlog日志DTO列表。
/// </summary>
/// <param name="count">要获取的日志条目数量。</param>
Task<List<NlogDto>> GetLatestLogsAsync(int count);
// 可以在这里添加更多针对日志的查询服务方法,例如:
// Task<List<NlogDto>> GetLogsByLevelAsync(string level);
// Task<List<NlogDto>> GetLogsByDateRangeAsync(DateTime startDate, DateTime endDate);
// Task<List<NlogDto>> SearchLogsAsync(string searchTerm);
}

View File

@@ -0,0 +1,90 @@
using AutoMapper;
using DMS.Application.DTOs;
using DMS.Application.Interfaces;
using DMS.Core.Interfaces;
namespace DMS.Application.Services;
/// <summary>
/// Nlog日志应用服务负责处理Nlog日志相关的业务逻辑。
/// 实现 <see cref="INlogAppService"/> 接口。
/// </summary>
public class NlogAppService : INlogAppService
{
private readonly IRepositoryManager _repoManager;
private readonly IMapper _mapper;
/// <summary>
/// 构造函数通过依赖注入获取仓储管理器和AutoMapper实例。
/// </summary>
/// <param name="repoManager">仓储管理器实例。</param>
/// <param name="mapper">AutoMapper 实例。</param>
public NlogAppService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
_mapper = mapper;
}
/// <summary>
/// 异步根据ID获取Nlog日志数据传输对象。
/// </summary>
/// <param name="id">日志ID。</param>
/// <returns>Nlog日志数据传输对象。</returns>
public async Task<NlogDto> GetLogByIdAsync(int id)
{
var log = await _repoManager.Nlogs.GetByIdAsync(id);
return _mapper.Map<NlogDto>(log);
}
/// <summary>
/// 异步获取所有Nlog日志数据传输对象列表。
/// </summary>
/// <returns>Nlog日志数据传输对象列表。</returns>
public async Task<List<NlogDto>> GetAllLogsAsync()
{
var logs = await _repoManager.Nlogs.GetAllAsync();
return _mapper.Map<List<NlogDto>>(logs);
}
/// <summary>
/// 异步获取指定数量的最新Nlog日志数据传输对象列表。
/// </summary>
/// <param name="count">要获取的日志条目数量。</param>
/// <returns>最新的Nlog日志数据传输对象列表。</returns>
public async Task<List<NlogDto>> GetLatestLogsAsync(int count)
{
// 注意这里的实现假设仓储层或数据库支持按时间倒序排列并取前N条。
// 如果 BaseRepository 没有提供这种能力,可能需要直接访问 DbNlog 实体。
// 例如var dbLogs = await _repoManager.Nlogs.Db.Queryable<Infrastructure.Entities.DbNlog>().OrderByDescending(n => n.LogTime).Take(count).ToListAsync();
// var logs = _mapper.Map<List<Core.Models.Nlog>>(dbLogs);
// return _mapper.Map<List<NlogDto>>(logs);
// 为简化起见,这里先调用 GetAll 然后在内存中排序和截取(仅适用于日志量不大的情况)。
// 生产环境中建议优化数据库查询。
var allLogs = await GetAllLogsAsync();
return allLogs.OrderByDescending(l => l.LogTime).Take(count).ToList();
}
// 可以在这里实现 INlogAppService 接口中定义的其他方法
// 例如:
/*
public async Task<List<NlogDto>> GetLogsByLevelAsync(string level)
{
// 假设 INlogRepository 有 GetLogsByLevelAsync 方法
var logs = await _repoManager.Nlogs.GetLogsByLevelAsync(level);
return _mapper.Map<List<NlogDto>>(logs);
}
public async Task<List<NlogDto>> GetLogsByDateRangeAsync(DateTime startDate, DateTime endDate)
{
var logs = await _repoManager.Nlogs.GetLogsByDateRangeAsync(startDate, endDate);
return _mapper.Map<List<NlogDto>>(logs);
}
public async Task<List<NlogDto>> SearchLogsAsync(string searchTerm)
{
var logs = await _repoManager.Nlogs.SearchLogsAsync(searchTerm);
return _mapper.Map<List<NlogDto>>(logs);
}
*/
}

View File

@@ -49,6 +49,11 @@ public interface IRepositoryManager : IDisposable
/// </summary>
IUserRepository Users { get; set; }
/// <summary>
/// 获取Nlog日志仓储的实例。
/// </summary>
INlogRepository Nlogs { get; set; }
/// <summary>
/// 初始化数据库
/// </summary>

View File

@@ -0,0 +1,15 @@
using DMS.Core.Models;
namespace DMS.Core.Interfaces.Repositories;
/// <summary>
/// Nlog日志仓储接口定义了对Nlog实体的特定数据访问方法。
/// 继承自通用仓储接口 IBaseRepository<Nlog>。
/// </summary>
public interface INlogRepository : IBaseRepository<Nlog>
{
// 可以在此处添加 Nlog 特定的查询方法,例如:
// Task<List<Nlog>> GetLogsByLevelAsync(string level);
// Task<List<Nlog>> GetLogsByDateRangeAsync(DateTime startDate, DateTime endDate);
// Task<List<Nlog>> SearchLogsAsync(string searchTerm);
}

74
DMS.Core/Models/Nlog.cs Normal file
View File

@@ -0,0 +1,74 @@
using System;
namespace DMS.Core.Models;
/// <summary>
/// 代表一条NLog日志记录。
/// </summary>
public class Nlog
{
/// <summary>
/// 日志ID。
/// </summary>
public int Id { get; set; }
/// <summary>
/// 日志记录时间。
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
/// 日志级别 (如 INFO, ERROR 等)。
/// </summary>
public string Level { get; set; }
/// <summary>
/// 线程ID。
/// </summary>
public int ThreadId { get; set; }
/// <summary>
/// 线程名称。
/// </summary>
public string ThreadName { get; set; }
/// <summary>
/// 调用点(通常是记录日志的方法名)。
/// </summary>
public string Callsite { get; set; }
/// <summary>
/// 调用点所在的行号。
/// </summary>
public int CallsiteLineNumber { get; set; }
/// <summary>
/// 日志消息内容。
/// </summary>
public string Message { get; set; }
/// <summary>
/// 记录日志的记录器名称。
/// </summary>
public string Logger { get; set; }
/// <summary>
/// 异常信息(如果有的话)。
/// </summary>
public string Exception { get; set; }
/// <summary>
/// 调用方文件路径。
/// </summary>
public string CallerFilePath { get; set; }
/// <summary>
/// 调用方行号。
/// </summary>
public int CallerLineNumber { get; set; }
/// <summary>
/// 调用方成员(方法名)。
/// </summary>
public string CallerMember { get; set; }
}

View File

@@ -0,0 +1,88 @@
using SqlSugar;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// NLog日志实体类对应数据库中的 nlog 表。
/// </summary>
[SugarTable("nlog")]
public class DbNlog
{
/// <summary>
/// 日志ID主键且自增。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID")]
public int Id { get; set; }
/// <summary>
/// 日志记录时间。
/// </summary>
[SugarColumn(ColumnName = "LogTime")]
public DateTime LogTime { get; set; }
/// <summary>
/// 日志级别 (如 INFO, ERROR 等)。
/// </summary>
[SugarColumn(ColumnName = "Level")]
public string Level { get; set; }
/// <summary>
/// 线程ID。
/// </summary>
[SugarColumn(ColumnName = "ThreadID")]
public int ThreadId { get; set; }
/// <summary>
/// 线程名称。
/// </summary>
[SugarColumn(ColumnName = "ThreadName", IsNullable = true)]
public string ThreadName { get; set; }
/// <summary>
/// 调用点(通常是记录日志的方法名)。
/// </summary>
[SugarColumn(ColumnName = "Callsite", IsNullable = true)]
public string Callsite { get; set; }
/// <summary>
/// 调用点所在的行号。
/// </summary>
[SugarColumn(ColumnName = "CallsiteLineNumber")]
public int CallsiteLineNumber { get; set; }
/// <summary>
/// 日志消息内容。
/// </summary>
[SugarColumn(ColumnName = "Message")]
public string Message { get; set; }
/// <summary>
/// 记录日志的记录器名称。
/// </summary>
[SugarColumn(ColumnName = "Logger")]
public string Logger { get; set; }
/// <summary>
/// 异常信息(如果有的话)。
/// </summary>
[SugarColumn(ColumnName = "Exception", IsNullable = true)]
public string Exception { get; set; }
/// <summary>
/// 调用方文件路径。
/// </summary>
[SugarColumn(ColumnName = "CallerFilePath", IsNullable = true)]
public string CallerFilePath { get; set; }
/// <summary>
/// 调用方行号。
/// </summary>
[SugarColumn(ColumnName = "CallerLineNumber")]
public int CallerLineNumber { get; set; }
/// <summary>
/// 调用方成员(方法名)。
/// </summary>
[SugarColumn(ColumnName = "CallerMember", IsNullable = true)]
public string CallerMember { get; set; }
}

View File

@@ -0,0 +1,130 @@
using AutoMapper;
using DMS.Core.Interfaces.Repositories;
using DMS.Core.Models;
using DMS.Infrastructure.Data;
using DMS.Infrastructure.Entities;
using Microsoft.Extensions.Logging;
namespace DMS.Infrastructure.Repositories;
/// <summary>
/// Nlog日志仓储实现类负责Nlog日志数据的持久化操作。
/// 继承自 <see cref="BaseRepository{DbNlog}"/> 并实现 <see cref="INlogRepository"/> 接口。
/// </summary>
public class NlogRepository : BaseRepository<DbNlog>, INlogRepository
{
private readonly IMapper _mapper;
/// <summary>
/// 构造函数,注入 AutoMapper 和 SqlSugarDbContext。
/// </summary>
/// <param name="mapper">AutoMapper 实例,用于实体模型和数据库模型之间的映射。</param>
/// <param name="dbContext">SqlSugar 数据库上下文,用于数据库操作。</param>
/// <param name="logger">日志记录器实例。</param>
public NlogRepository(IMapper mapper, SqlSugarDbContext dbContext, ILogger<NlogRepository> logger)
: base(dbContext, logger)
{
_mapper = mapper;
}
// Nlog 通常是只读或追加的日志,因此像 AddAsync, UpdateAsync, DeleteAsync 这样的修改方法
// 可能不需要在仓储接口中暴露,或者可以省略具体实现或抛出 NotSupportedException。
// 但为了保持与基类一致性并满足接口要求,这里显式实现它们。
/// <summary>
/// 异步获取所有Nlog日志条目。
/// </summary>
/// <returns>包含所有Nlog日志实体的列表。</returns>
public new async Task<List<Core.Models.Nlog>> GetAllAsync()
{
var dbList = await base.GetAllAsync();
return _mapper.Map<List<Core.Models.Nlog>>(dbList);
}
/// <summary>
/// 异步根据ID获取单个Nlog日志条目。
/// </summary>
/// <param name="id">日志条目的唯一标识符。</param>
/// <returns>对应的Nlog日志实体如果不存在则为null。</returns>
public new async Task<Core.Models.Nlog> GetByIdAsync(int id)
{
var dbNlog = await base.GetByIdAsync(id);
return _mapper.Map<Core.Models.Nlog>(dbNlog);
}
/// <summary>
/// 异步添加一个新Nlog日志条目。
/// 注意直接写入数据库日志表通常不推荐NLog本身负责写入。
/// 此方法主要用于满足接口契约,实际使用应谨慎。
/// </summary>
/// <param name="entity">要添加的Nlog日志实体。</param>
/// <returns>添加后的Nlog日志实体包含ID等信息。</returns>
public new async Task<Core.Models.Nlog> AddAsync(Core.Models.Nlog entity)
{
var dbEntity = _mapper.Map<DbNlog>(entity);
var addedDbEntity = await base.AddAsync(dbEntity);
return _mapper.Map(addedDbEntity, entity);
}
/// <summary>
/// 异步更新一个Nlog日志条目。
/// 注意:直接更新数据库日志表通常不推荐,日志应视为不可变。
/// 此方法主要用于满足接口契约,实际使用应谨慎。
/// </summary>
/// <param name="entity">要更新的Nlog日志实体。</param>
/// <returns>受影响的行数。</returns>
public new async Task<int> UpdateAsync(Core.Models.Nlog entity)
{
var dbEntity = _mapper.Map<DbNlog>(entity);
return await base.UpdateAsync(dbEntity);
}
/// <summary>
/// 异步删除一个Nlog日志条目。
/// 注意:直接删除数据库日志表记录通常不推荐,除非是清理过期日志。
/// 此方法主要用于满足接口契约,实际使用应谨慎。
/// </summary>
/// <param name="entity">要删除的Nlog日志实体。</param>
/// <returns>受影响的行数。</returns>
public new async Task<int> DeleteAsync(Core.Models.Nlog entity)
{
var dbEntity = _mapper.Map<DbNlog>(entity);
return await base.DeleteAsync(dbEntity);
}
/// <summary>
/// 异步根据ID删除一个Nlog日志条目。
/// 注意:直接删除数据库日志表记录通常不推荐,除非是清理过期日志。
/// 此方法主要用于满足接口契约,实际使用应谨慎。
/// </summary>
/// <param name="id">要删除的Nlog日志条目的ID。</param>
/// <returns>受影响的行数。</returns>
public new async Task<int> DeleteByIdAsync(int id)
{
return await base.DeleteByIdsAsync(new List<int>(){id});
}
/// <summary>
/// 异步获取指定数量的Nlog日志条目。
/// </summary>
/// <param name="number">要获取的条目数量。</param>
/// <returns>包含指定数量Nlog日志实体的列表。</returns>
public new async Task<List<Core.Models.Nlog>> TakeAsync(int number)
{
var dbList = await base.TakeAsync(number);
return _mapper.Map<List<Core.Models.Nlog>>(dbList);
}
/// <summary>
/// 异步批量添加Nlog日志条目。
/// 注意直接批量写入数据库日志表通常不推荐NLog本身负责写入。
/// 此方法主要用于满足接口契约,实际使用应谨慎。
/// </summary>
/// <param name="entities">要添加的Nlog日志实体列表。</param>
/// <returns>操作是否成功。</returns>
public new async Task<bool> AddBatchAsync(List<Core.Models.Nlog> entities)
{
var dbEntities = _mapper.Map<List<DbNlog>>(entities);
return await base.AddBatchAsync(dbEntities);
}
}

View File

@@ -27,6 +27,7 @@ public class RepositoryManager : IRepositoryManager
/// <param name="menus">菜单仓储实例。</param>
/// <param name="variableHistories">变量历史仓储实例。</param>
/// <param name="users">用户仓储实例。</param>
/// <param name="nlogs">Nlog日志仓储实例。</param>
public RepositoryManager( SqlSugarDbContext dbContext,
IInitializeRepository initializeRepository,
IDeviceRepository devices,
@@ -36,7 +37,8 @@ public class RepositoryManager : IRepositoryManager
IVariableMqttAliasRepository variableMqttAliases,
IMenuRepository menus,
IVariableHistoryRepository variableHistories,
IUserRepository users)
IUserRepository users,
INlogRepository nlogs)
{
_dbContext = dbContext;
InitializeRepository = initializeRepository;
@@ -48,6 +50,7 @@ public class RepositoryManager : IRepositoryManager
Menus = menus;
VariableHistories = variableHistories;
Users = users;
Nlogs = nlogs;
_db = dbContext.GetInstance();
}
@@ -93,6 +96,10 @@ public class RepositoryManager : IRepositoryManager
/// </summary>
public IUserRepository Users { get; set; }
/// <summary>
/// 获取Nlog日志仓储实例。
/// </summary>
public INlogRepository Nlogs { get; set; }
/// <summary>
/// 获取初始化仓储实例。
/// </summary>
public IInitializeRepository InitializeRepository { get; set; }

View File

@@ -204,6 +204,7 @@ public partial class App : System.Windows.Application
services.AddSingleton<IMenuRepository, MenuRepository>();
services.AddSingleton<IVariableHistoryRepository, VariableHistoryRepository>();
services.AddSingleton<IUserRepository, UserRepository>();
services.AddSingleton<INlogRepository, NlogRepository>();
services.AddSingleton<IRepositoryManager, RepositoryManager>();
services.AddSingleton<IExcelService, ExcelService>();

View File

@@ -0,0 +1,50 @@
// 文件: DMS.WPF/ViewModels/Items/NlogItemViewModel.cs
using CommunityToolkit.Mvvm.ComponentModel;
namespace DMS.WPF.ViewModels.Items;
/// <summary>
/// 代表日志列表中的单个日志项的ViewModel。
/// 实现了INotifyPropertyChanged其任何属性变化都会自动通知UI。
/// </summary>
public partial class NlogItemViewModel : ObservableObject
{
public int Id { get; set; }
[ObservableProperty]
private DateTime _logTime;
[ObservableProperty]
private string _level;
[ObservableProperty]
private int _threadId;
[ObservableProperty]
private string _threadName;
[ObservableProperty]
private string _callsite;
[ObservableProperty]
private int _callsiteLineNumber;
[ObservableProperty]
private string _message;
[ObservableProperty]
private string _logger;
[ObservableProperty]
private string _exception;
[ObservableProperty]
private string _callerFilePath;
[ObservableProperty]
private int _callerLineNumber;
[ObservableProperty]
private string _callerMember;
}

66
QWEN.md
View File

@@ -1,48 +1,48 @@
# Project Overview: DMS (Device Management System)
# 项目概述:DMS (Device Management System - 设备管理系统)
This directory contains the source code for the Device Management System (DMS), a C#/.NET 8 application. The system is primarily composed of a WPF desktop application for the user interface, backed by a layered architecture including Core, Application, and Infrastructure projects. It also includes dedicated unit test projects for both the infrastructure and WPF layers.
此目录包含了设备管理系统 (DMS) 的源代码,这是一个基于 C#/.NET 8 构建的应用程序。该系统主要由一个用于用户界面的 WPF 桌面应用程序组成,后端采用分层架构,包括 Core核心Application(应用)和 Infrastructure(基础设施)项目。此外,还为基础设施层和 WPF 层配备了专门的单元测试项目。
A significant feature described in the README is an OPC UA service implementation, suggesting the system is designed for industrial device communication and management.
项目自述文件中提到的一个重要特性是 OPC UA 服务实现,表明该系统是为工业设备通信和管理而设计的。
## Project Structure
## 项目结构
The solution (`DMS.sln`) is organized into several key projects:
解决方案 (`DMS.sln`) 由几个关键项目组成:
* **`DMS.Core`**: Contains fundamental, reusable components and shared models. Likely includes utilities, common data transfer objects (DTOs), and core business logic abstractions. It references `Microsoft.Extensions.Logging.Abstractions`, `Newtonsoft.Json`, and `NLog`.
* **`DMS.Application`**: Implements application-specific business logic. It depends on `DMS.Core` and uses libraries like `AutoMapper` for object mapping and `Microsoft.Extensions` for hosting and logging abstractions.
* **`DMS.Infrastructure`**: Handles data access, external integrations, and technical implementations. It references `DMS.Core` and `DMS.Application`. Key dependencies include:
* `SqlSugarCore`: For database interaction (MySQL).
* `MQTTnet`: For MQTT protocol communication.
* `OPCFoundation.NetStandard.Opc.Ua`: For OPC UA communication.
* `S7netplus`: For Siemens S7 PLC communication.
* `NPOI`: For reading/writing Excel files.
* `AutoMapper.Extensions.Microsoft.DependencyInjection`: For dependency injection setup of AutoMapper.
* **`DMS.WPF`**: The main WPF desktop application. It targets `net8.0-windows` and uses WPF-specific libraries like `CommunityToolkit.Mvvm`, `HandyControl` (UI toolkit), `Hardcodet.NotifyIcon.Wpf` (system tray icon), and `iNKORE.UI.WPF.Modern` (modern UI styling). It depends on `DMS.Application` and `DMS.Infrastructure`.
* **`DMS.Infrastructure.UnitTests`**: Unit tests for the `DMS.Infrastructure` project. Uses `xunit`, `Moq`, `Bogus` (for fake data), and `Microsoft.NET.Test.Sdk`.
* **`DMS.WPF.UnitTests`**: Unit tests for the `DMS.WPF` project. Also uses `xunit`, `Moq`, and `Bogus`.
* **`DMS.Core`**: 包含基础的、可复用的组件和共享模型。可能包括实用工具、通用数据传输对象 (DTOs) 以及核心业务逻辑抽象。它引用了 `Microsoft.Extensions.Logging.Abstractions``Newtonsoft.Json` `NLog`
* **`DMS.Application`**: 实现应用特定的业务逻辑。它依赖于 `DMS.Core`,并使用 `AutoMapper`(用于对象映射)和 `Microsoft.Extensions`(用于托管和日志记录抽象)等库。
* **`DMS.Infrastructure`**: 处理数据访问、外部集成和技术实现。它引用了 `DMS.Core` `DMS.Application`。关键依赖包括:
* `SqlSugarCore`:用于数据库交互(MySQL)。
* `MQTTnet`:用于 MQTT 协议通信。
* `OPCFoundation.NetStandard.Opc.Ua`:用于 OPC UA 通信。
* `S7netplus`:用于西门子 S7 PLC 通信。
* `NPOI`:用于读写 Excel 文件。
* `AutoMapper.Extensions.Microsoft.DependencyInjection`:用于 AutoMapper 的依赖注入设置。
* **`DMS.WPF`**:主 WPF 桌面应用程序。它以 `net8.0-windows` 为目标,并使用 WPF 特定的库,如 `CommunityToolkit.Mvvm``HandyControl`UI 工具包)、`Hardcodet.NotifyIcon.Wpf`(系统托盘图标)和 `iNKORE.UI.WPF.Modern`(现代 UI 样式)。它依赖于 `DMS.Application` `DMS.Infrastructure`
* **`DMS.Infrastructure.UnitTests`**:针对 `DMS.Infrastructure` 项目的单元测试。使用 `xunit``Moq``Bogus`(用于伪造数据)和 `Microsoft.NET.Test.Sdk`
* **`DMS.WPF.UnitTests`**:针对 `DMS.WPF` 项目的单元测试。同样使用 `xunit``Moq` `Bogus`
## Building and Running
## 构建与运行
This is a .NET 8 solution. You will need the .NET 8 SDK and an IDE like Visual Studio or JetBrains Rider to build and run it.
这是一个 .NET 8 解决方案。您需要安装 .NET 8 SDK 以及 Visual Studio JetBrains Rider 等 IDE 来构建和运行它。
**To Build:**
Use the standard .NET CLI command within the solution directory:
**构建:**
在解决方案目录下使用标准 .NET CLI 命令:
`dotnet build`
**To Run:**
The main executable is the WPF application (`DMS.WPF`). You can run it using:
**运行:**
主可执行文件是 WPF 应用程序 (`DMS.WPF`)。您可以使用以下命令运行它:
`dotnet run --project DMS.WPF`
**To Test:**
Unit tests are included in `DMS.Infrastructure.UnitTests` and `DMS.WPF.UnitTests`.
Run all tests using:
**测试:**
单元测试包含在 `DMS.Infrastructure.UnitTests` `DMS.WPF.UnitTests` 中。
使用以下命令运行所有测试:
`dotnet test`
## Development Conventions
## 开发规范
* **Language & Framework:** C# with .NET 8.
* **Architecture:** Layered architecture (Core, Application, Infrastructure) with a WPF presentation layer.
* **UI Pattern:** MVVM (Model-View-ViewModel), supported by `CommunityToolkit.Mvvm`.
* **DI (Dependency Injection):** Microsoft.Extensions.DependencyInjection is used, configured likely in the `DMS.WPF` project.
* **Logging:** NLog is used for logging, configured via `DMS.WPF\Configurations\nlog.config`.
* **Mapping:** AutoMapper is used for object-to-object mapping.
* **语言与框架:** C# 配合 .NET 8
* **架构:** 分层架构(Core, Application, Infrastructure)配合 WPF 表现层。
* **UI 模式:** MVVMModel-View-ViewModel),由 `CommunityToolkit.Mvvm` 支持。
* **依赖注入 (DI)** 使用 Microsoft.Extensions.DependencyInjection,在 `DMS.WPF` 项目中进行配置。
* **日志记录:** 使用 NLog 进行日志记录,配置文件位于 `DMS.WPF\Configurations\nlog.config`
* **对象映射:** 使用 AutoMapper 进行对象到对象的映射。