修改触发器相关的内容

This commit is contained in:
2025-09-23 09:28:08 +08:00
parent 2d457ae248
commit eb4bee8963
6 changed files with 60 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
using DMS.Application.DTOs; using DMS.Application.DTOs;
namespace DMS.Application.Services.Management namespace DMS.Application.Interfaces.Management
{ {
/// <summary> /// <summary>
/// 触发器管理服务接口 (负责 CRUD 操作) /// 触发器管理服务接口 (负责 CRUD 操作)

View File

@@ -5,6 +5,7 @@ using DMS.Core.Interfaces;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using DMS.Application.Events; using DMS.Application.Events;
using DMS.Application.Interfaces.Database; using DMS.Application.Interfaces.Database;
using DMS.Application.Interfaces.Management;
using DMS.Application.Services.Management; using DMS.Application.Services.Management;
using DMS.Core.Models; using DMS.Core.Models;
using DMS.Core.Models.Triggers; using DMS.Core.Models.Triggers;

View File

@@ -1,5 +1,7 @@
using AutoMapper; using AutoMapper;
using DMS.Application.DTOs; using DMS.Application.DTOs;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Management;
using DMS.Application.Services.Triggers; using DMS.Application.Services.Triggers;
using DMS.Core.Interfaces; using DMS.Core.Interfaces;
using DMS.Core.Models.Triggers; using DMS.Core.Models.Triggers;
@@ -13,11 +15,13 @@ namespace DMS.Application.Services.Management
{ {
private readonly IRepositoryManager _repositoryManager; private readonly IRepositoryManager _repositoryManager;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly IAppDataStorageService _appDataStorageService;
public TriggerManagementService(IRepositoryManager repositoryManager, IMapper mapper) public TriggerManagementService(IRepositoryManager repositoryManager, IMapper mapper, IAppDataStorageService appDataStorageService)
{ {
_repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager)); _repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_appDataStorageService = appDataStorageService ?? throw new ArgumentNullException(nameof(appDataStorageService));
} }
/// <summary> /// <summary>
@@ -55,7 +59,12 @@ namespace DMS.Application.Services.Management
var createdTrigger = await _repositoryManager.Triggers.AddAsync(triggerEntity); var createdTrigger = await _repositoryManager.Triggers.AddAsync(triggerEntity);
// 4. 转换回 DTO 并返回 // 4. 转换回 DTO 并返回
return _mapper.Map<TriggerDefinitionDto>(createdTrigger); var result = _mapper.Map<TriggerDefinitionDto>(createdTrigger);
// 5. 同步更新AppDataStorageService中的Triggers字典
_appDataStorageService.Triggers[result.Id] = result;
return result;
} }
/// <summary> /// <summary>
@@ -81,7 +90,12 @@ namespace DMS.Application.Services.Management
return null; return null;
// 5. 转换回 DTO 并返回 // 5. 转换回 DTO 并返回
return _mapper.Map<TriggerDefinitionDto>(updatedTrigger); var result = _mapper.Map<TriggerDefinitionDto>(updatedTrigger);
// 6. 同步更新AppDataStorageService中的Triggers字典
_appDataStorageService.Triggers[result.Id] = result;
return result;
} }
/// <summary> /// <summary>
@@ -89,7 +103,15 @@ namespace DMS.Application.Services.Management
/// </summary> /// </summary>
public async Task<bool> DeleteTriggerAsync(int id) public async Task<bool> DeleteTriggerAsync(int id)
{ {
return await _repositoryManager.Triggers.DeleteAsync(id); var result = await _repositoryManager.Triggers.DeleteAsync(id);
// 如果删除成功也从AppDataStorageService中的Triggers字典中移除
if (result)
{
_appDataStorageService.Triggers.TryRemove(id, out _);
}
return result;
} }
/// <summary> /// <summary>

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DMS.Application.DTOs; using DMS.Application.DTOs;
using DMS.Application.Interfaces.Management;
using DMS.Application.Services.Management; using DMS.Application.Services.Management;
// 明确指定 Timer 类型,避免歧义 // 明确指定 Timer 类型,避免歧义
using ThreadingTimer = System.Threading.Timer; using ThreadingTimer = System.Threading.Timer;

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DMS.WPF.Converters
{
/// <summary>
/// 当集合为空时返回Visibility.Visible否则返回Visibility.Collapsed
/// </summary>
public class EmptyCollectionToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ICollection collection)
{
return collection.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -26,6 +26,7 @@
<ui:ContentDialog.Resources> <ui:ContentDialog.Resources>
<converters:EnumToVisibilityConverter x:Key="LocalEnumToVisibilityConverter" /> <converters:EnumToVisibilityConverter x:Key="LocalEnumToVisibilityConverter" />
<converters:IntToVisibilityConverter x:Key="IntToVisibilityConverter" /> <converters:IntToVisibilityConverter x:Key="IntToVisibilityConverter" />
<converters:EmptyCollectionToVisibilityConverter x:Key="EmptyCollectionToVisibilityConverter" />
<ex:EnumBindingSource x:Key="ConditionTypeEnum" <ex:EnumBindingSource x:Key="ConditionTypeEnum"
EnumType="{x:Type enums:ConditionType}" /> EnumType="{x:Type enums:ConditionType}" />
<ex:EnumBindingSource x:Key="ActionTypeEnum" <ex:EnumBindingSource x:Key="ActionTypeEnum"
@@ -92,7 +93,7 @@
<TextBlock Text="暂无选择的变量" <TextBlock Text="暂无选择的变量"
FontStyle="Italic" FontStyle="Italic"
Foreground="Gray" Foreground="Gray"
Visibility="{Binding SelectedVariables.Count, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=0}"/> Visibility="{Binding SelectedVariables, Converter={StaticResource EmptyCollectionToVisibilityConverter}}"/>
</WrapPanel> </WrapPanel>
</Border> </Border>