Отчистка кода
This commit is contained in:
+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,8 +1,8 @@
|
|||||||
using dotenv.net;
|
using dotenv.net;
|
||||||
using dotenv.net.Utilities;
|
using dotenv.net.Utilities;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper
|
namespace Pf2eDataScrapper;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс настроек.
|
/// Класс настроек.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,4 +38,3 @@ namespace Pf2eDataScrapper
|
|||||||
|
|
||||||
public static string DatabaseConnection => EnvReader.GetStringValue("DATABASE_CONNECTION");
|
public static string DatabaseConnection => EnvReader.GetStringValue("DATABASE_CONNECTION");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Pf2eDataScrapper.Importers.Repositories;
|
using Pf2eDataScrapper.Importers.Repositories;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers
|
namespace Pf2eDataScrapper.Importers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Абстрактный класс импортёра
|
/// Абстрактный класс импортёра
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,4 +39,3 @@ namespace Pf2eDataScrapper.Importers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract void BuildSchemas();
|
public abstract void BuildSchemas();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
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 Name => "Archives of Nethys Pathfinder 2e";
|
||||||
@@ -26,7 +26,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
|
|
||||||
public override void BuildSchemas()
|
public override void BuildSchemas()
|
||||||
{
|
{
|
||||||
var builder = new AonprdSchemaBuilder(Loader);
|
AonprdSchemaBuilder builder = new(Loader);
|
||||||
|
|
||||||
builder.BuildSchemas();
|
builder.BuildSchemas();
|
||||||
builder.Save(EnvSettings.OutputDir);
|
builder.Save(EnvSettings.OutputDir);
|
||||||
@@ -37,4 +37,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
using Newtonsoft.Json.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
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 AonprdImporter Importer = importer;
|
||||||
@@ -14,15 +13,15 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
|
|
||||||
public void Prepare()
|
public void Prepare()
|
||||||
{
|
{
|
||||||
using var indexFile = new StreamReader(Path.Combine(Importer.Dir, "index.json"));
|
using StreamReader indexFile = new(Path.Combine(Importer.Dir, "index.json"));
|
||||||
var indexJson = JObject.Parse(indexFile.ReadToEnd());
|
JObject indexJson = JObject.Parse(indexFile.ReadToEnd());
|
||||||
|
|
||||||
foreach (var kvp in indexJson)
|
foreach (KeyValuePair<string, JToken?> kvp in indexJson)
|
||||||
{
|
{
|
||||||
var file = kvp.Key.ToString();
|
string file = kvp.Key.ToString();
|
||||||
var items = (JArray)kvp.Value!;
|
JArray items = (JArray) kvp.Value!;
|
||||||
|
|
||||||
foreach (var item in items)
|
foreach (JToken item in items)
|
||||||
{
|
{
|
||||||
Compendium.AddReference(item.ToString(), file);
|
Compendium.AddReference(item.ToString(), file);
|
||||||
}
|
}
|
||||||
@@ -31,7 +30,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
|
|
||||||
public IEnumerable<LoaderEntry> Entries()
|
public IEnumerable<LoaderEntry> Entries()
|
||||||
{
|
{
|
||||||
return Entries(Compendium.Types.Keys.ToArray());
|
return Entries([.. Compendium.Types.Keys]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<LoaderEntry> Entries(string types)
|
public IEnumerable<LoaderEntry> Entries(string types)
|
||||||
@@ -41,26 +40,26 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
|
|
||||||
public IEnumerable<LoaderEntry> Entries(string[] types)
|
public IEnumerable<LoaderEntry> Entries(string[] types)
|
||||||
{
|
{
|
||||||
foreach (var file in Compendium.Files(types))
|
foreach (string? file in Compendium.Files(types))
|
||||||
{
|
{
|
||||||
if (file is null)
|
if (file is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var fileReader = new StreamReader(Path.Combine(Importer.Dir, $"{file}.json"));
|
using StreamReader fileReader = new(Path.Combine(Importer.Dir, $"{file}.json"));
|
||||||
var array = JArray.Parse(fileReader.ReadToEnd());
|
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)
|
if (id is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry = new LoaderEntry(id, file, (JObject)item);
|
LoaderEntry entry = new(id, file, (JObject) item);
|
||||||
|
|
||||||
if (types.Contains(entry.Type))
|
if (types.Contains(entry.Type))
|
||||||
{
|
{
|
||||||
@@ -76,4 +75,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
public JObject Json { get; } = itemJson;
|
public JObject Json { get; } = itemJson;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Pf2eDataScrapper.Importers.Repositories;
|
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 readonly string SearchUrl = searchUrl;
|
||||||
@@ -17,9 +17,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
url = SearchUrl + url;
|
url = SearchUrl + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var client = new HttpClient();
|
using HttpClient client = new();
|
||||||
using var stream = client.GetStreamAsync(url);
|
using Task<Stream> stream = client.GetStreamAsync(url);
|
||||||
using var reader = new StreamReader(stream.Result);
|
using StreamReader reader = new(stream.Result);
|
||||||
|
|
||||||
return reader.ReadToEnd();
|
return reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
@@ -44,22 +44,22 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
WriteFile("revision.txt", Revision.ToString());
|
WriteFile("revision.txt", Revision.ToString());
|
||||||
|
|
||||||
Console.WriteLine("Загрузка индекса...");
|
Console.WriteLine("Загрузка индекса...");
|
||||||
var indexContent = Load($"/json-data/aon{Revision}-index.json");
|
string indexContent = Load($"/json-data/aon{Revision}-index.json");
|
||||||
WriteFile("index.json", indexContent);
|
WriteFile("index.json", indexContent);
|
||||||
|
|
||||||
var indexJson = JObject.Parse(indexContent);
|
JObject indexJson = JObject.Parse(indexContent);
|
||||||
|
|
||||||
Console.WriteLine("Загрузка индексных файлов...");
|
Console.WriteLine("Загрузка индексных файлов...");
|
||||||
|
|
||||||
var bar = new ProgressBar(indexJson.Count);
|
ProgressBar bar = new(indexJson.Count);
|
||||||
var i = 0;
|
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);
|
bar.Refresh(i++, fileName);
|
||||||
|
|
||||||
var fileContent = Load($"/json-data/{fileName}.json");
|
string fileContent = Load($"/json-data/{fileName}.json");
|
||||||
WriteFile($"{fileName}.json", fileContent);
|
WriteFile($"{fileName}.json", fileContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,30 +73,29 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd
|
|||||||
/// <returns>true - актуальная ревизия, false - устаревшая/отсутсвует</returns>
|
/// <returns>true - актуальная ревизия, false - устаревшая/отсутсвует</returns>
|
||||||
private bool CheckRevision()
|
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"));
|
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))
|
if (!File.Exists(revisionFile))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var reader = new StreamReader(revisionFile);
|
using StreamReader reader = new(revisionFile);
|
||||||
var lastRevision = reader.ReadToEnd();
|
string lastRevision = reader.ReadToEnd();
|
||||||
return lastRevision == Revision.ToString();
|
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))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
File.Delete(filePath);
|
File.Delete(filePath);
|
||||||
}
|
}
|
||||||
using var writer = new StreamWriter(filePath);
|
using StreamWriter writer = new(filePath);
|
||||||
writer.Write(content);
|
writer.Write(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
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 readonly Dictionary<string, AonprdType> Types = [];
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
{
|
{
|
||||||
AonprdReference reference = new(id, 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);
|
type.Add(reference);
|
||||||
}
|
}
|
||||||
@@ -25,4 +25,3 @@
|
|||||||
.SelectMany(t => t.Files)
|
.SelectMany(t => t.Files)
|
||||||
.Distinct();
|
.Distinct();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
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 Id = id;
|
||||||
@@ -13,23 +13,11 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium
|
|||||||
{
|
{
|
||||||
static string? subType(string type, string cat)
|
static string? subType(string type, string cat)
|
||||||
{
|
{
|
||||||
if (type.StartsWith($"{cat}-") && type != cat)
|
return type.StartsWith($"{cat}-") && type != cat ? type.EndsWith("-bonus") ? $"{cat}-bonus" : $"{cat}-sub" : null;
|
||||||
{
|
|
||||||
if (type.EndsWith("-bonus"))
|
|
||||||
{
|
|
||||||
return $"{cat}-bonus";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $"{cat}-sub";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 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;
|
return subType(type, "equipment") ?? subType(type, "weapon") ?? type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
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 string Type = type;
|
||||||
@@ -20,4 +20,3 @@
|
|||||||
|
|
||||||
public int Count => Items.Count;
|
public int Count => Items.Count;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+13
-14
@@ -2,8 +2,8 @@
|
|||||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
||||||
using Pf2eDataScrapper.SchemaBuilder;
|
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 AonprdLoader Loader = loader;
|
||||||
@@ -33,10 +33,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Building schemas...");
|
Console.WriteLine("Building schemas...");
|
||||||
|
|
||||||
var bar = new ProgressBar(Loader.ItemCount);
|
ProgressBar bar = new ProgressBar(Loader.ItemCount);
|
||||||
var i = 0;
|
int i = 0;
|
||||||
|
|
||||||
foreach (var entry in Loader.Entries())
|
foreach (AonprdLoader.LoaderEntry entry in Loader.Entries())
|
||||||
{
|
{
|
||||||
bar.Refresh(i++, entry.Type);
|
bar.Refresh(i++, entry.Type);
|
||||||
GetSchema(entry).AddValue(entry.Json);
|
GetSchema(entry).AddValue(entry.Json);
|
||||||
@@ -51,10 +51,10 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
|||||||
|
|
||||||
targetDir = Path.Combine(targetDir, Loader.Importer.Slug);
|
targetDir = Path.Combine(targetDir, Loader.Importer.Slug);
|
||||||
|
|
||||||
var bar = new ProgressBar(Schemas.Count);
|
ProgressBar bar = new(Schemas.Count);
|
||||||
var i = 0;
|
int i = 0;
|
||||||
|
|
||||||
foreach (var kvp in Schemas)
|
foreach (KeyValuePair<string, SchemaNode> kvp in Schemas)
|
||||||
{
|
{
|
||||||
bar.Refresh(i++, kvp.Key);
|
bar.Refresh(i++, kvp.Key);
|
||||||
SaveSchema(targetDir, kvp.Key, kvp.Value);
|
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)
|
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
||||||
{
|
{
|
||||||
var invalids = Path.GetInvalidFileNameChars();
|
char[] invalids = Path.GetInvalidFileNameChars();
|
||||||
var fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
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))
|
if (dirPath is not null && !Directory.Exists(dirPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dirPath);
|
Directory.CreateDirectory(dirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var writer = new StreamWriter(path);
|
using StreamWriter writer = new(path);
|
||||||
|
|
||||||
schema.Beautify();
|
schema.Beautify();
|
||||||
|
|
||||||
@@ -84,4 +84,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.SchemaBuilder
|
|||||||
}, schema.Types[0].GetYamlData()));
|
}, schema.Types[0].GetYamlData()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип документов компендиума.
|
/// Тип документов компендиума.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -15,4 +15,3 @@
|
|||||||
RollTable,
|
RollTable,
|
||||||
Scene
|
Scene
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+3
-4
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Папка компендиума.
|
/// Папка компендиума.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -43,7 +43,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
|||||||
/// <param name="json"></param>
|
/// <param name="json"></param>
|
||||||
public CompendiumFolder(JObject json)
|
public CompendiumFolder(JObject json)
|
||||||
{
|
{
|
||||||
if (json.TryGetValue("_id", out var id))
|
if (json.TryGetValue("_id", out JToken? id))
|
||||||
{
|
{
|
||||||
// Вложенная папка через _folders.json
|
// Вложенная папка через _folders.json
|
||||||
Id = id!.ToString();
|
Id = id!.ToString();
|
||||||
@@ -85,4 +85,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
|||||||
return $"CompendiumFolder([Id={Id}][Type={Type}][Name={Name}][Path={Path}][Parent={Parent?.Name ?? "null"}])";
|
return $"CompendiumFolder([Id={Id}][Type={Type}][Name={Name}][Path={Path}][Parent={Parent?.Name ?? "null"}])";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Коллекция папок компендиума
|
/// Коллекция папок компендиума
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -25,4 +25,3 @@
|
|||||||
return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor && x.Name == "Conditions")];
|
return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor && x.Name == "Conditions")];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузчик данных компендиума
|
/// Загрузчик данных компендиума
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,25 +36,25 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
|||||||
/// <param name="parent"></param>
|
/// <param name="parent"></param>
|
||||||
protected void ProcessPackFolders(JArray folders, CompendiumFolder? parent)
|
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++}";
|
string id = $"folder-{_folderCount++}";
|
||||||
var name = obj["name"]!.ToString();
|
string name = obj["name"]!.ToString();
|
||||||
|
|
||||||
var folder = new CompendiumFolder(id, name)
|
CompendiumFolder folder = new(id, name)
|
||||||
{
|
{
|
||||||
Parent = parent
|
Parent = parent
|
||||||
};
|
};
|
||||||
Collection.Add(folder);
|
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();
|
string packId = jToken.ToString();
|
||||||
var child = Collection.GetById(packId);
|
CompendiumFolder? child = Collection.GetById(packId);
|
||||||
|
|
||||||
if (child is not null)
|
if (child is not null)
|
||||||
{
|
{
|
||||||
@@ -63,7 +63,7 @@ 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>
|
/// </summary>
|
||||||
public void Prepare()
|
public void Prepare()
|
||||||
{
|
{
|
||||||
using var systemFile = new StreamReader(Path.Combine(Importer.Dir, "static", "system.json"));
|
using StreamReader systemFile = new(Path.Combine(Importer.Dir, "static", "system.json"));
|
||||||
var systemData = JObject.Parse(systemFile.ReadToEnd());
|
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);
|
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
|
// Поиск _folders.json
|
||||||
foreach (var parent in Collection.ToList())
|
foreach (CompendiumFolder? parent in Collection.ToList())
|
||||||
{
|
{
|
||||||
if (parent.Path is null)
|
if (parent.Path is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dirPath = Path.Combine(Importer.Dir, parent.Path);
|
string dirPath = Path.Combine(Importer.Dir, parent.Path);
|
||||||
|
|
||||||
ItemCount += Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories)
|
ItemCount += Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories)
|
||||||
.Length;
|
.Length;
|
||||||
|
|
||||||
foreach (var foldersFilePath in Directory.GetFiles(dirPath, "_folders.json", SearchOption.AllDirectories))
|
foreach (string foldersFilePath in Directory.GetFiles(dirPath, "_folders.json", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
ItemCount--;
|
ItemCount--;
|
||||||
using var file = new StreamReader(foldersFilePath);
|
using StreamReader file = new(foldersFilePath);
|
||||||
var data = JArray.Parse(file.ReadToEnd());
|
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);
|
Collection.Add(folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,24 +131,24 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
|||||||
|
|
||||||
public IEnumerable<LoaderEnrty> Enrties()
|
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")
|
if (file.Name == "_folders.json")
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var reader = new StreamReader(file.FullName);
|
using StreamReader reader = new(file.FullName);
|
||||||
var itemJson = JObject.Parse(reader.ReadToEnd());
|
JObject itemJson = JObject.Parse(reader.ReadToEnd());
|
||||||
|
|
||||||
var itemFolder = folder;
|
CompendiumFolder? itemFolder = folder;
|
||||||
if (itemJson.TryGetValue("folder", out var itemJsonFolder))
|
if (itemJson.TryGetValue("folder", out JToken? itemJsonFolder))
|
||||||
{
|
{
|
||||||
itemFolder = Collection.GetById(itemJsonFolder.ToString());
|
itemFolder = Collection.GetById(itemJsonFolder.ToString());
|
||||||
}
|
}
|
||||||
@@ -167,4 +167,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
|||||||
?? throw new Exception($"Expected to have `type` field in file {file.FullName}");
|
?? throw new Exception($"Expected to have `type` field in file {file.FullName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+8
-15
@@ -1,11 +1,11 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NpgsqlTypes;
|
using NpgsqlTypes;
|
||||||
using Pf2eDataScrapper.Model;
|
using Pf2eDataScrapper.Model;
|
||||||
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
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 Pf2eTestContext Context = new();
|
||||||
@@ -14,7 +14,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
|
|
||||||
protected DataBuilderHelper Helper = DataBuilderHelper.Instance;
|
protected DataBuilderHelper Helper = DataBuilderHelper.Instance;
|
||||||
|
|
||||||
public Entity Entity { get; set; } = new Entity();
|
public Entity Entity { get; set; } = new();
|
||||||
|
|
||||||
public abstract EntityType Type { get; }
|
public abstract EntityType Type { get; }
|
||||||
|
|
||||||
@@ -28,7 +28,6 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
Entity.Name = GetRequired<string>("name");
|
Entity.Name = GetRequired<string>("name");
|
||||||
Entity.Img = GetRequired<string>("img");
|
Entity.Img = GetRequired<string>("img");
|
||||||
Entity.Description = GetRequired<string>("system.description.value");
|
Entity.Description = GetRequired<string>("system.description.value");
|
||||||
Entity.DescriptionGm = GetOptional<string>("system.description.gm");
|
|
||||||
|
|
||||||
Entity.IsTranslated = false;
|
Entity.IsTranslated = false;
|
||||||
Entity.IsChecked = false;
|
Entity.IsChecked = false;
|
||||||
@@ -49,21 +48,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
|
|
||||||
public T GetRequired<T>(string path)
|
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");
|
return token.ToObject<T>() ?? throw new NullReferenceException($"'{path}' is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? GetOptional<T>(string path)
|
public T? GetOptional<T>(string path)
|
||||||
{
|
{
|
||||||
var token = Input.SelectToken(path) ?? null;
|
JToken? token = Input.SelectToken(path) ?? null;
|
||||||
|
|
||||||
if (token is null)
|
return token is null ? default! : token.ToObject<T>() ?? default;
|
||||||
{
|
|
||||||
return default!;
|
|
||||||
}
|
|
||||||
|
|
||||||
return token.ToObject<T>() ?? default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T EnumRequired<T>(string path) where T : Enum
|
public T EnumRequired<T>(string path) where T : Enum
|
||||||
@@ -80,7 +74,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
return default;
|
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.GetCustomAttribute(field, typeof(PgNameAttribute)) is PgNameAttribute attribute)
|
||||||
{
|
{
|
||||||
@@ -101,4 +95,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+3
-4
@@ -1,7 +1,7 @@
|
|||||||
using Slugify;
|
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 Pf2eDatabase Database = Pf2eDatabase.Instance;
|
||||||
@@ -23,6 +23,5 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public readonly static DataBuilderHelper Instance = new();
|
public static readonly DataBuilderHelper Instance = new();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-16
@@ -3,8 +3,8 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||||
using System.Reflection;
|
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;
|
public Pf2eDatabase Database = Pf2eDatabase.Instance;
|
||||||
@@ -29,25 +29,20 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
|
|
||||||
public void PrepareProcessors()
|
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)
|
if (type.GetCustomAttributes(typeof(Pf2eTypeProcessor), true).Length <= 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var attribute = type.GetCustomAttribute<Pf2eTypeProcessor>();
|
Pf2eTypeProcessor? attribute = type.GetCustomAttribute<Pf2eTypeProcessor>();
|
||||||
Processors.Add(attribute!.Type, type.GetConstructor(new[] { typeof(JObject) })!);
|
Processors.Add(attribute!.Type, type.GetConstructor([typeof(JObject)])!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractProcessor? GetProcessor(string type, JObject input)
|
public AbstractProcessor? GetProcessor(string type, JObject input)
|
||||||
{
|
{
|
||||||
if (Processors.TryGetValue(type, out var constructor))
|
return Processors.TryGetValue(type, out ConstructorInfo? constructor) ? (AbstractProcessor) constructor.Invoke([input]) : null;
|
||||||
{
|
|
||||||
return (AbstractProcessor)constructor.Invoke([input]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TruncateTables()
|
public void TruncateTables()
|
||||||
@@ -63,14 +58,14 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Building data...");
|
Console.WriteLine("Building data...");
|
||||||
|
|
||||||
var bar = new ProgressBar(Loader.ItemCount);
|
ProgressBar bar = new(Loader.ItemCount);
|
||||||
var i = 0;
|
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}");
|
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)
|
if (processor is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -83,4 +78,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
|||||||
bar.Refresh(Loader.ItemCount, "Done!");
|
bar.Refresh(Loader.ItemCount, "Done!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
|
||||||
{
|
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
internal class Pf2eTypeProcessor(string type, int priority = 0) : Attribute
|
internal class Pf2eTypeProcessor(string type, int priority = 0) : Attribute
|
||||||
{
|
{
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
|
|
||||||
public readonly int Priority = priority;
|
public readonly int Priority = priority;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+2
-3
@@ -2,8 +2,8 @@
|
|||||||
using Pf2eDataScrapper.Model;
|
using Pf2eDataScrapper.Model;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
using Pf2eDataScrapper.Model.Enum;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors;
|
||||||
{
|
|
||||||
[Pf2eTypeProcessor("Item.condition")]
|
[Pf2eTypeProcessor("Item.condition")]
|
||||||
internal class ConditionProcessor(JObject input) : AbstractProcessor(input)
|
internal class ConditionProcessor(JObject input) : AbstractProcessor(input)
|
||||||
{
|
{
|
||||||
@@ -30,4 +30,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Pro
|
|||||||
Context.Conditions.Add(Object);
|
Context.Conditions.Add(Object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder;
|
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder;
|
||||||
using Pf2eDataScrapper.Importers.Repositories;
|
using Pf2eDataScrapper.Importers.Repositories;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Импортёр для модуля Pf2e FoundryVTT.
|
/// Импортёр для модуля Pf2e FoundryVTT.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -47,7 +47,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Import()
|
public override void Import()
|
||||||
{
|
{
|
||||||
var builder = new PF2eFoundryDataBuilder(Loader);
|
PF2eFoundryDataBuilder builder = new(Loader);
|
||||||
|
|
||||||
builder.TruncateTables();
|
builder.TruncateTables();
|
||||||
builder.Build();
|
builder.Build();
|
||||||
@@ -58,10 +58,9 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void BuildSchemas()
|
public override void BuildSchemas()
|
||||||
{
|
{
|
||||||
var builder = new CompendiumSchemaBuilder(Loader);
|
CompendiumSchemaBuilder builder = new(Loader);
|
||||||
|
|
||||||
builder.BuildSchemas();
|
builder.BuildSchemas();
|
||||||
builder.Save(EnvSettings.OutputDir);
|
builder.Save(EnvSettings.OutputDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+22
-28
@@ -2,8 +2,8 @@
|
|||||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
|
||||||
using Pf2eDataScrapper.SchemaBuilder;
|
using Pf2eDataScrapper.SchemaBuilder;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс построения схемы компендиумов.
|
/// Класс построения схемы компендиумов.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -75,16 +75,11 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected List<SchemaNode> GetItemSchemas(CompendiumFolder folder, string? itemType)
|
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 _equipmentTypes.Contains(itemType)
|
||||||
{
|
? [GetPackSchema(folder), GetTypeSchema(key), GetTypeSchema("Equipment")]
|
||||||
return [GetPackSchema(folder), GetTypeSchema(key), GetTypeSchema("Equipment")];
|
: [GetPackSchema(folder), GetTypeSchema(key)];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return [GetPackSchema(folder), GetTypeSchema(key)];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -94,16 +89,16 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Building schemas...");
|
Console.WriteLine("Building schemas...");
|
||||||
|
|
||||||
var bar = new ProgressBar(Loader.ItemCount);
|
ProgressBar bar = new(Loader.ItemCount);
|
||||||
var i = 0;
|
int i = 0;
|
||||||
|
|
||||||
foreach (var entry in Loader.Enrties())
|
foreach (CompendiumLoader.LoaderEnrty entry in Loader.Enrties())
|
||||||
{
|
{
|
||||||
bar.Refresh(i++, entry.Folder.Name);
|
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);
|
schema.AddValue(entry.Json);
|
||||||
}
|
}
|
||||||
@@ -120,8 +115,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Dumping schemas...");
|
Console.WriteLine("Dumping schemas...");
|
||||||
|
|
||||||
var bar = new ProgressBar(PackSchemas.Count + TypeSchemas.Count);
|
ProgressBar bar = new(PackSchemas.Count + TypeSchemas.Count);
|
||||||
var i = 0;
|
int i = 0;
|
||||||
|
|
||||||
targetDir = Path.Combine(targetDir, Loader.Importer.Slug);
|
targetDir = Path.Combine(targetDir, Loader.Importer.Slug);
|
||||||
|
|
||||||
@@ -132,19 +127,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
Array.ForEach(Directory.GetFiles(@targetDir), File.Delete);
|
Array.ForEach(Directory.GetFiles(@targetDir), File.Delete);
|
||||||
|
|
||||||
// Packs
|
// Packs
|
||||||
var packsDir = Path.Combine(targetDir, "packs");
|
string packsDir = Path.Combine(targetDir, "packs");
|
||||||
Directory.CreateDirectory(packsDir);
|
Directory.CreateDirectory(packsDir);
|
||||||
|
|
||||||
foreach (var pair in PackSchemas)
|
foreach (KeyValuePair<CompendiumFolder, SchemaNode> pair in PackSchemas)
|
||||||
{
|
{
|
||||||
bar.Refresh(i++, pair.Key.Name);
|
bar.Refresh(i++, pair.Key.Name);
|
||||||
SaveSchema(packsDir, pair.Key.Name, pair.Value);
|
SaveSchema(packsDir, pair.Key.Name, pair.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
var typesDir = Path.Combine(targetDir, "types");
|
string typesDir = Path.Combine(targetDir, "types");
|
||||||
Directory.CreateDirectory(typesDir);
|
Directory.CreateDirectory(typesDir);
|
||||||
foreach (var pair in TypeSchemas)
|
foreach (KeyValuePair<string, SchemaNode> pair in TypeSchemas)
|
||||||
{
|
{
|
||||||
bar.Refresh(i++, pair.Key);
|
bar.Refresh(i++, pair.Key);
|
||||||
SaveSchema(typesDir, pair.Key, pair.Value);
|
SaveSchema(typesDir, pair.Key, pair.Value);
|
||||||
@@ -161,19 +156,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
/// <param name="schema">Сохраняемая схема.</param>
|
/// <param name="schema">Сохраняемая схема.</param>
|
||||||
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
protected void SaveSchema(string dir, string name, SchemaNode schema)
|
||||||
{
|
{
|
||||||
var invalids = Path.GetInvalidFileNameChars();
|
char[] invalids = Path.GetInvalidFileNameChars();
|
||||||
var fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
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))
|
if (dirPath is not null && !Directory.Exists(dirPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dirPath);
|
Directory.CreateDirectory(dirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var writer = new StreamWriter(path);
|
using StreamWriter writer = new(path);
|
||||||
|
|
||||||
schema.Beautify();
|
schema.Beautify();
|
||||||
|
|
||||||
@@ -189,4 +184,3 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
//writer.Write(schema.ToString());
|
//writer.Write(schema.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+5
-14
@@ -2,8 +2,8 @@
|
|||||||
using Pf2eDataScrapper.SchemaBuilder;
|
using Pf2eDataScrapper.SchemaBuilder;
|
||||||
using Pf2eDataScrapper.SchemaBuilder.Types;
|
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 class FoundryRulesSchemaType(SchemaNode parent) : IgnoreSchemaType(parent)
|
||||||
@@ -46,17 +46,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.SchemaBuilder
|
|||||||
/// <returns>Новый тип для схемы данных. `null`, что бы использовать значение по умолчанию</returns>
|
/// <returns>Новый тип для схемы данных. `null`, что бы использовать значение по умолчанию</returns>
|
||||||
protected override AbstractSchemaType? CustomResolve(SchemaNode node, JToken? value)
|
protected override AbstractSchemaType? CustomResolve(SchemaNode node, JToken? value)
|
||||||
{
|
{
|
||||||
if (CheckPath(node, DictionaryPaths))
|
return CheckPath(node, DictionaryPaths)
|
||||||
{
|
? new DictionarySchemaType(node)
|
||||||
return new DictionarySchemaType(node);
|
: node.Path.EndsWith(".rules") ? new FoundryRulesSchemaType(node) : (AbstractSchemaType?) null;
|
||||||
}
|
|
||||||
|
|
||||||
if (node.Path.EndsWith(".rules"))
|
|
||||||
{
|
|
||||||
return new FoundryRulesSchemaType(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
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 readonly AbstractImporter Importer = importer;
|
||||||
@@ -10,4 +10,3 @@
|
|||||||
|
|
||||||
public abstract void Update();
|
public abstract void Update();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System.Data.Common;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
|
namespace Pf2eDataScrapper.Importers.Repositories;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Repositories
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузчик данных из git-репозиториев
|
/// Загрузчик данных из git-репозиториев
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -16,12 +15,12 @@ namespace Pf2eDataScrapper.Importers.Repositories
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
var gitPath = Path.Combine(RepositoryDirPath, importer.Slug);
|
string gitPath = Path.Combine(RepositoryDirPath, importer.Slug);
|
||||||
|
|
||||||
if (Directory.Exists(gitPath))
|
if (Directory.Exists(gitPath))
|
||||||
{
|
{
|
||||||
// git pull
|
// git pull
|
||||||
var process = new Process
|
Process process = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo()
|
StartInfo = new ProcessStartInfo()
|
||||||
{
|
{
|
||||||
@@ -35,7 +34,7 @@ namespace Pf2eDataScrapper.Importers.Repositories
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// git clone
|
// git clone
|
||||||
var process = new Process
|
Process process = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo()
|
StartInfo = new ProcessStartInfo()
|
||||||
{
|
{
|
||||||
@@ -49,4 +48,3 @@ namespace Pf2eDataScrapper.Importers.Repositories
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using NpgsqlTypes;
|
using NpgsqlTypes;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model.Enum
|
namespace Pf2eDataScrapper.Model.Enum;
|
||||||
{
|
|
||||||
public enum EntityRarity
|
public enum EntityRarity
|
||||||
{
|
{
|
||||||
[PgName("common")]
|
[PgName("common")]
|
||||||
@@ -16,4 +16,3 @@ namespace Pf2eDataScrapper.Model.Enum
|
|||||||
[PgName("unique")]
|
[PgName("unique")]
|
||||||
Unique
|
Unique
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using NpgsqlTypes;
|
using NpgsqlTypes;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model.Enum
|
namespace Pf2eDataScrapper.Model.Enum;
|
||||||
{
|
|
||||||
public enum TraitType
|
public enum TraitType
|
||||||
{
|
{
|
||||||
[PgName("regular")]
|
[PgName("regular")]
|
||||||
@@ -10,4 +10,3 @@ namespace Pf2eDataScrapper.Model.Enum
|
|||||||
[PgName("tradition")]
|
[PgName("tradition")]
|
||||||
Tradition
|
Tradition
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model
|
namespace Pf2eDataScrapper.Model;
|
||||||
{
|
|
||||||
internal interface IEntity
|
internal interface IEntity
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -9,4 +9,3 @@ namespace Pf2eDataScrapper.Model
|
|||||||
public Entity Entity { get; set; }
|
public Entity Entity { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Pf2eDataScrapper.Model.Common;
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Model;
|
namespace Pf2eDataScrapper.Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Npgsql;
|
using Npgsql;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper
|
namespace Pf2eDataScrapper;
|
||||||
{
|
|
||||||
public partial class Pf2eDatabase
|
public partial class Pf2eDatabase
|
||||||
{
|
{
|
||||||
public NpgsqlConnection Connection;
|
public NpgsqlConnection Connection;
|
||||||
@@ -51,7 +51,7 @@ namespace Pf2eDataScrapper
|
|||||||
|
|
||||||
public void ExecuteCommand(string sql)
|
public void ExecuteCommand(string sql)
|
||||||
{
|
{
|
||||||
var command = GetCommand(sql);
|
NpgsqlCommand command = GetCommand(sql);
|
||||||
|
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@@ -120,4 +120,3 @@ namespace Pf2eDataScrapper
|
|||||||
[GeneratedRegex(@"(?:^|;)User=(.*?)(?:$|;)")]
|
[GeneratedRegex(@"(?:^|;)User=(.*?)(?:$|;)")]
|
||||||
private static partial Regex UsernamePattern();
|
private static partial Regex UsernamePattern();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Pf2eDataScrapper.Model;
|
using Pf2eDataScrapper.Model;
|
||||||
|
using Pf2eDataScrapper.Model.Common;
|
||||||
using Pf2eDataScrapper.Model.Enum;
|
using Pf2eDataScrapper.Model.Enum;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Pf2eDataScrapper;
|
namespace Pf2eDataScrapper;
|
||||||
|
|
||||||
@@ -103,8 +101,10 @@ public partial class Pf2eTestContext : DbContext
|
|||||||
public virtual DbSet<Trait> Traits { get; set; }
|
public virtual DbSet<Trait> Traits { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
EnvSettings.Load();
|
||||||
optionsBuilder.UseNpgsql(EnvSettings.DatabaseConnection,
|
optionsBuilder.UseNpgsql(EnvSettings.DatabaseConnection,
|
||||||
builder =>
|
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)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.UseIdentityByDefaultColumns();
|
modelBuilder.UseIdentityByDefaultColumns();
|
||||||
@@ -198,8 +154,7 @@ public partial class Pf2eTestContext : DbContext
|
|||||||
entity.Property(e => e.Id).HasColumnName("id");
|
entity.Property(e => e.Id).HasColumnName("id");
|
||||||
entity.Property(e => e.Description).HasColumnName("description");
|
entity.Property(e => e.Description).HasColumnName("description");
|
||||||
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
|
||||||
entity.Property(e => e.Type)
|
entity.Property(e => e.Type).HasColumnName("type");
|
||||||
.HasColumnName("type");
|
|
||||||
entity.Property(e => e.Img)
|
entity.Property(e => e.Img)
|
||||||
.HasMaxLength(150)
|
.HasMaxLength(150)
|
||||||
.HasColumnName("img");
|
.HasColumnName("img");
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using Pf2eDataScrapper;
|
using Pf2eDataScrapper;
|
||||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
||||||
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
|
|
||||||
|
|
||||||
EnvSettings.Load();
|
EnvSettings.Load();
|
||||||
|
|
||||||
var importer = new AonprdImporter();
|
AonprdImporter importer = new AonprdImporter();
|
||||||
importer.Prepare();
|
importer.Prepare();
|
||||||
importer.BuildSchemas();
|
importer.BuildSchemas();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Pf2eDataScrapper.SchemaBuilder.Types;
|
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Элемент схемы данных.
|
/// Элемент схемы данных.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -93,7 +93,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
Values++;
|
Values++;
|
||||||
|
|
||||||
foreach (var type in Types)
|
foreach (AbstractSchemaType type in Types)
|
||||||
{
|
{
|
||||||
if (type.IsCompatibleValue(value))
|
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))
|
if (newType.IsCompatibleValue(value))
|
||||||
{
|
{
|
||||||
@@ -111,7 +111,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var fallbackType = Resolver.Resolve(this, value, true);
|
AbstractSchemaType fallbackType = Resolver.Resolve(this, value, true);
|
||||||
Types.Add(fallbackType);
|
Types.Add(fallbackType);
|
||||||
fallbackType.AddValue(value);
|
fallbackType.AddValue(value);
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
return Types[0].GetTypeName();
|
return Types[0].GetTypeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
var typeNames = Types.Select(t => t.GetTypeName()).ToList();
|
List<string> typeNames = [.. Types.Select(t => t.GetTypeName())];
|
||||||
|
|
||||||
return string.Join(" | ", typeNames);
|
return string.Join(" | ", typeNames);
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
/// <returns>Строковое представление элемента.</returns>
|
/// <returns>Строковое представление элемента.</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var result = new Dictionary<string, string>()
|
Dictionary<string, string> result = new()
|
||||||
{
|
{
|
||||||
["type"] = GetTypeName(),
|
["type"] = GetTypeName(),
|
||||||
["path"] = Path,
|
["path"] = Path,
|
||||||
@@ -159,7 +159,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
List<string> types = [];
|
List<string> types = [];
|
||||||
|
|
||||||
foreach (var type in Types)
|
foreach (AbstractSchemaType type in Types)
|
||||||
{
|
{
|
||||||
types.Add(Indent(type?.ToString() ?? ""));
|
types.Add(Indent(type?.ToString() ?? ""));
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Beautify()
|
public void Beautify()
|
||||||
{
|
{
|
||||||
foreach (var type in Types)
|
foreach (AbstractSchemaType type in Types)
|
||||||
{
|
{
|
||||||
type.Beautify();
|
type.Beautify();
|
||||||
}
|
}
|
||||||
@@ -207,11 +207,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
/// <returns>Строка форматированных данных</returns>
|
/// <returns>Строка форматированных данных</returns>
|
||||||
public static string FormatYaml(params List<Dictionary<string, string>> input)
|
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";
|
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)
|
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))
|
if (result.ContainsKey(kvp.Key))
|
||||||
{
|
{
|
||||||
@@ -241,4 +241,3 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Pf2eDataScrapper.SchemaBuilder.Types;
|
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс для определения типа поля в схеме данных.
|
/// Класс для определения типа поля в схеме данных.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,15 +21,10 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
return path == node.Path;
|
return path == node.Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pathParts = path.Split('.');
|
string[] pathParts = path.Split('.');
|
||||||
var nodeParts = node.Path.Split('.');
|
string[] nodeParts = node.Path.Split('.');
|
||||||
|
|
||||||
if (pathParts.Length > nodeParts.Length)
|
return pathParts.Length > nodeParts.Length ? false : !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -50,12 +45,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
/// <returns>Типа значения.</returns>
|
/// <returns>Типа значения.</returns>
|
||||||
public JTokenType TokenType(JToken? value)
|
public JTokenType TokenType(JToken? value)
|
||||||
{
|
{
|
||||||
if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None)
|
return value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None ? JTokenType.Null : value.Type;
|
||||||
{
|
|
||||||
return JTokenType.Null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value.Type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -84,7 +74,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
{
|
{
|
||||||
if (!disableResolve)
|
if (!disableResolve)
|
||||||
{
|
{
|
||||||
var customType = this.CustomResolve(node, value);
|
AbstractSchemaType? customType = this.CustomResolve(node, value);
|
||||||
|
|
||||||
if (customType is not null)
|
if (customType is not null)
|
||||||
{
|
{
|
||||||
@@ -92,14 +82,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = TokenType(value);
|
JTokenType type = TokenType(value);
|
||||||
|
|
||||||
if (type == JTokenType.Null)
|
return type == JTokenType.Null
|
||||||
{
|
? throw new ArgumentNullException(nameof(value))
|
||||||
throw new ArgumentNullException(nameof(value));
|
: type switch
|
||||||
}
|
|
||||||
|
|
||||||
return type switch
|
|
||||||
{
|
{
|
||||||
JTokenType.Array => new ArraySchemaType(node),
|
JTokenType.Array => new ArraySchemaType(node),
|
||||||
JTokenType.Object => new ObjectSchemaType(node),
|
JTokenType.Object => new ObjectSchemaType(node),
|
||||||
@@ -122,4 +109,3 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
return this.Resolve(node, value, false);
|
return this.Resolve(node, value, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Абстрактный тип представоления данных в схеме.
|
/// Абстрактный тип представоления данных в схеме.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -62,4 +62,3 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
return SchemaNode.FormatYaml(GetYamlData());
|
return SchemaNode.FormatYaml(GetYamlData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип представоления массива в схеме.
|
/// Тип представоления массива в схеме.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -44,12 +44,12 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
throw new Exception("Value is not an array, did you forget to call IsCompatibleValue?");
|
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);
|
MinCount = Math.Min(MinCount, array.Count);
|
||||||
MaxCount = Math.Max(MaxCount, array.Count);
|
MaxCount = Math.Max(MaxCount, array.Count);
|
||||||
|
|
||||||
foreach (var item in array)
|
foreach (JToken item in array)
|
||||||
{
|
{
|
||||||
ElementSchema.AddValue(item);
|
ElementSchema.AddValue(item);
|
||||||
}
|
}
|
||||||
@@ -86,4 +86,3 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип представоления словаря в схеме.
|
/// Тип представоления словаря в схеме.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,9 +34,9 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
/// <param name="value">Новое значение.</param>
|
/// <param name="value">Новое значение.</param>
|
||||||
public override void AddValue(JToken value)
|
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);
|
KeyNode.AddValue(pair.Key);
|
||||||
ItemNode.AddValue(pair.Value);
|
ItemNode.AddValue(pair.Value);
|
||||||
@@ -74,4 +74,3 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип, указывающий, что данные игнорируются.
|
/// Тип, указывающий, что данные игнорируются.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,4 +52,3 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип представоления объектов в схеме.
|
/// Тип представоления объектов в схеме.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -29,9 +29,9 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
/// <param name="value">Новое значение.</param>
|
/// <param name="value">Новое значение.</param>
|
||||||
public override void AddValue(JToken value)
|
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))
|
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)
|
if (field is null)
|
||||||
{
|
{
|
||||||
@@ -60,15 +60,10 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
{
|
{
|
||||||
Fields.Sort((a, b) =>
|
Fields.Sort((a, b) =>
|
||||||
{
|
{
|
||||||
if (a.IsNullable && !b.IsNullable)
|
return a.IsNullable && !b.IsNullable ? 0 : string.Compare(a.Name, b.Name, StringComparison.Ordinal);
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return string.Compare(a.Name, b.Name, StringComparison.Ordinal);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var field in Fields)
|
foreach (SchemaNode field in Fields)
|
||||||
{
|
{
|
||||||
field.Beautify();
|
field.Beautify();
|
||||||
}
|
}
|
||||||
@@ -89,19 +84,12 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
/// <returns>Словарь данных</returns>
|
/// <returns>Словарь данных</returns>
|
||||||
public Dictionary<string, string> GetSchemaYaml()
|
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;
|
string s = field.Name;
|
||||||
if (field.IsNullable)
|
s = field.IsNullable ? $"[{s}]" : $"'{s}'";
|
||||||
{
|
|
||||||
s = $"[{s}]";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
s = $"'{s}'";
|
|
||||||
}
|
|
||||||
result.Add(s, field.ToString());
|
result.Add(s, field.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,5 +108,3 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
namespace Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип представоления простых значений в схеме.
|
/// Тип представоления простых значений в схеме.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -47,11 +47,11 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
{
|
{
|
||||||
if (Type == JTokenType.String)
|
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.TryAdd(newValue, 0);
|
||||||
newValues[newValue] += pair.Value;
|
newValues[newValue] += pair.Value;
|
||||||
}
|
}
|
||||||
@@ -77,14 +77,14 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
/// <returns>Словарь данных</returns>
|
/// <returns>Словарь данных</returns>
|
||||||
public override Dictionary<string, string> GetYamlData()
|
public override Dictionary<string, string> GetYamlData()
|
||||||
{
|
{
|
||||||
var values = new List<string>();
|
List<string> values = [];
|
||||||
var count = Values.Count;
|
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'))))
|
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})");
|
values.Add($"{prefix}{kvp.Key} (x{kvp.Value})");
|
||||||
}
|
}
|
||||||
@@ -99,4 +99,3 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user