refactor:完成重构设备的添加,删除,更新。
This commit is contained in:
@@ -17,14 +17,14 @@ namespace DMS.Application.Services.Management
|
||||
/// </summary>
|
||||
public class TriggerManagementService : ITriggerManagementService
|
||||
{
|
||||
private readonly IAppStorageService _appStorageService;
|
||||
private readonly IAppDataService _appDataService;
|
||||
private readonly ITriggerAppService _triggerAppService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IEventService _eventService;
|
||||
|
||||
public TriggerManagementService(IAppStorageService appStorageService, ITriggerAppService triggerAppService, IMapper mapper, IEventService eventService)
|
||||
public TriggerManagementService(IAppDataService appStorageService, ITriggerAppService triggerAppService, IMapper mapper, IEventService eventService)
|
||||
{
|
||||
_appStorageService = appStorageService;
|
||||
_appDataService = appStorageService;
|
||||
_triggerAppService = triggerAppService;
|
||||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||
_eventService = eventService;
|
||||
@@ -35,7 +35,7 @@ namespace DMS.Application.Services.Management
|
||||
/// </summary>
|
||||
public List<Trigger> GetAllTriggersAsync()
|
||||
{
|
||||
var triggers = _appStorageService.Triggers.Values.ToList();
|
||||
var triggers = _appDataService.Triggers.Values.ToList();
|
||||
return _mapper.Map<List<Trigger>>(triggers);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace DMS.Application.Services.Management
|
||||
/// </summary>
|
||||
public async Task<Trigger?> GetTriggerByIdAsync(int id)
|
||||
{
|
||||
_appStorageService.Triggers.TryGetValue(id, out var trigger);
|
||||
_appDataService.Triggers.TryGetValue(id, out var trigger);
|
||||
return trigger;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace DMS.Application.Services.Management
|
||||
// 创建成功后,将触发器添加到内存中
|
||||
if (createdTrigger != null)
|
||||
{
|
||||
if (_appStorageService.Triggers.TryAdd(createdTrigger.Id, createdTrigger))
|
||||
if (_appDataService.Triggers.TryAdd(createdTrigger.Id, createdTrigger))
|
||||
{
|
||||
_eventService.RaiseTriggerChanged(this, new TriggerChangedEventArgs(DataChangeType.Added, createdTrigger));
|
||||
}
|
||||
@@ -81,12 +81,12 @@ namespace DMS.Application.Services.Management
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_appStorageService.Triggers.TryAdd(result.Trigger.Id, result.Trigger))
|
||||
if (_appDataService.Triggers.TryAdd(result.Trigger.Id, result.Trigger))
|
||||
{
|
||||
_eventService.RaiseTriggerChanged(this, new TriggerChangedEventArgs(DataChangeType.Added, result.Trigger));
|
||||
}
|
||||
|
||||
if (_appStorageService.Menus.TryAdd(result.TriggerMenu.Id, result.TriggerMenu))
|
||||
if (_appDataService.Menus.TryAdd(result.TriggerMenu.Id, result.TriggerMenu))
|
||||
{
|
||||
_eventService.RaiseMenuChanged(this, new MenuChangedEventArgs(DataChangeType.Added, result.TriggerMenu));
|
||||
}
|
||||
@@ -107,7 +107,7 @@ namespace DMS.Application.Services.Management
|
||||
return res;
|
||||
|
||||
// 6. 同步更新AppDataStorageService中的Triggers字典
|
||||
if (_appStorageService.Triggers.TryGetValue(trigger.Id, out var memTrigger))
|
||||
if (_appDataService.Triggers.TryGetValue(trigger.Id, out var memTrigger))
|
||||
{
|
||||
_mapper.Map(trigger, memTrigger);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ namespace DMS.Application.Services.Management
|
||||
// 如果删除成功,也从AppDataStorageService中的Triggers字典中移除
|
||||
if (await _triggerAppService.DeleteTriggerByIdAsync(id))
|
||||
{
|
||||
_appStorageService.Triggers.TryRemove(id, out _);
|
||||
_appDataService.Triggers.TryRemove(id, out _);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -150,11 +150,11 @@ namespace DMS.Application.Services.Management
|
||||
/// </summary>
|
||||
public async Task LoadAllTriggersAsync()
|
||||
{
|
||||
_appStorageService.Triggers.Clear();
|
||||
_appDataService.Triggers.Clear();
|
||||
var triggerDefinitions = await _triggerAppService.GetAllTriggersAsync();
|
||||
foreach (var triggerDefinition in triggerDefinitions)
|
||||
{
|
||||
_appStorageService.Triggers.TryAdd(triggerDefinition.Id, triggerDefinition);
|
||||
_appDataService.Triggers.TryAdd(triggerDefinition.Id, triggerDefinition);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user