Files
DMS/DMS.Application/Services/Triggers/Impl/TriggerActionExecutor.cs
David P.G 72d2440314 1 feat: 重构触发器设计,移除触发条件并添加名称字段
2
    3 - 从Trigger、DbTriggerDefinition和TriggerItem类中移除了所有条件相关的属性(Condition, Threshold, LowerBound, UpperBound)
    4 - 删除了ConditionType枚举,简化了触发器逻辑
    5 - 为触发器添加了Name字段,在核心模型、数据库实体和视图模型中都添加了该属性
    6 - 删除了TriggerDialog界面中的变量选择和搜索功能
    7 - 从TriggerDialog界面中删除了触发条件相关的UI元素
    8 - 更新了TriggerDialogViewModel,移除了条件相关的验证和业务逻辑
    9 - 更新了TriggersViewModel,移除了条件的初始化设置
   10 - 更新了AutoMapper配置文件,增加TriggerItem与Trigger之间的映射
   11 - 在TriggerEvaluationService中移除了条件判断逻辑,现在激活的触发器会直接执行动作
   12 - 更新了App.xaml,移除了对已删除枚举的引用
   13 - 修改了保存验证逻辑,确保触发器名称不能为空
2025-10-18 18:55:08 +08:00

65 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using DMS.Application.Services.Triggers;
using DMS.Core.Interfaces.Services;
using DMS.Core.Models.Triggers;
using Microsoft.Extensions.Logging; // 使用标准日志接口
namespace DMS.Application.Services.Triggers.Impl
{
/// <summary>
/// 触发器动作执行器实现
/// </summary>
public class TriggerActionExecutor : ITriggerActionExecutor
{
// 假设这些服务将在未来实现或通过依赖注入提供
// 目前我们将它们设为 null并在使用时进行空检查
private readonly IEmailService _emailService; // 假设已在项目中存在或将来实现
private readonly ILogger<TriggerActionExecutor> _logger; // 使用标准日志接口
public TriggerActionExecutor(
// 可以选择性地注入这些服务,如果暂时不需要可以留空或使用占位符
IEmailService emailService,
ILogger<TriggerActionExecutor> logger)
{
_emailService = emailService; // 可能为 null
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
/// <summary>
/// 执行触发动作
/// </summary>
public async Task ExecuteActionAsync(TriggerContext context)
{
try
{
switch (context.Trigger.Action)
{
case ActionType.SendEmail:
// await ExecuteSendEmail(context);
break;
case ActionType.ActivateAlarm:
_logger.LogWarning("Action 'ActivateAlarm' is not implemented yet.");
// await ExecuteActivateAlarm(context);
break;
case ActionType.WriteToLog:
_logger.LogWarning("Action 'WriteToLog' is not implemented yet.");
// await ExecuteWriteToLog(context);
break;
default:
_logger.LogWarning("Unsupported action type: {ActionType}", context.Trigger.Action);
break;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error executing action '{ActionType}' for trigger '{TriggerId}'.", context.Trigger.Action, context.Trigger.Id);
// 可以选择是否重新抛出异常或静默处理
// throw;
}
}
}
}