重载加载数据代码
This commit is contained in:
@@ -39,4 +39,9 @@ public interface IAppDataStorageService
|
|||||||
/// 安全字典,用于存储所有日志数据
|
/// 安全字典,用于存储所有日志数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ConcurrentDictionary<int, NlogDto> Nlogs { get; }
|
ConcurrentDictionary<int, NlogDto> Nlogs { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 安全字典,用于存储所有MQTT变量别名的数据
|
||||||
|
/// </summary>
|
||||||
|
ConcurrentDictionary<int, VariableMqttAliasDto> VariableMqttAliases { get; }
|
||||||
}
|
}
|
||||||
@@ -17,32 +17,32 @@ public interface IDataLoaderService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有设备数据
|
/// 异步加载所有设备数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<List<DeviceDto>> LoadAllDevicesAsync();
|
Task LoadAllDevicesAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有变量表数据
|
/// 异步加载所有变量表数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<List<VariableTableDto>> LoadAllVariableTablesAsync();
|
Task LoadAllVariableTablesAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有变量数据
|
/// 异步加载所有变量数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<List<VariableDto>> LoadAllVariablesAsync();
|
Task LoadAllVariablesAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有菜单数据
|
/// 异步加载所有菜单数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<List<MenuBeanDto>> LoadAllMenusAsync();
|
Task LoadAllMenusAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有MQTT服务器数据
|
/// 异步加载所有MQTT服务器数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<List<MqttServerDto>> LoadAllMqttServersAsync();
|
Task LoadAllMqttServersAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有日志数据
|
/// 异步加载所有日志数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<List<NlogDto>> LoadAllNlogsAsync(int count);
|
Task LoadAllNlogsAsync(int count);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当数据加载完成时触发
|
/// 当数据加载完成时触发
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ public class AppDataStorageService : IAppDataStorageService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ConcurrentDictionary<int, MqttServerDto> MqttServers { get; } = new();
|
public ConcurrentDictionary<int, MqttServerDto> MqttServers { get; } = new();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 安全字典,用于存储所有MQTT变量别名的数据
|
||||||
|
/// </summary>
|
||||||
|
public ConcurrentDictionary<int, VariableMqttAliasDto> VariableMqttAliases { get; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 安全字典,用于存储所有日志数据
|
/// 安全字典,用于存储所有日志数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class DataLoaderService : IDataLoaderService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<DataLoadCompletedEventArgs> OnLoadDataCompleted;
|
public event EventHandler<DataLoadCompletedEventArgs> OnLoadDataCompleted;
|
||||||
|
|
||||||
|
public const int LoadLogCount =100;
|
||||||
public DataLoaderService(
|
public DataLoaderService(
|
||||||
IRepositoryManager repositoryManager,
|
IRepositoryManager repositoryManager,
|
||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
@@ -50,149 +51,148 @@ public class DataLoaderService : IDataLoaderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有设备及其关联数据到内存中
|
/// 异步加载所有设备及其关联数据到内存中
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task LoadAllDataToMemoryAsync()
|
public async Task LoadAllDataToMemoryAsync()
|
||||||
{
|
{
|
||||||
// 清空现有数据
|
|
||||||
_appDataStorageService.Devices.Clear();
|
|
||||||
_appDataStorageService.VariableTables.Clear();
|
|
||||||
_appDataStorageService.Variables.Clear();
|
|
||||||
_appDataStorageService.Menus.Clear();
|
|
||||||
_appDataStorageService.MenuTrees.Clear();
|
|
||||||
_appDataStorageService.MqttServers.Clear();
|
|
||||||
_appDataStorageService.Nlogs.Clear();
|
|
||||||
|
|
||||||
// 加载所有设备
|
await LoadAllDevicesAsync();
|
||||||
var deviceDtos = await LoadAllDevicesAsync();
|
|
||||||
|
|
||||||
// 加载所有变量表
|
await LoadAllVariableTablesAsync();
|
||||||
var variableTableDtos = await LoadAllVariableTablesAsync();
|
|
||||||
|
|
||||||
// 加载所有变量
|
|
||||||
var variableDtos = await LoadAllVariablesAsync();
|
|
||||||
|
|
||||||
|
await LoadAllVariablesAsync();
|
||||||
// 加载所有菜单
|
// 加载所有菜单
|
||||||
var menuDtos = await LoadAllMenusAsync();
|
await LoadAllMenusAsync();
|
||||||
|
|
||||||
// 加载所有MQTT服务器
|
// 加载所有MQTT服务器
|
||||||
var mqttServerDtos = await LoadAllMqttServersAsync();
|
await LoadAllMqttServersAsync();
|
||||||
|
|
||||||
// 加载所有日志
|
// 加载所有日志
|
||||||
var nlogDtos = await LoadAllNlogsAsync(100);
|
await LoadAllNlogsAsync(LoadLogCount);
|
||||||
|
|
||||||
// 获取变量MQTT别名
|
// 获取变量MQTT别名
|
||||||
|
await LoadAllVariableMqttAliases();
|
||||||
|
|
||||||
|
OnLoadDataCompleted?.Invoke(this, new DataLoadCompletedEventArgs(true, "数据加载成功"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadAllVariableMqttAliases()
|
||||||
|
{
|
||||||
|
|
||||||
var variableMqttAliases = await _repositoryManager.VariableMqttAliases.GetAllAsync();
|
var variableMqttAliases = await _repositoryManager.VariableMqttAliases.GetAllAsync();
|
||||||
|
var variableMqttAliasDtos = _mapper.Map<IEnumerable<VariableMqttAliasDto>>(variableMqttAliases);
|
||||||
|
foreach (var variableMqttAliasDto in variableMqttAliasDtos)
|
||||||
|
{
|
||||||
|
_appDataStorageService.VariableMqttAliases.TryAdd(variableMqttAliasDto.Id, variableMqttAliasDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步加载所有设备数据
|
||||||
|
/// </summary>
|
||||||
|
public async Task LoadAllDevicesAsync()
|
||||||
|
{
|
||||||
|
_appDataStorageService.Devices.Clear();
|
||||||
|
var devices = await _repositoryManager.Devices.GetAllAsync();
|
||||||
|
var devicesDtos = _mapper.Map<List<DeviceDto>>(devices);
|
||||||
|
|
||||||
// 建立设备与变量表的关联
|
// 建立设备与变量表的关联
|
||||||
foreach (var deviceDto in deviceDtos)
|
foreach (var deviceDto in devicesDtos)
|
||||||
{
|
{
|
||||||
deviceDto.VariableTables = variableTableDtos
|
|
||||||
.Where(vt => vt.DeviceId == deviceDto.Id)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
// 将设备添加到安全字典
|
// 将设备添加到安全字典
|
||||||
_appDataStorageService.Devices.TryAdd(deviceDto.Id, deviceDto);
|
_appDataStorageService.Devices.TryAdd(deviceDto.Id, deviceDto);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步加载所有变量表数据
|
||||||
|
/// </summary>
|
||||||
|
public async Task LoadAllVariableTablesAsync()
|
||||||
|
{
|
||||||
|
_appDataStorageService.VariableTables.Clear();
|
||||||
|
var variableTables = await _repositoryManager.VariableTables.GetAllAsync();
|
||||||
|
var variableTableDtos = _mapper.Map<List<VariableTableDto>>(variableTables);
|
||||||
// 建立变量表与变量的关联
|
// 建立变量表与变量的关联
|
||||||
foreach (var variableTableDto in variableTableDtos)
|
foreach (var variableTableDto in variableTableDtos)
|
||||||
{
|
{
|
||||||
variableTableDto.Variables = variableDtos
|
|
||||||
.Where(v => v.VariableTableId == variableTableDto.Id)
|
|
||||||
.ToList();
|
|
||||||
if (_appDataStorageService.Devices.TryGetValue(variableTableDto.DeviceId, out var deviceDto))
|
if (_appDataStorageService.Devices.TryGetValue(variableTableDto.DeviceId, out var deviceDto))
|
||||||
{
|
{
|
||||||
variableTableDto.Device = deviceDto;
|
variableTableDto.Device = deviceDto;
|
||||||
|
variableTableDto.Device.VariableTables.Add(variableTableDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将变量表添加到安全字典
|
// 将变量表添加到安全字典
|
||||||
_appDataStorageService.VariableTables.TryAdd(variableTableDto.Id, variableTableDto);
|
_appDataStorageService.VariableTables.TryAdd(variableTableDto.Id, variableTableDto);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 加载MQTT服务器数据到内存
|
/// <summary>
|
||||||
foreach (var mqttServerDto in mqttServerDtos)
|
/// 异步加载所有变量数据
|
||||||
{
|
/// </summary>
|
||||||
_appDataStorageService.MqttServers.TryAdd(mqttServerDto.Id, mqttServerDto);
|
public async Task LoadAllVariablesAsync()
|
||||||
}
|
{
|
||||||
|
_appDataStorageService.Variables.Clear();
|
||||||
// 加载日志数据到内存
|
|
||||||
foreach (var nlogDto in nlogDtos)
|
|
||||||
{
|
|
||||||
_appDataStorageService.Nlogs.TryAdd(nlogDto.Id, nlogDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var variables = await _repositoryManager.Variables.GetAllAsync();
|
||||||
|
var variableDtos = _mapper.Map<List<VariableDto>>(variables);
|
||||||
// 将变量添加到安全字典
|
// 将变量添加到安全字典
|
||||||
foreach (var variableDto in variableDtos)
|
foreach (var variableDto in variableDtos)
|
||||||
{
|
{
|
||||||
if (_appDataStorageService.VariableTables.TryGetValue(variableDto.VariableTableId, out var variableTableDto))
|
if (_appDataStorageService.VariableTables.TryGetValue(variableDto.VariableTableId,
|
||||||
|
out var variableTableDto))
|
||||||
{
|
{
|
||||||
variableDto.VariableTable = variableTableDto;
|
variableDto.VariableTable = variableTableDto;
|
||||||
|
variableDto.VariableTable.Variables.Add(variableDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
_appDataStorageService.Variables.TryAdd(variableDto.Id, variableDto);
|
_appDataStorageService.Variables.TryAdd(variableDto.Id, variableDto);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步加载所有菜单数据
|
||||||
|
/// </summary>
|
||||||
|
public async Task LoadAllMenusAsync()
|
||||||
|
{
|
||||||
|
_appDataStorageService.Menus.Clear();
|
||||||
|
_appDataStorageService.MenuTrees.Clear();
|
||||||
|
var menus = await _repositoryManager.Menus.GetAllAsync();
|
||||||
|
var menuDtos = _mapper.Map<List<MenuBeanDto>>(menus);
|
||||||
// 将菜单添加到安全字典
|
// 将菜单添加到安全字典
|
||||||
foreach (var menuDto in menuDtos)
|
foreach (var menuDto in menuDtos)
|
||||||
{
|
{
|
||||||
_appDataStorageService.Menus.TryAdd(menuDto.Id, menuDto);
|
_appDataStorageService.Menus.TryAdd(menuDto.Id, menuDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnLoadDataCompleted?.Invoke(this,new DataLoadCompletedEventArgs(true,"数据加载成功"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步加载所有设备数据
|
|
||||||
/// </summary>
|
|
||||||
public async Task<List<DeviceDto>> LoadAllDevicesAsync()
|
|
||||||
{
|
|
||||||
var devices = await _repositoryManager.Devices.GetAllAsync();
|
|
||||||
return _mapper.Map<List<DeviceDto>>(devices);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步加载所有变量表数据
|
|
||||||
/// </summary>
|
|
||||||
public async Task<List<VariableTableDto>> LoadAllVariableTablesAsync()
|
|
||||||
{
|
|
||||||
var variableTables = await _repositoryManager.VariableTables.GetAllAsync();
|
|
||||||
return _mapper.Map<List<VariableTableDto>>(variableTables);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步加载所有变量数据
|
|
||||||
/// </summary>
|
|
||||||
public async Task<List<VariableDto>> LoadAllVariablesAsync()
|
|
||||||
{
|
|
||||||
var variables = await _repositoryManager.Variables.GetAllAsync();
|
|
||||||
return _mapper.Map<List<VariableDto>>(variables);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步加载所有菜单数据
|
|
||||||
/// </summary>
|
|
||||||
public async Task<List<MenuBeanDto>> LoadAllMenusAsync()
|
|
||||||
{
|
|
||||||
var menus = await _repositoryManager.Menus.GetAllAsync();
|
|
||||||
return _mapper.Map<List<MenuBeanDto>>(menus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有MQTT服务器数据
|
/// 异步加载所有MQTT服务器数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<List<MqttServerDto>> LoadAllMqttServersAsync()
|
public async Task LoadAllMqttServersAsync()
|
||||||
{
|
{
|
||||||
return await _mqttAppService.GetAllMqttServersAsync();
|
_appDataStorageService.MqttServers.Clear();
|
||||||
|
var mqttServerDtos =await _mqttAppService.GetAllMqttServersAsync();
|
||||||
|
// 加载MQTT服务器数据到内存
|
||||||
|
foreach (var mqttServerDto in mqttServerDtos)
|
||||||
|
{
|
||||||
|
_appDataStorageService.MqttServers.TryAdd(mqttServerDto.Id, mqttServerDto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载所有日志数据
|
/// 异步加载所有日志数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<List<NlogDto>> LoadAllNlogsAsync(int count)
|
public async Task LoadAllNlogsAsync(int count)
|
||||||
{
|
{
|
||||||
return await _nlogAppService.GetLatestLogsAsync(count);
|
_appDataStorageService.Nlogs.Clear();
|
||||||
|
var nlogDtos =await _nlogAppService.GetLatestLogsAsync(count);
|
||||||
|
// 加载日志数据到内存
|
||||||
|
foreach (var nlogDto in nlogDtos)
|
||||||
|
{
|
||||||
|
_appDataStorageService.Nlogs.TryAdd(nlogDto.Id, nlogDto);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,15 +3,17 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:vm="clr-namespace:DMS.WPF.ViewModels"
|
||||||
|
d:DataContext="{d:DesignInstance vm:SplashViewModel}"
|
||||||
xmlns:local="clr-namespace:DMS.WPF.Views"
|
xmlns:local="clr-namespace:DMS.WPF.Views"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="SplashWindow" Height="400" Width="600"
|
Title="正在启动..." Height="400" Width="600"
|
||||||
WindowStyle="None" WindowStartupLocation="CenterScreen" AllowsTransparency="True" Background="Transparent">
|
WindowStyle="None" WindowStartupLocation="CenterScreen" AllowsTransparency="True" Background="Transparent">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Border CornerRadius="10" Background="#FF333333">
|
<Border CornerRadius="10" Background="#FF333333">
|
||||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||||
<Image Source="/Assets/AppIcon2.ico" Width="100" Height="100"/>
|
<Image Source="/Assets/AppIcon2.ico" Width="100" Height="100"/>
|
||||||
<TextBlock Text="{Binding LoadingMessage}" Foreground="White" FontSize="16" Margin="0,20,0,0"/>
|
<TextBlock VerticalAlignment="Center" TextWrapping="Wrap" MaxWidth="500" Text="{Binding LoadingMessage}" Foreground="White" FontSize="16" Margin="0,20,0,0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user