Глобальное обновление #1

Merged
kozhilya merged 33 commits from dev into master 2025-06-01 22:28:15 +04:00
32 changed files with 1621 additions and 83 deletions
Showing only changes of commit 1d63b695d1 - Show all commits
@@ -184,6 +184,14 @@ internal class ProcessorCollection
Items = AllItems.Where(item => nameFlags.ContainsKey(item.Name)).ToList();
}
/// <summary>
/// Получить список типов, которые обрабатываются в компендиуме.
/// </summary>
/// <param name="compendium">Тип компендиума.</param>
/// <returns>Набор типов.</returns>
public ICollection<string> GetTypesOfCompendium(ProcessorCompendiumEnum compendium) =>
Items.Select(item => item.InnerType).OfType<string>().ToList();
}
/// <summary>
+1
View File
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.IO;
using dotenv.net;
using dotenv.net.Utilities;
+2 -1
View File
@@ -1,4 +1,5 @@
using dotenv.net;
using System.IO;
using dotenv.net;
using dotenv.net.Utilities;
namespace Pf2eDataScrapper;
@@ -167,6 +167,7 @@ public sealed partial class EntityTreeViewerControl : UserControl
public EntityTreeViewerControl()
{
InitializeComponent();
ContentImage = new(ContentWidth, Height);
DoubleBuffered = true;
VerticalScroll.Visible = true;
@@ -213,6 +214,11 @@ public sealed partial class EntityTreeViewerControl : UserControl
/// </summary>
public void UpdateRenders()
{
if (EntityView?.Entity is null)
{
return;
}
int maxNameWidth = -1;
foreach (EntityTreeViewerControlRow row in _viewerRows)
@@ -239,6 +245,11 @@ public sealed partial class EntityTreeViewerControl : UserControl
/// </summary>
public void UpdateView()
{
if (EntityView?.Entity is null)
{
return;
}
_viewerRows.ForEach(row => row.UpdateButton());
List<EntityTreeViewerControlRow> rows = _viewerRows.Where(r => r.Item.Visible).ToList();
@@ -0,0 +1,36 @@
namespace Pf2eDataScrapper.Forms.Controls.EntityTreeViewer;
partial class EntityViewerControl
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pf2eDataScrapper.Forms.Controls.EntityTreeViewer;
public partial class EntityViewerControl : UserControl
{
public EntityViewerControl()
{
InitializeComponent();
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+15 -15
View File
@@ -37,7 +37,7 @@ partial class EntityViewForm
ResultSplitContainer = new SplitContainer();
DescriptionTextBox = new TextBox();
DatabaseViewer = new DatabaseViewerControl();
EntityTreeViewerControl = new EntityTreeViewerControl();
_entityTreeViewerCntrl = new EntityTreeViewerControl();
MenuStrip = new MenuStrip();
FileToolStripMenuItem = new ToolStripMenuItem();
ExitToolStripMenuItem = new ToolStripMenuItem();
@@ -137,20 +137,20 @@ partial class EntityViewForm
DatabaseViewer.Size = new Size(322, 731);
DatabaseViewer.TabIndex = 1;
//
// EntityTreeViewerControl
// _entityTreeViewerCntrl
//
EntityTreeViewerControl.AutoScroll = true;
EntityTreeViewerControl.ButtonSize = 15;
EntityTreeViewerControl.DepthSize = 15;
EntityTreeViewerControl.Dock = DockStyle.Fill;
EntityTreeViewerControl.Font = new Font("Consolas", 9F);
EntityTreeViewerControl.HoverColor = SystemColors.ControlDark;
EntityTreeViewerControl.ItemHeight = 20;
EntityTreeViewerControl.Location = new Point(0, 0);
EntityTreeViewerControl.Name = "EntityTreeViewerControl";
EntityTreeViewerControl.Size = new Size(582, 861);
EntityTreeViewerControl.TabIndex = 0;
EntityTreeViewerControl.TypeFontSize = 7F;
_entityTreeViewerCntrl.AutoScroll = true;
_entityTreeViewerCntrl.ButtonSize = 15;
_entityTreeViewerCntrl.DepthSize = 15;
_entityTreeViewerCntrl.Dock = DockStyle.Fill;
_entityTreeViewerCntrl.Font = new Font("Consolas", 9F);
_entityTreeViewerCntrl.HoverColor = SystemColors.ControlDark;
_entityTreeViewerCntrl.ItemHeight = 20;
_entityTreeViewerCntrl.Location = new Point(0, 0);
_entityTreeViewerCntrl.Name = "_entityTreeViewerCntrl";
_entityTreeViewerCntrl.Size = new Size(582, 861);
_entityTreeViewerCntrl.TabIndex = 0;
_entityTreeViewerCntrl.TypeFontSize = 7F;
//
// MenuStrip
//
@@ -229,7 +229,7 @@ partial class EntityViewForm
private ListBox TypesListBox;
private SplitContainer ResultSplitContainer;
private TextBox DescriptionTextBox;
private EntityTreeViewerControl EntityTreeViewerControl;
private EntityTreeViewerControl _entityTreeViewerCntrl;
private DatabaseViewerControl DatabaseViewer;
private MenuStrip MenuStrip;
private ToolStripMenuItem FileToolStripMenuItem;
+2 -2
View File
@@ -18,10 +18,10 @@ internal partial class EntityViewForm : Form
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public EntityView? CurrentView
{
get => EntityTreeViewerControl.EntityView;
get => _entityTreeViewerCntrl.EntityView;
set
{
EntityTreeViewerControl.EntityView = value;
_entityTreeViewerCntrl.EntityView = value;
Application.DoEvents();
}
}
+58 -53
View File
@@ -1,10 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using System.ComponentModel;
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Pf2eDataScrapper.App;
using Pf2eDataScrapper.Forms;
using Pf2eDataScrapper.Helpers;
using Pf2eDataScrapper.Processors;
using Pf2eDataScrapper.WPF;
using Pf2eDataScrapper.WPF.Views;
using Pf2eModel;
using Slugify;
using StartForm = Pf2eDataScrapper.WPF.Views.StartForm;
namespace Pf2eDataScrapper;
@@ -20,7 +24,8 @@ internal sealed class ImportApplication : ApplicationContext
Settings = settings;
Processors = processors;
CurrentStage = ApplicationStage.InitialSettings;
//CurrentStage = ApplicationStage.InitialSettings;
CurrentStage = ApplicationStage.Viewer;
}
#region "Поля"
@@ -46,30 +51,20 @@ internal sealed class ImportApplication : ApplicationContext
#region "Формы"
private StartForm? _startForm;
private StartForm? _startFormWpf;
private ProgressForm? _progressForm;
private ProgressFormWpf? _progressFormWpf;
private EntityViewForm? _entityViewForm;
private EntityForm? _entityForm;
#endregion
#region "Жизненный цикл"
private Form? CurrentForm { get; set; }
private Window? CurrentWpfForm { get; set; }
public delegate void ApplicationStateChangeDelegate(object sender, ApplicationStage nextStage);
public void ApplicationStateChange(object sender, ApplicationStage nextStage)
{
if (sender != CurrentForm)
{
return;
}
CurrentStage = nextStage;
}
private void StartStage(ApplicationStage stage)
{
switch (stage)
@@ -80,13 +75,13 @@ internal sealed class ImportApplication : ApplicationContext
);
case ApplicationStage.InitialSettings:
_startForm = ActivatorUtilities.CreateInstance<StartForm>(ServiceProvider);
_startForm.StartPosition = FormStartPosition.CenterParent;
_startForm.ApplicationStateChange += ApplicationStateChange;
_startForm.FormClosing += HandleFormClosing;
_startForm.Show();
_startFormWpf = ActivatorUtilities.CreateInstance<StartForm>(ServiceProvider);
_startFormWpf.WindowStartupLocation = WindowStartupLocation.CenterOwner;
_startFormWpf.Closing += Wpf_HandleFormClosing;
_startFormWpf.ApplicationStateChange += ApplicationStateChange;
_startFormWpf.Show();
CurrentForm = _startForm;
CurrentWpfForm = _startFormWpf;
break;
case ApplicationStage.ImportProcess:
@@ -94,38 +89,37 @@ internal sealed class ImportApplication : ApplicationContext
ServiceProvider
);
_progressForm = ActivatorUtilities.CreateInstance<ProgressForm>(ServiceProvider);
_progressForm.StartPosition = FormStartPosition.CenterParent;
_progressForm.FormClosing += HandleFormClosing;
_progressFormWpf = ActivatorUtilities.CreateInstance<ProgressFormWpf>(
ServiceProvider
);
_progressFormWpf.WindowStartupLocation = WindowStartupLocation.CenterOwner;
_progressFormWpf.Closing += Wpf_HandleFormClosing;
_progressFormWpf.ApplicationStateChange += ApplicationStateChange;
_progressForm.Show();
CurrentForm = _progressForm;
CurrentWpfForm = _progressFormWpf;
_progressFormWpf.Show();
executor.Start();
break;
case ApplicationStage.Viewer:
_entityViewForm = ActivatorUtilities.CreateInstance<EntityViewForm>(
ServiceProvider
);
_entityViewForm.StartPosition = FormStartPosition.CenterParent;
_entityViewForm.ApplicationStateChange += ApplicationStateChange;
_entityViewForm.FormClosing += HandleFormClosing;
_entityForm = ActivatorUtilities.CreateInstance<EntityForm>(ServiceProvider);
_entityForm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
_entityForm.Closing += Wpf_HandleFormClosing;
//_entityForm.ApplicationStateChange += ApplicationStateChange;
_entityForm.Show();
_entityViewForm.Show();
CurrentForm = _entityViewForm;
CurrentWpfForm = _entityForm;
break;
default:
throw new ArgumentOutOfRangeException();
}
Application.DoEvents();
}
private void CloseStage(ApplicationStage stage)
{
CurrentForm = null;
CurrentWpfForm = null;
switch (stage)
{
case ApplicationStage.BootUp:
@@ -133,38 +127,48 @@ internal sealed class ImportApplication : ApplicationContext
break;
case ApplicationStage.InitialSettings:
_startForm!.Hide();
_startForm!.Close();
_startForm = null;
_startFormWpf!.Hide();
_startFormWpf!.Close();
_startFormWpf = null;
break;
case ApplicationStage.ImportProcess:
break;
case ApplicationStage.Viewer:
_entityViewForm!.Hide();
_entityViewForm!.Close();
_entityViewForm = null;
_entityForm!.Hide();
_entityForm!.Close();
_entityForm = null;
break;
default:
throw new ArgumentOutOfRangeException();
}
Application.DoEvents();
}
private void HandleFormClosing(object? sender, FormClosingEventArgs e)
#endregion
#region "События"
public void ApplicationStateChange(object sender, ApplicationStage nextStage)
{
if (sender != CurrentForm)
if (sender?.Equals(CurrentWpfForm) ?? false)
{
e.Cancel = true;
return;
CurrentStage = nextStage;
}
}
private void Wpf_HandleFormClosing(object? sender, CancelEventArgs e)
{
if (sender?.Equals(CurrentWpfForm) ?? false)
{
ExitThread();
}
else
{
e.Cancel = true;
}
}
#endregion
#region "Внедрение зависимостей"
@@ -177,6 +181,7 @@ internal sealed class ImportApplication : ApplicationContext
{
// Контекст базы данных
services.AddEntityFrameworkNpgsql();
services.AddDbContext<Pf2eDbContext>();
//services.AddDbContextPool<Pf2eDbContext>(options =>
//{
+1
View File
@@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>True</UseWPF>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Importers\Implementations\FoundryEn\DataBuilder\**" />
@@ -5,7 +5,7 @@ using Pf2eDataScrapper.App;
using Pf2eDataScrapper.Helpers;
using Pf2eDataScrapper.Importers;
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
using Pf2eDataScrapper.Importers.Implementations.FoundryEn;
using Pf2eDataScrapper.Importers.Implementations.FoundryEn.Compendium;
namespace Pf2eDataScrapper.Processors;
@@ -116,15 +116,13 @@ internal sealed class ProcessorExecutor(
_ => throw new($"Не могу выбрать импортёр для группы {item.Group}"),
};
Progress.Local.Reset(
item.InnerType is null ? compendium.Count() : compendium.Count(item.InnerType)
);
ICollection<string> types = item.InnerType is null
? Collection.GetTypesOfCompendium(item.Compendium ?? throw new("impossible"))
: [item.InnerType];
foreach (
(AbstractCompendiumItem compendiumItem, JObject json) in compendium.Iterate(
item.InnerType
)
)
Progress.Local.Reset(compendium.Count(types));
foreach ((AbstractCompendiumItem compendiumItem, JObject json) in compendium.Iterate(types))
{
Progress.Local.Start(compendiumItem.Id);
+3
View File
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
using Pf2eDataScrapper.Importers.Implementations.FoundryEn;
using Pf2eDataScrapper.WPF;
namespace Pf2eDataScrapper;
@@ -37,6 +38,8 @@ internal static class Program
{
IServiceCollection services = new ServiceCollection();
services.RegisterWpfServices();
ImportApplication.RegisterServices(services);
AonprdImporter.RegisterServices(services);
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using System.IO;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Helpers;
using Pf2eDataScrapper.Importers;
using Pf2eDataScrapper.Processors;
@@ -0,0 +1,88 @@
<UserControl
x:Class="Pf2eDataScrapper.WPF.Components.DbEntityListControl"
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:local="clr-namespace:Pf2eDataScrapper.WPF.Components"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Pf2eDataScrapper.WPF.ViewModels"
d:DataContext="{d:DesignInstance Type=viewModels:DbEntityListViewModel}"
d:DesignHeight="450"
d:DesignWidth="400"
x:ClassModifier="internal"
mc:Ignorable="d">
<UserControl.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlColorKey}}" />
</UserControl.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0">
<Button
Width="25"
Margin="0,0,3,0"
Content="&lt;&lt;"
DockPanel.Dock="Left" />
<Button
Width="25"
Margin="0,0,3,0"
Content="&lt;"
DockPanel.Dock="Left" />
<Button
Width="25"
Margin="3,0,0,0"
Content="&gt;&gt;"
DockPanel.Dock="Right" />
<Button
Width="25"
Margin="3,0,0,0"
Content="&gt;"
DockPanel.Dock="Right" />
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Label VerticalContentAlignment="Center" Content="Страница" />
<TextBox
Width="30"
VerticalContentAlignment="Center"
Text="{Binding Page, StringFormat=\{0:D\}}" />
<Label VerticalContentAlignment="Center" Content="из" />
<Label VerticalContentAlignment="Center" Content="{Binding PageCount, Mode=OneWay}" />
</StackPanel>
</DockPanel>
<TextBox
Grid.Row="1"
VerticalAlignment="Center"
Text="TextBox"
TextWrapping="Wrap" />
<ListView
Grid.Row="2"
d:ItemsSource="{d:SampleData ItemCount=50}"
ItemsSource="{Binding Entities}">
<ListView.View>
<GridView>
<GridViewColumn
Width="Auto"
DisplayMemberBinding="{Binding Id}"
Header="ID" />
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Название" />
<GridViewColumn
Width="Auto"
DisplayMemberBinding="{Binding Rarity}"
Header="Редк." />
</GridView>
</ListView.View>
</ListView>
</Grid>
</UserControl>
@@ -0,0 +1,28 @@
using Pf2eDataScrapper.WPF.ViewModels;
namespace Pf2eDataScrapper.WPF.Components;
/// <summary>
/// Логика взаимодействия для DbEntityListControl.xaml
/// </summary>
internal partial class DbEntityListControl : System.Windows.Controls.UserControl
{
public DbEntityListViewModel? ViewModel
{
get => _viewModel;
set
{
_viewModel = value;
DataContext = ViewModel;
}
}
private DbEntityListViewModel? _viewModel;
public DbEntityListControl()
{
InitializeComponent();
}
//https://www.youtube.com/watch?v=54ZmhbpjBmg
}
@@ -0,0 +1,414 @@
<UserControl
x:Class="Pf2eDataScrapper.WPF.Components.ProcessorCollectionControl"
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"
d:DesignHeight="400"
d:DesignWidth="300"
x:ClassModifier="internal"
BorderThickness="2,2,2,2"
mc:Ignorable="d">
<UserControl.Resources>
<Style x:Key="HeaderCheckbox" TargetType="{x:Type CheckBox}">
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style x:Key="ElementBorder" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="10,5,10,20" />
<Setter Property="BorderThickness" Value="1,1,1,1" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
<Style x:Key="ElementPanelStyle" TargetType="{x:Type WrapPanel}">
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}" />
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ElementCheckBox" TargetType="CheckBox">
<Setter Property="Margin" Value="4,2,4,2" />
</Style>
</UserControl.Resources>
<UserControl.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlColorKey}}" />
</UserControl.Background>
<ScrollViewer>
<StackPanel
x:Name="RootPanel"
Margin="3,3,3,3"
ScrollViewer.CanContentScroll="True">
<CheckBox
x:Name="Test"
Content="Test Header 1"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
<CheckBox
Content="Test Header 2"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2 Test 2 Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
<CheckBox
Content="Test Header 2"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2 Test 2 Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
<CheckBox
Content="Test Header 2"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2 Test 2 Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
<CheckBox
Content="Test Header 2"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2 Test 2 Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
<CheckBox
Content="Test Header 2"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2 Test 2 Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
<CheckBox
Content="Test Header 2"
IsChecked="False"
Style="{DynamicResource HeaderCheckbox}" />
<Border Style="{DynamicResource ElementBorder}">
<WrapPanel Style="{StaticResource ElementPanelStyle}">
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2 Test 2 Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 1"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 2"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 3"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
<CheckBox
Content="Test 4"
IsChecked="False"
Style="{DynamicResource ElementCheckBox}" />
</WrapPanel>
</Border>
</StackPanel>
</ScrollViewer>
</UserControl>
@@ -0,0 +1,160 @@
using System.ComponentModel;
using System.Windows;
using Pf2eDataScrapper.App;
using CheckBox = System.Windows.Controls.CheckBox;
namespace Pf2eDataScrapper.WPF.Components;
/// <summary>
/// Логика взаимодействия для ProcessorCollectionControl.xaml
/// </summary>
internal partial class ProcessorCollectionControl : System.Windows.Controls.UserControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ProcessorCollection Collection
{
get => _collection;
set
{
_collection = value;
SetContent();
}
}
private ProcessorCollection _collection = null!;
public ProcessorCollectionControl()
{
InitializeComponent();
}
private Dictionary<ProcessorGroupEnum, CheckBox> GroupCheckBoxes { get; } = [];
private Dictionary<ProcessorGroupEnum, bool?> GroupLastStats { get; } = [];
private Dictionary<string, CheckBox> ItemCheckBoxes { get; } = [];
private void SetContent()
{
RootPanel.Children.Clear();
foreach (ProcessorGroupEnum group in Enum.GetValues<ProcessorGroupEnum>())
{
GroupCheckBoxes[group] = new()
{
Content = group.ToString(),
IsThreeState = true,
Style = (Style)Resources["HeaderCheckbox"]!,
};
GroupCheckBoxes[group].Click += GroupCheckBox_Click;
System.Windows.Controls.Border border = new()
{
Style = (Style)Resources["ElementBorder"]!,
};
System.Windows.Controls.WrapPanel wrapPanel = new()
{
Style = (Style)Resources["ElementPanelStyle"]!,
};
foreach (
ProcessorCollectionItem item in Collection.AllItems.Where(item =>
item.Group == group
)
)
{
ItemCheckBoxes[item.Name] = new()
{
Content = item.Description,
ToolTip = item.Name,
IsChecked = item.Active,
Style = (Style)Resources["ElementCheckBox"]!,
};
ItemCheckBoxes[item.Name].Click += ItemCheckBox_Click;
wrapPanel.Children.Add(ItemCheckBoxes[item.Name]);
}
border.Child = wrapPanel;
RootPanel.Children.Add(GroupCheckBoxes[group]);
RootPanel.Children.Add(border);
}
UpdateContent();
}
private void UpdateContent()
{
GroupLastStats.Clear();
List<string> checkedItems = [];
foreach ((string key, CheckBox? checkBox) in ItemCheckBoxes)
{
ProcessorCollectionItem item = Collection[key];
bool isChecked = checkBox.IsChecked ?? false;
if (GroupLastStats.TryGetValue(item.Group, out bool? state))
{
/*
* | true | false | null
* | Checked | Unchecked | Indeterminate
* -------+---------+-----------+---------------
* true | true | null | null
* false | null | false | null
*/
GroupLastStats[item.Group] =
isChecked && state == true ? true
: !isChecked && state == false ? false
: null;
}
else
{
GroupLastStats[item.Group] = isChecked;
}
if (isChecked)
{
checkedItems.Add(key);
}
}
foreach ((ProcessorGroupEnum groupEnum, CheckBox? checkBox) in GroupCheckBoxes)
{
checkBox.IsChecked = GroupLastStats.GetValueOrDefault(groupEnum, null);
}
Collection.FilterProcessors(checkedItems);
}
private void GroupCheckBox_Click(object sender, RoutedEventArgs e)
{
CheckBox groupCheckBox = (CheckBox)sender;
ProcessorGroupEnum groupEnum = GroupCheckBoxes
.First(pair => pair.Value == groupCheckBox)
.Key;
groupCheckBox.IsChecked =
GroupLastStats[groupEnum] is null || groupCheckBox.IsChecked is not null;
foreach (
(string _, CheckBox checkBox) in ItemCheckBoxes.Where(pair =>
Collection[pair.Key].Group == groupEnum
)
)
{
checkBox.IsChecked = groupCheckBox.IsChecked;
}
UpdateContent();
}
private void ItemCheckBox_Click(object sender, RoutedEventArgs e)
{
UpdateContent();
}
}
@@ -0,0 +1,20 @@
using Pf2eModel.Model.Base;
namespace Pf2eDataScrapper.WPF.Stores;
public class SelectedEntityStore
{
private Entity? _selectedEntityType;
public Entity? SelectedEntityType
{
get => _selectedEntityType;
set
{
_selectedEntityType = value;
SelectedEntityTypeChanged?.Invoke(SelectedEntityType);
}
}
public event Action<Entity?>? SelectedEntityTypeChanged;
}
@@ -0,0 +1,20 @@
using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.WPF.Stores;
internal class SelectedEntityTypeStore
{
private EntityType? _selectedEntityType;
public EntityType? SelectedEntityType
{
get => _selectedEntityType;
set
{
_selectedEntityType = value;
SelectedEntityTypeChanged?.Invoke(SelectedEntityType);
}
}
public event Action<EntityType?>? SelectedEntityTypeChanged;
}
+23
View File
@@ -0,0 +1,23 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Pf2eDataScrapper.WPF;
internal abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new(propertyName));
}
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value))
return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
@@ -0,0 +1,155 @@
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using Pf2eDataScrapper.WPF.Stores;
using Pf2eModel;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.WPF.ViewModels;
internal class DbEntityListViewModel : ViewModelBase
{
public Pf2eDbContext Context { get; }
public SelectedEntityTypeStore SelectedEntityTypeStore { get; }
private EntityType? SelectedEntityType => SelectedEntityTypeStore.SelectedEntityType;
public int Page
{
get => _page;
set
{
_page = Math.Clamp(value, 1, PageCount);
OnPropertyChanged();
}
}
private int _page = 1;
public int EntitiesCount
{
get => _entitiesCount;
set
{
_entitiesCount = value;
OnPropertyChanged();
OnPropertyChanged(nameof(PageCount));
}
}
private int _entitiesCount = 1;
public int PerPage
{
get => _perPage;
set
{
_perPage = value;
OnPropertyChanged();
OnPropertyChanged(nameof(PageCount));
}
}
private int _perPage = 30;
public string Search
{
get => _search;
set
{
_search = value;
OnPropertyChanged();
}
}
private string _search = "";
public int PageCount => Convert.ToInt32(Math.Ceiling(1.0 * EntitiesCount / PerPage));
public IEnumerable<Entity> Entities
{
get => _entities;
set
{
_entities = [.. value];
OnPropertyChanged();
}
}
private ObservableCollection<Entity> _entities = [];
public DbEntityListViewModel(
Pf2eDbContext context,
SelectedEntityTypeStore selectedEntityTypeStore
)
{
Context = context;
SelectedEntityTypeStore = selectedEntityTypeStore;
SelectedEntityTypeStore.SelectedEntityTypeChanged +=
SelectedEntityTypeStore_SelectedEntityTypeChanged;
}
~DbEntityListViewModel()
{
SelectedEntityTypeStore.SelectedEntityTypeChanged -=
SelectedEntityTypeStore_SelectedEntityTypeChanged;
}
private void SelectedEntityTypeStore_SelectedEntityTypeChanged(EntityType? entityType)
{
if (entityType is null)
{
Page = 1;
EntitiesCount = 1;
Entities = [];
return;
}
Query();
}
/// <summary>
/// Поток, в котором будет выполняться запрос к базе данных.
/// </summary>
private Thread? _queryThread;
private void Query()
{
Abort();
_queryThread = new(PerformQuery);
_queryThread.Start();
}
/// <summary>
/// Прерывает выполнение потока, если он ещё не завершён.
/// </summary>
public void Abort()
{
_queryThread?.Interrupt();
_queryThread = null;
}
/// <summary>
/// Выполняет запрос к базе данных и обрабатывает результаты.
/// </summary>
private void PerformQuery()
{
try
{
Pf2eDbContext dbContext = new();
IQueryable<Entity> query =
Search == ""
? dbContext.Entities.Where(e => e.Type == SelectedEntityType)
:
// ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall
dbContext.Entities.Where(e =>
e.Type == SelectedEntityType && Pf2eDbContext.LocaleSearch(e.Name, Search)
);
Page = 1;
EntitiesCount = query.Count();
Entities = query.OrderBy(e => e.Id).Skip((Page - 1) * PerPage).Take(PerPage).ToList();
}
catch (ThreadInterruptedException)
{
// Ignore
}
}
}
@@ -0,0 +1,49 @@
using Pf2eDataScrapper.WPF.Stores;
using Pf2eModel;
using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.WPF.ViewModels;
internal class EntityFormViewModel : ViewModelBase
{
public IServiceProvider ServiceProvider { get; }
public Pf2eDbContext Context { get; }
public SelectedEntityTypeStore SelectedEntityTypeStore { get; }
public IEnumerable<EntityType> EntityTypes { get; set; } = [];
public EntityType? SelectedEntityType
{
get => SelectedEntityTypeStore.SelectedEntityType;
set
{
SelectedEntityTypeStore.SelectedEntityType = value;
OnPropertyChanged();
}
}
public string TestText => SelectedEntityType?.ToString() ?? "null";
public EntityFormViewModel(
IServiceProvider serviceProvider,
Pf2eDbContext context,
SelectedEntityTypeStore selectedEntityTypeStore
)
{
ServiceProvider = serviceProvider;
Context = context;
SelectedEntityTypeStore = selectedEntityTypeStore;
Update();
}
public void Update()
{
LoadEntityTypes();
}
private void LoadEntityTypes()
{
EntityTypes = Context.Entities.Select(e => e.Type).Distinct().ToList();
OnPropertyChanged(nameof(EntityTypes));
}
}
@@ -0,0 +1,69 @@
<Window
x:Class="Pf2eDataScrapper.WPF.Views.EntityForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:components="clr-namespace:Pf2eDataScrapper.WPF.Components"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Pf2eDataScrapper.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Pf2eDataScrapper.WPF.ViewModels"
Title="EntityForm"
Width="1000"
Height="600"
d:DataContext="{d:DesignInstance Type=viewModels:EntityFormViewModel}"
x:ClassModifier="internal"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="150" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<GridSplitter
Grid.Row="0"
Grid.RowSpan="4"
Grid.Column="1"
Width="5"
HorizontalAlignment="Stretch" />
<GridSplitter
Grid.Row="0"
Grid.RowSpan="4"
Grid.Column="3"
Width="5"
HorizontalAlignment="Stretch" />
<GridSplitter
Grid.Row="2"
Grid.Column="0"
Height="5"
HorizontalAlignment="Stretch"
Cursor="SizeNS"
ResizeDirection="Rows" />
<ListBox
x:Name="EntityTypeListBox"
Grid.Row="1"
Grid.Column="0"
d:ItemsSource="{d:SampleData ItemCount=10}"
ItemsSource="{Binding EntityTypes}"
SelectedItem="{Binding SelectedEntityType}" />
<components:DbEntityListControl x:Name="DbEntityListControl" Grid.Row="2" Grid.Column="0" />
<TextBox
Grid.Row="0"
Grid.RowSpan="4"
Grid.Column="4"
IsReadOnly="True"
Text="{Binding TestText, Mode=OneWay}"
TextWrapping="Wrap" />
</Grid>
</Window>
@@ -0,0 +1,29 @@
using System.Collections.ObjectModel;
using System.Windows;
using Pf2eDataScrapper.WPF.ViewModels;
using Pf2eModel;
using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.WPF.Views;
/// <summary>
/// Логика взаимодействия для EntityForm.xaml
/// </summary>
internal partial class EntityForm : Window
{
public Pf2eDbContext Context { get; }
public EntityFormViewModel ViewModel { get; }
public EntityForm(
Pf2eDbContext context,
EntityFormViewModel viewModel,
DbEntityListViewModel dbEntityListViewModel
)
{
Context = context;
ViewModel = viewModel;
DataContext = ViewModel;
InitializeComponent();
DbEntityListControl.ViewModel = dbEntityListViewModel;
}
}
@@ -0,0 +1,85 @@
<Window
x:Class="Pf2eDataScrapper.WPF.ProgressFormWpf"
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:local="clr-namespace:Pf2eDataScrapper.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="ProgressWindow"
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}"
ScrollViewer.CanContentScroll="True">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto" Header="Время" />
<GridViewColumn Width="Auto" Header="Тип" />
<GridViewColumn Width="Auto" Header="Сообщение" />
</GridView>
</ListView.View>
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type local:ListViewRow}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
HorizontalAlignment="Left"
Background="{Binding Path=Color}"
Text="{Binding Path=Time}" />
<TextBlock
Grid.Column="1"
HorizontalAlignment="Left"
Background="{Binding Path=Color}"
Text="{Binding Path=Level}" />
<TextBlock
Grid.Column="2"
HorizontalAlignment="Left"
Background="{Binding Path=Color}"
Text="{Binding Path=Message}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
@@ -0,0 +1,78 @@
using System.Collections.ObjectModel;
using System.Windows;
using Pf2eDataScrapper.Helpers;
namespace Pf2eDataScrapper.WPF;
/// <summary>
/// Логика взаимодействия для ProgressFormWpf.xaml
/// </summary>
internal partial class ProgressFormWpf : Window
{
public ProcessProgress Progress { get; }
public ObservableCollection<ListViewRow> ViewRows { get; set; } = [];
public ProgressFormWpf(ProcessProgress progress)
{
Progress = progress;
InitializeComponent();
Progress.ProgressUpdate += Progress_ProgressUpdate;
Progress.ProgressMessage += Progress_ProgressMessage;
}
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);
}
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;
}
+61
View File
@@ -0,0 +1,61 @@
<Window
x:Class="Pf2eDataScrapper.WPF.Views.StartForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:components="clr-namespace:Pf2eDataScrapper.WPF.Components"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Pf2eDataScrapper.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="StartForm"
Width="800"
Height="600"
x:ClassModifier="internal"
Loaded="Window_Loaded"
mc:Ignorable="d">
<Window.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlColorKey}}" />
</Window.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5*" MinWidth="200" />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Row="0"
Grid.Column="0"
Margin="3,3,3,3">
<Button
Margin="0,0,0,3"
Click="ViewerButton_Click"
Content="Просмотр сущностей" />
<Button Content="Просмотр правил" />
</StackPanel>
<Button
Grid.Row="1"
Grid.Column="0"
Margin="3,3,3,3"
Click="StartButton_Click"
Content="Старт" />
<GridSplitter
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Width="5"
HorizontalAlignment="Stretch" />
<components:ProcessorCollectionControl
x:Name="ProcessorCollectionControl"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="2" />
</Grid>
</Window>
@@ -0,0 +1,35 @@
using System.Windows;
using Pf2eDataScrapper.App;
namespace Pf2eDataScrapper.WPF.Views;
/// <summary>
/// Логика взаимодействия для StartForm.xaml
/// </summary>
internal partial class StartForm : Window
{
public ProcessorCollection Collection { get; }
public StartForm(ProcessorCollection collection)
{
Collection = collection;
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ProcessorCollectionControl.Collection = Collection;
}
private void ViewerButton_Click(object sender, RoutedEventArgs e)
{
ApplicationStateChange?.Invoke(this, ApplicationStage.Viewer);
}
private void StartButton_Click(object sender, RoutedEventArgs e)
{
ApplicationStateChange?.Invoke(this, ApplicationStage.ImportProcess);
}
public event ImportApplication.ApplicationStateChangeDelegate? ApplicationStateChange;
}
@@ -0,0 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
using Pf2eDataScrapper.WPF.Stores;
using Pf2eDataScrapper.WPF.ViewModels;
namespace Pf2eDataScrapper.WPF;
public static class WpfServiceProviderExtension
{
public static IServiceCollection RegisterWpfServices(this IServiceCollection collection)
{
return collection
// ViewModels
.AddTransient<EntityFormViewModel>()
.AddTransient<DbEntityListViewModel>()
// Stores
.AddSingleton<SelectedEntityTypeStore>()
.AddSingleton<SelectedEntityStore>()
//
;
}
}
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations
{
[DbContext(typeof(Pf2eDbContext))]
[Migration("20250515054227_1")]
[Migration("20250515080518_1")]
partial class _1
{
/// <inheritdoc />