Исправление типов схем

This commit is contained in:
2025-03-29 16:02:37 +04:00
parent de3cd3c631
commit cabcb54816
10 changed files with 54 additions and 20 deletions
@@ -144,6 +144,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
using var writer = new StreamWriter(path);
schema.Beautify();
writer.WriteLine(name);
writer.WriteLine($"Different values: {schema.Values}");
writer.WriteLine("=====================================");
@@ -5,20 +5,17 @@ using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.SchemaBuilder;
using Pf2eDataScrapper.SchemaBuilder.Types;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
{
internal class CompendiumSchemaTypeResolver : TypeResolver
{
public class FoundryRulesSchemaType(SchemaNode parent) : ArraySchemaType(parent)
public class FoundryRulesSchemaType(SchemaNode parent) : IgnoreSchemaType(parent)
{
public override string GetTypeName()
{
return "###FoundryRulesObject###";
}
public override string ToString()
{
return GetTypeName();
return "ignored (Foundry rules object)";
}
}
+5 -1
View File
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.SchemaBuilder.Types;
namespace Pf2eDataScrapper.SchemaBuilder
{
@@ -98,7 +99,10 @@ namespace Pf2eDataScrapper.SchemaBuilder
public void Beautify()
{
foreach (var type in Types)
{
type.Beautify();
}
}
}
}
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.SchemaBuilder.Types;
namespace Pf2eDataScrapper.SchemaBuilder
{
@@ -1,7 +1,7 @@
using System.ComponentModel.Design.Serialization;
using Newtonsoft.Json.Linq;
namespace Pf2eDataScrapper.SchemaBuilder
namespace Pf2eDataScrapper.SchemaBuilder.Types
{
internal abstract class AbstractSchemaType(SchemaNode parent)
{
@@ -32,7 +32,10 @@ namespace Pf2eDataScrapper.SchemaBuilder
/// <returns></returns>
public abstract string GetTypeName();
public abstract override string ToString();
public override string ToString()
{
return $"{GetTypeName()} {Parent.Path}";
}
/// <summary>
@@ -3,9 +3,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using Newtonsoft.Json.Linq;
namespace Pf2eDataScrapper.SchemaBuilder
namespace Pf2eDataScrapper.SchemaBuilder.Types
{
internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
{
@@ -53,7 +54,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
public override string ToString()
{
return string.Join("\n" + Tab, [
GetTypeName() + $" {{{Parent?.Path ?? ""}}}",
base.ToString(),
$"Length: min={MinCount} max={MaxCount}",
"Value type: " + Indent(ElementSchema.ToString())
]);
@@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace Pf2eDataScrapper.SchemaBuilder
namespace Pf2eDataScrapper.SchemaBuilder.Types
{
internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
{
@@ -42,7 +42,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
public override string ToString()
{
return string.Join("\n" + Tab, [
GetTypeName() + $" {{{Parent?.Path ?? ""}}}",
base.ToString(),
"Key:" + Indent(KeyNode.ToString()),
"Value:" + Indent(ItemNode.ToString())
]);
@@ -0,0 +1,27 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pf2eDataScrapper.SchemaBuilder.Types
{
internal class IgnoreSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
{
public override bool IsCompatibleValue(JToken value)
{
return true;
}
public override void AddValue(JToken value)
{
}
public override void Beautify()
{
}
public override string GetTypeName()
{
return "ignore";
}
}
}
@@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pf2eDataScrapper.SchemaBuilder
namespace Pf2eDataScrapper.SchemaBuilder.Types
{
internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
{
@@ -34,7 +34,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
if (field is null)
{
field = new SchemaNode(this.Parent, pair.Key);
field = new SchemaNode(Parent, pair.Key);
Fields.Add(field);
}
@@ -67,11 +67,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
public override string ToString()
{
List<string> rows = [$"object {{{Parent?.Path ?? ""}}}"];
List<string> rows = [base.ToString()];
foreach (var field in Fields)
{
string s = field.Name;
var s = field.Name;
if (field.IsNullable)
{
@@ -1,6 +1,6 @@
using Newtonsoft.Json.Linq;
namespace Pf2eDataScrapper.SchemaBuilder
namespace Pf2eDataScrapper.SchemaBuilder.Types
{
internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSchemaType(parent)
{
@@ -46,7 +46,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
public override string ToString()
{
var result = GetTypeName() + $" {{{Parent?.Path ?? ""}}}";
var result = base.ToString();
var count = Values.Count;
if (count == Root.Values)
@@ -68,7 +68,6 @@ namespace Pf2eDataScrapper.SchemaBuilder
return result.Trim();
}
result += "\n";
result = Values.Aggregate(result, (current, value) => current + $"{Tab}{value.Key} (x{value.Value})\n");