Больше документации!
This commit is contained in:
@@ -1,26 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using dotenv.net;
|
||||
using dotenv.net;
|
||||
using dotenv.net.Utilities;
|
||||
|
||||
namespace Pf2eDataScrapper
|
||||
{
|
||||
internal class EnvSettings
|
||||
/// <summary>
|
||||
/// Класс настроек.
|
||||
/// </summary>
|
||||
internal static class EnvSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузка файла настроек `.env`.
|
||||
/// </summary>
|
||||
public static void Load()
|
||||
{
|
||||
DotEnv.Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Путь к папке с входными данными.
|
||||
/// </summary>
|
||||
public static string DataDirPath => EnvReader.GetStringValue("DATA_DIR");
|
||||
|
||||
/// <summary>
|
||||
/// Папка в входными данными.
|
||||
/// </summary>
|
||||
public static DirectoryInfo DataDir => new(DataDirPath);
|
||||
|
||||
/// <summary>
|
||||
/// Путь к папке для сохранения результатов.
|
||||
/// </summary>
|
||||
public static string OutputDirPath => EnvReader.GetStringValue("OUTPUT_DIR");
|
||||
|
||||
/// <summary>
|
||||
/// Папка для сохранения результатов.
|
||||
/// </summary>
|
||||
public static string OutputDir => new(OutputDirPath);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers
|
||||
namespace Pf2eDataScrapper.Importers
|
||||
{
|
||||
/// <summary>
|
||||
/// Абстрактный класс импортёра
|
||||
/// </summary>
|
||||
internal abstract class AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
@@ -28,7 +25,14 @@ namespace Pf2eDataScrapper.Importers
|
||||
/// </summary>
|
||||
public string Dir => Path.Combine(EnvSettings.DataDirPath, Slug);
|
||||
|
||||
/// <summary>
|
||||
/// Метод подготовки данных для импорта
|
||||
/// </summary>
|
||||
public abstract void Prepare();
|
||||
|
||||
/// <summary>
|
||||
/// Импорт данных
|
||||
/// </summary>
|
||||
public abstract void Import();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers
|
||||
{
|
||||
internal class GitLoader(string DataDirPath)
|
||||
/// <summary>
|
||||
/// Загрузчик данных из git-репозиториев
|
||||
/// </summary>
|
||||
/// <param name="repositoryDirPath"></param>
|
||||
internal class GitLoader(string repositoryDirPath)
|
||||
{
|
||||
public readonly string DataDirPath = DataDirPath;
|
||||
public DirectoryInfo DataDir = new(DataDirPath);
|
||||
/// <summary>
|
||||
/// Путь к директории репозитория
|
||||
/// </summary>
|
||||
public readonly string RepositoryDirPath = repositoryDirPath;
|
||||
|
||||
/// <summary>
|
||||
/// Директория репозитория
|
||||
/// </summary>
|
||||
public DirectoryInfo RepositoryDir = new(repositoryDirPath);
|
||||
|
||||
/// <summary>
|
||||
/// Обновление импортёра
|
||||
/// </summary>
|
||||
/// <param name="importer"></param>
|
||||
public void UpdateImporter(AbstractImporter importer)
|
||||
{
|
||||
string gitPath = Path.Combine(DataDirPath, importer.Slug);
|
||||
var gitPath = Path.Combine(RepositoryDirPath, importer.Slug);
|
||||
|
||||
if (Directory.Exists(gitPath))
|
||||
{
|
||||
@@ -38,7 +48,7 @@ namespace Pf2eDataScrapper.Importers
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = "git",
|
||||
WorkingDirectory = DataDirPath,
|
||||
WorkingDirectory = RepositoryDirPath,
|
||||
Arguments = $"clone {importer.GitUrl} {importer.Slug}",
|
||||
}
|
||||
};
|
||||
|
||||
+4
-7
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип документов компендиума.
|
||||
/// </summary>
|
||||
internal enum CompendiumDocumentType
|
||||
{
|
||||
Actor,
|
||||
|
||||
+37
-8
@@ -1,32 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
{
|
||||
/// <summary>
|
||||
/// Папка компендиума.
|
||||
/// </summary>
|
||||
internal class CompendiumFolder
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор папки.
|
||||
/// </summary>
|
||||
public readonly string Id;
|
||||
|
||||
/// <summary>
|
||||
/// Название папки.
|
||||
/// </summary>
|
||||
public readonly string Name;
|
||||
|
||||
/// <summary>
|
||||
/// Путь к папке.
|
||||
/// </summary>
|
||||
public readonly string? Path;
|
||||
|
||||
/// <summary>
|
||||
/// Указатель, что папка содержится в других папках.
|
||||
/// </summary>
|
||||
public readonly bool IsContained;
|
||||
|
||||
/// <summary>
|
||||
/// Родительская папка.
|
||||
/// </summary>
|
||||
public CompendiumFolder? Parent;
|
||||
|
||||
/// <summary>
|
||||
/// Тип документов в папке.
|
||||
/// </summary>
|
||||
public readonly CompendiumDocumentType Type;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор папки компендиума из JSON-объекта.
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
public CompendiumFolder(JObject json)
|
||||
{
|
||||
if (json.ContainsKey("_id"))
|
||||
if (json.TryGetValue("_id", out var id))
|
||||
{
|
||||
// Вложенная папка через _folders.json
|
||||
Id = json["_id"]!.ToString();
|
||||
Id = id!.ToString();
|
||||
Name = json["name"]!.ToString();
|
||||
Path = null;
|
||||
IsContained = true;
|
||||
@@ -43,6 +63,11 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
Type = (CompendiumDocumentType)Enum.Parse(typeof(CompendiumDocumentType), json["type"]!.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор папки компендиума.
|
||||
/// </summary>
|
||||
/// <param name="id">Идентификатор папки.</param>
|
||||
/// <param name="name">Название папки.</param>
|
||||
public CompendiumFolder(string id, string name)
|
||||
{
|
||||
Id = id;
|
||||
@@ -51,6 +76,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
IsContained = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Строковое представление данных о папки компендиума.
|
||||
/// </summary>
|
||||
/// <returns>Строковое представление данных о папки компендиума.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"CompendiumFolder([Id={Id}][Type={Type}][Name={Name}][Path={Path}][Parent={Parent?.Name ?? "null"}])";
|
||||
|
||||
+9
-8
@@ -1,14 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
{
|
||||
/// <summary>
|
||||
/// Коллекция папок компендиума
|
||||
/// </summary>
|
||||
internal class CompendiumFolderCollection : List<CompendiumFolder>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Получение папки по идентификатору
|
||||
/// </summary>
|
||||
/// <param name="id">Искомый идентификатор</param>
|
||||
/// <returns>Искомая папка</returns>
|
||||
public CompendiumFolder? GetById(string id)
|
||||
{
|
||||
return this.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
+38
-7
@@ -1,27 +1,46 @@
|
||||
using Konsole;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.SchemaBuilder;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс построения схемы компендиумов.
|
||||
/// </summary>
|
||||
/// <param name="loader">Загрузчик данных.</param>
|
||||
internal class CompendiumSchemaBuilder(CompendiumLoader loader)
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузчик данных.
|
||||
/// </summary>
|
||||
public CompendiumLoader Loader = loader;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция папок компендиума.
|
||||
/// </summary>
|
||||
public CompendiumFolderCollection Collection = loader.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// Объект для определения типов полей в компендиумах PF2E.
|
||||
/// </summary>
|
||||
public CompendiumSchemaTypeResolver Resolver = new();
|
||||
|
||||
/// <summary>
|
||||
/// Схемы данных по папкам.
|
||||
/// </summary>
|
||||
public Dictionary<CompendiumFolder, SchemaNode> PackSchemas = [];
|
||||
|
||||
/// <summary>
|
||||
/// Схемы данных по типам.
|
||||
/// </summary>
|
||||
public Dictionary<string, SchemaNode> TypeSchemas = [];
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение набора схем, к которым относится проверяемый объект.
|
||||
/// </summary>
|
||||
/// <param name="folder">Папка компендиума, в которой находится объект.</param>
|
||||
/// <param name="itemType">Указанный тип объекта.</param>
|
||||
/// <returns></returns>
|
||||
protected List<SchemaNode> GetItemSchemas(CompendiumFolder folder, string? itemType)
|
||||
{
|
||||
if (!PackSchemas.ContainsKey(folder))
|
||||
@@ -47,6 +66,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
return [PackSchemas[folder], TypeSchemas[key]];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Построение схем данных.
|
||||
/// </summary>
|
||||
public void BuildSchemas()
|
||||
{
|
||||
Console.WriteLine("Building schemas...");
|
||||
@@ -90,6 +112,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
bar.Refresh(Loader.ItemCount, "Done!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение данных.
|
||||
/// </summary>
|
||||
/// <param name="targetDir">Папка для сохранения.</param>
|
||||
public void Save(string targetDir)
|
||||
{
|
||||
Console.WriteLine("Dumping schemas...");
|
||||
@@ -127,6 +153,12 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение конкретной схемы.
|
||||
/// </summary>
|
||||
/// <param name="dir">Корневая папка для сохранения этой категории схем.</param>
|
||||
/// <param name="name">Название сохраняемой схемы.</param>
|
||||
/// <param name="schema">Сохраняемая схема.</param>
|
||||
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
||||
{
|
||||
var invalids = System.IO.Path.GetInvalidFileNameChars();
|
||||
@@ -134,7 +166,6 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
|
||||
var path = Path.Combine(dir, fileName + ".txt");
|
||||
|
||||
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
|
||||
if (!Directory.Exists(dirPath))
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text.RegularExpressions;
|
||||
using Konsole;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
using Pf2eDataScrapper.SchemaBuilder;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
{
|
||||
internal class CompendiumLoader(Pf2eFoundryImporter importer)
|
||||
/// <summary>
|
||||
/// Загрузчик данных компендиума
|
||||
/// </summary>
|
||||
/// <param name="importer">Импортёр</param>
|
||||
internal class CompendiumLoader(Pf2EFoundryImporter importer)
|
||||
{
|
||||
public readonly Pf2eFoundryImporter Importer = importer;
|
||||
/// <summary>
|
||||
/// Импортёр
|
||||
/// </summary>
|
||||
public readonly Pf2EFoundryImporter Importer = importer;
|
||||
|
||||
/// <summary>
|
||||
/// Набор папок компендиума
|
||||
/// </summary>
|
||||
public CompendiumFolderCollection Collection = [];
|
||||
|
||||
/// <summary>
|
||||
/// Счётчик папок
|
||||
/// </summary>
|
||||
private int _folderCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Общее количество элементов в компендиуме
|
||||
/// </summary>
|
||||
public int ItemCount { get; protected set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Обработка папок компендиума в поле `packFolders`.
|
||||
/// </summary>
|
||||
/// <param name="folders"></param>
|
||||
/// <param name="parent"></param>
|
||||
protected void ProcessPackFolders(JArray folders, CompendiumFolder? parent)
|
||||
{
|
||||
foreach (var token in folders)
|
||||
@@ -53,6 +70,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Подготовка набора папок компендиума
|
||||
/// </summary>
|
||||
public void Prepare()
|
||||
{
|
||||
using var systemFile = new StreamReader(Path.Combine(Importer.Dir, "static", "system.json"));
|
||||
@@ -104,10 +124,5 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
|
||||
Console.WriteLine($"Total items: {ItemCount}");
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
this.Prepare();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
{
|
||||
internal class Pf2eFoundryImporter : AbstractImporter
|
||||
/// <summary>
|
||||
/// Импортёр для модуля Pf2e FoundryVTT.
|
||||
/// </summary>
|
||||
internal class Pf2EFoundryImporter : AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Отображаемое имя импортёра
|
||||
/// Отображаемое имя импортёра.
|
||||
/// </summary>
|
||||
public override string Name => "Pf2e FoundryVTT module";
|
||||
|
||||
/// <summary>
|
||||
/// Короткое имя импортёра
|
||||
/// Короткое имя импортёра.
|
||||
/// </summary>
|
||||
public override string Slug => "pf2e";
|
||||
|
||||
/// <summary>
|
||||
/// Ссылка на git-репозиторий для клонирования
|
||||
/// Ссылка на git-репозиторий для клонирования.
|
||||
/// </summary>
|
||||
public override string GitUrl => "https://github.com/foundryvtt/pf2e.git";
|
||||
|
||||
/// <summary>
|
||||
/// Загрузчик данных компендиума.
|
||||
/// </summary>
|
||||
public CompendiumLoader Loader { get; }
|
||||
|
||||
public Pf2eFoundryImporter()
|
||||
/// <summary>
|
||||
/// Конструктор импортёра.
|
||||
/// </summary>
|
||||
public Pf2EFoundryImporter()
|
||||
{
|
||||
Loader = new CompendiumLoader(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод подготовки данных для импорта.
|
||||
/// </summary>
|
||||
public override void Prepare()
|
||||
{
|
||||
Loader.Prepare();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Импорт данных.
|
||||
/// </summary>
|
||||
public override void Import()
|
||||
{
|
||||
Loader.Run();
|
||||
Loader.Prepare();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ EnvSettings.Load();
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
||||
|
||||
//var loader = new GitLoader(EnvSettings.DataDirPath);
|
||||
//var loader = new GitLoader(EnvSettings.RepositoryDirPath);
|
||||
|
||||
|
||||
var importer = new Pf2eFoundryImporter();
|
||||
var importer = new Pf2EFoundryImporter();
|
||||
|
||||
//loader.UpdateImporter(importer);
|
||||
|
||||
|
||||
@@ -55,8 +55,7 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
return $"{GetTypeName()} {Parent.Path}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Отступ для строкового представления.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user