From 0dc457bf7e3c3f386b33a750d464425885cec6f7 Mon Sep 17 00:00:00 2001 From: Esiur Project Date: Mon, 20 Jun 2022 20:51:04 +0300 Subject: [PATCH] inheritance --- Esiur.Stores.EntityCore/EsiurExtensions.cs | 1 + Esiur/Esiur.csproj | 2 +- Esiur/Resource/Template/TypeTemplate.cs | 29 +++++++++++++--------- Esiur/TODO | 4 ++- Test/Program.cs | 18 +++++++------- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Esiur.Stores.EntityCore/EsiurExtensions.cs b/Esiur.Stores.EntityCore/EsiurExtensions.cs index f81dda0..35661d8 100644 --- a/Esiur.Stores.EntityCore/EsiurExtensions.cs +++ b/Esiur.Stores.EntityCore/EsiurExtensions.cs @@ -47,6 +47,7 @@ public static class EsiurExtensions //} + public static T AddResource(this DbSet dbSet, T resource) where T : class, IResource => AddResourceAsync(dbSet, resource).Wait(); diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 6f95e7e..ba0e3cf 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -6,7 +6,7 @@ Ahmed Kh. Zamil http://www.esiur.com true - 2.2.4.4 + 2.2.5 https://github.com/esiur/esiur-dotnet Ahmed Kh. Zamil diff --git a/Esiur/Resource/Template/TypeTemplate.cs b/Esiur/Resource/Template/TypeTemplate.cs index 468a41b..974257b 100644 --- a/Esiur/Resource/Template/TypeTemplate.cs +++ b/Esiur/Resource/Template/TypeTemplate.cs @@ -219,16 +219,6 @@ public class TypeTemplate // Add self list.Add(template); - // Add parents - var parentType = template.ParentDefinedType; - - // Get parents - while (parentType != null) - { - var parentTemplate = Warehouse.GetTemplateByType(parentType); - list.Add(parentTemplate); - parentType = parentTemplate.ParentDefinedType; - } Action> getDependenciesFunc = null; @@ -237,6 +227,20 @@ public class TypeTemplate if (template.DefinedType == null) return; + // Add parents + var parentType = tmp.ParentDefinedType; + + // Get parents + while (parentType != null) + { + var parentTemplate = Warehouse.GetTemplateByType(parentType); + if (parentTemplate != null) + { + list.Add(parentTemplate); + parentType = parentTemplate.ParentDefinedType; + } + } + // functions foreach (var f in tmp.functions) { @@ -803,7 +807,7 @@ public class TypeTemplate if (hasParent) { // find the first parent type that implements IResource - var ParentDefinedType = ResourceProxy.GetBaseType(type.BaseType); + ParentDefinedType = ResourceProxy.GetBaseType(type.BaseType); var parentId = GetTypeGuid(ParentDefinedType); b.AddGuid(parentId); } @@ -838,7 +842,8 @@ public class TypeTemplate var parent = type.BaseType; if (parent == typeof(Resource) - || parent == typeof(Record)) + || parent == typeof(Record) + || parent == typeof(EntryPoint)) return false; while (parent != null) diff --git a/Esiur/TODO b/Esiur/TODO index f7cc1ec..bcabc5e 100644 --- a/Esiur/TODO +++ b/Esiur/TODO @@ -1,2 +1,4 @@ 1- Change branch to main -2- Generic Records/Resources \ No newline at end of file +2- Generic Records/Resources +3- Static functions calls +4- Scan assembly for child classes \ No newline at end of file diff --git a/Test/Program.cs b/Test/Program.cs index b7dc888..9bc4724 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -55,14 +55,14 @@ namespace Test { // Create stores to keep objects. - var system = await Warehouse.Put("mem", new MemoryStore()); - var server = await Warehouse.Put("mem/server", new DistributedServer()); - var web = await Warehouse.Put("mem/web", new HTTPServer() { Port = 8888}); + var system = await Warehouse.Put("sys", new MemoryStore()); + var server = await Warehouse.Put("sys/server", new DistributedServer()); + var web = await Warehouse.Put("sys/web", new HTTPServer() { Port = 8888}); - var service = await Warehouse.Put("mem/service", new MyService()); - var res1 = await Warehouse.Put("mem/service/r1", new MyResource() { Description = "Testing 1", CategoryId = 10 }); - var res2 = await Warehouse.Put("mem/service/r2", new MyResource() { Description = "Testing 2", CategoryId = 11 }); - var res3 = await Warehouse.Put("mem/service/c1", new MyChildResource() { ChildName = "Child 1", Description = "Child Testing 3", CategoryId = 12 }); + var service = await Warehouse.Put("sys/service", new MyService()); + var res1 = await Warehouse.Put("sys/service/r1", new MyResource() { Description = "Testing 1", CategoryId = 10 }); + var res2 = await Warehouse.Put("sys/service/r2", new MyResource() { Description = "Testing 2", CategoryId = 11 }); + var res3 = await Warehouse.Put("sys/service/c1", new MyChildResource() { ChildName = "Child 1", Description = "Child Testing 3", CategoryId = 12 }); service.Resource = res1; @@ -92,7 +92,7 @@ namespace Test private static async void TestClient(IResource local) { - dynamic remote = await Warehouse.Get("iip://localhost/mem/service"); + dynamic remote = await Warehouse.Get("iip://localhost/sys/service"); var con = remote.Connection as DistributedConnection; var template = await con.GetTemplateByClassName("Test.MyResource"); @@ -134,7 +134,7 @@ namespace Test //var childTemplate = remote.Child.Instance.Template; - var path = TemplateGenerator.GetTemplate("iip://localhost/mem/service", "Generated"); + var path = TemplateGenerator.GetTemplate("iip://localhost/sys/service", "Generated"); Console.WriteLine(path);