Files
Pf2eDataScrapper/Pf2e/WPF/ProgressForm/ProgressForm.xaml.cs
T

90 lines
2.5 KiB
C#

using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Windows;
using LinqToDB.Tools;
using Pf2e.Scrapper.Helpers;
namespace Pf2e.WPF.ProgressForm;
/// <summary>
/// Логика взаимодействия для ProgressFormWpf.xaml
/// </summary>
internal partial class ProgressForm : Window
{
public ProcessProgress Progress { get; }
public ObservableCollection<ListViewRow> ViewRows { get; set; } = [];
public ProgressForm(ProcessProgress progress)
{
Progress = progress;
InitializeComponent();
Progress.ProgressUpdate += Progress_ProgressUpdate;
Progress.ProgressMessage += Progress_ProgressMessage;
Progress.ProgressComplete += Progress_ProgressComplete;
}
private void Progress_ProgressUpdate(ProcessProgress sender)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(() => Progress_ProgressUpdate(sender));
return;
}
ProcessorsLabel.Content = sender.Processors.ToString();
ProcessorsProgressBar.Maximum = sender.Processors.Count;
ProcessorsProgressBar.Value = sender.Processors.Current;
LocalLabel.Content = sender.Local.ToString();
LocalProgressBar.Maximum = sender.Local.Count;
LocalProgressBar.Value = sender.Local.Current;
}
private void Progress_ProgressMessage(ProcessProgress sender, LogLevel level, string message)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(() => Progress_ProgressMessage(sender, level, message));
return;
}
ListViewRow item = new(level, message) { IsVisible = true };
ViewRows.Add(item);
MessageListView.ScrollIntoView(item);
}
private void Progress_ProgressComplete(ProcessProgress sender)
{
ApplicationStateChange?.Invoke(this, ApplicationStage.Viewer);
}
public event ImportApplication.ApplicationStateChangeDelegate? ApplicationStateChange;
}
internal class ListViewRow(LogLevel level, string message)
{
public string Time { get; } = DateTime.Now.ToString("HH:mm:ss.fff");
public LogLevel Level { get; } = level;
public string Message { get; } = message;
public Color Color { get; } =
level switch
{
LogLevel.Important => Color.Salmon,
LogLevel.Warning => Color.Khaki,
LogLevel.Information => Color.White,
LogLevel.Progress => Color.LightGray,
_ => Color.White,
};
public bool IsVisible { get; set; } = true;
}