Финализация рефакторинга
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<Window
|
||||
x:Class="Pf2e.WPF.Progress.ProgressForm"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
x:Name="_this"
|
||||
Title="Выполняется обработка..."
|
||||
Width="400"
|
||||
Height="500"
|
||||
x:ClassModifier="internal"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Margin="3,3,3,3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="1*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label
|
||||
x:Name="ProcessorsLabel"
|
||||
Grid.Row="0"
|
||||
VerticalContentAlignment="Center"
|
||||
Content="Label" />
|
||||
<ProgressBar
|
||||
x:Name="ProcessorsProgressBar"
|
||||
Grid.Row="1"
|
||||
Margin="0,0,0,5" />
|
||||
<Label
|
||||
x:Name="LocalLabel"
|
||||
Grid.Row="2"
|
||||
VerticalContentAlignment="Center"
|
||||
Content="Label" />
|
||||
<ProgressBar
|
||||
x:Name="LocalProgressBar"
|
||||
Grid.Row="3"
|
||||
Margin="0,0,0,5" />
|
||||
<WrapPanel Grid.Row="4" />
|
||||
<ListView
|
||||
x:Name="MessageListView"
|
||||
Grid.Row="5"
|
||||
ItemsSource="{Binding ViewRows, ElementName=_this}"
|
||||
ScrollViewer.CanContentScroll="True">
|
||||
|
||||
<ListView.Resources>
|
||||
<Style TargetType="{x:Type ListViewItem}">
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Level}" Value="Progress">
|
||||
<Setter Property="Background" Value="LightGray" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListView.Resources>
|
||||
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn
|
||||
Width="Auto"
|
||||
DisplayMemberBinding="{Binding Time}"
|
||||
Header="Время" />
|
||||
<GridViewColumn
|
||||
Width="Auto"
|
||||
DisplayMemberBinding="{Binding Level}"
|
||||
Header="Тип" />
|
||||
<GridViewColumn DisplayMemberBinding="{Binding Message}" Header="Сообщение" />
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{Binding Path=Color}" />
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{Binding Path=Color}" />
|
||||
<TextBlock
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{Binding Path=Color}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Windows;
|
||||
using LinqToDB.Tools;
|
||||
using Pf2e.Scrapper.Helpers;
|
||||
|
||||
namespace Pf2e.WPF.Progress;
|
||||
|
||||
/// <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;
|
||||
}
|
||||
Reference in New Issue
Block a user