Отчистика кода

This commit is contained in:
2025-04-18 17:32:23 +04:00
parent 9a711c5a9d
commit 02d35d72d2
11 changed files with 1181 additions and 1229 deletions
@@ -1,12 +1,4 @@
using Pf2eDataScrapper.Importers.Repositories; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static LinqToDB.Reflection.Methods.LinqToDB.Insert;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
public static class AonprdEnumResolver public static class AonprdEnumResolver
@@ -48,7 +40,7 @@ public static class AonprdEnumResolver
Solver<T> tSolver = (Solver<T>) solver; Solver<T> tSolver = (Solver<T>) solver;
return tSolver.Data.TryGetValue(value, out var data) ? data : throw new EnumResolverValueUnknownException(type, value); return tSolver.Data.TryGetValue(value, out T? data) ? data : throw new EnumResolverValueUnknownException(type, value);
} }
private abstract class Solver private abstract class Solver
@@ -62,7 +62,7 @@ internal class ActionProcessor(ProcessorInput input) : AbstractProcessor(input)
Object.IsPassive = true; Object.IsPassive = true;
break; break;
} }
Object.Extra = new JObject() Object.Extra = new JObject()
{ {
{ "school", Input.GetOptional<JToken>("school") }, { "school", Input.GetOptional<JToken>("school") },
@@ -3,7 +3,7 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
[AonprdProcessor("trait", new string[] {})] [AonprdProcessor("trait", new string[] { })]
internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input) internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input)
{ {
public override EntityType Type => EntityType.Trait; public override EntityType Type => EntityType.Trait;
@@ -24,7 +24,7 @@ internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input)
// Во втором проходе // Во втором проходе
} }
protected override string GetDescription() protected override string GetDescription()
=> base.GetDescription() + AddedDescription([ => base.GetDescription() + AddedDescription([
"summary_markdown", "summary_markdown",
"search_markdown" "search_markdown"
+2 -2
View File
@@ -1,5 +1,5 @@
using Pf2eModel.Model.Base; using Pf2eModel.Model;
using Pf2eModel.Model; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.Reflection; using System.Reflection;
+15 -16
View File
@@ -2,15 +2,15 @@
#nullable disable #nullable disable
namespace Pf2eModel.Migrations namespace Pf2eModel.Migrations;
/// <inheritdoc />
public partial class Function : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class Function : Migration protected override void Up(MigrationBuilder migrationBuilder)
{ {
/// <inheritdoc /> migrationBuilder.Sql("""
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
CREATE OR REPLACE FUNCTION f_truncate_tables() CREATE OR REPLACE FUNCTION f_truncate_tables()
RETURNS void RETURNS void
LANGUAGE plpgsql AS LANGUAGE plpgsql AS
@@ -27,7 +27,7 @@ BEGIN
END END
$func$; $func$;
"""); """);
migrationBuilder.Sql(""" migrationBuilder.Sql("""
CREATE OR REPLACE FUNCTION f_drop_tables() CREATE OR REPLACE FUNCTION f_drop_tables()
RETURNS void RETURNS void
LANGUAGE plpgsql AS LANGUAGE plpgsql AS
@@ -43,7 +43,7 @@ BEGIN
END END
$func$; $func$;
"""); """);
migrationBuilder.Sql(""" migrationBuilder.Sql("""
CREATE OR REPLACE FUNCTION f_permission_tables(_username text) CREATE OR REPLACE FUNCTION f_permission_tables(_username text)
RETURNS void RETURNS void
LANGUAGE plpgsql AS LANGUAGE plpgsql AS
@@ -62,14 +62,13 @@ BEGIN
END END
$func$; $func$;
"""); """);
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.Sql("DROP FUNCTION f_truncate_tables;"); migrationBuilder.Sql("DROP FUNCTION f_truncate_tables;");
migrationBuilder.Sql("DROP FUNCTION f_drop_tables;"); migrationBuilder.Sql("DROP FUNCTION f_drop_tables;");
migrationBuilder.Sql("DROP FUNCTION f_permission_tables;"); migrationBuilder.Sql("DROP FUNCTION f_permission_tables;");
}
} }
} }
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
+2 -2
View File
@@ -18,10 +18,10 @@ public partial class Action : IEntity
[Column(Order = 3)] [Column(Order = 3)]
public int? Actions { get; set; } = null; public int? Actions { get; set; } = null;
[Column(Order = 4)] [Column(Order = 4)]
public int? MaxActions { get; set; } = null; public int? MaxActions { get; set; } = null;
[Column(Order = 5)] [Column(Order = 5)]
public bool IsReaction { get; set; } = false; public bool IsReaction { get; set; } = false;
[Column(Order = 6)] [Column(Order = 6)]
+1 -3
View File
@@ -1,5 +1,4 @@
using LinqToDB.Common; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Base.Keywords; using Pf2eModel.Model.Base.Keywords;
@@ -14,7 +13,6 @@ using Pf2eModel.Model.Structure.ClassRelation;
using Pf2eModel.Model.Structure.DeityRelation; using Pf2eModel.Model.Structure.DeityRelation;
using Pf2eModel.Model.Structure.FeatRelation; using Pf2eModel.Model.Structure.FeatRelation;
using Pf2eModel.Model.Structure.SpellRelation; using Pf2eModel.Model.Structure.SpellRelation;
using System.Reflection;
namespace Pf2eModel.Model; namespace Pf2eModel.Model;
+5 -38
View File
@@ -1,12 +1,9 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Pf2eModel;
using Pf2eModel.Model; using Pf2eModel.Model;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Structure; using Pf2eModel.Model.Structure;
using Processor = System.Func<Newtonsoft.Json.JsonWriter, object, Newtonsoft.Json.JsonSerializer, Pf2eModel.Model.Pf2eDbContext, Newtonsoft.Json.Linq.JObject>;
namespace Pf2eViewer; namespace Pf2eViewer;
internal class EntityConventor : JsonConverter internal class EntityConventor : JsonConverter
@@ -43,11 +40,11 @@ internal class EntityConventor : JsonConverter
JObject ProcessEntity(JObject obj, Entity e) JObject ProcessEntity(JObject obj, Entity e)
{ {
var traitIds = e.Traits.Select(t => t.Id).ToList(); List<int> traitIds = e.Traits.Select(t => t.Id).ToList();
var 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 (var item in (JArray) obj.SelectToken("Traits"))
foreach (JToken item in (JArray) obj.SelectToken("Traits"))
{ {
JObject o = (JObject) item; JObject o = (JObject) item;
int id = o.SelectToken("Id").ToObject<int>(); int id = o.SelectToken("Id").ToObject<int>();
@@ -57,42 +54,12 @@ internal class EntityConventor : JsonConverter
obj.Remove("Description"); obj.Remove("Description");
return obj; return obj;
} }
private JArray GetFromSet<T>(DbSet<T> set, Func<T, bool> where) where T : Type
{
return new(set.Where(where).Select(JToken.FromObject).ToArray());
}
private JObject Process(JsonWriter writer, Entity e, JsonSerializer serializer)
{
JObject result = new();
// result.Add("Aliases", GetFromSet<EntityAlias>(context.EntityAliases, o => o.Entity == e));
result.Add("Sources", new JArray(e.Sources.Select(o => JToken.FromObject(o)).ToArray()));
result.Add("Keywords", new JArray(e.Keywords.Select(o => JToken.FromObject(o)).ToArray()));
result.Add("Externals", new JArray(e.Externals.Select(o => JToken.FromObject(o)).ToArray()));
result.Add("Traits", new JArray(e.Traits.Select(o => JToken.FromObject(o)).ToArray()));
return result;
}
public override bool CanRead => false; public override bool CanRead => false;
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+10 -11
View File
@@ -1,12 +1,10 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Pf2eModel; using Pf2eModel;
using Pf2eModel.Model; using Pf2eModel.Model;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using static LinqToDB.Common.Configuration;
namespace Pf2eViewer; namespace Pf2eViewer;
@@ -37,7 +35,7 @@ public partial class MainViewForm : Form
{ {
return; return;
} }
EntityGridView.DataSource = Context.Entities EntityGridView.DataSource = Context.Entities
.Where(e => e.Type == (EntityType) TypesListBox.SelectedItem) .Where(e => e.Type == (EntityType) TypesListBox.SelectedItem)
.OrderBy(e => e.Id) .OrderBy(e => e.Id)
@@ -50,16 +48,17 @@ public partial class MainViewForm : Form
private void EntityGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e) private void EntityGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{ {
var rowsCount = EntityGridView.SelectedRows.Count; int rowsCount = EntityGridView.SelectedRows.Count;
if (rowsCount == 0 || rowsCount > 1){ if (rowsCount == 0 || rowsCount > 1)
{
return; return;
} }
var row = EntityGridView.SelectedRows[0]; DataGridViewRow row = EntityGridView.SelectedRows[0];
var data = (EntityGridRow) row.DataBoundItem; EntityGridRow data = (EntityGridRow) row.DataBoundItem;
var json = SerializeEntity(data.GetEntity()); string json = SerializeEntity(data.GetEntity());
JsonToTreeview(EntityTreeView, json, "Entity"); JsonToTreeview(EntityTreeView, json, "Entity");
@@ -68,9 +67,9 @@ public partial class MainViewForm : Form
public string SerializeEntity(Entity entity) public string SerializeEntity(Entity entity)
{ {
var settings = new JsonSerializerSettings() JsonSerializerSettings settings = new JsonSerializerSettings()
{ {
Converters = [ new EntityConventor() ] Converters = [new EntityConventor()]
// ContractResolver = new CamelCasePropertyNamesContractResolver(), // ContractResolver = new CamelCasePropertyNamesContractResolver(),
}; };
@@ -92,7 +91,7 @@ public partial class MainViewForm : Form
treeView.Nodes.Clear(); treeView.Nodes.Clear();
foreach(TreeNode node in Element2TreeNode(json, rootName).Nodes) foreach (TreeNode node in Element2TreeNode(json, rootName).Nodes)
{ {
treeView.Nodes.Add(node); treeView.Nodes.Add(node);
} }