Больше обработчиков

This commit is contained in:
2025-04-18 20:39:17 +04:00
parent 5b1fad3372
commit 38bc6152ed
30 changed files with 1474 additions and 1492 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
using Pf2eModel.Model;
using Pf2eModel;
using Slugify;
namespace Pf2eDataScrapper.Importers;
@@ -42,11 +42,6 @@ internal class AonprdLoader(AonprdImporter importer)
{
foreach (string? file in Compendium.Files(types))
{
if (file is null)
{
continue;
}
using StreamReader fileReader = new(Path.Combine(Importer.Dir, $"{file}.json"));
JArray array = JArray.Parse(fileReader.ReadToEnd());
@@ -1,5 +1,6 @@
using LinqToDB;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using Pf2eModel;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Source;
@@ -49,7 +50,7 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
Context.SaveChanges();
}
protected string AddedDescription(string path) => $"\n\n---\n[{path}]\n\n{Input.GetOptional<string>(path) ?? ""}";
protected string AddedDescription(string path) => $"\r\n\r\n========== [{path}] ==========\r\n\r\n{Input.GetOptional<string>(path) ?? ""}";
protected string AddedDescription(string[] paths) => string.Join("", paths.Select(AddedDescription));
@@ -60,7 +61,7 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
Entity.Id = Helper.NextEntityId;
Entity.Type = Type;
Entity.Name = Input.GetRequired<string>("name");
Entity.Img = ""; // GetRequired<string>("img");
Entity.Img = "";
Entity.Description = GetDescription();
Entity.Rarity = Input.EnumOptional<EntityRarity>("rarity", EntityRarity.Common);
Entity.Slug = Helper.GenerateSlug(Entity.Name);
@@ -85,8 +86,11 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
JArray? legacyIdArray = Input.GetOptional<JArray>("legacy_id");
if (legacyIdArray is not null)
if (legacyIdArray is null)
{
return;
}
string legacyId = legacyIdArray[0].ToString();
if (LegacyAliases.TryGetValue(legacyId, out string? legacyName))
@@ -111,8 +115,6 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
}
}
}
protected virtual void AddSource()
{
string name = Input.GetRequired<string>("source[0]");
@@ -185,6 +187,8 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
.ToList();
List<Trait> traits = Context.Traits
.Include(t => t.Entity)
.ThenInclude(e => e.Aliases)
.Where(t => traitEntities.Contains(t.Entity))
.ToList();
@@ -202,39 +206,15 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
}
}
protected IEnumerable<Trait> GetTraits(IEnumerable<string> names)
{
List<Trait> result = Context.Traits.Where(t => names.Contains(t.Entity.Name)).ToList();
foreach (string name in names)
{
if (result.Any(t => t.Entity.Name == name))
{
continue;
}
/*
Trait trait = new()
{
Name = name,
Slug = name,
Type = TraitType.Regular,
Description = "",
};
Context.Traits.Add(trait);
result.Add(trait);
*/
}
return result;
}
protected void ProcessLegacy(string id, string name)
{
if (RemasterWithoutLegacy.TryGetValue(id, out Entity? remastered))
{
if (remastered.Name != name)
if (remastered.Name == name)
{
return;
}
EntityAlias alias = new()
{
Type = AliasType.LegacyEnglish,
@@ -243,7 +223,6 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
};
Context.EntityAliases.Add(alias);
}
}
else
{
LegacyAliases.Add(id, name);
@@ -52,7 +52,7 @@ internal class AonprdDataBuilder(AonprdLoader loader)
foreach (AonprdLoader.LoaderEntry entry in Loader.Entries(item.Attribute.Type))
{
bar2.Refresh(i++, $"{entry.Id}");
bar2.Refresh(j++, $"{entry.Id}");
AonprdProcessorInput input = new(entry.Json);
AbstractProcessor processor = (AbstractProcessor) item.Constructor.Invoke([input]);
@@ -68,7 +68,7 @@ internal class AonprdDataBuilder(AonprdLoader loader)
}
}
bar2.Refresh(j, "Processor complited");
bar2.Refresh(j, "Processor completed");
}
bar1.Refresh(i, "Done!");
@@ -1,11 +0,0 @@
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
[AttributeUsage(AttributeTargets.Field)]
internal class AonprdEnumAttribute(string[] values) : Attribute
{
public readonly string[] Values = values;
public AonprdEnumAttribute(string value) : this([value])
{
}
}
@@ -4,7 +4,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
public static class AonprdEnumResolver
{
private static readonly ICollection<Solver> Solvers = [
new Solver<ActionType>(new() {
new Solver<ActionType>(new()
{
{ "Single Action", ActionType.SingleAction },
{ "Reaction or One Action", ActionType.SingleAction },
{ "Free Action or One Action", ActionType.SingleAction },
@@ -16,7 +17,8 @@ public static class AonprdEnumResolver
{ "Single Action to Two Actions", ActionType.SingleToTwoActions },
}),
new Solver<SourceCategory>(new() {
new Solver<SourceCategory>(new()
{
{ "Rulebooks", SourceCategory.Rulebooks },
{ "Adventure Paths", SourceCategory.AdventurePaths },
{ "Lost Omens", SourceCategory.LostOmens },
@@ -25,6 +27,17 @@ public static class AonprdEnumResolver
{ "Blog Posts", SourceCategory.BlogPosts },
{ "Society", SourceCategory.Society },
}),
new Solver<AncestryVision>(new()
{
{ "Low-Light Vision", AncestryVision.LowLightVision },
{ "Darkvision", AncestryVision.DarkVision },
}),
new Solver<AttributeValues>(new()
{
{ "Consitution", AttributeValues.Constitution }
})
];
public static T Resolve<T>(string value) where T : Enum
@@ -0,0 +1,78 @@
using LinqToDB;
using Newtonsoft.Json.Linq;
using Pf2eModel.Model;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure;
using Pf2eModel.Model.Structure.AncestryRelation;
using System.Text.RegularExpressions;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
[AonprdProcessor("ancestry", ["trait", "language"])]
internal class AncestryProcessor(ProcessorInput input) : AbstractProcessor(input)
{
public override EntityType Type { get; } = EntityType.Ancestry;
public override Ancestry Object { get; } = new Ancestry();
public override void Process()
{
string type = Input.GetRequired<string>("type");
if (type != "Ancestry")
{
return;
}
base.Process();
Object.Size = Input.GetRequired<JArray>("size").Select(t => Input.Enum<Size>(t.ToString())).ToArray();
string hp = Input.GetRequired<string>("hp_raw");
Object.Hp = Convert.ToInt32((hp != "") ? hp : "0");
Object.Speed = Convert.ToInt32(Input.GetOptional<int>("speed.land"));
Object.Vision = Input.EnumOptional<AncestryVision>("vision", AncestryVision.Normal);
AddBoosts("attribute", true);
AddBoosts("attribute_flaw", false);
// TODO - import languages from Foundry!
// ProcessLanguages();
}
protected void AddBoosts(string path, bool isBoost)
{
List<string> boosts = Input.GetOptional<JArray>(path)?.ToArray().Select(t => t.ToString()).ToList() ?? [];
if (boosts.Contains("Two free ability boosts"))
{
boosts.Remove("Two free ability boosts");
boosts.Add("Free");
boosts.Add("Free");
}
foreach (string boost in boosts)
{
AncestryBoost ancestryBoost = new()
{
Ancestry = Object,
Boost = isBoost,
Value = Input.Enum<AttributeValues>(boost),
};
Context.AncestryBoosts.Add(ancestryBoost);
}
}
protected override string GetDescription()
=> base.GetDescription() + AddedDescription([
"source_markdown",
"summary_markdown",
"trait_markdown",
"search_markdown"
]);
}
@@ -0,0 +1,13 @@
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
[AonprdProcessor("language")]
internal class LanguageProcessor(ProcessorInput input) : AbstractProcessor(input)
{
public override EntityType Type { get; } = EntityType.Language;
public override Language Object { get; } = new Language();
}
@@ -21,7 +21,7 @@ internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input)
protected override void AddTraits()
{
// Во втором проходе
// Необходимо пропускать
}
protected override string GetDescription()
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using Pf2eModel;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Source;
+1 -1
View File
@@ -1,7 +1,7 @@
using Pf2eDataScrapper;
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
Console.SetWindowSize(Console.LargestWindowWidth - 20, Console.LargestWindowHeight - 10);
//Console.SetWindowSize(Console.LargestWindowWidth - 20, Console.LargestWindowHeight - 10);
EnvSettings.Load();
File diff suppressed because it is too large Load Diff
@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Pf2eModel.Model;
using Pf2eModel;
using Pf2eModel.Model.Enum;
#nullable disable
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations
{
[DbContext(typeof(Pf2eDbContext))]
[Migration("20250418083111_1")]
[Migration("20250418160209_1")]
partial class _1
{
/// <inheritdoc />
@@ -27,8 +27,8 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "action_category", new[] { "unknown", "offensive", "defensive", "interaction", "familiar", "army_tactic", "army_war_action", "kingdom_activity", "kingdom_feat", "kingdom_feature" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "action_type", new[] { "none", "1_action", "2_actions", "3_actions", "1-3_actions", "1-2_actions" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "alias_type", new[] { "legacy", "english", "legacy_english", "hobby", "other" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "ancestry_vision", new[] { "normal", "low-light-vision", "darkvision" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "attribute_values", new[] { "any", "str", "dex", "con", "int", "wis", "cha" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "ancestry_vision", new[] { "normal", "low-light-vision", "dark-vision" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "attribute_values", new[] { "free", "str", "dex", "con", "int", "wis", "cha" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "class_progression_type", new[] { "entity", "ancestry_feat", "class_feat", "general_feat", "skill_feat", "skill_increase" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "condition_group", new[] { "unknown", "senses", "abilities", "death", "attitudes", "detection" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_category", new[] { "deity", "pantheon", "covenant", "philosophy" });
@@ -38,7 +38,7 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_type", new[] { "unknown", "trait", "action", "ancestry", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_action_type", new[] { "passive", "action", "reaction", "free" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_category", new[] { "ancestryfeature", "classfeature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon", "campaign_feature" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "size", new[] { "med", "tiny" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "size", new[] { "tiny", "small", "medium", "large" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "source_category", new[] { "rulebook", "adventure-path", "lost-omens", "adventures", "comics", "blog-posts", "society" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "spell_area_type", new[] { "burst", "emanation", "cone", "line", "square", "cube", "cylinder" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "spell_damage_category", new[] { "persistent", "splash" });
@@ -543,25 +543,21 @@ namespace Pf2eModel.Migrations
.HasColumnName("hp")
.HasColumnOrder(3);
b.Property<int>("Reach")
.HasColumnType("integer")
.HasColumnName("reach")
.HasColumnOrder(4);
b.Property<Size>("Size")
.HasColumnType("size")
b.PrimitiveCollection<Size[]>("Size")
.IsRequired()
.HasColumnType("size[]")
.HasColumnName("size")
.HasColumnOrder(2);
b.Property<int>("Speed")
.HasColumnType("integer")
.HasColumnName("speed")
.HasColumnOrder(5);
.HasColumnOrder(4);
b.Property<AncestryVision>("Vision")
.HasColumnType("ancestry_vision")
.HasColumnName("vision")
.HasColumnOrder(6);
.HasColumnOrder(5);
b.HasKey("Id")
.HasName("pk_ancestries");
File diff suppressed because it is too large Load Diff
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Pf2eModel.Model;
using Pf2eModel;
using Pf2eModel.Model.Enum;
#nullable disable
@@ -24,8 +24,8 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "action_category", new[] { "unknown", "offensive", "defensive", "interaction", "familiar", "army_tactic", "army_war_action", "kingdom_activity", "kingdom_feat", "kingdom_feature" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "action_type", new[] { "none", "1_action", "2_actions", "3_actions", "1-3_actions", "1-2_actions" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "alias_type", new[] { "legacy", "english", "legacy_english", "hobby", "other" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "ancestry_vision", new[] { "normal", "low-light-vision", "darkvision" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "attribute_values", new[] { "any", "str", "dex", "con", "int", "wis", "cha" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "ancestry_vision", new[] { "normal", "low-light-vision", "dark-vision" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "attribute_values", new[] { "free", "str", "dex", "con", "int", "wis", "cha" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "class_progression_type", new[] { "entity", "ancestry_feat", "class_feat", "general_feat", "skill_feat", "skill_increase" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "condition_group", new[] { "unknown", "senses", "abilities", "death", "attitudes", "detection" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_category", new[] { "deity", "pantheon", "covenant", "philosophy" });
@@ -35,7 +35,7 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_type", new[] { "unknown", "trait", "action", "ancestry", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_action_type", new[] { "passive", "action", "reaction", "free" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_category", new[] { "ancestryfeature", "classfeature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon", "campaign_feature" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "size", new[] { "med", "tiny" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "size", new[] { "tiny", "small", "medium", "large" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "source_category", new[] { "rulebook", "adventure-path", "lost-omens", "adventures", "comics", "blog-posts", "society" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "spell_area_type", new[] { "burst", "emanation", "cone", "line", "square", "cube", "cylinder" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "spell_damage_category", new[] { "persistent", "splash" });
@@ -540,25 +540,21 @@ namespace Pf2eModel.Migrations
.HasColumnName("hp")
.HasColumnOrder(3);
b.Property<int>("Reach")
.HasColumnType("integer")
.HasColumnName("reach")
.HasColumnOrder(4);
b.Property<Size>("Size")
.HasColumnType("size")
b.PrimitiveCollection<Size[]>("Size")
.IsRequired()
.HasColumnType("size[]")
.HasColumnName("size")
.HasColumnOrder(2);
b.Property<int>("Speed")
.HasColumnType("integer")
.HasColumnName("speed")
.HasColumnOrder(5);
.HasColumnOrder(4);
b.Property<AncestryVision>("Vision")
.HasColumnType("ancestry_vision")
.HasColumnName("vision")
.HasColumnOrder(6);
.HasColumnOrder(5);
b.HasKey("Id")
.HasName("pk_ancestries");
-24
View File
@@ -1,24 +0,0 @@
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Common;
public partial class Language
{
[System.ComponentModel.DataAnnotations.Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column(Order = 1)]
public int Id { get; set; }
[Column(Order = 2)]
[MaxLength(Pf2eDbContext.NameLength)]
public string Name { get; set; } = null!;
[Column(Order = 3)]
[MaxLength(Pf2eDbContext.NameLength)]
public string Slug { get; set; } = null!;
[Column(Order = 4)]
public EntityRarity Rarity { get; set; }
}
+3 -3
View File
@@ -5,11 +5,11 @@ namespace Pf2eModel.Model.Enum;
public enum AncestryVision
{
[PgName("normal")]
normal,
Normal,
[PgName("low-light-vision")]
LowLightVision,
[PgName("darkvision")]
darkvision,
[PgName("dark-vision")]
DarkVision,
}
+2 -2
View File
@@ -4,8 +4,8 @@ namespace Pf2eModel.Model.Enum;
public enum AttributeValues
{
[PgName("any")]
Any,
[PgName("free")]
Free,
[PgName("str")]
Strength,
+4 -1
View File
@@ -41,5 +41,8 @@ public enum EntityType
Heritage,
[PgName("spell")]
Spell
Spell,
[PgName("language")]
Language
}
+10 -4
View File
@@ -4,9 +4,15 @@ namespace Pf2eModel.Model.Enum;
public enum Size
{
[PgName("med")]
med,
[PgName("tiny")]
tiny,
Tiny,
[PgName("small")]
Small,
[PgName("medium")]
Medium,
[PgName("large")]
Large,
}
+3 -6
View File
@@ -16,19 +16,16 @@ public partial class Ancestry : IEntity
public Entity Entity { get; set; } = null!;
[Column(Order = 2)]
public Size Size { get; set; } = Size.med;
public Size[] Size { get; set; }
[Column(Order = 3)]
public int Hp { get; set; }
[Column(Order = 4)]
public int Reach { get; set; }
[Column(Order = 5)]
public int Speed { get; set; }
[Column(Order = 6)]
public AncestryVision Vision { get; set; } = AncestryVision.normal;
[Column(Order = 5)]
public AncestryVision Vision { get; set; } = AncestryVision.Normal;
public virtual ICollection<AncestryBoost> AncestryBoosts { get; set; } = [];
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Common;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.AncestryRelation;
+18
View File
@@ -0,0 +1,18 @@
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Language)]
public partial class Language: IEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column(Order = 1)]
public int Id { get; set; }
public Entity Entity { get; set; } = null!;
}
+2 -2
View File
@@ -15,7 +15,7 @@ using Pf2eModel.Model.Structure.DeityRelation;
using Pf2eModel.Model.Structure.FeatRelation;
using Pf2eModel.Model.Structure.SpellRelation;
namespace Pf2eModel.Model;
namespace Pf2eModel;
public partial class Pf2eDbContext : DbContext
{
@@ -30,7 +30,7 @@ public partial class Pf2eDbContext : DbContext
#region DbSets
public virtual DbSet<Structure.Action> Actions { get; set; }
public virtual DbSet<Model.Structure.Action> Actions { get; set; }
public virtual DbSet<Ancestry> Ancestries { get; set; }
+3 -85
View File
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Keywords;
using Pf2eModel.Model.Base.Source;
@@ -14,7 +15,7 @@ using Pf2eModel.Model.Structure.DeityRelation;
using Pf2eModel.Model.Structure.FeatRelation;
using Pf2eModel.Model.Structure.SpellRelation;
namespace Pf2eModel.Model;
namespace Pf2eModel;
public partial class Pf2eDbContext
{
@@ -28,7 +29,6 @@ public partial class Pf2eDbContext
DefineBase(modelBuilder);
DefineCommon(modelBuilder);
DefineStructure(modelBuilder);
DefineFunctions(modelBuilder);
}
private void DefineEnums(ModelBuilder modelBuilder)
@@ -135,7 +135,7 @@ public partial class Pf2eDbContext
private void DefineStructure(ModelBuilder modelBuilder)
{
// Action
modelBuilder.Entity<Structure.Action>(entity =>
modelBuilder.Entity<Model.Structure.Action>(entity =>
{
BindEntity(entity);
});
@@ -325,86 +325,4 @@ public partial class Pf2eDbContext
BindEntity(entity);
});
}
private void DefineFunctions(ModelBuilder modelBuilder)
{
// modelBuilder.HasDbFunction(typeof(Pf2eDbContext).GetMethod(nameof(FTruncateTables), Array.Empty<Type>()))
/*
modelBuilder.HasPostgresExtension($"""
CREATE OR REPLACE FUNCTION f_truncate_tables()
RETURNS void
LANGUAGE plpgsql AS
$func$
BEGIN
EXECUTE (
SELECT 'TRUNCATE TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE;'
FROM pg_tables
WHERE schemaname = 'public'
AND tablename != '__EFMigrationsHistory'
);
END
$func$;
""")
;
/*
Database.ExecuteSql($"""
CREATE OR REPLACE FUNCTION f_truncate_tables()
RETURNS void
LANGUAGE plpgsql AS
$func$
BEGIN
EXECUTE (
SELECT 'TRUNCATE TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE;'
FROM pg_tables
WHERE schemaname = 'public'
AND tablename != '__EFMigrationsHistory'
);
END
$func$;
""");
Database.ExecuteSql($"""
CREATE OR REPLACE FUNCTION f_drop_tables()
RETURNS void
LANGUAGE plpgsql AS
$func$
BEGIN
EXECUTE (
SELECT 'DROP TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE;'
FROM pg_tables
WHERE schemaname = 'public'
);
END
$func$;
""");
Database.ExecuteSql($"""
CREATE OR REPLACE FUNCTION f_permission_tables(_username text)
RETURNS void
LANGUAGE plpgsql AS
$func$
DECLARE
_tbl text;
_sch text;
BEGIN
FOR _sch, _tbl IN
SELECT schemaname, tablename
FROM pg_tables
WHERE schemaname = 'public'
LOOP
EXECUTE format('ALTER TABLE %I.%I OWNER TO %I', _sch, _tbl, _username);
END LOOP;
END
$func$;
""");
*/
}
}
+18
View File
@@ -27,4 +27,22 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup>
<ItemGroup>
<None Update="RebuildDatabase.bat">
<Generator></Generator>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="RebuildDatabase.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>RebuildDatabase.bat</DependentUpon>
</Compile>
</ItemGroup>
</Project>
+10
View File
@@ -0,0 +1,10 @@
@echo off
del /s .\Migrations\Pf2eDbContextModelSnapshot.cs
del /s .\Migrations\*_1.cs
del /s .\Migrations\*_1.Designer.cs
dotnet ef database drop -f
dotnet ef migrations add 1
dotnet ef database update
@@ -1,14 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pf2eModel;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Structure;
namespace Pf2eViewer;
internal class EntityConventor : JsonConverter
internal class EntityConverter : JsonConverter
{
private Pf2eDbContext Context = new();
private readonly Pf2eDbContext _context = new();
public override bool CanConvert(Type objectType)
{
@@ -34,48 +35,31 @@ internal class EntityConventor : JsonConverter
break;
}
obj.WriteTo(writer);
}
JObject ProcessEntity(JObject obj, Entity e)
private JObject ProcessEntity(JObject obj, Entity e)
{
List<int> traitIds = e.Traits.Select(t => t.Id).ToList();
List<Trait> traits = Context.Traits.Where(t => traitIds.Contains(t.Id)).Include(t => t.Entity).ToList();
List<Trait> traits = _context.Traits.Where(t => traitIds.Contains(t.Id)).Include(t => t.Entity).ToList();
foreach (JToken item in (JArray) obj.SelectToken("Traits"))
foreach (JToken item in (JArray) obj.SelectToken("Traits")!)
{
JObject o = (JObject) item;
int id = o.SelectToken("Id").ToObject<int>();
int id = o.SelectToken("Id")!.ToObject<int>();
o.Add("Name", traits.FirstOrDefault(t => t.Id == id)!.Entity.Name);
}
obj.Remove("Description");
return obj;
}
public override bool CanRead => false;
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
private abstract class Conventer<T>(JsonWriter writer, T value, JsonSerializer serializer, Pf2eDbContext context)
{
public JsonWriter Writer { get; } = writer;
public T Value { get; } = value;
public JsonSerializer Serializer { get; } = serializer;
public Pf2eDbContext Context { get; } = context;
public abstract JObject Process();
}
}
+10 -11
View File
@@ -65,8 +65,8 @@ partial class MainViewForm
//
RootSplitContainer.Panel2.Controls.Add(ResultSplitContainer);
RootSplitContainer.Panel2MinSize = 400;
RootSplitContainer.Size = new Size(811, 688);
RootSplitContainer.SplitterDistance = 324;
RootSplitContainer.Size = new Size(1181, 688);
RootSplitContainer.SplitterDistance = 200;
RootSplitContainer.TabIndex = 0;
//
// InnerSplitContainer
@@ -83,7 +83,7 @@ partial class MainViewForm
// InnerSplitContainer.Panel2
//
InnerSplitContainer.Panel2.Controls.Add(EntityGridView);
InnerSplitContainer.Size = new Size(324, 688);
InnerSplitContainer.Size = new Size(200, 688);
InnerSplitContainer.SplitterDistance = 274;
InnerSplitContainer.TabIndex = 1;
//
@@ -94,7 +94,7 @@ partial class MainViewForm
TypesListBox.ItemHeight = 15;
TypesListBox.Location = new Point(0, 0);
TypesListBox.Name = "TypesListBox";
TypesListBox.Size = new Size(324, 274);
TypesListBox.Size = new Size(200, 274);
TypesListBox.TabIndex = 0;
TypesListBox.SelectedIndexChanged += TypesListBox_SelectedIndexChanged;
//
@@ -112,7 +112,7 @@ partial class MainViewForm
EntityGridView.RowHeadersVisible = false;
EntityGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
EntityGridView.ShowEditingIcon = false;
EntityGridView.Size = new Size(324, 410);
EntityGridView.Size = new Size(200, 410);
EntityGridView.TabIndex = 0;
EntityGridView.RowStateChanged += EntityGridView_RowStateChanged;
//
@@ -121,7 +121,6 @@ partial class MainViewForm
ResultSplitContainer.Dock = DockStyle.Fill;
ResultSplitContainer.Location = new Point(0, 0);
ResultSplitContainer.Name = "ResultSplitContainer";
ResultSplitContainer.Orientation = Orientation.Horizontal;
//
// ResultSplitContainer.Panel1
//
@@ -130,8 +129,8 @@ partial class MainViewForm
// ResultSplitContainer.Panel2
//
ResultSplitContainer.Panel2.Controls.Add(DescriptionTextBox);
ResultSplitContainer.Size = new Size(483, 688);
ResultSplitContainer.SplitterDistance = 269;
ResultSplitContainer.Size = new Size(977, 688);
ResultSplitContainer.SplitterDistance = 495;
ResultSplitContainer.TabIndex = 1;
//
// EntityTreeView
@@ -139,7 +138,7 @@ partial class MainViewForm
EntityTreeView.Dock = DockStyle.Fill;
EntityTreeView.Location = new Point(0, 0);
EntityTreeView.Name = "EntityTreeView";
EntityTreeView.Size = new Size(483, 269);
EntityTreeView.Size = new Size(495, 688);
EntityTreeView.TabIndex = 0;
//
// DescriptionTextBox
@@ -150,14 +149,14 @@ partial class MainViewForm
DescriptionTextBox.Name = "DescriptionTextBox";
DescriptionTextBox.ReadOnly = true;
DescriptionTextBox.ScrollBars = ScrollBars.Vertical;
DescriptionTextBox.Size = new Size(483, 415);
DescriptionTextBox.Size = new Size(478, 688);
DescriptionTextBox.TabIndex = 0;
//
// MainViewForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(811, 688);
ClientSize = new Size(1181, 688);
Controls.Add(RootSplitContainer);
Name = "MainViewForm";
Text = "DataBaseViewer";
+13 -20
View File
@@ -29,7 +29,7 @@ public partial class MainViewForm : Form
TypesListBox.SelectedIndex = 0;
}
private void TypesListBox_SelectedIndexChanged(object sender, EventArgs e)
private void TypesListBox_SelectedIndexChanged(object sender, EventArgs _)
{
if (TypesListBox.SelectedItem is null)
{
@@ -39,7 +39,10 @@ public partial class MainViewForm : Form
EntityGridView.DataSource = Context.Entities
.Where(e => e.Type == (EntityType) TypesListBox.SelectedItem)
.OrderBy(e => e.Id)
.Include(e => e.Sources).Include(e => e.Aliases).Include(e => e.Keywords).Include(e => e.Externals)
.Include(e => e.Sources)
.Include(e => e.Aliases)
.Include(e => e.Keywords)
.Include(e => e.Externals)
.Include(e => e.Traits)
.Select(e => new EntityGridRow(e))
.ToList();
@@ -49,7 +52,7 @@ public partial class MainViewForm : Form
private void EntityGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
int rowsCount = EntityGridView.SelectedRows.Count;
if (rowsCount == 0 || rowsCount > 1)
if (rowsCount is 0 or > 1)
{
return;
}
@@ -62,23 +65,22 @@ public partial class MainViewForm : Form
JsonToTreeview(EntityTreeView, json, "Entity");
DescriptionTextBox.Text = data.GetEntity().Description;
DescriptionTextBox.Text = data.GetEntity().Description.Replace("\\r", "").Replace("\\n", "\\r\\n");
}
public string SerializeEntity(Entity entity)
{
JsonSerializerSettings settings = new JsonSerializerSettings()
JsonSerializerSettings settings = new()
{
Converters = [new EntityConventor()]
// ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = [new EntityConverter()]
};
string result = JsonConvert.SerializeObject(entity, settings);
Type type = EntityOfTypeAttribute.Resolve(entity);
string subReuslt = JsonConvert.SerializeObject(Context.Find(type, entity.Id), settings);
string subResult = JsonConvert.SerializeObject(Context.Find(type, entity.Id), settings);
return result[..^1] + $",\"SubEntity\":{subReuslt}}}";
return result[..^1] + $",\"SubEntity\":{subResult}}}";
}
@@ -114,10 +116,7 @@ public partial class MainViewForm : Form
case "JArray":
JArray jArray = (JArray) element;
int i = 0;
foreach (JToken oJtok in jArray)
{
subNodes.Add(Element2TreeNode(oJtok, string.Format("[{0}]", i++)));
}
subNodes.AddRange(jArray.Select(token => Element2TreeNode(token, $"[{i++}]")));
if (i == 0)
{
@@ -147,17 +146,11 @@ public partial class MainViewForm : Form
return treeNode;
}
private class EntityGridRow(Entity e)
{
public int Id { get; set; } = e.Id;
public string Name { get; set; } = e.Name;
//public string Slug { get; set; } = e.Slug;
//public EntityRarity Rarity { get; set; } = e.Rarity;
public EntityRarity Rarity { get; set; } = e.Rarity;
private readonly Entity _e = e;
public Entity GetEntity() => _e;