Добавление метода, который позволяет обрабатывать только определённые процессоры
This commit is contained in:
@@ -3,29 +3,35 @@
|
||||
namespace Pf2eDataScrapper.Importers;
|
||||
|
||||
/// <summary>
|
||||
/// Абстрактный класс импортёра
|
||||
/// Абстрактный класс импортёра.
|
||||
/// </summary>
|
||||
internal abstract class AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Отображаемое имя импортёра
|
||||
/// Отображаемое имя импортёра.
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Короткое имя импортёра
|
||||
/// Короткое имя импортёра.
|
||||
/// </summary>
|
||||
public abstract string Slug { get; }
|
||||
|
||||
public abstract AbstractImporterRepository Repository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Путь к директории с данными для импортёра
|
||||
/// Путь к директории с данными для импортёра.
|
||||
/// </summary>
|
||||
public string Dir => Path.Combine(EnvSettings.DataDirPath, Slug);
|
||||
|
||||
/// <summary>
|
||||
/// Метод подготовки данных для импорта
|
||||
/// Перечисление процессоров, которые будут использоваться для обработки данных.
|
||||
/// При пустом массиве будут обработаны все доступные процессоры.
|
||||
/// </summary>
|
||||
public string[] ProcessorNames { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Метод подготовки данных для импорта.
|
||||
/// </summary>
|
||||
public abstract void Prepare();
|
||||
|
||||
@@ -35,7 +41,7 @@ internal abstract class AbstractImporter
|
||||
public abstract void Import();
|
||||
|
||||
/// <summary>
|
||||
/// Построение схем данных
|
||||
/// Построение схем данных.
|
||||
/// </summary>
|
||||
public abstract void BuildSchemas();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ internal class AonprdImporter : AbstractImporter
|
||||
public override void Import()
|
||||
{
|
||||
AonprdDataBuilder builder = new(Loader);
|
||||
builder.Processors.UseOnlyNames(ProcessorNames);
|
||||
|
||||
builder.TruncateTables();
|
||||
builder.Build();
|
||||
|
||||
+29
-1
@@ -14,7 +14,9 @@ internal class AonprdProcessorCollection
|
||||
public int Priority = -1;
|
||||
}
|
||||
|
||||
public readonly List<ProcessorItem> Items = [];
|
||||
private readonly List<ProcessorItem> _allItems;
|
||||
|
||||
public List<ProcessorItem> Items { get; private set; } = [];
|
||||
|
||||
public AonprdProcessorCollection()
|
||||
{
|
||||
@@ -50,6 +52,8 @@ internal class AonprdProcessorCollection
|
||||
|
||||
Items.Add(new(attribute, constructor));
|
||||
}
|
||||
|
||||
_allItems = Items.ToList();
|
||||
}
|
||||
|
||||
private void CheckDependencies()
|
||||
@@ -109,4 +113,28 @@ internal class AonprdProcessorCollection
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
public void UseOnlyNames(string[] processorNames)
|
||||
{
|
||||
Dictionary<string, bool> nameFlags = processorNames.ToDictionary(name => name, _ => false);
|
||||
|
||||
while (nameFlags.Values.Any(v => !v))
|
||||
{
|
||||
foreach (
|
||||
KeyValuePair<string, bool> pair in nameFlags.Where(pair => !pair.Value).ToList()
|
||||
)
|
||||
{
|
||||
ProcessorItem item = _allItems.First(item => item.Attribute.Name == pair.Key);
|
||||
|
||||
foreach (string dependency in item.Attribute.Dependencies)
|
||||
{
|
||||
nameFlags.TryAdd(dependency, false);
|
||||
}
|
||||
|
||||
nameFlags[pair.Key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
Items = _allItems.Where(item => nameFlags.ContainsKey(item.Attribute.Name)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ Pf2EFoundryImporter importer = new();
|
||||
*/
|
||||
|
||||
AonprdImporter importer = new();
|
||||
|
||||
importer.ProcessorNames = ["rules"];
|
||||
|
||||
importer.Prepare();
|
||||
importer.Import();
|
||||
// importer.BuildSchemas();
|
||||
|
||||
Reference in New Issue
Block a user