1 feat: 为MqttServerDetailView添加取消关联功能
2 3 - 在MqttServerDetailView的DataGrid右键菜单中添加"取消关联"选项 4 - 实现UnassignAlias命令,允许用户从MQTT服务器取消关联变量 5 - 使用确认对话框以防止误操作 6 - 集成现有的删除API来实际移除变量与MQTT服务器的关联 7 - 更新UI以提供用户反馈 8 9 此功能允许用户通过右键菜单轻松取消MQTT服务器与变量的关联。
This commit is contained in:
@@ -32,15 +32,17 @@ public class MqttAliasManagementService : IMqttAliasManagementService
|
||||
// Add to cache
|
||||
if (_storageService.MqttServers.TryGetValue(newAlias.MqttServerId, out var server))
|
||||
{
|
||||
newAlias.MqttServer = server;
|
||||
server.VariableAliases.Add(newAlias);
|
||||
}
|
||||
|
||||
// Add to cache
|
||||
if (_storageService.Variables.TryGetValue(newAlias.VariableId, out var variable))
|
||||
{
|
||||
newAlias.Variable = variable;
|
||||
variable.MqttAliases.Add(newAlias);
|
||||
}
|
||||
|
||||
_storageService.MqttAliases.TryAdd(newAlias.Id, newAlias);
|
||||
_eventService.RaiseMqttAliasChanged(this, new MqttAliasChangedEventArgs(ActionChangeType.Added, newAlias));
|
||||
}
|
||||
|
||||
@@ -90,51 +92,19 @@ public class MqttAliasManagementService : IMqttAliasManagementService
|
||||
|
||||
public async Task<bool> DeleteAsync(int id)
|
||||
{
|
||||
var res = await DeleteBatchAsync(new List<int> { id });
|
||||
return res > 0;
|
||||
}
|
||||
var result = await _appService.RemoveAliasAsync(id);
|
||||
if (result == 0) return false;
|
||||
|
||||
public async Task<int> DeleteBatchAsync(List<int> ids)
|
||||
{
|
||||
int counter = 0;
|
||||
foreach (var id in ids)
|
||||
if (_storageService.MqttAliases.TryGetValue(id, out var mqttAlias))
|
||||
{
|
||||
if (!_storageService.MqttAliases.TryGetValue(id, out var mqttAlias))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var variableId = mqttAlias.VariableId;
|
||||
var mqttServerId = mqttAlias.MqttServerId;
|
||||
|
||||
var result = await _appService.RemoveAliasAsync(id);
|
||||
if (result == 0) continue;
|
||||
|
||||
// Remove from cache
|
||||
if (_storageService.MqttServers.TryGetValue(mqttServerId, out var server))
|
||||
{
|
||||
var aliasToRemove = server.VariableAliases.FirstOrDefault(a => a.Id == id);
|
||||
if (aliasToRemove != null)
|
||||
{
|
||||
server.VariableAliases.Remove(aliasToRemove);
|
||||
|
||||
}
|
||||
}
|
||||
// Remove from cache
|
||||
if (_storageService.Variables.TryGetValue(mqttServerId, out var variable))
|
||||
{
|
||||
var aliasToRemove = variable.MqttAliases.FirstOrDefault(a => a.Id == id);
|
||||
if (aliasToRemove != null)
|
||||
{
|
||||
variable.MqttAliases.Remove(aliasToRemove);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mqttAlias.MqttServer.VariableAliases.Remove(mqttAlias);
|
||||
mqttAlias.Variable.MqttAliases.Remove(mqttAlias);
|
||||
_storageService.MqttAliases.TryRemove(mqttAlias.Id,out _);
|
||||
_eventService.RaiseMqttAliasChanged(
|
||||
this, new MqttAliasChangedEventArgs(ActionChangeType.Deleted, mqttAlias));
|
||||
counter++;
|
||||
|
||||
}
|
||||
return counter;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user