59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using UIShare.GlobalVariable;
|
|
using Logger;
|
|
using Prism.Mvvm;
|
|
using System.Collections.ObjectModel;
|
|
using System.Reflection;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
using UIShare.ViewModelBase;
|
|
|
|
namespace TestingModule.ViewModels
|
|
{
|
|
public class LogAreaViewModel : NavigateViewModelBase
|
|
{
|
|
// 日志集合
|
|
private ObservableCollection<LogItem> _logs = new();
|
|
|
|
|
|
public ObservableCollection<LogItem> Logs
|
|
{
|
|
get => _logs;
|
|
set => SetProperty(ref _logs, value);
|
|
}
|
|
public ICommand ClearLogCommand { get; set; }
|
|
|
|
public LogAreaViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
|
{
|
|
ClearLogCommand = new DelegateCommand(ClearLog);
|
|
LoggerHelper.Progress = new System.Progress<(string message, string color, int depth)>(
|
|
log =>
|
|
{
|
|
var brush = (Brush)new BrushConverter().ConvertFromString(log.color);
|
|
Logs.Add(new LogItem(log.message, brush, log.depth));
|
|
});
|
|
}
|
|
|
|
|
|
private void ClearLog()
|
|
{
|
|
Logs.Clear();
|
|
}
|
|
}
|
|
|
|
// 日志条目类
|
|
public class LogItem
|
|
{
|
|
public string Message { get; set; }
|
|
public Brush Color { get; set; } = Brushes.Black;
|
|
public int Depth { get; set; }
|
|
public LogItem(string message, Brush color, int depth = 0)
|
|
{
|
|
Message = new string(' ', depth * 20) + message;
|
|
Color = color;
|
|
Depth = depth;
|
|
}
|
|
}
|
|
}
|