Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
414ac03f83 | ||
|
|
4fec054ac6 |
+267
@@ -0,0 +1,267 @@
|
||||
# Удалите строку ниже, если вы хотите наследовать параметры .editorconfig из каталогов, расположенных выше в иерархии
|
||||
root = true
|
||||
|
||||
# Файлы C#
|
||||
[*.cs]
|
||||
|
||||
#### Основные параметры EditorConfig ####
|
||||
|
||||
# Отступы и интервалы
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
tab_width = 4
|
||||
|
||||
# Предпочтения для новых строк
|
||||
end_of_line = crlf
|
||||
insert_final_newline = false
|
||||
|
||||
#### Действия кода .NET ####
|
||||
|
||||
# Члены типа
|
||||
dotnet_hide_advanced_members = false
|
||||
dotnet_member_insertion_location = with_other_members_of_the_same_kind
|
||||
dotnet_property_generation_behavior = prefer_throwing_properties
|
||||
|
||||
# Поиск символов
|
||||
dotnet_search_reference_assemblies = true
|
||||
|
||||
#### Рекомендации по написанию кода .NET ####
|
||||
|
||||
# Упорядочение Using
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = false
|
||||
file_header_template = unset
|
||||
|
||||
# Предпочтения для this. и Me.
|
||||
dotnet_style_qualification_for_event = false
|
||||
dotnet_style_qualification_for_field = false
|
||||
dotnet_style_qualification_for_method = false
|
||||
dotnet_style_qualification_for_property = false
|
||||
|
||||
# Параметры использования ключевых слов языка и типов BCL
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||
dotnet_style_predefined_type_for_member_access = true
|
||||
|
||||
# Предпочтения для скобок
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||
|
||||
# Предпочтения модификатора
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members
|
||||
|
||||
# Выражения уровень предпочтения
|
||||
dotnet_prefer_system_hash_code = true
|
||||
dotnet_style_coalesce_expression = true
|
||||
dotnet_style_collection_initializer = true
|
||||
dotnet_style_explicit_tuple_names = true
|
||||
dotnet_style_namespace_match_folder = true
|
||||
dotnet_style_null_propagation = true
|
||||
dotnet_style_object_initializer = true
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
dotnet_style_prefer_auto_properties = true
|
||||
dotnet_style_prefer_collection_expression = when_types_loosely_match
|
||||
dotnet_style_prefer_compound_assignment = true
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = true
|
||||
dotnet_style_prefer_conditional_expression_over_return = true
|
||||
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true
|
||||
dotnet_style_prefer_inferred_tuple_names = true
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true
|
||||
dotnet_style_prefer_simplified_interpolation = true
|
||||
|
||||
# Предпочтения для полей
|
||||
dotnet_style_readonly_field = true
|
||||
|
||||
# Настройки параметров
|
||||
dotnet_code_quality_unused_parameters = all
|
||||
|
||||
# Параметры подавления
|
||||
dotnet_remove_unnecessary_suppression_exclusions = none
|
||||
|
||||
# Предпочтения для новых строк
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = true
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = true
|
||||
|
||||
#### Рекомендации по написанию кода C# ####
|
||||
|
||||
# Предпочтения var
|
||||
csharp_style_var_elsewhere = false
|
||||
csharp_style_var_for_built_in_types = false
|
||||
csharp_style_var_when_type_is_apparent = false
|
||||
|
||||
# Члены, заданные выражениями
|
||||
csharp_style_expression_bodied_accessors = true
|
||||
csharp_style_expression_bodied_constructors = false
|
||||
csharp_style_expression_bodied_indexers = true
|
||||
csharp_style_expression_bodied_lambdas = true
|
||||
csharp_style_expression_bodied_local_functions = false
|
||||
csharp_style_expression_bodied_methods = false
|
||||
csharp_style_expression_bodied_operators = false
|
||||
csharp_style_expression_bodied_properties = true
|
||||
|
||||
# Настройки соответствия шаблонов
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true
|
||||
csharp_style_prefer_extended_property_pattern = true
|
||||
csharp_style_prefer_not_pattern = true
|
||||
csharp_style_prefer_pattern_matching = true
|
||||
csharp_style_prefer_switch_expression = true
|
||||
|
||||
# Настройки проверки на null
|
||||
csharp_style_conditional_delegate_call = true
|
||||
|
||||
# Предпочтения модификатора
|
||||
csharp_prefer_static_anonymous_function = true
|
||||
csharp_prefer_static_local_function = true
|
||||
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
|
||||
csharp_style_prefer_readonly_struct = true
|
||||
csharp_style_prefer_readonly_struct_member = true
|
||||
|
||||
# Предпочтения для блоков кода
|
||||
csharp_prefer_braces = true
|
||||
csharp_prefer_simple_using_statement = true
|
||||
csharp_prefer_system_threading_lock = true
|
||||
csharp_style_namespace_declarations = file_scoped
|
||||
csharp_style_prefer_method_group_conversion = true
|
||||
csharp_style_prefer_primary_constructors = true
|
||||
csharp_style_prefer_top_level_statements = true
|
||||
|
||||
# Выражения уровень предпочтения
|
||||
csharp_prefer_simple_default_expression = true:suggestion
|
||||
csharp_style_deconstructed_variable_declaration = true:suggestion
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
|
||||
csharp_style_inlined_variable_declaration = true:suggestion
|
||||
csharp_style_prefer_index_operator = true:suggestion
|
||||
csharp_style_prefer_local_over_anonymous_function = true:suggestion
|
||||
csharp_style_prefer_null_check_over_type_check = true:suggestion
|
||||
csharp_style_prefer_range_operator = true:suggestion
|
||||
csharp_style_prefer_tuple_swap = true:suggestion
|
||||
csharp_style_prefer_unbound_generic_type_in_nameof = true:suggestion
|
||||
csharp_style_prefer_utf8_string_literals = true:suggestion
|
||||
csharp_style_throw_expression = true:suggestion
|
||||
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
|
||||
|
||||
# предпочтения для директивы using
|
||||
csharp_using_directive_placement = outside_namespace
|
||||
|
||||
# Предпочтения для новых строк
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true
|
||||
|
||||
#### Правила форматирования C# ####
|
||||
|
||||
# Предпочтения для новых строк
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
|
||||
# Параметры отступов
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = false
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
|
||||
# Предпочтения для интервалов
|
||||
csharp_space_after_cast = true
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_name_and_open_parenthesis = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
|
||||
# Параметры переноса
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = false
|
||||
|
||||
#### Стили именования ####
|
||||
|
||||
# Правила именования
|
||||
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||
|
||||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
|
||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||
|
||||
# Спецификации символов
|
||||
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
|
||||
# Стили именования
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
|
||||
[*.{cs,vb}]
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
|
||||
dotnet_style_prefer_auto_properties = true:silent
|
||||
dotnet_style_object_initializer = true:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
|
||||
dotnet_style_prefer_conditional_expression_over_return = true:silent
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
|
||||
dotnet_style_prefer_compound_assignment = true:suggestion
|
||||
dotnet_style_prefer_simplified_interpolation = true:suggestion
|
||||
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
|
||||
dotnet_style_namespace_match_folder = true:suggestion
|
||||
dotnet_code_quality_unused_parameters = all:suggestion
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
tab_width = 4
|
||||
indent_size = 4
|
||||
@@ -1,13 +1,13 @@
|
||||
using dotenv.net;
|
||||
using dotenv.net.Utilities;
|
||||
|
||||
namespace Pf2eDataScrapper
|
||||
namespace Pf2eDataScrapper;
|
||||
|
||||
/// <summary>
|
||||
/// Класс настроек.
|
||||
/// </summary>
|
||||
internal static class EnvSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс настроек.
|
||||
/// </summary>
|
||||
internal static class EnvSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузка файла настроек `.env`.
|
||||
/// </summary>
|
||||
@@ -37,5 +37,4 @@ namespace Pf2eDataScrapper
|
||||
public static string OutputDir => new(OutputDirPath);
|
||||
|
||||
public static string DatabaseConnection => EnvReader.GetStringValue("DATABASE_CONNECTION");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Pf2eDataScrapper.Importers.Repositories;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers
|
||||
namespace Pf2eDataScrapper.Importers;
|
||||
|
||||
/// <summary>
|
||||
/// Абстрактный класс импортёра
|
||||
/// </summary>
|
||||
internal abstract class AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Абстрактный класс импортёра
|
||||
/// </summary>
|
||||
internal abstract class AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Отображаемое имя импортёра
|
||||
/// </summary>
|
||||
@@ -38,5 +38,4 @@ namespace Pf2eDataScrapper.Importers
|
||||
/// Построение схем данных
|
||||
/// </summary>
|
||||
public abstract void BuildSchemas();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Pf2eDataScrapper.Importers.Repositories;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder;
|
||||
using Pf2eDataScrapper.Importers.Repositories;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
||||
|
||||
internal class AonprdImporter : AbstractImporter
|
||||
{
|
||||
internal class AonprdImporter : AbstractImporter
|
||||
{
|
||||
public override string Name => "Archives of Nethys Pathfinder 2e";
|
||||
|
||||
public override string Slug => "aonprd";
|
||||
@@ -26,7 +26,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
|
||||
public override void BuildSchemas()
|
||||
{
|
||||
var builder = new AonprdSchemaBuilder(Loader);
|
||||
AonprdSchemaBuilder builder = new(Loader);
|
||||
|
||||
builder.BuildSchemas();
|
||||
builder.Save(EnvSettings.OutputDir);
|
||||
@@ -36,5 +36,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
||||
|
||||
internal class AonprdLoader(AonprdImporter importer)
|
||||
{
|
||||
internal class AonprdLoader (AonprdImporter importer)
|
||||
{
|
||||
public AonprdImporter Importer = importer;
|
||||
|
||||
public AonprdCompendium Compendium = new();
|
||||
@@ -14,15 +13,15 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
|
||||
public void Prepare()
|
||||
{
|
||||
using var indexFile = new StreamReader(Path.Combine(Importer.Dir, "index.json"));
|
||||
var indexJson = JObject.Parse(indexFile.ReadToEnd());
|
||||
using StreamReader indexFile = new(Path.Combine(Importer.Dir, "index.json"));
|
||||
JObject indexJson = JObject.Parse(indexFile.ReadToEnd());
|
||||
|
||||
foreach (var kvp in indexJson)
|
||||
foreach (KeyValuePair<string, JToken?> kvp in indexJson)
|
||||
{
|
||||
var file = kvp.Key.ToString();
|
||||
var items = (JArray)kvp.Value!;
|
||||
string file = kvp.Key.ToString();
|
||||
JArray items = (JArray) kvp.Value!;
|
||||
|
||||
foreach (var item in items)
|
||||
foreach (JToken item in items)
|
||||
{
|
||||
Compendium.AddReference(item.ToString(), file);
|
||||
}
|
||||
@@ -31,7 +30,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
|
||||
public IEnumerable<LoaderEntry> Entries()
|
||||
{
|
||||
return Entries(Compendium.Types.Keys.ToArray());
|
||||
return Entries([.. Compendium.Types.Keys]);
|
||||
}
|
||||
|
||||
public IEnumerable<LoaderEntry> Entries(string types)
|
||||
@@ -41,26 +40,26 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
|
||||
public IEnumerable<LoaderEntry> Entries(string[] types)
|
||||
{
|
||||
foreach (var file in Compendium.Files(types))
|
||||
foreach (string? file in Compendium.Files(types))
|
||||
{
|
||||
if (file is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
using var fileReader = new StreamReader(Path.Combine(Importer.Dir, $"{file}.json"));
|
||||
var array = JArray.Parse(fileReader.ReadToEnd());
|
||||
using StreamReader fileReader = new(Path.Combine(Importer.Dir, $"{file}.json"));
|
||||
JArray array = JArray.Parse(fileReader.ReadToEnd());
|
||||
|
||||
foreach (var item in array)
|
||||
foreach (JToken item in array)
|
||||
{
|
||||
var id = item.SelectToken("id")?.ToString();
|
||||
string? id = item.SelectToken("id")?.ToString();
|
||||
|
||||
if (id is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var entry = new LoaderEntry(id, file, (JObject)item);
|
||||
LoaderEntry entry = new(id, file, (JObject) item);
|
||||
|
||||
if (types.Contains(entry.Type))
|
||||
{
|
||||
@@ -75,5 +74,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
{
|
||||
public JObject Json { get; } = itemJson;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.Importers.Repositories;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
||||
|
||||
internal class AonprdRepository(AbstractImporter importer, string searchUrl) : AbstractImporterRepository(importer)
|
||||
{
|
||||
internal class AonprdRepository(AbstractImporter importer, string searchUrl): AbstractImporterRepository(importer)
|
||||
{
|
||||
public readonly string SearchUrl = searchUrl;
|
||||
|
||||
public int Revision { get; private set; }
|
||||
@@ -17,9 +17,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
url = SearchUrl + url;
|
||||
}
|
||||
|
||||
using var client = new HttpClient();
|
||||
using var stream = client.GetStreamAsync(url);
|
||||
using var reader = new StreamReader(stream.Result);
|
||||
using HttpClient client = new();
|
||||
using Task<Stream> stream = client.GetStreamAsync(url);
|
||||
using StreamReader reader = new(stream.Result);
|
||||
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
@@ -44,22 +44,22 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
WriteFile("revision.txt", Revision.ToString());
|
||||
|
||||
Console.WriteLine("Загрузка индекса...");
|
||||
var indexContent = Load($"/json-data/aon{Revision}-index.json");
|
||||
string indexContent = Load($"/json-data/aon{Revision}-index.json");
|
||||
WriteFile("index.json", indexContent);
|
||||
|
||||
var indexJson = JObject.Parse(indexContent);
|
||||
JObject indexJson = JObject.Parse(indexContent);
|
||||
|
||||
Console.WriteLine("Загрузка индексных файлов...");
|
||||
|
||||
var bar = new ProgressBar(indexJson.Count);
|
||||
var i = 0;
|
||||
ProgressBar bar = new(indexJson.Count);
|
||||
int i = 0;
|
||||
|
||||
foreach (var kvp in indexJson)
|
||||
foreach (KeyValuePair<string, JToken?> kvp in indexJson)
|
||||
{
|
||||
var fileName = kvp.Key;
|
||||
string fileName = kvp.Key;
|
||||
bar.Refresh(i++, fileName);
|
||||
|
||||
var fileContent = Load($"/json-data/{fileName}.json");
|
||||
string fileContent = Load($"/json-data/{fileName}.json");
|
||||
WriteFile($"{fileName}.json", fileContent);
|
||||
}
|
||||
|
||||
@@ -73,30 +73,29 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
||||
/// <returns>true - актуальная ревизия, false - устаревшая/отсутсвует</returns>
|
||||
private bool CheckRevision()
|
||||
{
|
||||
var page = JObject.Parse(Load("/aon/_doc/feat-1"));
|
||||
JObject page = JObject.Parse(Load("/aon/_doc/feat-1"));
|
||||
|
||||
Revision = Convert.ToInt32(page.SelectToken("_index")?.ToObject<string>()?.Replace("aon", "") ?? throw new Exception("Can't get revision"));
|
||||
|
||||
var revisionFile = Path.Combine(RepositoryDirPath, "revision.txt");
|
||||
string revisionFile = Path.Combine(RepositoryDirPath, "revision.txt");
|
||||
if (!File.Exists(revisionFile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(revisionFile);
|
||||
var lastRevision = reader.ReadToEnd();
|
||||
using StreamReader reader = new(revisionFile);
|
||||
string lastRevision = reader.ReadToEnd();
|
||||
return lastRevision == Revision.ToString();
|
||||
}
|
||||
|
||||
private void WriteFile (string path, string content)
|
||||
private void WriteFile(string path, string content)
|
||||
{
|
||||
var filePath = Path.Combine(RepositoryDirPath, path);
|
||||
string filePath = Path.Combine(RepositoryDirPath, path);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
using var writer = new StreamWriter(filePath);
|
||||
using StreamWriter writer = new(filePath);
|
||||
writer.Write(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
||||
|
||||
internal class AonprdCompendium
|
||||
{
|
||||
internal class AonprdCompendium
|
||||
{
|
||||
public readonly Dictionary<string, AonprdType> Types = [];
|
||||
|
||||
public void AddReference(string id, string file)
|
||||
{
|
||||
AonprdReference reference = new(id, file);
|
||||
|
||||
if (Types.TryGetValue(reference.Type, out var type))
|
||||
if (Types.TryGetValue(reference.Type, out AonprdType? type))
|
||||
{
|
||||
type.Add(reference);
|
||||
}
|
||||
@@ -24,5 +24,4 @@
|
||||
.Where(t => types.Contains(t.Type))
|
||||
.SelectMany(t => t.Files)
|
||||
.Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
||||
|
||||
internal class AonprdReference(string id, string file)
|
||||
{
|
||||
internal class AonprdReference(string id, string file)
|
||||
{
|
||||
public readonly string Id = id;
|
||||
|
||||
public readonly string Type = ResolveType(id);
|
||||
@@ -13,23 +13,11 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium
|
||||
{
|
||||
static string? subType(string type, string cat)
|
||||
{
|
||||
if (type.StartsWith($"{cat}-") && type != cat)
|
||||
{
|
||||
if (type.EndsWith("-bonus"))
|
||||
{
|
||||
return $"{cat}-bonus";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{cat}-sub";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return type.StartsWith($"{cat}-") && type != cat ? type.EndsWith("-bonus") ? $"{cat}-bonus" : $"{cat}-sub" : null;
|
||||
}
|
||||
|
||||
var type = string.Join('-', id.Split('-')[0..^1]);
|
||||
string type = string.Join('-', id.Split('-')[0..^1]);
|
||||
|
||||
return subType(type, "equipment") ?? subType(type, "weapon") ?? type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
||||
|
||||
internal class AonprdType(string type)
|
||||
{
|
||||
internal class AonprdType(string type)
|
||||
{
|
||||
public readonly string Type = type;
|
||||
|
||||
public readonly List<AonprdReference> Items = [];
|
||||
@@ -19,5 +19,4 @@
|
||||
public List<string> Files => [.. Items.Select(x => x.File).Distinct()];
|
||||
|
||||
public int Count => Items.Count;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-15
@@ -2,10 +2,10 @@
|
||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
||||
using Pf2eDataScrapper.SchemaBuilder;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder;
|
||||
|
||||
internal class AonprdSchemaBuilder(AonprdLoader loader)
|
||||
{
|
||||
internal class AonprdSchemaBuilder(AonprdLoader loader)
|
||||
{
|
||||
public readonly AonprdLoader Loader = loader;
|
||||
|
||||
public readonly AonprdCompendium Compendium = loader.Compendium;
|
||||
@@ -33,10 +33,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
||||
{
|
||||
Console.WriteLine("Building schemas...");
|
||||
|
||||
var bar = new ProgressBar(Loader.ItemCount);
|
||||
var i = 0;
|
||||
ProgressBar bar = new ProgressBar(Loader.ItemCount);
|
||||
int i = 0;
|
||||
|
||||
foreach (var entry in Loader.Entries())
|
||||
foreach (AonprdLoader.LoaderEntry entry in Loader.Entries())
|
||||
{
|
||||
bar.Refresh(i++, entry.Type);
|
||||
GetSchema(entry).AddValue(entry.Json);
|
||||
@@ -51,10 +51,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
||||
|
||||
targetDir = Path.Combine(targetDir, Loader.Importer.Slug);
|
||||
|
||||
var bar = new ProgressBar(Schemas.Count);
|
||||
var i = 0;
|
||||
ProgressBar bar = new(Schemas.Count);
|
||||
int i = 0;
|
||||
|
||||
foreach (var kvp in Schemas)
|
||||
foreach (KeyValuePair<string, SchemaNode> kvp in Schemas)
|
||||
{
|
||||
bar.Refresh(i++, kvp.Key);
|
||||
SaveSchema(targetDir, kvp.Key, kvp.Value);
|
||||
@@ -63,17 +63,17 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
||||
|
||||
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
||||
{
|
||||
var invalids = Path.GetInvalidFileNameChars();
|
||||
var fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
||||
var path = Path.Combine(dir, fileName + ".yaml");
|
||||
char[] invalids = Path.GetInvalidFileNameChars();
|
||||
string fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
||||
string path = Path.Combine(dir, fileName + ".yaml");
|
||||
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
string? dirPath = Path.GetDirectoryName(path);
|
||||
if (dirPath is not null && !Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.CreateDirectory(dirPath);
|
||||
}
|
||||
|
||||
using var writer = new StreamWriter(path);
|
||||
using StreamWriter writer = new(path);
|
||||
|
||||
schema.Beautify();
|
||||
|
||||
@@ -83,5 +83,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
||||
["values"] = schema.Values.ToString()
|
||||
}, schema.Types[0].GetYamlData()));
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -1,10 +1,10 @@
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
|
||||
/// <summary>
|
||||
/// Тип документов компендиума.
|
||||
/// </summary>
|
||||
internal enum CompendiumDocumentType
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип документов компендиума.
|
||||
/// </summary>
|
||||
internal enum CompendiumDocumentType
|
||||
{
|
||||
Actor,
|
||||
Adventure,
|
||||
Cards,
|
||||
@@ -14,5 +14,4 @@
|
||||
Playlist,
|
||||
RollTable,
|
||||
Scene
|
||||
}
|
||||
}
|
||||
|
||||
+8
-9
@@ -1,12 +1,12 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
|
||||
/// <summary>
|
||||
/// Папка компендиума.
|
||||
/// </summary>
|
||||
internal class CompendiumFolder
|
||||
{
|
||||
/// <summary>
|
||||
/// Папка компендиума.
|
||||
/// </summary>
|
||||
internal class CompendiumFolder
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор папки.
|
||||
/// </summary>
|
||||
@@ -43,7 +43,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
/// <param name="json"></param>
|
||||
public CompendiumFolder(JObject json)
|
||||
{
|
||||
if (json.TryGetValue("_id", out var id))
|
||||
if (json.TryGetValue("_id", out JToken? id))
|
||||
{
|
||||
// Вложенная папка через _folders.json
|
||||
Id = id!.ToString();
|
||||
@@ -60,7 +60,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
IsContained = false;
|
||||
}
|
||||
|
||||
Type = (CompendiumDocumentType)Enum.Parse(typeof(CompendiumDocumentType), json["type"]!.ToString());
|
||||
Type = (CompendiumDocumentType) Enum.Parse(typeof(CompendiumDocumentType), json["type"]!.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,5 +84,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
{
|
||||
return $"CompendiumFolder([Id={Id}][Type={Type}][Name={Name}][Path={Path}][Parent={Parent?.Name ?? "null"}])";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -1,10 +1,10 @@
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция папок компендиума
|
||||
/// </summary>
|
||||
internal class CompendiumFolderCollection : List<CompendiumFolder>
|
||||
{
|
||||
/// <summary>
|
||||
/// Коллекция папок компендиума
|
||||
/// </summary>
|
||||
internal class CompendiumFolderCollection : List<CompendiumFolder>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение папки по идентификатору
|
||||
/// </summary>
|
||||
@@ -24,5 +24,4 @@
|
||||
// return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor)];
|
||||
return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor && x.Name == "Conditions")];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
|
||||
|
||||
/// <summary>
|
||||
/// Загрузчик данных компендиума
|
||||
/// </summary>
|
||||
/// <param name="importer">Импортёр</param>
|
||||
internal class CompendiumLoader(Pf2EFoundryImporter importer)
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузчик данных компендиума
|
||||
/// </summary>
|
||||
/// <param name="importer">Импортёр</param>
|
||||
internal class CompendiumLoader(Pf2EFoundryImporter importer)
|
||||
{
|
||||
/// <summary>
|
||||
/// Импортёр
|
||||
/// </summary>
|
||||
@@ -36,25 +36,25 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
/// <param name="parent"></param>
|
||||
protected void ProcessPackFolders(JArray folders, CompendiumFolder? parent)
|
||||
{
|
||||
foreach (var token in folders)
|
||||
foreach (JToken token in folders)
|
||||
{
|
||||
JObject obj = (JObject)token;
|
||||
JObject obj = (JObject) token;
|
||||
|
||||
var id = $"folder-{_folderCount++}";
|
||||
var name = obj["name"]!.ToString();
|
||||
string id = $"folder-{_folderCount++}";
|
||||
string name = obj["name"]!.ToString();
|
||||
|
||||
var folder = new CompendiumFolder(id, name)
|
||||
CompendiumFolder folder = new(id, name)
|
||||
{
|
||||
Parent = parent
|
||||
};
|
||||
Collection.Add(folder);
|
||||
|
||||
if (obj.TryGetValue("packs", out var packs))
|
||||
if (obj.TryGetValue("packs", out JToken? packs))
|
||||
{
|
||||
foreach (var jToken in packs!)
|
||||
foreach (JToken jToken in packs!)
|
||||
{
|
||||
var packId = jToken.ToString();
|
||||
var child = Collection.GetById(packId);
|
||||
string packId = jToken.ToString();
|
||||
CompendiumFolder? child = Collection.GetById(packId);
|
||||
|
||||
if (child is not null)
|
||||
{
|
||||
@@ -63,9 +63,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.TryGetValue("folders", out var innerFolders))
|
||||
if (obj.TryGetValue("folders", out JToken? innerFolders))
|
||||
{
|
||||
ProcessPackFolders((JArray)innerFolders!, folder);
|
||||
ProcessPackFolders((JArray) innerFolders!, folder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,43 +77,43 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
/// </summary>
|
||||
public void Prepare()
|
||||
{
|
||||
using var systemFile = new StreamReader(Path.Combine(Importer.Dir, "static", "system.json"));
|
||||
var systemData = JObject.Parse(systemFile.ReadToEnd());
|
||||
using StreamReader systemFile = new(Path.Combine(Importer.Dir, "static", "system.json"));
|
||||
JObject systemData = JObject.Parse(systemFile.ReadToEnd());
|
||||
|
||||
foreach (var pack in systemData["packs"]!)
|
||||
foreach (JToken pack in systemData["packs"]!)
|
||||
{
|
||||
var folder = new CompendiumFolder((JObject)pack);
|
||||
CompendiumFolder folder = new((JObject) pack);
|
||||
|
||||
Collection.Add(folder);
|
||||
}
|
||||
|
||||
if (systemData.TryGetValue("packFolders", out var packFolders))
|
||||
if (systemData.TryGetValue("packFolders", out JToken? packFolders))
|
||||
{
|
||||
ProcessPackFolders((JArray)packFolders, null);
|
||||
ProcessPackFolders((JArray) packFolders, null);
|
||||
}
|
||||
|
||||
// Поиск _folders.json
|
||||
foreach (var parent in Collection.ToList())
|
||||
foreach (CompendiumFolder? parent in Collection.ToList())
|
||||
{
|
||||
if (parent.Path is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dirPath = Path.Combine(Importer.Dir, parent.Path);
|
||||
string dirPath = Path.Combine(Importer.Dir, parent.Path);
|
||||
|
||||
ItemCount += Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories)
|
||||
.Length;
|
||||
|
||||
foreach (var foldersFilePath in Directory.GetFiles(dirPath, "_folders.json", SearchOption.AllDirectories))
|
||||
foreach (string foldersFilePath in Directory.GetFiles(dirPath, "_folders.json", SearchOption.AllDirectories))
|
||||
{
|
||||
ItemCount--;
|
||||
using var file = new StreamReader(foldersFilePath);
|
||||
var data = JArray.Parse(file.ReadToEnd());
|
||||
using StreamReader file = new(foldersFilePath);
|
||||
JArray data = JArray.Parse(file.ReadToEnd());
|
||||
|
||||
foreach (var pack in data)
|
||||
foreach (JToken pack in data)
|
||||
{
|
||||
var folder = new CompendiumFolder((JObject)pack) { Parent = parent };
|
||||
CompendiumFolder folder = new((JObject) pack) { Parent = parent };
|
||||
Collection.Add(folder);
|
||||
}
|
||||
}
|
||||
@@ -131,24 +131,24 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
|
||||
public IEnumerable<LoaderEnrty> Enrties()
|
||||
{
|
||||
foreach (var folder in Collection.FindAll(f => f.Path is not null))
|
||||
foreach (CompendiumFolder folder in Collection.FindAll(f => f.Path is not null))
|
||||
{
|
||||
var dirPath = Path.Combine(Importer.Dir, folder.Path!);
|
||||
string dirPath = Path.Combine(Importer.Dir, folder.Path!);
|
||||
|
||||
foreach (var filePath in Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories))
|
||||
foreach (string filePath in Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories))
|
||||
{
|
||||
var file = new FileInfo(filePath);
|
||||
FileInfo file = new(filePath);
|
||||
|
||||
if (file.Name == "_folders.json")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(file.FullName);
|
||||
var itemJson = JObject.Parse(reader.ReadToEnd());
|
||||
using StreamReader reader = new(file.FullName);
|
||||
JObject itemJson = JObject.Parse(reader.ReadToEnd());
|
||||
|
||||
var itemFolder = folder;
|
||||
if (itemJson.TryGetValue("folder", out var itemJsonFolder))
|
||||
CompendiumFolder? itemFolder = folder;
|
||||
if (itemJson.TryGetValue("folder", out JToken? itemJsonFolder))
|
||||
{
|
||||
itemFolder = Collection.GetById(itemJsonFolder.ToString());
|
||||
}
|
||||
@@ -166,5 +166,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
public string Type { get; } = itemJson["type"]?.ToString()
|
||||
?? throw new Exception($"Expected to have `type` field in file {file.FullName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-18
@@ -1,20 +1,20 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NpgsqlTypes;
|
||||
using Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
|
||||
|
||||
internal abstract class AbstractProcessor(JObject input)
|
||||
{
|
||||
internal abstract class AbstractProcessor(JObject input)
|
||||
{
|
||||
public readonly Pf2eTestContext Context = new();
|
||||
|
||||
public readonly JObject Input = input;
|
||||
|
||||
protected DataBuilderHelper Helper = DataBuilderHelper.Instance;
|
||||
|
||||
public Entity Entity { get; set; } = new Entity();
|
||||
public Entity Entity { get; set; } = new();
|
||||
|
||||
public abstract EntityType Type { get; }
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
Entity.Name = GetRequired<string>("name");
|
||||
Entity.Img = GetRequired<string>("img");
|
||||
Entity.Description = GetRequired<string>("system.description.value");
|
||||
Entity.DescriptionGm = GetOptional<string>("system.description.gm");
|
||||
|
||||
Entity.IsTranslated = false;
|
||||
Entity.IsChecked = false;
|
||||
@@ -49,21 +48,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
|
||||
public T GetRequired<T>(string path)
|
||||
{
|
||||
var token = Input.SelectToken(path) ?? throw new NullReferenceException($"'{path}' is null");
|
||||
JToken token = Input.SelectToken(path) ?? throw new NullReferenceException($"'{path}' is null");
|
||||
|
||||
return token.ToObject<T>() ?? throw new NullReferenceException($"'{path}' is null");
|
||||
}
|
||||
|
||||
public T? GetOptional<T>(string path)
|
||||
{
|
||||
var token = Input.SelectToken(path) ?? null;
|
||||
JToken? token = Input.SelectToken(path) ?? null;
|
||||
|
||||
if (token is null)
|
||||
{
|
||||
return default!;
|
||||
}
|
||||
|
||||
return token.ToObject<T>() ?? default;
|
||||
return token is null ? default! : token.ToObject<T>() ?? default;
|
||||
}
|
||||
|
||||
public T EnumRequired<T>(string path) where T : Enum
|
||||
@@ -80,25 +74,24 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
return default;
|
||||
}
|
||||
|
||||
foreach (var field in typeof(T).GetFields())
|
||||
foreach (System.Reflection.FieldInfo field in typeof(T).GetFields())
|
||||
{
|
||||
if (Attribute.GetCustomAttribute(field, typeof(PgNameAttribute)) is PgNameAttribute attribute)
|
||||
{
|
||||
if (attribute.PgName == value)
|
||||
{
|
||||
return (T)field.GetValue(null);
|
||||
return (T) field.GetValue(null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (field.Name == value)
|
||||
{
|
||||
return (T)field.GetValue(null);
|
||||
return (T) field.GetValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,9 +1,9 @@
|
||||
using Slugify;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
|
||||
|
||||
internal class DataBuilderHelper
|
||||
{
|
||||
internal class DataBuilderHelper
|
||||
{
|
||||
public Pf2eDatabase Database = Pf2eDatabase.Instance;
|
||||
|
||||
public SlugHelper Slugger = new();
|
||||
@@ -23,6 +23,5 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
|
||||
|
||||
|
||||
public readonly static DataBuilderHelper Instance = new();
|
||||
}
|
||||
public static readonly DataBuilderHelper Instance = new();
|
||||
}
|
||||
|
||||
+11
-17
@@ -3,10 +3,10 @@ using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
|
||||
|
||||
internal class PF2eFoundryDataBuilder
|
||||
{
|
||||
internal class PF2eFoundryDataBuilder
|
||||
{
|
||||
public Pf2eDatabase Database = Pf2eDatabase.Instance;
|
||||
|
||||
/// <summary>
|
||||
@@ -29,25 +29,20 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
|
||||
public void PrepareProcessors()
|
||||
{
|
||||
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
|
||||
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
|
||||
{
|
||||
if (type.GetCustomAttributes(typeof(Pf2eTypeProcessor), true).Length <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var attribute = type.GetCustomAttribute<Pf2eTypeProcessor>();
|
||||
Processors.Add(attribute!.Type, type.GetConstructor(new[] { typeof(JObject) })!);
|
||||
Pf2eTypeProcessor? attribute = type.GetCustomAttribute<Pf2eTypeProcessor>();
|
||||
Processors.Add(attribute!.Type, type.GetConstructor([typeof(JObject)])!);
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractProcessor? GetProcessor(string type, JObject input)
|
||||
{
|
||||
if (Processors.TryGetValue(type, out var constructor))
|
||||
{
|
||||
return (AbstractProcessor)constructor.Invoke([input]);
|
||||
}
|
||||
|
||||
return null;
|
||||
return Processors.TryGetValue(type, out ConstructorInfo? constructor) ? (AbstractProcessor) constructor.Invoke([input]) : null;
|
||||
}
|
||||
|
||||
public void TruncateTables()
|
||||
@@ -63,14 +58,14 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
{
|
||||
Console.WriteLine("Building data...");
|
||||
|
||||
var bar = new ProgressBar(Loader.ItemCount);
|
||||
var i = 0;
|
||||
ProgressBar bar = new(Loader.ItemCount);
|
||||
int i = 0;
|
||||
|
||||
foreach (var entry in Loader.Enrties())
|
||||
foreach (CompendiumLoader.LoaderEnrty entry in Loader.Enrties())
|
||||
{
|
||||
bar.Refresh(i++, $"{entry.Folder.Name}/{entry.File.Name}");
|
||||
|
||||
var processor = GetProcessor($"{entry.Folder.Type}.{entry.Type}", entry.Json);
|
||||
AbstractProcessor? processor = GetProcessor($"{entry.Folder.Type}.{entry.Type}", entry.Json);
|
||||
if (processor is null)
|
||||
{
|
||||
continue;
|
||||
@@ -82,5 +77,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
|
||||
bar.Refresh(Loader.ItemCount, "Done!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,10 +1,9 @@
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
internal class Pf2eTypeProcessor(string type, int priority = 0) : Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
internal class Pf2eTypeProcessor(string type, int priority = 0) : Attribute
|
||||
{
|
||||
public readonly string Type = type;
|
||||
|
||||
public readonly int Priority = priority;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -2,11 +2,11 @@
|
||||
using Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors;
|
||||
|
||||
[Pf2eTypeProcessor("Item.condition")]
|
||||
internal class ConditionProcessor(JObject input) : AbstractProcessor(input)
|
||||
{
|
||||
[Pf2eTypeProcessor("Item.condition")]
|
||||
internal class ConditionProcessor(JObject input) : AbstractProcessor(input)
|
||||
{
|
||||
public override EntityType Type => EntityType.Condition;
|
||||
|
||||
public override Condition Object { get; } = new();
|
||||
@@ -29,5 +29,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Pro
|
||||
|
||||
Context.Conditions.Add(Object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder;
|
||||
using Pf2eDataScrapper.Importers.Repositories;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
|
||||
|
||||
/// <summary>
|
||||
/// Импортёр для модуля Pf2e FoundryVTT.
|
||||
/// </summary>
|
||||
internal class Pf2EFoundryImporter : AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Импортёр для модуля Pf2e FoundryVTT.
|
||||
/// </summary>
|
||||
internal class Pf2EFoundryImporter : AbstractImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Отображаемое имя импортёра.
|
||||
/// </summary>
|
||||
@@ -47,7 +47,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
/// </summary>
|
||||
public override void Import()
|
||||
{
|
||||
var builder = new PF2eFoundryDataBuilder(Loader);
|
||||
PF2eFoundryDataBuilder builder = new(Loader);
|
||||
|
||||
builder.TruncateTables();
|
||||
builder.Build();
|
||||
@@ -58,10 +58,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
||||
/// </summary>
|
||||
public override void BuildSchemas()
|
||||
{
|
||||
var builder = new CompendiumSchemaBuilder(Loader);
|
||||
CompendiumSchemaBuilder builder = new(Loader);
|
||||
|
||||
builder.BuildSchemas();
|
||||
builder.Save(EnvSettings.OutputDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-33
@@ -2,14 +2,14 @@
|
||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||
using Pf2eDataScrapper.SchemaBuilder;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder;
|
||||
|
||||
/// <summary>
|
||||
/// Класс построения схемы компендиумов.
|
||||
/// </summary>
|
||||
/// <param name="loader">Загрузчик данных.</param>
|
||||
internal class CompendiumSchemaBuilder(CompendiumLoader loader)
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс построения схемы компендиумов.
|
||||
/// </summary>
|
||||
/// <param name="loader">Загрузчик данных.</param>
|
||||
internal class CompendiumSchemaBuilder(CompendiumLoader loader)
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузчик данных.
|
||||
/// </summary>
|
||||
@@ -75,16 +75,11 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
/// <returns></returns>
|
||||
protected List<SchemaNode> GetItemSchemas(CompendiumFolder folder, string? itemType)
|
||||
{
|
||||
var key = folder.Type.ToString() + (itemType is not null ? $".{itemType}" : "");
|
||||
string key = folder.Type.ToString() + (itemType is not null ? $".{itemType}" : "");
|
||||
|
||||
if (_equipmentTypes.Contains(itemType))
|
||||
{
|
||||
return [GetPackSchema(folder), GetTypeSchema(key), GetTypeSchema("Equipment")];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [GetPackSchema(folder), GetTypeSchema(key)];
|
||||
}
|
||||
return _equipmentTypes.Contains(itemType)
|
||||
? [GetPackSchema(folder), GetTypeSchema(key), GetTypeSchema("Equipment")]
|
||||
: [GetPackSchema(folder), GetTypeSchema(key)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,16 +89,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
{
|
||||
Console.WriteLine("Building schemas...");
|
||||
|
||||
var bar = new ProgressBar(Loader.ItemCount);
|
||||
var i = 0;
|
||||
ProgressBar bar = new(Loader.ItemCount);
|
||||
int i = 0;
|
||||
|
||||
foreach (var entry in Loader.Enrties())
|
||||
foreach (CompendiumLoader.LoaderEnrty entry in Loader.Enrties())
|
||||
{
|
||||
bar.Refresh(i++, entry.Folder.Name);
|
||||
|
||||
var schemas = GetItemSchemas(entry.Folder, entry.Type);
|
||||
List<SchemaNode> schemas = GetItemSchemas(entry.Folder, entry.Type);
|
||||
|
||||
foreach (var schema in schemas)
|
||||
foreach (SchemaNode schema in schemas)
|
||||
{
|
||||
schema.AddValue(entry.Json);
|
||||
}
|
||||
@@ -120,8 +115,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
{
|
||||
Console.WriteLine("Dumping schemas...");
|
||||
|
||||
var bar = new ProgressBar(PackSchemas.Count + TypeSchemas.Count);
|
||||
var i = 0;
|
||||
ProgressBar bar = new(PackSchemas.Count + TypeSchemas.Count);
|
||||
int i = 0;
|
||||
|
||||
targetDir = Path.Combine(targetDir, Loader.Importer.Slug);
|
||||
|
||||
@@ -132,19 +127,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
Array.ForEach(Directory.GetFiles(@targetDir), File.Delete);
|
||||
|
||||
// Packs
|
||||
var packsDir = Path.Combine(targetDir, "packs");
|
||||
string packsDir = Path.Combine(targetDir, "packs");
|
||||
Directory.CreateDirectory(packsDir);
|
||||
|
||||
foreach (var pair in PackSchemas)
|
||||
foreach (KeyValuePair<CompendiumFolder, SchemaNode> pair in PackSchemas)
|
||||
{
|
||||
bar.Refresh(i++, pair.Key.Name);
|
||||
SaveSchema(packsDir, pair.Key.Name, pair.Value);
|
||||
}
|
||||
|
||||
// Types
|
||||
var typesDir = Path.Combine(targetDir, "types");
|
||||
string typesDir = Path.Combine(targetDir, "types");
|
||||
Directory.CreateDirectory(typesDir);
|
||||
foreach (var pair in TypeSchemas)
|
||||
foreach (KeyValuePair<string, SchemaNode> pair in TypeSchemas)
|
||||
{
|
||||
bar.Refresh(i++, pair.Key);
|
||||
SaveSchema(typesDir, pair.Key, pair.Value);
|
||||
@@ -161,19 +156,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
/// <param name="schema">Сохраняемая схема.</param>
|
||||
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
||||
{
|
||||
var invalids = Path.GetInvalidFileNameChars();
|
||||
var fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
||||
char[] invalids = Path.GetInvalidFileNameChars();
|
||||
string fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
||||
|
||||
var path = Path.Combine(dir, fileName + ".yaml");
|
||||
string path = Path.Combine(dir, fileName + ".yaml");
|
||||
|
||||
var dirPath = Path.GetDirectoryName(path);
|
||||
string? dirPath = Path.GetDirectoryName(path);
|
||||
|
||||
if (dirPath is not null && !Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.CreateDirectory(dirPath);
|
||||
}
|
||||
|
||||
using var writer = new StreamWriter(path);
|
||||
using StreamWriter writer = new(path);
|
||||
|
||||
schema.Beautify();
|
||||
|
||||
@@ -188,5 +183,4 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
//writer.WriteLine("=====================================");
|
||||
//writer.Write(schema.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-15
@@ -2,10 +2,10 @@
|
||||
using Pf2eDataScrapper.SchemaBuilder;
|
||||
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder;
|
||||
|
||||
internal class CompendiumSchemaTypeResolver : TypeResolver
|
||||
{
|
||||
internal class CompendiumSchemaTypeResolver : TypeResolver
|
||||
{
|
||||
public class FoundryRulesSchemaType(SchemaNode parent) : IgnoreSchemaType(parent)
|
||||
{
|
||||
public override string GetTypeName()
|
||||
@@ -46,17 +46,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
||||
/// <returns>Новый тип для схемы данных. `null`, что бы использовать значение по умолчанию</returns>
|
||||
protected override AbstractSchemaType? CustomResolve(SchemaNode node, JToken? value)
|
||||
{
|
||||
if (CheckPath(node, DictionaryPaths))
|
||||
{
|
||||
return new DictionarySchemaType(node);
|
||||
}
|
||||
|
||||
if (node.Path.EndsWith(".rules"))
|
||||
{
|
||||
return new FoundryRulesSchemaType(node);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return CheckPath(node, DictionaryPaths)
|
||||
? new DictionarySchemaType(node)
|
||||
: node.Path.EndsWith(".rules") ? new FoundryRulesSchemaType(node) : (AbstractSchemaType?) null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Pf2eDataScrapper.Importers.Repositories
|
||||
namespace Pf2eDataScrapper.Importers.Repositories;
|
||||
|
||||
internal abstract class AbstractImporterRepository(AbstractImporter importer)
|
||||
{
|
||||
internal abstract class AbstractImporterRepository (AbstractImporter importer)
|
||||
{
|
||||
public readonly AbstractImporter Importer = importer;
|
||||
|
||||
public string RepositoryDirPath => Importer.Dir;
|
||||
@@ -9,5 +9,4 @@
|
||||
public DirectoryInfo RepositoryDir => new(RepositoryDirPath);
|
||||
|
||||
public abstract void Update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Repositories
|
||||
namespace Pf2eDataScrapper.Importers.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Загрузчик данных из git-репозиториев
|
||||
/// </summary>
|
||||
/// <param name="repositoryDirPath"></param>
|
||||
internal class GitRepository(AbstractImporter importer, string url) : AbstractImporterRepository(importer)
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузчик данных из git-репозиториев
|
||||
/// </summary>
|
||||
/// <param name="repositoryDirPath"></param>
|
||||
internal class GitRepository(AbstractImporter importer, string url) : AbstractImporterRepository(importer)
|
||||
{
|
||||
public readonly string Url = url;
|
||||
|
||||
/// <summary>
|
||||
@@ -16,12 +15,12 @@ namespace Pf2eDataScrapper.Importers.Repositories
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
var gitPath = Path.Combine(RepositoryDirPath, importer.Slug);
|
||||
string gitPath = Path.Combine(RepositoryDirPath, importer.Slug);
|
||||
|
||||
if (Directory.Exists(gitPath))
|
||||
{
|
||||
// git pull
|
||||
var process = new Process
|
||||
Process process = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
@@ -35,7 +34,7 @@ namespace Pf2eDataScrapper.Importers.Repositories
|
||||
else
|
||||
{
|
||||
// git clone
|
||||
var process = new Process
|
||||
Process process = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
@@ -48,5 +47,4 @@ namespace Pf2eDataScrapper.Importers.Repositories
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class AncestryItem
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class BackgroundItem
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class ClassProgression
|
||||
{
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Common;
|
||||
|
||||
[Table("entity")]
|
||||
public class Entity
|
||||
{
|
||||
[Key]
|
||||
[Column("id", Order = 1)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("name", Order = 2)]
|
||||
[StringLength(255)]
|
||||
[Required]
|
||||
[Comment("Отображаемое имя")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Column("type", Order = 3)]
|
||||
[Required]
|
||||
[Comment("Тип объекта")]
|
||||
public EntityType Type { get; set; }
|
||||
|
||||
[Column("slug", Order = 4)]
|
||||
[Required]
|
||||
[Comment("Часть имени в URL")]
|
||||
public string Slug { get; set; } = null!;
|
||||
|
||||
[Column("img", Order = 5)]
|
||||
[StringLength(255)]
|
||||
[Comment("Изображение объекта")]
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
[Column("description")]
|
||||
[Comment("Текстовое описание объекта")]
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
[Column("rarity")]
|
||||
public EntityRarity Rarity { get; set; } = EntityRarity.Common;
|
||||
|
||||
[Column("is_translated")]
|
||||
[Comment("Флаг, указывающий, что у объекта существует перевод")]
|
||||
public bool? IsTranslated { get; set; } = false;
|
||||
|
||||
[Column("is_checked")]
|
||||
[Comment("Флаг, указывающий, что объект был проверен и не требует автоматической перезаписи")]
|
||||
public bool? IsChecked { get; set; } = false;
|
||||
|
||||
public virtual ICollection<Trait> Traits { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Common;
|
||||
|
||||
[Table("entity_alias")]
|
||||
public partial class EntityAlias
|
||||
{
|
||||
[Key]
|
||||
[Column("id", Order = 1)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("entity_id", Order = 2)]
|
||||
[ForeignKey("Entity")]
|
||||
public int EntityId { get; set; }
|
||||
|
||||
[Column("type", Order = 3)]
|
||||
public AliasType Type { get; set; } = AliasType.Other;
|
||||
|
||||
[Column("alias", Order = 4)]
|
||||
public string Alias { get; set; } = null!;
|
||||
|
||||
public virtual Entity Entity { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Common;
|
||||
|
||||
[Table("trait")]
|
||||
public partial class Trait
|
||||
{
|
||||
[Key]
|
||||
[Column("id", Order = 1)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("name", Order = 2)]
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Column("type", Order = 3)]
|
||||
public TraitType Type { get; set; }
|
||||
|
||||
[Column("slug", Order = 4)]
|
||||
[Required]
|
||||
public string Slug { get; set; } = null!;
|
||||
|
||||
[Column("description", Order = 5)]
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Entity> Entities { get; set; } = [];
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public class Entity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string Img { get; set; } = null!;
|
||||
|
||||
public EntityType Type { get; set; }
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
public string? DescriptionGm { get; set; }
|
||||
|
||||
public string Slug { get; set; } = null!;
|
||||
|
||||
public bool? IsTranslated { get; set; }
|
||||
|
||||
public bool? IsChecked { get; set; }
|
||||
|
||||
public virtual ICollection<Trait> Traits { get; set; } = [];
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class EntityAlias
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int EntityId { get; set; }
|
||||
|
||||
public string Alias { get; set; } = null!;
|
||||
|
||||
public virtual Entity Entity { get; set; } = null!;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class EntityExternal
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class EntityKeyword
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class EntitySource
|
||||
{
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum ActionCategory
|
||||
{
|
||||
[PgName("offensive")]
|
||||
offensive,
|
||||
|
||||
[PgName("defensive")]
|
||||
defensive,
|
||||
|
||||
[PgName("interaction")]
|
||||
interaction,
|
||||
|
||||
[PgName("familiar")]
|
||||
familiar,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
[PgName("action")]
|
||||
action,
|
||||
|
||||
[PgName("free")]
|
||||
free,
|
||||
|
||||
[PgName("reaction")]
|
||||
reaction,
|
||||
|
||||
[PgName("passive")]
|
||||
passive,
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum AliasType
|
||||
{
|
||||
[PgName("old")]
|
||||
Old,
|
||||
|
||||
[PgName("english")]
|
||||
English,
|
||||
|
||||
[PgName("old_english")]
|
||||
OldEnglish,
|
||||
|
||||
[PgName("hobby")]
|
||||
Hobby,
|
||||
|
||||
[PgName("other")]
|
||||
Other,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum AncestryVision
|
||||
{
|
||||
[PgName("normal")]
|
||||
normal,
|
||||
|
||||
[PgName("low-light-vision")]
|
||||
LowLightVision,
|
||||
|
||||
[PgName("darkvision")]
|
||||
darkvision,
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum CampaignFeatureCategory
|
||||
{
|
||||
[PgName("army_tactic")]
|
||||
ArmyTactic,
|
||||
|
||||
[PgName("army_war_action")]
|
||||
ArmyWarAction,
|
||||
|
||||
[PgName("kingdom_activity")]
|
||||
KingdomActivity,
|
||||
|
||||
[PgName("kingdom_feat")]
|
||||
KingdomFeat,
|
||||
|
||||
[PgName("kingdom_feature")]
|
||||
KingdomFeature,
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum ClassProgressionType
|
||||
{
|
||||
[PgName("entity")]
|
||||
Entity,
|
||||
|
||||
[PgName("ancestry_feat")]
|
||||
AncestryFeat,
|
||||
|
||||
[PgName("class_feat")]
|
||||
ClassFeat,
|
||||
|
||||
[PgName("general_feat")]
|
||||
GeneralFeat,
|
||||
|
||||
[PgName("skill_feat")]
|
||||
SkillFeat,
|
||||
|
||||
[PgName("skill_increase")]
|
||||
SkillIncrease,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum DeityCategory
|
||||
{
|
||||
[PgName("deity")]
|
||||
Deity,
|
||||
|
||||
[PgName("pantheon")]
|
||||
Pantheon,
|
||||
|
||||
[PgName("covenant")]
|
||||
Covenant,
|
||||
|
||||
[PgName("philosophy")]
|
||||
Philosophy,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum DeityFonts
|
||||
{
|
||||
[PgName("none")]
|
||||
None,
|
||||
|
||||
[PgName("heal")]
|
||||
Heal,
|
||||
|
||||
[PgName("harm")]
|
||||
Harm,
|
||||
|
||||
[PgName("any")]
|
||||
Any,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum DeitySanctification
|
||||
{
|
||||
[PgName("holy")]
|
||||
Holy,
|
||||
|
||||
[PgName("unholy")]
|
||||
Unholy,
|
||||
|
||||
[PgName("any")]
|
||||
Any,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum EntityRarity
|
||||
{
|
||||
[PgName("common")]
|
||||
Common,
|
||||
|
||||
[PgName("uncommon")]
|
||||
Uncommon,
|
||||
|
||||
[PgName("rare")]
|
||||
Rare,
|
||||
|
||||
[PgName("unique")]
|
||||
Unique
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum FeatActionType
|
||||
{
|
||||
[PgName("passive")]
|
||||
Passive,
|
||||
|
||||
[PgName("action")]
|
||||
Action,
|
||||
|
||||
[PgName("reaction")]
|
||||
Reaction,
|
||||
|
||||
[PgName("free")]
|
||||
Free,
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum FeatCategory
|
||||
{
|
||||
[PgName("ancestryfeature")]
|
||||
Ancestryfeature,
|
||||
|
||||
[PgName("classfeature")]
|
||||
Classfeature,
|
||||
|
||||
[PgName("calling")]
|
||||
Calling,
|
||||
|
||||
[PgName("class")]
|
||||
Class,
|
||||
|
||||
[PgName("skill")]
|
||||
Skill,
|
||||
|
||||
[PgName("general")]
|
||||
General,
|
||||
|
||||
[PgName("ancestry")]
|
||||
Ancestry,
|
||||
|
||||
[PgName("bonus")]
|
||||
Bonus,
|
||||
|
||||
[PgName("deityboon")]
|
||||
Deityboon,
|
||||
|
||||
[PgName("curse")]
|
||||
Curse,
|
||||
|
||||
[PgName("pfsboon")]
|
||||
Pfsboon,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum Size
|
||||
{
|
||||
[PgName("med")]
|
||||
med,
|
||||
|
||||
[PgName("tiny")]
|
||||
tiny,
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum SpellAreaType
|
||||
{
|
||||
[PgName("burst")]
|
||||
Burst,
|
||||
|
||||
[PgName("emanation")]
|
||||
Emanation,
|
||||
|
||||
[PgName("cone")]
|
||||
Cone,
|
||||
|
||||
[PgName("line")]
|
||||
Line,
|
||||
|
||||
[PgName("square")]
|
||||
Square,
|
||||
|
||||
[PgName("cube")]
|
||||
Cube,
|
||||
|
||||
[PgName("cylinder")]
|
||||
Cylinder,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum SpellDamageCategory
|
||||
{
|
||||
[PgName("persistent")]
|
||||
Persistent,
|
||||
|
||||
[PgName("splash")]
|
||||
Splash,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum SpellDamageKinds
|
||||
{
|
||||
[PgName("damage")]
|
||||
Damage,
|
||||
|
||||
[PgName("healing")]
|
||||
Healing,
|
||||
|
||||
[PgName("any")]
|
||||
Any,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using NpgsqlTypes;
|
||||
|
||||
namespace Pf2eDataScrapper.Model.Enum;
|
||||
|
||||
public enum TraitType
|
||||
{
|
||||
[PgName("regular")]
|
||||
Regular,
|
||||
|
||||
[PgName("tradition")]
|
||||
Tradition
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Frequency
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
namespace Pf2eDataScrapper.Model
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
internal interface IEntity
|
||||
{
|
||||
internal interface IEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Pf2eDataScrapper.Model;
|
||||
|
||||
public partial class Trait
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string Slug { get; set; } = null!;
|
||||
|
||||
public string Description { get; set; } = null!;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using Npgsql;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Pf2eDataScrapper
|
||||
namespace Pf2eDataScrapper;
|
||||
|
||||
public partial class Pf2eDatabase
|
||||
{
|
||||
public partial class Pf2eDatabase
|
||||
{
|
||||
public NpgsqlConnection Connection;
|
||||
|
||||
public readonly string Username;
|
||||
@@ -51,7 +51,7 @@ namespace Pf2eDataScrapper
|
||||
|
||||
public void ExecuteCommand(string sql)
|
||||
{
|
||||
var command = GetCommand(sql);
|
||||
NpgsqlCommand command = GetCommand(sql);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
@@ -119,5 +119,4 @@ namespace Pf2eDataScrapper
|
||||
|
||||
[GeneratedRegex(@"(?:^|;)User=(.*?)(?:$|;)")]
|
||||
private static partial Regex UsernamePattern();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Pf2eDataScrapper.Model;
|
||||
using Pf2eDataScrapper.Model.Common;
|
||||
using Pf2eDataScrapper.Model.Enum;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pf2eDataScrapper;
|
||||
|
||||
@@ -103,8 +101,10 @@ public partial class Pf2eTestContext : DbContext
|
||||
public virtual DbSet<Trait> Traits { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
EnvSettings.Load();
|
||||
optionsBuilder.UseNpgsql(EnvSettings.DatabaseConnection,
|
||||
builder =>
|
||||
{
|
||||
@@ -115,50 +115,6 @@ public partial class Pf2eTestContext : DbContext
|
||||
);
|
||||
}
|
||||
|
||||
protected string FromEnum<T>(T enumValue) where T : Enum
|
||||
{
|
||||
var enumFieldName = enumValue.ToString();
|
||||
var field = typeof(T).GetField(enumFieldName);
|
||||
if (field is null)
|
||||
{
|
||||
return enumFieldName;
|
||||
}
|
||||
|
||||
var attribute = field.GetCustomAttribute<DescriptionAttribute>();
|
||||
return attribute is null ? enumFieldName : attribute.Description;
|
||||
}
|
||||
|
||||
protected T ToEnum<T>(string enumValue) where T : Enum
|
||||
{
|
||||
var enumType = typeof(T);
|
||||
foreach (var field in enumType.GetFields())
|
||||
{
|
||||
var attribute = field.GetCustomAttribute<DescriptionAttribute>();
|
||||
if (attribute is null)
|
||||
{
|
||||
if (field.Name == enumValue)
|
||||
{
|
||||
return (T)field.GetValue(null)!;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (attribute.Description == enumValue)
|
||||
{
|
||||
return (T)field.GetValue(null)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new ArgumentException($"No matching value found for {enumValue} in {enumType.Name}");
|
||||
}
|
||||
|
||||
protected ValueConverter<T, string> GetEnumConverter<T>() where T : Enum
|
||||
{
|
||||
return new ValueConverter<T, string>(
|
||||
v => FromEnum(v),
|
||||
v => ToEnum<T>(v));
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.UseIdentityByDefaultColumns();
|
||||
@@ -198,8 +154,7 @@ public partial class Pf2eTestContext : DbContext
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.Description).HasColumnName("description");
|
||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||
entity.Property(e => e.Type)
|
||||
.HasColumnName("type");
|
||||
entity.Property(e => e.Type).HasColumnName("type");
|
||||
entity.Property(e => e.Img)
|
||||
.HasMaxLength(150)
|
||||
.HasColumnName("img");
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Pf2eDataScrapper;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
|
||||
|
||||
EnvSettings.Load();
|
||||
|
||||
var importer = new AonprdImporter();
|
||||
AonprdImporter importer = new AonprdImporter();
|
||||
importer.Prepare();
|
||||
importer.BuildSchemas();
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder
|
||||
namespace Pf2eDataScrapper.SchemaBuilder;
|
||||
|
||||
/// <summary>
|
||||
/// Элемент схемы данных.
|
||||
/// </summary>
|
||||
internal class SchemaNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Элемент схемы данных.
|
||||
/// </summary>
|
||||
internal class SchemaNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Отображаемое имя элемента.
|
||||
/// </summary>
|
||||
@@ -93,7 +93,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
|
||||
Values++;
|
||||
|
||||
foreach (var type in Types)
|
||||
foreach (AbstractSchemaType type in Types)
|
||||
{
|
||||
if (type.IsCompatibleValue(value))
|
||||
{
|
||||
@@ -102,7 +102,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
}
|
||||
}
|
||||
|
||||
var newType = Resolver.Resolve(this, value);
|
||||
AbstractSchemaType newType = Resolver.Resolve(this, value);
|
||||
|
||||
if (newType.IsCompatibleValue(value))
|
||||
{
|
||||
@@ -111,7 +111,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
}
|
||||
else
|
||||
{
|
||||
var fallbackType = Resolver.Resolve(this, value, true);
|
||||
AbstractSchemaType fallbackType = Resolver.Resolve(this, value, true);
|
||||
Types.Add(fallbackType);
|
||||
fallbackType.AddValue(value);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
return Types[0].GetTypeName();
|
||||
}
|
||||
|
||||
var typeNames = Types.Select(t => t.GetTypeName()).ToList();
|
||||
List<string> typeNames = [.. Types.Select(t => t.GetTypeName())];
|
||||
|
||||
return string.Join(" | ", typeNames);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
/// <returns>Строковое представление элемента.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var result = new Dictionary<string, string>()
|
||||
Dictionary<string, string> result = new()
|
||||
{
|
||||
["type"] = GetTypeName(),
|
||||
["path"] = Path,
|
||||
@@ -159,7 +159,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
|
||||
List<string> types = [];
|
||||
|
||||
foreach (var type in Types)
|
||||
foreach (AbstractSchemaType type in Types)
|
||||
{
|
||||
types.Add(Indent(type?.ToString() ?? ""));
|
||||
}
|
||||
@@ -172,7 +172,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
/// </summary>
|
||||
public void Beautify()
|
||||
{
|
||||
foreach (var type in Types)
|
||||
foreach (AbstractSchemaType type in Types)
|
||||
{
|
||||
type.Beautify();
|
||||
}
|
||||
@@ -207,11 +207,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
/// <returns>Строка форматированных данных</returns>
|
||||
public static string FormatYaml(params List<Dictionary<string, string>> input)
|
||||
{
|
||||
var result = "";
|
||||
string result = "";
|
||||
|
||||
foreach (var kvp in MergeDictionaries(input))
|
||||
foreach (KeyValuePair<string, string> kvp in MergeDictionaries(input))
|
||||
{
|
||||
var val = kvp.Value.Contains("\r\n") ? $"\r\n{Tab}{Indent(kvp.Value)}" : kvp.Value;
|
||||
string val = kvp.Value.Contains("\r\n") ? $"\r\n{Tab}{Indent(kvp.Value)}" : kvp.Value;
|
||||
|
||||
result += $"{kvp.Key}: {val}\r\n";
|
||||
}
|
||||
@@ -221,11 +221,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
|
||||
public static Dictionary<string, string> MergeDictionaries(params List<Dictionary<string, string>> input)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
Dictionary<string, string> result = [];
|
||||
|
||||
foreach (var item in input)
|
||||
foreach (Dictionary<string, string> item in input)
|
||||
{
|
||||
foreach (var kvp in item)
|
||||
foreach (KeyValuePair<string, string> kvp in item)
|
||||
{
|
||||
if (result.ContainsKey(kvp.Key))
|
||||
{
|
||||
@@ -240,5 +240,4 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder
|
||||
namespace Pf2eDataScrapper.SchemaBuilder;
|
||||
|
||||
/// <summary>
|
||||
/// Класс для определения типа поля в схеме данных.
|
||||
/// </summary>
|
||||
internal class TypeResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для определения типа поля в схеме данных.
|
||||
/// </summary>
|
||||
internal class TypeResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Проверка соответствия пути.
|
||||
/// </summary>
|
||||
@@ -21,15 +21,10 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
return path == node.Path;
|
||||
}
|
||||
|
||||
var pathParts = path.Split('.');
|
||||
var nodeParts = node.Path.Split('.');
|
||||
string[] pathParts = path.Split('.');
|
||||
string[] nodeParts = node.Path.Split('.');
|
||||
|
||||
if (pathParts.Length > nodeParts.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
|
||||
return pathParts.Length > nodeParts.Length ? false : !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,12 +45,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
/// <returns>Типа значения.</returns>
|
||||
public JTokenType TokenType(JToken? value)
|
||||
{
|
||||
if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None)
|
||||
{
|
||||
return JTokenType.Null;
|
||||
}
|
||||
|
||||
return value.Type;
|
||||
return value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None ? JTokenType.Null : value.Type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,7 +74,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
{
|
||||
if (!disableResolve)
|
||||
{
|
||||
var customType = this.CustomResolve(node, value);
|
||||
AbstractSchemaType? customType = this.CustomResolve(node, value);
|
||||
|
||||
if (customType is not null)
|
||||
{
|
||||
@@ -92,14 +82,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
}
|
||||
}
|
||||
|
||||
var type = TokenType(value);
|
||||
JTokenType type = TokenType(value);
|
||||
|
||||
if (type == JTokenType.Null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
return type switch
|
||||
return type == JTokenType.Null
|
||||
? throw new ArgumentNullException(nameof(value))
|
||||
: type switch
|
||||
{
|
||||
JTokenType.Array => new ArraySchemaType(node),
|
||||
JTokenType.Object => new ObjectSchemaType(node),
|
||||
@@ -121,5 +108,4 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
||||
{
|
||||
return this.Resolve(node, value, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Абстрактный тип представоления данных в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal abstract class AbstractSchemaType(SchemaNode parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Абстрактный тип представоления данных в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal abstract class AbstractSchemaType(SchemaNode parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Элемент схемы данных, к которому относится тип.
|
||||
/// </summary>
|
||||
@@ -61,5 +61,4 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
return SchemaNode.FormatYaml(GetYamlData());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Тип представоления массива в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип представоления массива в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Минимальное количество элементов в массиве.
|
||||
/// </summary>
|
||||
@@ -44,12 +44,12 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
throw new Exception("Value is not an array, did you forget to call IsCompatibleValue?");
|
||||
}
|
||||
|
||||
var array = (JArray)value;
|
||||
JArray array = (JArray) value;
|
||||
|
||||
MinCount = Math.Min(MinCount, array.Count);
|
||||
MaxCount = Math.Max(MaxCount, array.Count);
|
||||
|
||||
foreach (var item in array)
|
||||
foreach (JToken item in array)
|
||||
{
|
||||
ElementSchema.AddValue(item);
|
||||
}
|
||||
@@ -85,5 +85,4 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
["value_type"] = ElementSchema.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Тип представоления словаря в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип представоления словаря в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Схема ключей словаря.
|
||||
/// </summary>
|
||||
@@ -34,9 +34,9 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
/// <param name="value">Новое значение.</param>
|
||||
public override void AddValue(JToken value)
|
||||
{
|
||||
var obj = (JObject)value;
|
||||
JObject obj = (JObject) value;
|
||||
|
||||
foreach (var pair in obj)
|
||||
foreach (KeyValuePair<string, JToken?> pair in obj)
|
||||
{
|
||||
KeyNode.AddValue(pair.Key);
|
||||
ItemNode.AddValue(pair.Value);
|
||||
@@ -73,5 +73,4 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
["_value"] = ItemNode.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Тип, указывающий, что данные игнорируются.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class IgnoreSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип, указывающий, что данные игнорируются.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class IgnoreSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Проверка, что значение совместимо с текущим типом.
|
||||
/// </summary>
|
||||
@@ -51,5 +51,4 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Тип представоления объектов в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип представоления объектов в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Элемнты полей объекта.
|
||||
/// </summary>
|
||||
@@ -29,9 +29,9 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
/// <param name="value">Новое значение.</param>
|
||||
public override void AddValue(JToken value)
|
||||
{
|
||||
var obj = (JObject)value;
|
||||
JObject obj = (JObject) value;
|
||||
|
||||
foreach (var field in Fields)
|
||||
foreach (SchemaNode field in Fields)
|
||||
{
|
||||
if (!obj.ContainsKey(field.Name))
|
||||
{
|
||||
@@ -39,9 +39,9 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var pair in obj)
|
||||
foreach (KeyValuePair<string, JToken?> pair in obj)
|
||||
{
|
||||
var field = Fields.FirstOrDefault(f => f.Name == pair.Key);
|
||||
SchemaNode? field = Fields.FirstOrDefault(f => f.Name == pair.Key);
|
||||
|
||||
if (field is null)
|
||||
{
|
||||
@@ -60,15 +60,10 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
Fields.Sort((a, b) =>
|
||||
{
|
||||
if (a.IsNullable && !b.IsNullable)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return string.Compare(a.Name, b.Name, StringComparison.Ordinal);
|
||||
return a.IsNullable && !b.IsNullable ? 0 : string.Compare(a.Name, b.Name, StringComparison.Ordinal);
|
||||
});
|
||||
|
||||
foreach (var field in Fields)
|
||||
foreach (SchemaNode field in Fields)
|
||||
{
|
||||
field.Beautify();
|
||||
}
|
||||
@@ -89,19 +84,12 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
/// <returns>Словарь данных</returns>
|
||||
public Dictionary<string, string> GetSchemaYaml()
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
Dictionary<string, string> result = new();
|
||||
|
||||
foreach (var field in Fields)
|
||||
foreach (SchemaNode field in Fields)
|
||||
{
|
||||
var s = field.Name;
|
||||
if (field.IsNullable)
|
||||
{
|
||||
s = $"[{s}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
s = $"'{s}'";
|
||||
}
|
||||
string s = field.Name;
|
||||
s = field.IsNullable ? $"[{s}]" : $"'{s}'";
|
||||
result.Add(s, field.ToString());
|
||||
}
|
||||
|
||||
@@ -119,6 +107,4 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
["schema"] = SchemaNode.FormatYaml(GetSchemaYaml())
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Тип представоления простых значений в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
/// <param name="type">Тип значения.</param>
|
||||
internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип представоления простых значений в схеме.
|
||||
/// </summary>
|
||||
/// <param name="parent">Элемент, к которому добавляется тип.</param>
|
||||
/// <param name="type">Тип значения.</param>
|
||||
internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSchemaType(parent)
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип значения.
|
||||
/// </summary>
|
||||
@@ -47,11 +47,11 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
{
|
||||
if (Type == JTokenType.String)
|
||||
{
|
||||
var newValues = new Dictionary<JToken, int>();
|
||||
Dictionary<JToken, int> newValues = new();
|
||||
|
||||
foreach (var pair in Values)
|
||||
foreach (KeyValuePair<JToken, int> pair in Values)
|
||||
{
|
||||
var newValue = "\"" + pair.Key.ToString().Trim().Replace("\"", "\\\"") + "\"";
|
||||
string newValue = "\"" + pair.Key.ToString().Trim().Replace("\"", "\\\"") + "\"";
|
||||
newValues.TryAdd(newValue, 0);
|
||||
newValues[newValue] += pair.Value;
|
||||
}
|
||||
@@ -77,14 +77,14 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
/// <returns>Словарь данных</returns>
|
||||
public override Dictionary<string, string> GetYamlData()
|
||||
{
|
||||
var values = new List<string>();
|
||||
var count = Values.Count;
|
||||
List<string> values = [];
|
||||
int count = Values.Count;
|
||||
|
||||
var prefix = (count == 1) ? "" : "- ";
|
||||
string prefix = (count == 1) ? "" : "- ";
|
||||
|
||||
if (count is <= SchemaNode.ElementLimit and > 0 && (Type != JTokenType.String || !Values.Any(s => s.ToString().Contains('\n'))))
|
||||
{
|
||||
foreach (var kvp in Values)
|
||||
foreach (KeyValuePair<JToken, int> kvp in Values)
|
||||
{
|
||||
values.Add($"{prefix}{kvp.Key} (x{kvp.Value})");
|
||||
}
|
||||
@@ -98,5 +98,4 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||
["variants"] = (values.Count > 0) ? string.Join("\r\n", values) : "[omitted]"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user