chore(wpf): 为ImportViewModel添加操作日志记录
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using WCTDataMiner.Core.Services;
|
using WCTDataMiner.Core.Services;
|
||||||
@@ -12,6 +13,7 @@ namespace WCTDataMiner.Wpf.ViewModels;
|
|||||||
public partial class ImportViewModel : ObservableObject
|
public partial class ImportViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
private readonly ParseService _parseService;
|
private readonly ParseService _parseService;
|
||||||
|
private readonly ILogger<ImportViewModel> _logger;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string _selectedPath = "";
|
private string _selectedPath = "";
|
||||||
@@ -31,9 +33,10 @@ public partial class ImportViewModel : ObservableObject
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ObservableCollection<ImportResultItem> _importResults = new();
|
private ObservableCollection<ImportResultItem> _importResults = new();
|
||||||
|
|
||||||
public ImportViewModel(ParseService parseService)
|
public ImportViewModel(ParseService parseService, ILogger<ImportViewModel> logger)
|
||||||
{
|
{
|
||||||
_parseService = parseService;
|
_parseService = parseService;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
@@ -50,6 +53,7 @@ public partial class ImportViewModel : ObservableObject
|
|||||||
{
|
{
|
||||||
SelectedPath = dialog.FileName;
|
SelectedPath = dialog.FileName;
|
||||||
StatusMessage = $"已选择文件: {System.IO.Path.GetFileName(SelectedPath)}";
|
StatusMessage = $"已选择文件: {System.IO.Path.GetFileName(SelectedPath)}";
|
||||||
|
_logger.LogDebug("用户选择文件: {FilePath}", SelectedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +70,7 @@ public partial class ImportViewModel : ObservableObject
|
|||||||
{
|
{
|
||||||
SelectedPath = dialog.FolderName;
|
SelectedPath = dialog.FolderName;
|
||||||
StatusMessage = $"已选择目录: {System.IO.Path.GetFileName(SelectedPath)}";
|
StatusMessage = $"已选择目录: {System.IO.Path.GetFileName(SelectedPath)}";
|
||||||
|
_logger.LogDebug("用户选择目录: {FolderPath}, 递归={IsRecursive}", SelectedPath, IsRecursive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +87,8 @@ public partial class ImportViewModel : ObservableObject
|
|||||||
ImportResults.Clear();
|
ImportResults.Clear();
|
||||||
StatusMessage = "正在导入...";
|
StatusMessage = "正在导入...";
|
||||||
|
|
||||||
|
_logger.LogInformation("开始导入: {Path}, 递归={IsRecursive}", SelectedPath, IsRecursive);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (System.IO.File.Exists(SelectedPath))
|
if (System.IO.File.Exists(SelectedPath))
|
||||||
@@ -90,6 +97,8 @@ public partial class ImportViewModel : ObservableObject
|
|||||||
var report = await _parseService.ParseFileAsync(SelectedPath);
|
var report = await _parseService.ParseFileAsync(SelectedPath);
|
||||||
ImportResults.Add(new ImportResultItem(report));
|
ImportResults.Add(new ImportResultItem(report));
|
||||||
StatusMessage = $"导入完成: Qfod={report.QfodCount}, Ploss={report.PlossCount}, 错误={report.ErrorCount}";
|
StatusMessage = $"导入完成: Qfod={report.QfodCount}, Ploss={report.PlossCount}, 错误={report.ErrorCount}";
|
||||||
|
_logger.LogInformation("单文件导入完成: {FileName}, Qfod={Qfod}, Ploss={Ploss}, 错误={Errors}",
|
||||||
|
report.FileName, report.QfodCount, report.PlossCount, report.ErrorCount);
|
||||||
}
|
}
|
||||||
else if (System.IO.Directory.Exists(SelectedPath))
|
else if (System.IO.Directory.Exists(SelectedPath))
|
||||||
{
|
{
|
||||||
@@ -107,15 +116,19 @@ public partial class ImportViewModel : ObservableObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
StatusMessage = $"导入完成: {reports.Count} 个文件, Qfod={totalQfod}, Ploss={totalPloss}, 错误={totalErrors}";
|
StatusMessage = $"导入完成: {reports.Count} 个文件, Qfod={totalQfod}, Ploss={totalPloss}, 错误={totalErrors}";
|
||||||
|
_logger.LogInformation("目录导入完成: {FileCount} 个文件, Qfod={Qfod}, Ploss={Ploss}, 错误={Errors}",
|
||||||
|
reports.Count, totalQfod, totalPloss, totalErrors);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
StatusMessage = "路径不存在";
|
StatusMessage = "路径不存在";
|
||||||
|
_logger.LogWarning("导入路径不存在: {Path}", SelectedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
StatusMessage = $"导入失败: {ex.Message}";
|
StatusMessage = $"导入失败: {ex.Message}";
|
||||||
|
_logger.LogError(ex, "导入失败: {Path}", SelectedPath);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user