Финализация рефакторинга
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.ViewModel;
|
||||
using Pf2e.WPF.EntityViewer.ViewModel;
|
||||
|
||||
namespace Pf2e.WPF.EntityViewer;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Pf2e.Database;
|
||||
using Pf2e.Database.Model.Base;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.Stores;
|
||||
using Pf2e.WPF.EntityViewer.Stores;
|
||||
|
||||
namespace Pf2e.WPF.EntityViewer.ViewModel;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using Pf2e.Database;
|
||||
using Pf2e.Database.Model.Base;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.Stores;
|
||||
using Pf2e.WPF.EntityViewer.Stores;
|
||||
|
||||
namespace Pf2e.WPF.EntityViewer.ViewModel;
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Pf2e.Common;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Scrapper.Helpers;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.EntityViewStructure;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.Stores;
|
||||
using Pf2e.WPF.EntityViewer.EntityViewStructure;
|
||||
using Pf2e.WPF.EntityViewer.Stores;
|
||||
|
||||
namespace Pf2e.WPF.EntityViewer.ViewModel;
|
||||
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Scrapper;
|
||||
using Pf2e.Scrapper.Helpers;
|
||||
using Pf2e.Scrapper.Processors;
|
||||
using Pf2e.Scrapper.Processors.Collection;
|
||||
using Pf2e.WPF.EntityViewer;
|
||||
using Pf2e.WPF.Progress;
|
||||
using Pf2e.WPF.Start;
|
||||
using Slugify;
|
||||
|
||||
namespace Pf2e.WPF;
|
||||
|
||||
public sealed class ImportApplication : Application
|
||||
{
|
||||
public ImportApplication(
|
||||
IServiceProvider serviceProvider,
|
||||
ApplicationSettings settings,
|
||||
ProcessorCollection processors
|
||||
)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
Settings = settings;
|
||||
Processors = processors;
|
||||
|
||||
CurrentStage = ApplicationStage.InitialSettings;
|
||||
//CurrentStage = ApplicationStage.Viewer;
|
||||
}
|
||||
|
||||
#region "Поля"
|
||||
|
||||
/// <summary>
|
||||
/// Текущий этап выполнения программы.
|
||||
/// </summary>
|
||||
public ApplicationStage CurrentStage
|
||||
{
|
||||
get => _currentStage;
|
||||
set
|
||||
{
|
||||
ApplicationStage oldValue = _currentStage;
|
||||
_currentStage = value;
|
||||
|
||||
CloseStage(oldValue);
|
||||
StartStage(_currentStage);
|
||||
}
|
||||
}
|
||||
private ApplicationStage _currentStage = ApplicationStage.BootUp;
|
||||
|
||||
#endregion
|
||||
|
||||
#region "Жизненный цикл"
|
||||
|
||||
private StartForm? _startFormWpf;
|
||||
|
||||
private ProgressForm? _progressFormWpf;
|
||||
|
||||
private EntityForm? _entityForm;
|
||||
|
||||
private Window? CurrentWpfForm { get; set; }
|
||||
|
||||
public delegate void ApplicationStateChangeDelegate(object sender, ApplicationStage nextStage);
|
||||
|
||||
private void StartStage(ApplicationStage stage)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case ApplicationStage.BootUp:
|
||||
throw new(
|
||||
$"{CurrentStage} никогда не должен быть установлен через поле \"CurrentStage\"."
|
||||
);
|
||||
|
||||
case ApplicationStage.InitialSettings:
|
||||
_startFormWpf = ActivatorUtilities.CreateInstance<StartForm>(ServiceProvider);
|
||||
_startFormWpf.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
_startFormWpf.Closing += Wpf_HandleFormClosing;
|
||||
_startFormWpf.ApplicationStateChange += ApplicationStateChange;
|
||||
_startFormWpf.Show();
|
||||
|
||||
CurrentWpfForm = _startFormWpf;
|
||||
break;
|
||||
|
||||
case ApplicationStage.ImportProcess:
|
||||
ProcessorExecutor executor = ActivatorUtilities.CreateInstance<ProcessorExecutor>(
|
||||
ServiceProvider
|
||||
);
|
||||
|
||||
_progressFormWpf = ActivatorUtilities.CreateInstance<ProgressForm>(ServiceProvider);
|
||||
_progressFormWpf.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
_progressFormWpf.Closing += Wpf_HandleFormClosing;
|
||||
_progressFormWpf.ApplicationStateChange += ApplicationStateChange;
|
||||
_progressFormWpf.Show();
|
||||
|
||||
CurrentWpfForm = _progressFormWpf;
|
||||
|
||||
executor.Start();
|
||||
break;
|
||||
|
||||
case ApplicationStage.Viewer:
|
||||
_entityForm = ActivatorUtilities.CreateInstance<EntityForm>(ServiceProvider);
|
||||
_entityForm.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
_entityForm.Closing += Wpf_HandleFormClosing;
|
||||
_entityForm.ApplicationStateChange += ApplicationStateChange;
|
||||
_entityForm.Show();
|
||||
|
||||
CurrentWpfForm = _entityForm;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseStage(ApplicationStage stage)
|
||||
{
|
||||
CurrentWpfForm = null;
|
||||
|
||||
switch (stage)
|
||||
{
|
||||
case ApplicationStage.BootUp:
|
||||
// Нечего закрывать
|
||||
break;
|
||||
|
||||
case ApplicationStage.InitialSettings:
|
||||
_startFormWpf!.Hide();
|
||||
_startFormWpf!.Close();
|
||||
_startFormWpf = null;
|
||||
break;
|
||||
|
||||
case ApplicationStage.ImportProcess:
|
||||
_progressFormWpf!.Hide();
|
||||
_progressFormWpf!.Close();
|
||||
_progressFormWpf = null;
|
||||
break;
|
||||
|
||||
case ApplicationStage.Viewer:
|
||||
_entityForm!.Hide();
|
||||
_entityForm!.Close();
|
||||
_entityForm = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(stage));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "События"
|
||||
|
||||
public void ApplicationStateChange(object sender, ApplicationStage nextStage)
|
||||
{
|
||||
if (sender?.Equals(CurrentWpfForm) ?? false)
|
||||
{
|
||||
CurrentStage = nextStage;
|
||||
}
|
||||
}
|
||||
|
||||
private void Wpf_HandleFormClosing(object? sender, CancelEventArgs e)
|
||||
{
|
||||
if (sender?.Equals(CurrentWpfForm) ?? false)
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region "Внедрение зависимостей"
|
||||
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
public ApplicationSettings Settings { get; }
|
||||
public ProcessorCollection Processors { get; }
|
||||
|
||||
public static void RegisterServices(IServiceCollection services)
|
||||
{
|
||||
// Контекст базы данных
|
||||
services.AddEntityFrameworkNpgsql();
|
||||
|
||||
services.AddDbContext<Pf2eDbContext>();
|
||||
//services.AddDbContextPool<Pf2eDbContext>(options =>
|
||||
//{
|
||||
// options.Us
|
||||
//});
|
||||
|
||||
// Основная программа
|
||||
services.AddSingleton<ImportApplication>();
|
||||
|
||||
// Настройки программы
|
||||
services.AddSingleton<ApplicationSettings>();
|
||||
|
||||
// Набор процессоров
|
||||
services.AddSingleton<ProcessorCollection>();
|
||||
|
||||
// Помощник идентификации базы данных
|
||||
services.AddSingleton<DatabaseHelper>();
|
||||
|
||||
// Помощник создание URL-совместимых названий
|
||||
services.AddTransient<SlugHelper>();
|
||||
|
||||
// Счётчик прогресса
|
||||
services.AddSingleton<ProcessProgress>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum ApplicationStage
|
||||
{
|
||||
BootUp,
|
||||
InitialSettings,
|
||||
ImportProcess,
|
||||
Viewer,
|
||||
Rules,
|
||||
}
|
||||
@@ -30,13 +30,13 @@
|
||||
<Compile Update="EntityViewer\EntityForm.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="ProgressForm\ProgressForm.xaml.cs">
|
||||
<Compile Update="Progress\ProgressForm.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="StartForm\Components\ProcessorCollectionControl.xaml.cs">
|
||||
<Compile Update="Start\Components\ProcessorCollectionControl.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="StartForm\StartForm.xaml.cs">
|
||||
<Compile Update="Start\StartForm.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
+2
-1
@@ -4,8 +4,9 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Pf2e.Scrapper.Importers.Implementations.Aonprd;
|
||||
using Pf2e.Scrapper.Importers.Implementations.FoundryEn;
|
||||
using Pf2e.Scrapper.WPF;
|
||||
using Pf2e.WPF;
|
||||
|
||||
namespace Pf2e.Scrapper;
|
||||
namespace Pf2e.WPF;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<Window
|
||||
x:Class="Pf2e.WPF.ProgressForm.ProgressForm"
|
||||
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"
|
||||
@@ -5,7 +5,7 @@ using System.Windows;
|
||||
using LinqToDB.Tools;
|
||||
using Pf2e.Scrapper.Helpers;
|
||||
|
||||
namespace Pf2e.WPF.ProgressForm;
|
||||
namespace Pf2e.WPF.Progress;
|
||||
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для ProgressFormWpf.xaml
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<UserControl
|
||||
x:Class="Pf2e.Scrapper.WPF.StartForm.Components.ProcessorCollectionControl"
|
||||
x:Class="Pf2e.WPF.Start.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"
|
||||
+2
-1
@@ -4,10 +4,11 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Pf2e.Scrapper.Processors.Attributes;
|
||||
using Pf2e.Scrapper.Processors.Attributes.Enum;
|
||||
using Pf2e.Scrapper.Processors.Collection;
|
||||
using CheckBox = System.Windows.Controls.CheckBox;
|
||||
|
||||
namespace Pf2e.Scrapper.WPF.StartForm.Components;
|
||||
namespace Pf2e.WPF.Start.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для ProcessorCollectionControl.xaml
|
||||
@@ -1,8 +1,8 @@
|
||||
<Window
|
||||
x:Class="Pf2e.WPF.StartForm.StartForm"
|
||||
x:Class="Pf2e.WPF.Start.StartForm"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:comp="clr-namespace:Pf2e.WPF.StartForm.Components"
|
||||
xmlns:comp="clr-namespace:Pf2e.WPF.Start.Components"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Title="StartForm"
|
||||
@@ -2,7 +2,7 @@
|
||||
using Pf2e.Scrapper;
|
||||
using Pf2e.Scrapper.Processors.Collection;
|
||||
|
||||
namespace Pf2e.WPF.StartForm;
|
||||
namespace Pf2e.WPF.Start;
|
||||
|
||||
/// <summary>
|
||||
/// Класс начальной формы приложения.
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.Stores;
|
||||
using Pf2e.Scrapper.WPF.EntityViewer.ViewModel;
|
||||
using Pf2e.WPF.EntityViewer.Stores;
|
||||
using Pf2e.WPF.EntityViewer.ViewModel;
|
||||
|
||||
namespace Pf2e.WPF;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user