Compare commits

...
3 Commits
34 changed files with 400 additions and 276 deletions
@@ -36,9 +36,16 @@ internal class ProcessProgress : AbstractLogger
ProgressMessage?.Invoke(this, level, message);
}
public void Complete()
{
ProgressComplete?.Invoke(this);
}
public delegate void ProgressUpdateDelegate(ProcessProgress sender);
public event ProgressUpdateDelegate? ProgressUpdate;
public event ProgressUpdateDelegate? ProgressComplete;
public delegate void ProgressMessageDelegate(
ProcessProgress sender,
LogLevel level,
+8 -8
View File
@@ -7,7 +7,8 @@ using Pf2eDataScrapper.Helpers;
using Pf2eDataScrapper.Processors;
using Pf2eDataScrapper.WPF;
using Pf2eDataScrapper.WPF.EntityViewer;
using Pf2eDataScrapper.WPF.Views;
using Pf2eDataScrapper.WPF.ProgressForm;
using Pf2eDataScrapper.WPF.StartForm;
using Pf2eModel;
using Slugify;
@@ -25,8 +26,8 @@ internal sealed class ImportApplication : Application
Settings = settings;
Processors = processors;
//CurrentStage = ApplicationStage.InitialSettings;
CurrentStage = ApplicationStage.Viewer;
CurrentStage = ApplicationStage.InitialSettings;
//CurrentStage = ApplicationStage.Viewer;
}
#region "Поля"
@@ -50,7 +51,7 @@ internal sealed class ImportApplication : Application
#endregion
#region "Формы"
#region "Жизненный цикл"
private StartForm? _startFormWpf;
@@ -58,10 +59,6 @@ internal sealed class ImportApplication : Application
private EntityForm? _entityForm;
#endregion
#region "Жизненный цикл"
private Window? CurrentWpfForm { get; set; }
public delegate void ApplicationStateChangeDelegate(object sender, ApplicationStage nextStage);
@@ -133,6 +130,9 @@ internal sealed class ImportApplication : Application
break;
case ApplicationStage.ImportProcess:
_progressFormWpf!.Hide();
_progressFormWpf!.Close();
_progressFormWpf = null;
break;
case ApplicationStage.Viewer:
@@ -59,14 +59,14 @@ internal partial class StringHelper
}
/// <summary>
/// Извлечение информации о названии источника.
/// Извлечение суффикса из описания источника.
/// </summary>
/// <param name="input">Исходная строка.</param>
/// <returns>Название источника.</returns>
public string ResolveSource(string input)
/// <returns>Суффикс.</returns>
public string ResolveSourceSuffix(string input)
{
Match match = SourceSuffixRegex().Match(input);
return match.Captures.Count > 0 ? match.Captures[0].Value : "";
return match.Captures.Count > 0 ? match.Groups[1].Value : "";
}
/// <summary>
@@ -173,7 +173,9 @@ internal abstract class AbstractEntityProcessor(
{
Entity = Entity,
SourceId = Globals.SourceIds[sourceName],
Suffix = StringHelper.ResolveSource(Input.GetRequired<string>("source_markdown")),
Suffix = StringHelper.ResolveSourceSuffix(
Input.GetRequired<string>("source_markdown")
),
IsRemaster = Input.GetOptional<JArray>("legacy_id") is not null,
};
@@ -195,6 +197,7 @@ internal abstract class AbstractEntityProcessor(
Md5 = Input.Md5(),
};
Entity.Externals.Add(external);
Context.EntityExternals.Add(external);
}
@@ -33,16 +33,17 @@ internal class LegacyRemasterProcessors(ProcessorInput input) : AbstractInputPro
{
Context.LegacyRemasters.Add(new() { LegacyId = entityId, RemasterId = remasterId });
}
/*
foreach (int legacyId in GetEntityIds("legacy_id"))
{
Context.LegacyRemasters.Add(new() { LegacyId = legacyId, RemasterId = entityId });
}
*/
}
protected List<int> GetEntityIds(string path)
{
List<string> aonprdIds = (Input.GetOptional<JArray>("path") ?? [])
List<string> aonprdIds = (Input.GetOptional<JArray>(path) ?? [])
.Select(token => token.ToString())
.ToList();
@@ -109,6 +109,10 @@ internal class SpellProcessor(
{
A(new() { Spell = Object, Type = SpellAreaType.Square });
}
if (areaDetails.Contains("fungi"))
{
areaDetails = [areaDetails[0] + " or " + areaDetails[1]];
}
if (areaTypes.Count != areaDetails.Count)
{
@@ -94,6 +94,7 @@ internal sealed class ProcessorExecutor(
else
{
Progress.Processors.Complete();
Progress.Complete();
}
}
@@ -3,7 +3,6 @@
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:viewmodel="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.ViewModel"
Padding="3,3,3,3"
@@ -6,6 +6,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:fa="http://schemas.awesome.incremented/wpf/xaml/fontawesome.sharp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:struct="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure"
xmlns:viewmodel="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.ViewModel"
x:Name="_this"
d:DataContext="{d:DesignInstance Type=viewmodel:ViewViewModel}"
@@ -17,15 +18,15 @@
<UserControl.Resources>
<FontFamily x:Key="FontAwesome">/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Free Solid</FontFamily>
<struct:ColorAdapterConverter x:Key="ColorAdapterConverter" />
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="FontSize" Value="{Binding ButtonSize, ElementName=_this}" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Width" Value="{Binding ButtonSize, ElementName=_this}" />
<Setter Property="Height" Value="{Binding ButtonSize, ElementName=_this}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderThickness" Value="2,2,1,1" />
<Setter Property="Background">
<Setter.Value>
@@ -41,7 +42,17 @@
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="DarkGray" />
<Setter Property="Foreground" Value="DarkSlateGray" />
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Transparent" />
</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>
<SolidColorBrush Color="Transparent" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
@@ -52,6 +63,14 @@
TargetType="Button">
<Setter Property="FontFamily" Value="{StaticResource FontAwesome}" />
</Style>
<Style x:Key="HoverRow" TargetType="Grid">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrush}}" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<UserControl.BorderBrush>
@@ -63,7 +82,7 @@
</UserControl.Background>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Rows}">
<ItemsControl AlternationCount="2" ItemsSource="{Binding Rows}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Grid.IsSharedSizeScope="True" />
@@ -72,7 +91,11 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="{Binding ItemHeight, ElementName=_this}" Visibility="{Binding ItemVisibility}">
<Grid
x:Name="FooBar"
Height="{Binding ItemHeight, ElementName=_this}"
Visibility="{Binding ItemVisibility}">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ColumnOne" />
<ColumnDefinition Width="*" />
@@ -86,13 +109,15 @@
Ladder="{Binding Ladder}" />
<Button
Margin="-22,0,0,0"
Margin="-20,0,0,0"
Padding="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Command="{Binding CollapseCommand}"
Content="{Binding ButtonIcon}"
Style="{StaticResource FaButtonStyle}"
Visibility="{Binding ButtonVisibility}" />
Visibility="{Binding ButtonVisibility}">
<TextBlock Margin="-3,-3,0,0" Text="{Binding ButtonIcon}" />
</Button>
<TextBlock
Margin="2,0,10,0"
@@ -108,14 +133,35 @@
VerticalAlignment="Center"
FontSize="{Binding TypeFontSize, ElementName=_this}"
FontStyle="Italic"
Text="{Binding Type}" />
Text="{Binding Type}">
<TextBlock.Foreground>
<MultiBinding Converter="{StaticResource ColorAdapterConverter}">
<Binding Path="AccentColor" />
</MultiBinding>
</TextBlock.Foreground>
</TextBlock>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Value}" />
Text="{Binding Value}"
TextTrimming="CharacterEllipsis">
<TextBlock.Foreground>
<MultiBinding Converter="{StaticResource ColorAdapterConverter}">
<Binding Path="AccentColor" />
</MultiBinding>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
</Grid>
<DataTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter TargetName="FooBar" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrush}}" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter TargetName="FooBar" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrush}}" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
@@ -5,16 +5,18 @@
xmlns:component="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.Component"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewmodel="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.ViewModel"
Title="EntityForm"
Width="1400"
Height="800"
d:DataContext="{d:DesignInstance Type=viewmodel:EntityFormViewModel}"
x:ClassModifier="internal"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
Loaded="Window_Loaded"
mc:Ignorable="d">
<Grid ClipToBounds="True">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="150" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
@@ -47,6 +49,11 @@
Cursor="SizeNS"
ResizeDirection="Rows" />
<Button
Margin="3,4,0,0"
Click="Button_Click"
Content="&lt;&lt;&lt; Вернуться в начало" />
<ListBox
x:Name="EntityTypeListBox"
Grid.Row="1"
@@ -75,7 +82,7 @@
Grid.RowSpan="4"
Grid.Column="4"
IsReadOnly="True"
Text="{Binding TestText, Mode=OneWay}"
Text="{Binding SelectedEntityDescription, Mode=OneWay}"
TextWrapping="Wrap" />
</Grid>
</Window>
@@ -1,6 +1,5 @@
using System.Collections.ObjectModel;
using System.Windows;
using Pf2eDataScrapper.WPF.Components;
using Pf2eDataScrapper.WPF.EntityViewer.ViewModel;
using Pf2eModel;
using Pf2eModel.Model.Enum;
@@ -12,11 +11,7 @@ internal partial class EntityForm : Window
public Pf2eDbContext Context { get; }
public EntityFormViewModel ViewModel { get; }
public EntityForm(
Pf2eDbContext context,
EntityFormViewModel viewModel,
ViewViewModel entityViewViewModel
)
public EntityForm(Pf2eDbContext context, EntityFormViewModel viewModel)
{
Context = context;
ViewModel = viewModel;
@@ -31,4 +26,9 @@ internal partial class EntityForm : Window
}
private void Window_Loaded(object sender, RoutedEventArgs e) { }
private void Button_Click(object sender, RoutedEventArgs e)
{
(Application.Current as ImportApplication)!.CurrentStage = ApplicationStage.InitialSettings;
}
}
@@ -103,12 +103,7 @@ internal class StructureBuilder
return Create(name, value!, depth);
}
StructureFieldReference reference = new StructureFieldReference(
this,
name,
null,
depth
);
StructureFieldReference reference = new(this, name, null, depth);
processed.AddReference(reference);
return reference;
}
@@ -12,7 +12,8 @@ namespace Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure;
/// <param name="builder">Класс построения структуры данных.</param>
/// <param name="name">Название поля.</param>
/// <param name="depth">Глубина поля.</param>
internal abstract class StructureField(StructureBuilder builder, string name, int depth) : INotifyPropertyChanged
internal abstract class StructureField(StructureBuilder builder, string name, int depth)
: INotifyPropertyChanged
{
/// <summary>
/// Название поля.
@@ -216,3 +217,32 @@ internal class StructureFieldReference(
/// <inheritdoc/>
public override string GetValueString() => "<Reference>";
}
/// <summary>
/// Поле структуры пропускаемого объекта.
/// </summary>
/// <param name="builder">Класс построения структуры данных.</param>
/// <param name="name">Название поля.</param>
/// <param name="reference">Ссылка на объект.</param>
/// <param name="depth">Глубина поля.</param>
internal class StructureFieldIgnored(
StructureBuilder builder,
string name,
StructureFieldComplex? reference,
int depth
) : StructureField(builder, name, depth)
{
/// <summary>
/// Ссылка на объект.
/// </summary>
public StructureFieldComplex? Reference = reference;
/// <inheritdoc/>
public override StructureFieldType FieldType => StructureFieldType.Reference;
/// <inheritdoc/>
public override string GetTypeString() => Reference?.GetTypeString() ?? "???";
/// <inheritdoc/>
public override string GetValueString() => "<Ignored>";
}
@@ -41,6 +41,19 @@ internal class StructureFieldComplex : StructureField
}
private bool _collapsed;
/// <summary>
/// Флаг, указывающий, что у этот элемент можно свернуть.
/// </summary>
public bool Collapsable
{
get => Fields.Count > 0;
}
/// <summary>
/// Значение поля идентификатора элемента.
/// </summary>
public string? IdValue { get; private set; }
/// <inheritdoc/>
public override bool Visible
{
@@ -118,14 +131,20 @@ internal class StructureFieldComplex : StructureField
Type type = value.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
SetFieldsFromRecords(
properties
.Where(property =>
property.GetAttribute<Newtonsoft.Json.JsonIgnoreAttribute>() is null
)
.Select(property => new FieldRecord(property.Name, property.GetValue(value, null)))
.ToList()
);
var records = properties
.Where(property => property.GetAttribute<Newtonsoft.Json.JsonIgnoreAttribute>() is null)
.Select(property => new FieldRecord(property.Name, property.GetValue(value, null)))
.ToList();
var idRecord = records.FirstOrDefault(record => record.Name == "Id");
if (idRecord is not null && idRecord.Value is not null)
{
records.Remove(idRecord);
IdValue = idRecord.Value.ToString();
}
SetFieldsFromRecords(records);
}
/// <summary>
@@ -203,6 +222,12 @@ internal class StructureFieldComplex : StructureField
{
return Fields.Count.ToString() + (Fields.Count == 1 ? " item" : " items");
}
if (IdValue is not null)
{
return $"#{IdValue}";
}
return "";
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -9,6 +10,9 @@ using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using FontAwesome.Sharp;
using static System.Runtime.InteropServices.JavaScript.JSType;
using static LinqToDB.Sql;
using Color = System.Windows.Media.Color;
namespace Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure;
@@ -27,7 +31,8 @@ internal class StructureRow : INotifyPropertyChanged
/// <summary>
/// Флаг наличия кнопки.
/// </summary>
public bool HasButton => Field.FieldType == StructureFieldType.Complex;
public bool HasButton =>
Field.FieldType == StructureFieldType.Complex && ((StructureFieldComplex)Field).Collapsable;
/// <summary>
/// Флаг, указывающий, отображается ли строка.
@@ -47,7 +52,10 @@ internal class StructureRow : INotifyPropertyChanged
/// <summary>
/// Иконка кнопки.
/// </summary>
public string ButtonIcon => HasButton && !((StructureFieldComplex)Field).Collapsed ? IconChar.PlusSquare.ToChar() : IconChar.MinusSquare.ToChar();
public string ButtonIcon =>
HasButton && !((StructureFieldComplex)Field).Collapsed
? IconChar.PlusSquare.ToChar()
: IconChar.MinusSquare.ToChar();
/// <summary>
/// Глубина отображения поля.
@@ -78,7 +86,26 @@ internal class StructureRow : INotifyPropertyChanged
/// <summary>
/// Строковое представление значения поля.
/// </summary>
public string Value => Field.GetValueString();
public string Value => Field.GetValueString().Replace("\r", "").Replace("\n", "");
/// <summary>
/// Цвет значения
/// </summary>
public Color? AccentColor =>
Field switch
{
StructureFieldPrimitive primitive => System.Type.GetTypeCode(primitive.Type) switch
{
TypeCode.Boolean => Colors.DarkGoldenrod,
TypeCode.Int32 => Colors.Blue,
TypeCode.Double => Colors.Aqua,
TypeCode.String => Colors.Green,
_ => null,
},
StructureFieldEnum => Colors.Red,
StructureFieldNull => Colors.Transparent,
_ => null,
};
/// <summary>
/// Команда переключения.
@@ -147,3 +174,59 @@ internal class CollapseCommand(StructureRow structureRow) : ICommand
field.Collapsed = !field.Collapsed;
}
}
public class ColorAdapterConverter : IMultiValueConverter
{
private byte Mix(byte a, byte b, double rate) =>
System.Convert.ToByte(Math.Round(a * rate + b * (1 - rate)));
public object? Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
{
Color textColor = System.Windows.SystemColors.WindowTextColor;
double a = textColor.A;
double r = textColor.R;
double g = textColor.G;
double b = textColor.B;
int n = 1 + value.Length;
foreach (var item in value)
{
if (item == null || item is not Color)
{
n--;
continue;
}
Color color = (Color)item;
a += color.A;
r += color.R;
g += color.G;
b += color.B;
}
Color resultColor = Color.FromArgb(
System.Convert.ToByte(Math.Round(a / n)),
System.Convert.ToByte(Math.Round(r / n)),
System.Convert.ToByte(Math.Round(g / n)),
System.Convert.ToByte(Math.Round(b / n))
);
var @switch = new Dictionary<Type, Func<object>>
{
{ typeof(System.Windows.Media.Brush), () => new SolidColorBrush(resultColor) },
};
return @switch.TryGetValue(targetType, out var action) ? action() : null;
}
public object[] ConvertBack(
object value,
Type[] targetType,
object parameter,
CultureInfo culture
)
{
throw new NotImplementedException();
}
}
@@ -13,9 +13,9 @@ public class SelectedEntityStore
set
{
_selectedEntity = value;
SelectedEntityTypeChanged?.Invoke(SelectedEntity);
SelectedEntityChanged?.Invoke(SelectedEntity);
}
}
public event Action<Entity?>? SelectedEntityTypeChanged;
public event Action<Entity?>? SelectedEntityChanged;
}
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Pf2eDataScrapper.WPF.EntityViewer.Stores;
using Pf2eModel;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eDataScrapper.WPF.EntityViewer.ViewModel;
@@ -16,13 +17,15 @@ internal class EntityFormViewModel : ViewModelBase
public EntityListViewModel DbEntityListViewModel { get; }
public ViewViewModel ViewViewModel { get; }
public SelectedEntityTypeStore SelectedEntityTypeStore { get; }
public SelectedEntityStore SelectedEntityStore { get; }
public EntityFormViewModel(
IServiceProvider serviceProvider,
Pf2eDbContext context,
EntityListViewModel entityListViewModel,
ViewViewModel viewViewModel,
SelectedEntityTypeStore selectedEntityTypeStore
SelectedEntityTypeStore selectedEntityTypeStore,
SelectedEntityStore selectedEntityStore
)
{
ServiceProvider = serviceProvider;
@@ -30,7 +33,11 @@ internal class EntityFormViewModel : ViewModelBase
DbEntityListViewModel = entityListViewModel;
ViewViewModel = viewViewModel;
SelectedEntityTypeStore = selectedEntityTypeStore;
SelectedEntityStore = selectedEntityStore;
Update();
SelectedEntityStore.SelectedEntityChanged += SelectedEntityStore_SelectedEntityChanged;
}
public void Update()
@@ -64,5 +71,19 @@ internal class EntityFormViewModel : ViewModelBase
#endregion
#region "Текущий элемент"
public string SelectedEntityDescription
{
get => SelectedEntityStore.SelectedEntity?.Description ?? "";
}
private void SelectedEntityStore_SelectedEntityChanged(Entity? obj)
{
OnPropertyChanged(nameof(SelectedEntityDescription));
}
#endregion
public string TestText => SelectedEntityType?.ToString() ?? "null";
}
@@ -87,6 +87,7 @@ internal class EntityListViewModel : ViewModelBase
set
{
_entities = [.. value];
SelectedEntity = Entities.FirstOrDefault();
OnPropertyChanged();
}
}
@@ -144,55 +145,24 @@ internal class EntityListViewModel : ViewModelBase
#region "Запросы"
/// <summary>
/// Поток, в котором будет выполняться запрос к базе данных.
/// </summary>
private Thread? _queryThread;
public void Reload()
{
Abort();
_queryThread = new(PerformQuery);
_queryThread.Start();
}
/// <summary>
/// Прерывает выполнение потока, если он ещё не завершён.
/// </summary>
public void Abort()
{
_queryThread?.Interrupt();
_queryThread = null;
}
/// <summary>
/// Выполняет запрос к базе данных и обрабатывает результаты.
/// </summary>
private void PerformQuery()
public void Reload()
{
try
{
Pf2eDbContext dbContext = new();
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)
);
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)
);
EntitiesCount = query.Count();
Entities =
[
.. query.OrderBy(e => e.Id).Skip((Page - 1) * PerPage).Take(PerPage).ToList(),
];
}
catch (ThreadInterruptedException)
{
// Ignore
}
EntitiesCount = query.Count();
Entities = [.. query.OrderBy(e => e.Id).Skip((Page - 1) * PerPage).Take(PerPage).ToList()];
}
#endregion
@@ -31,7 +31,6 @@ internal class ViewViewModel : ViewModelBase
{
_rows = value;
OnPropertyChanged();
}
}
private ObservableCollection<StructureRow> _rows = [];
@@ -45,14 +44,12 @@ internal class ViewViewModel : ViewModelBase
Context = context;
SelectedEntityStore = selectedEntityStore;
SelectedEntityStore.SelectedEntityTypeChanged +=
SelectedEntityStore_SelectedEntityTypeChanged;
SelectedEntityStore.SelectedEntityChanged += SelectedEntityStore_SelectedEntityTypeChanged;
}
~ViewViewModel()
{
SelectedEntityStore.SelectedEntityTypeChanged -=
SelectedEntityStore_SelectedEntityTypeChanged;
SelectedEntityStore.SelectedEntityChanged -= SelectedEntityStore_SelectedEntityTypeChanged;
}
private void SelectedEntityStore_SelectedEntityTypeChanged(Pf2eModel.Model.Base.Entity? entity)
@@ -1,16 +1,17 @@
<Window
x:Class="Pf2eDataScrapper.WPF.ProgressForm"
x:Class="Pf2eDataScrapper.WPF.ProgressForm.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:local="clr-namespace:Pf2eDataScrapper.WPF"
xmlns:local="clr-namespace:Pf2eDataScrapper.WPF.ProgressForm"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="ProgressWindow"
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" />
@@ -42,40 +43,52 @@
<ListView
x:Name="MessageListView"
Grid.Row="5"
ItemsSource="{Binding ViewRows}"
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" Header="Время" />
<GridViewColumn Width="Auto" Header="Тип" />
<GridViewColumn Width="Auto" Header="Сообщение" />
<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 DataType="{x:Type local:ListViewRow}">
<DataTemplate>
<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}" />
Background="{Binding Path=Color}" />
<TextBlock
Grid.Column="1"
HorizontalAlignment="Left"
Background="{Binding Path=Color}"
Text="{Binding Path=Level}" />
Background="{Binding Path=Color}" />
<TextBlock
Grid.Column="2"
HorizontalAlignment="Left"
Background="{Binding Path=Color}"
Text="{Binding Path=Message}" />
Background="{Binding Path=Color}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
@@ -4,7 +4,7 @@ using System.Drawing;
using System.Windows;
using Pf2eDataScrapper.Helpers;
namespace Pf2eDataScrapper.WPF;
namespace Pf2eDataScrapper.WPF.ProgressForm;
/// <summary>
/// Логика взаимодействия для ProgressFormWpf.xaml
@@ -23,8 +23,10 @@ internal partial class ProgressForm : Window
Progress.ProgressUpdate += Progress_ProgressUpdate;
Progress.ProgressMessage += Progress_ProgressMessage;
Progress.ProgressComplete += Progress_ProgressComplete;
}
private void Progress_ProgressUpdate(ProcessProgress sender)
{
if (!Dispatcher.CheckAccess())
@@ -53,6 +55,12 @@ internal partial class ProgressForm : Window
ListViewRow item = new(level, message) { IsVisible = true };
ViewRows.Add(item);
MessageListView.ScrollIntoView(item);
}
private void Progress_ProgressComplete(ProcessProgress sender)
{
//(Application.Current as ImportApplication)!.CurrentStage = ApplicationStage.Viewer;
}
public event ImportApplication.ApplicationStateChangeDelegate? ApplicationStateChange;
@@ -1,5 +1,5 @@
<UserControl
x:Class="Pf2eDataScrapper.WPF.Components.ProcessorCollectionControl"
x:Class="Pf2eDataScrapper.WPF.StartForm.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"
@@ -6,7 +6,7 @@ using System.Windows;
using Pf2eDataScrapper.App;
using CheckBox = System.Windows.Controls.CheckBox;
namespace Pf2eDataScrapper.WPF.Components;
namespace Pf2eDataScrapper.WPF.StartForm.Components;
/// <summary>
/// Логика взаимодействия для ProcessorCollectionControl.xaml
@@ -1,8 +1,8 @@
<Window
x:Class="Pf2eDataScrapper.WPF.Views.StartForm"
x:Class="Pf2eDataScrapper.WPF.StartForm.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:comp="clr-namespace:Pf2eDataScrapper.WPF.StartForm.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"
@@ -52,10 +52,11 @@
Width="5"
HorizontalAlignment="Stretch" />
<components:ProcessorCollectionControl
<comp:ProcessorCollectionControl
x:Name="ProcessorCollectionControl"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="2" />
</Grid>
</Window>
@@ -1,11 +1,8 @@
using System.Windows;
using Pf2eDataScrapper.App;
namespace Pf2eDataScrapper.WPF.Views;
namespace Pf2eDataScrapper.WPF.StartForm;
/// <summary>
/// Логика взаимодействия для StartForm.xaml
/// </summary>
internal partial class StartForm : Window
{
public ProcessorCollection Collection { get; }
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Pf2eDataScrapper.WPF.Components;
using Pf2eDataScrapper.WPF.EntityViewer.Stores;
using Pf2eDataScrapper.WPF.EntityViewer.ViewModel;
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations
{
[DbContext(typeof(Pf2eDbContext))]
[Migration("20250516162158_1")]
[Migration("20250521102908_1")]
partial class _1
{
/// <inheritdoc />
@@ -288,36 +288,11 @@ namespace Pf2eModel.Migrations
.HasColumnOrder(2)
.HasComment("Идентификатор цели");
b.Property<int>("LegacyEntitiesId")
.HasColumnType("integer")
.HasColumnName("legacy_entities_id");
b.Property<int>("LegacyEntityId")
.HasColumnType("integer")
.HasColumnName("legacy_entity_id");
b.Property<int>("RemasterEntitiesId")
.HasColumnType("integer")
.HasColumnName("remaster_entities_id");
b.Property<int>("RemasterEntityId")
.HasColumnType("integer")
.HasColumnName("remaster_entity_id");
b.HasKey("LegacyId", "RemasterId")
.HasName("pk_legacy_remasters");
b.HasIndex("LegacyEntitiesId")
.HasDatabaseName("ix_legacy_remasters_legacy_entities_id");
b.HasIndex("LegacyEntityId")
.HasDatabaseName("ix_legacy_remasters_legacy_entity_id");
b.HasIndex("RemasterEntitiesId")
.HasDatabaseName("ix_legacy_remasters_remaster_entities_id");
b.HasIndex("RemasterEntityId")
.HasDatabaseName("ix_legacy_remasters_remaster_entity_id");
b.HasIndex("RemasterId")
.HasDatabaseName("ix_legacy_remasters_remaster_id");
b.ToTable("legacy_remasters", (string)null);
});
@@ -1973,33 +1948,19 @@ namespace Pf2eModel.Migrations
modelBuilder.Entity("Pf2eModel.Model.Base.LegacyRemaster", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", null)
.WithMany()
.HasForeignKey("LegacyEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_legacy_entities_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "LegacyEntity")
.WithMany()
.HasForeignKey("LegacyEntityId")
.WithMany("LegacyTransferEntities")
.HasForeignKey("LegacyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_legacy_entity_id");
b.HasOne("Pf2eModel.Model.Base.Entity", null)
.WithMany()
.HasForeignKey("RemasterEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_remaster_entities_id");
.HasConstraintName("fk_legacy_remasters_entities_legacy_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "RemasterEntity")
.WithMany()
.HasForeignKey("RemasterEntityId")
.WithMany("RemasterTransferEntities")
.HasForeignKey("RemasterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_remaster_entity_id");
.HasConstraintName("fk_legacy_remasters_entities_remaster_id");
b.Navigation("LegacyEntity");
@@ -2638,6 +2599,10 @@ namespace Pf2eModel.Migrations
b.Navigation("Externals");
b.Navigation("LegacyTransferEntities");
b.Navigation("RemasterTransferEntities");
b.Navigation("Sources");
});
@@ -316,36 +316,20 @@ namespace Pf2eModel.Migrations
columns: table => new
{
legacy_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор сущности"),
remaster_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор цели"),
legacy_entity_id = table.Column<int>(type: "integer", nullable: false),
remaster_entity_id = table.Column<int>(type: "integer", nullable: false),
legacy_entities_id = table.Column<int>(type: "integer", nullable: false),
remaster_entities_id = table.Column<int>(type: "integer", nullable: false)
remaster_id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор цели")
},
constraints: table =>
{
table.PrimaryKey("pk_legacy_remasters", x => new { x.legacy_id, x.remaster_id });
table.ForeignKey(
name: "fk_legacy_remasters_entities_legacy_entities_id",
column: x => x.legacy_entities_id,
name: "fk_legacy_remasters_entities_legacy_id",
column: x => x.legacy_id,
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_legacy_remasters_entities_legacy_entity_id",
column: x => x.legacy_entity_id,
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_legacy_remasters_entities_remaster_entities_id",
column: x => x.remaster_entities_id,
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_legacy_remasters_entities_remaster_entity_id",
column: x => x.remaster_entity_id,
name: "fk_legacy_remasters_entities_remaster_id",
column: x => x.remaster_id,
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
@@ -1362,24 +1346,9 @@ namespace Pf2eModel.Migrations
column: "entity_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_remasters_legacy_entities_id",
name: "ix_legacy_remasters_remaster_id",
table: "legacy_remasters",
column: "legacy_entities_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_remasters_legacy_entity_id",
table: "legacy_remasters",
column: "legacy_entity_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_remasters_remaster_entities_id",
table: "legacy_remasters",
column: "remaster_entities_id");
migrationBuilder.CreateIndex(
name: "ix_legacy_remasters_remaster_entity_id",
table: "legacy_remasters",
column: "remaster_entity_id");
column: "remaster_id");
migrationBuilder.CreateIndex(
name: "ix_ritual_checks_ritual_id",
@@ -285,36 +285,11 @@ namespace Pf2eModel.Migrations
.HasColumnOrder(2)
.HasComment("Идентификатор цели");
b.Property<int>("LegacyEntitiesId")
.HasColumnType("integer")
.HasColumnName("legacy_entities_id");
b.Property<int>("LegacyEntityId")
.HasColumnType("integer")
.HasColumnName("legacy_entity_id");
b.Property<int>("RemasterEntitiesId")
.HasColumnType("integer")
.HasColumnName("remaster_entities_id");
b.Property<int>("RemasterEntityId")
.HasColumnType("integer")
.HasColumnName("remaster_entity_id");
b.HasKey("LegacyId", "RemasterId")
.HasName("pk_legacy_remasters");
b.HasIndex("LegacyEntitiesId")
.HasDatabaseName("ix_legacy_remasters_legacy_entities_id");
b.HasIndex("LegacyEntityId")
.HasDatabaseName("ix_legacy_remasters_legacy_entity_id");
b.HasIndex("RemasterEntitiesId")
.HasDatabaseName("ix_legacy_remasters_remaster_entities_id");
b.HasIndex("RemasterEntityId")
.HasDatabaseName("ix_legacy_remasters_remaster_entity_id");
b.HasIndex("RemasterId")
.HasDatabaseName("ix_legacy_remasters_remaster_id");
b.ToTable("legacy_remasters", (string)null);
});
@@ -1970,33 +1945,19 @@ namespace Pf2eModel.Migrations
modelBuilder.Entity("Pf2eModel.Model.Base.LegacyRemaster", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", null)
.WithMany()
.HasForeignKey("LegacyEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_legacy_entities_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "LegacyEntity")
.WithMany()
.HasForeignKey("LegacyEntityId")
.WithMany("LegacyTransferEntities")
.HasForeignKey("LegacyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_legacy_entity_id");
b.HasOne("Pf2eModel.Model.Base.Entity", null)
.WithMany()
.HasForeignKey("RemasterEntitiesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_remaster_entities_id");
.HasConstraintName("fk_legacy_remasters_entities_legacy_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "RemasterEntity")
.WithMany()
.HasForeignKey("RemasterEntityId")
.WithMany("RemasterTransferEntities")
.HasForeignKey("RemasterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_legacy_remasters_entities_remaster_entity_id");
.HasConstraintName("fk_legacy_remasters_entities_remaster_id");
b.Navigation("LegacyEntity");
@@ -2635,6 +2596,10 @@ namespace Pf2eModel.Migrations
b.Navigation("Externals");
b.Navigation("LegacyTransferEntities");
b.Navigation("RemasterTransferEntities");
b.Navigation("Sources");
});
+10
View File
@@ -110,8 +110,18 @@ public class Entity
/// </summary>
public ICollection<Entity> LegacyEntities { get; set; } = [];
/// <summary>
/// Коллекция переходных объектов для устаревших сущностей.
/// </summary>
public ICollection<LegacyRemaster> LegacyTransferEntities { get; set; } = [];
/// <summary>
/// Коллекция обновлённых сущностей.
/// </summary>
public ICollection<Entity> RemasterEntities { get; set; } = [];
/// <summary>
/// Коллекция переходных объектов для обновлённых сущностей.
/// </summary>
public ICollection<LegacyRemaster> RemasterTransferEntities { get; set; } = [];
}
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
namespace Pf2eModel.Model.Base.Source;
@@ -50,6 +51,7 @@ public class EntitySource
/// <summary>
/// Сущность, к которой относится источник.
/// </summary>
[JsonIgnore]
public Entity Entity { get; set; } = null!;
/// <summary>
+2
View File
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Base.Source;
@@ -44,5 +45,6 @@ public class Source
/// <summary>
/// Связанные сущности.
/// </summary>
[JsonIgnore]
public ICollection<EntitySource> EntitySources { get; set; } = [];
}
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
namespace Pf2eModel.Model.Base.Targets;
@@ -45,5 +46,6 @@ public class ExternalTarget
/// <summary>
/// Коллекция сущностей, которые ссылаются на эту цель.
/// </summary>
[JsonIgnore]
public ICollection<EntityExternal> EntityExternals { get; set; } = [];
}
+8 -6
View File
@@ -123,12 +123,14 @@ public partial class Pf2eDbContext
.HasMany(e => e.LegacyEntities)
.WithMany(e => e.RemasterEntities)
.UsingEntity<LegacyRemaster>(
//l =>
// l.HasOne(lr => lr.LegacyEntity).WithMany().HasForeignKey(lr => lr.LegacyId),
//r =>
// r.HasOne(lr => lr.RemasterEntity)
// .WithMany()
// .HasForeignKey(lr => lr.RemasterId)
l =>
l.HasOne(lr => lr.LegacyEntity)
.WithMany(e => e.LegacyTransferEntities)
.HasForeignKey(lr => lr.LegacyId),
r =>
r.HasOne(lr => lr.RemasterEntity)
.WithMany(e => e.RemasterTransferEntities)
.HasForeignKey(lr => lr.RemasterId)
);
});