From 8fc07d6350ee06e3378d7f5101ba91d0990bcc18 Mon Sep 17 00:00:00 2001 From: ahmed Date: Tue, 17 Mar 2026 19:10:20 +0300 Subject: [PATCH] Renaming --- Esiur.Stores.EntityCore/EntityStore.cs | 4 +- Esiur.Stores.EntityCore/EsiurExtensions.cs | 2 +- Esiur.Stores.EntityCore/EsiurProxyRewrite.cs | 2 +- Esiur.Stores.MongoDB/MongoDBStore.cs | 26 +-- Esiur/Core/ExceptionCode.cs | 2 +- Esiur/Data/DataDeserializer - Copy.cs | 2 +- Esiur/Data/DataDeserializer.cs | 26 +-- Esiur/Data/DataSerializer.cs | 4 +- Esiur/Data/IDynamicResource.cs | 4 +- Esiur/Data/NullabilityInfoContext.cs | 14 +- Esiur/Data/ResourceJsonConverter.cs | 2 +- Esiur/Data/RuntimeCaster.cs | 2 +- Esiur/Data/TRU.cs | 14 +- .../Types/ArgumentDef.cs} | 10 +- .../Types/AttributeDef.cs} | 11 +- .../Types/ConstantDef.cs} | 15 +- Esiur/Data/Types/CustomEventOccurredEvent.cs | 9 ++ .../Types/DefinitionDataType.cs} | 0 .../Types/EventDef.cs} | 15 +- .../Types/FunctionDef.cs} | 23 +-- .../Template => Data/Types}/MemberData.cs | 5 +- .../Types/MemberDef.cs} | 8 +- .../Types/PropertyDef.cs} | 17 +- .../TypeTemplate.cs => Data/Types/TypeDef.cs} | 149 +++++++++--------- .../Types/TypeDefKind.cs} | 5 +- Esiur/Esiur.csproj | 2 + Esiur/Net/IIP/DistributedConnection.cs | 12 +- .../Net/IIP/DistributedConnectionProtocol.cs | 144 ++++++++--------- Esiur/Net/IIP/DistributedResource.cs | 40 ++--- Esiur/Net/IIP/DistributedServer.cs | 6 +- Esiur/Net/IIP/EntryPoint.cs | 2 +- Esiur/Net/Packets/IIPPacketAttachInfo.cs | 6 +- Esiur/Net/Packets/IIPPacketRequest.cs | 8 +- Esiur/Proxy/ResourceGenerator.cs | 18 +-- Esiur/Proxy/TemplateGenerator.cs | 58 +++---- Esiur/Resource/CustomEventOccurredInfo.cs | 6 +- Esiur/Resource/EventOccurredInfo.cs | 10 +- Esiur/Resource/ExportAttribute.cs | 1 - Esiur/Resource/IStore.cs | 4 +- Esiur/Resource/Instance.cs | 52 +++--- Esiur/Resource/PropertyModificationInfo.cs | 6 +- Esiur/Resource/StoreGeneric.cs | 4 +- .../Template/CustomEventOccurredEvent.cs | 10 -- Esiur/Resource/Warehouse.cs | 93 +++++------ .../Permissions/IPermissionsManager.cs | 4 +- .../Permissions/StorePermissionsManager.cs | 4 +- .../Permissions/UserPermissionsManager.cs | 4 +- Esiur/Stores/MemoryStore.cs | 4 +- Esiur/Stores/TemporaryStore.cs | 4 +- Test/Program.cs | 4 +- 50 files changed, 443 insertions(+), 434 deletions(-) rename Esiur/{Resource/Template/ArgumentTemplate.cs => Data/Types/ArgumentDef.cs} (90%) rename Esiur/{Resource/Template/AttributeTemplate.cs => Data/Types/AttributeDef.cs} (56%) rename Esiur/{Resource/Template/ConstantTemplate.cs => Data/Types/ConstantDef.cs} (87%) create mode 100644 Esiur/Data/Types/CustomEventOccurredEvent.cs rename Esiur/{Resource/Template/TemplateDataType.cs => Data/Types/DefinitionDataType.cs} (100%) rename Esiur/{Resource/Template/EventTemplate.cs => Data/Types/EventDef.cs} (90%) rename Esiur/{Resource/Template/FunctionTemplate.cs => Data/Types/FunctionDef.cs} (92%) rename Esiur/{Resource/Template => Data/Types}/MemberData.cs (97%) rename Esiur/{Resource/Template/MemberTemplate.cs => Data/Types/MemberDef.cs} (74%) rename Esiur/{Resource/Template/PropertyTemplate.cs => Data/Types/PropertyDef.cs} (92%) rename Esiur/{Resource/Template/TypeTemplate.cs => Data/Types/TypeDef.cs} (83%) rename Esiur/{Resource/Template/TemplateType.cs => Data/Types/TypeDefKind.cs} (64%) delete mode 100644 Esiur/Resource/Template/CustomEventOccurredEvent.cs diff --git a/Esiur.Stores.EntityCore/EntityStore.cs b/Esiur.Stores.EntityCore/EntityStore.cs index b8de6cd..f203e63 100644 --- a/Esiur.Stores.EntityCore/EntityStore.cs +++ b/Esiur.Stores.EntityCore/EntityStore.cs @@ -25,7 +25,6 @@ SOFTWARE. using Esiur.Core; using Esiur.Data; using Esiur.Resource; -using Esiur.Resource.Template; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -35,6 +34,7 @@ using Microsoft.EntityFrameworkCore.Metadata; using System.Reflection; using Esiur.Security.Authority; using System.Collections; +using Esiur.Data.Schema; namespace Esiur.Stores.EntityCore; public class EntityStore : IStore @@ -216,7 +216,7 @@ public class EntityStore : IStore throw new NotImplementedException(); } - public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) + public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) { throw new NotImplementedException(); } diff --git a/Esiur.Stores.EntityCore/EsiurExtensions.cs b/Esiur.Stores.EntityCore/EsiurExtensions.cs index c663739..4db4441 100644 --- a/Esiur.Stores.EntityCore/EsiurExtensions.cs +++ b/Esiur.Stores.EntityCore/EsiurExtensions.cs @@ -131,7 +131,7 @@ public static class EsiurExtensions var id = store.TypesByType[typeof(T)].PrimaryKey.GetValue(resource); - await options.Warehouse.Put($"{store.Instance.Name}/{typeof(T).Name}/{id}", res, null, 0, manager); + await options.Warehouse.Put($"{store.Instance.Name}/{typeof(T).Name}/{id}", res, 0, manager); return (T)res; } diff --git a/Esiur.Stores.EntityCore/EsiurProxyRewrite.cs b/Esiur.Stores.EntityCore/EsiurProxyRewrite.cs index 5e9877d..6c1cef5 100644 --- a/Esiur.Stores.EntityCore/EsiurProxyRewrite.cs +++ b/Esiur.Stores.EntityCore/EsiurProxyRewrite.cs @@ -71,7 +71,7 @@ public class EsiurProxyRewrite : IModelFinalizingConvention // check if the object exists var obj = options.Warehouse.Create(entityType.ClrType) as IResource; options.Store.TypesByType[entityType.ClrType].PrimaryKey.SetValue(obj, id); - options.Warehouse.Put($"{options.Store.Instance.Name}/{entityType.ClrType.Name}/{id}", obj, null, 0, manager).Wait(); + options.Warehouse.Put($"{options.Store.Instance.Name}/{entityType.ClrType.Name}/{id}", obj, 0, manager).Wait(); return obj; } else diff --git a/Esiur.Stores.MongoDB/MongoDBStore.cs b/Esiur.Stores.MongoDB/MongoDBStore.cs index 04d2696..af35733 100644 --- a/Esiur.Stores.MongoDB/MongoDBStore.cs +++ b/Esiur.Stores.MongoDB/MongoDBStore.cs @@ -32,10 +32,10 @@ using Esiur.Data; using System.Collections.Generic; using System.Reflection; using System.Threading.Tasks; -using Esiur.Resource.Template; using System.Linq; using Esiur.Security.Permissions; using Esiur.Proxy; +using Esiur.Data.Schema; namespace Esiur.Stores.MongoDB; @@ -342,7 +342,7 @@ public class MongoDBStore : IStore var parents = new BsonArray(); var children = new BsonArray(); - var template = resource.Instance.Template; + var schema = resource.Instance.Schema; // setup attributes resource.Instance.Variables["children"] = new string[0]; @@ -381,7 +381,7 @@ public class MongoDBStore : IStore var values = new BsonDocument(); - foreach (var pt in template.Properties) + foreach (var pt in schema.Properties) { var rt = pt.PropertyInfo.GetValue(resource, null); @@ -594,7 +594,7 @@ public class MongoDBStore : IStore var parents = new BsonArray(); var children = new BsonArray(); - var template = resource.Instance.Template; + var schema = resource.Instance.Schema; //foreach (IResource c in resource.Instance.Children) // children.Add(c.Instance.Link); @@ -607,7 +607,7 @@ public class MongoDBStore : IStore var values = new BsonDocument(); - foreach (var pt in template.Properties) + foreach (var pt in schema.Properties) { /* #if NETSTANDARD1_5 @@ -728,11 +728,11 @@ public class MongoDBStore : IStore return reply; } - AsyncReply> GetRecordByAge(IResource resource, ulong fromAge, ulong toAge) + AsyncReply> GetRecordByAge(IResource resource, ulong fromAge, ulong toAge) { - var properties = resource.Instance.Template.Properties.Where(x => x.Recordable).ToList(); + var properties = resource.Instance.Schema.Properties.Where(x => x.Recordable).ToList(); - var reply = new AsyncReply>(); + var reply = new AsyncReply>(); AsyncBag bag = new AsyncBag(); @@ -743,7 +743,7 @@ public class MongoDBStore : IStore bag.Then(x => { - var list = new KeyList(); + var list = new KeyList(); for (var i = 0; i < x.Length; i++) list.Add(properties[i], x[i]); @@ -754,11 +754,11 @@ public class MongoDBStore : IStore return reply; } - public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) + public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) { - var properties = resource.Instance.Template.Properties.Where(x => x.Recordable).ToList(); + var properties = resource.Instance.Schema.Properties.Where(x => x.Recordable).ToList(); - var reply = new AsyncReply>(); + var reply = new AsyncReply>(); AsyncBag bag = new AsyncBag(); @@ -769,7 +769,7 @@ public class MongoDBStore : IStore bag.Then(x => { - var list = new KeyList(); + var list = new KeyList(); for (var i = 0; i < x.Length; i++) list.Add(properties[i], x[i]); diff --git a/Esiur/Core/ExceptionCode.cs b/Esiur/Core/ExceptionCode.cs index 39ad4a7..b5624fa 100644 --- a/Esiur/Core/ExceptionCode.cs +++ b/Esiur/Core/ExceptionCode.cs @@ -29,7 +29,7 @@ public enum ExceptionCode : ushort UpdateAttributeFailed, GetAttributesFailed, ClearAttributesFailed, - TemplateNotFound, + TypeDefNotFound, RenameDenied, ClassNotFound, MethodNotFound, diff --git a/Esiur/Data/DataDeserializer - Copy.cs b/Esiur/Data/DataDeserializer - Copy.cs index b702a5c..c25cbc1 100644 --- a/Esiur/Data/DataDeserializer - Copy.cs +++ b/Esiur/Data/DataDeserializer - Copy.cs @@ -165,7 +165,7 @@ public static class DataDeserializer var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Record); - var initRecord = (TypeTemplate template) => + var initRecord = (TypeSchema template) => { ListParser(data, offset, length, connection, requestSequence).Then(r => { diff --git a/Esiur/Data/DataDeserializer.cs b/Esiur/Data/DataDeserializer.cs index ddc98e9..b372518 100644 --- a/Esiur/Data/DataDeserializer.cs +++ b/Esiur/Data/DataDeserializer.cs @@ -1,10 +1,10 @@ using Esiur.Core; using Esiur.Data; using Esiur.Data.GVWIE; +using Esiur.Data.Schema; using Esiur.Misc; using Esiur.Net.IIP; using Esiur.Resource; -using Esiur.Resource.Template; using Microsoft.CodeAnalysis.CSharp.Syntax; using System; using System.Collections; @@ -397,7 +397,7 @@ public static class DataDeserializer { var classId = tdu.Metadata.GetUUID(0); var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, - TemplateType.Record); + TypeDefKind.Record); var rt = new AsyncReply(); @@ -410,7 +410,7 @@ public static class DataDeserializer var length = tdu.ContentLength; var ends = offset + (uint)length; - var initRecord = (TypeTemplate template) => + var initRecord = (TypeDef template) => { for (var i = 0; i < template.Properties.Length; i++) { @@ -517,7 +517,7 @@ public static class DataDeserializer //var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Record); - //var initRecord = (TypeTemplate template) => + //var initRecord = (TypeSchema template) => //{ // ListParserAsync(tdu, connection, requestSequence).Then(r => // { @@ -585,12 +585,12 @@ public static class DataDeserializer public static unsafe object RecordParser(ParsedTDU tdu, Warehouse warehouse) { var classId = tdu.Metadata.GetUUID(0); - var template = warehouse.GetTemplateByClassId(classId, TemplateType.Record); + var template = warehouse.GetTypeDefByClassId(classId, TypeDefKind.Record); if (template == null) { // @TODO: add parse if no template settings - throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TemplateNotFound, + throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.SchemaNotFound, "Template not found for record."); } @@ -691,7 +691,7 @@ public static class DataDeserializer var index = tdu.Data[tdu.Offset]; var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, - TemplateType.Enum); + TypeDefKind.Enum); if (template != null) { @@ -717,7 +717,7 @@ public static class DataDeserializer var index = tdu.Data[tdu.Offset]; - var template = warehouse.GetTemplateByClassId(classId, TemplateType.Enum); + var template = warehouse.GetTemplateByClassId(classId, TypeDefKind.Enum); if (template != null) { @@ -725,7 +725,7 @@ public static class DataDeserializer } else { - throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TemplateNotFound, + throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.SchemaNotFound, "Template not found for enum."); } } @@ -1625,13 +1625,13 @@ public static class DataDeserializer return (16 + valueSize, reply); } - public static AsyncReply> HistoryParserAsync(byte[] data, uint offset, uint length, IResource resource, DistributedConnection connection, uint[] requestSequence) + public static AsyncReply> HistoryParserAsync(byte[] data, uint offset, uint length, IResource resource, DistributedConnection connection, uint[] requestSequence) { //var count = (int)toAge - (int)fromAge; - var list = new KeyList(); + var list = new KeyList(); - var reply = new AsyncReply>(); + var reply = new AsyncReply>(); var bagOfBags = new AsyncBag(); @@ -1639,7 +1639,7 @@ public static class DataDeserializer while (offset < ends) { var index = data[offset++]; - var pt = resource.Instance.Template.GetPropertyTemplateByIndex(index); + var pt = resource.Instance.Schema.GetPropertyDefByIndex(index); list.Add(pt, null); var cs = data.GetUInt32(offset, Endian.Little); offset += 4; diff --git a/Esiur/Data/DataSerializer.cs b/Esiur/Data/DataSerializer.cs index c7f1d12..7787fa9 100644 --- a/Esiur/Data/DataSerializer.cs +++ b/Esiur/Data/DataSerializer.cs @@ -1,8 +1,8 @@ using Esiur.Core; using Esiur.Data.GVWIE; +using Esiur.Data.Schema; using Esiur.Net.IIP; using Esiur.Resource; -using Esiur.Resource.Template; using Microsoft.CodeAnalysis; using System; using System.Buffers.Binary; @@ -943,7 +943,7 @@ public static class DataSerializer template.ClassId.Data); } - public static byte[] HistoryComposer(KeyList history, Warehouse warehouse, + public static byte[] HistoryComposer(KeyList history, Warehouse warehouse, DistributedConnection connection, bool prependLength = false) { //@TODO:Test diff --git a/Esiur/Data/IDynamicResource.cs b/Esiur/Data/IDynamicResource.cs index ba48227..68080ef 100644 --- a/Esiur/Data/IDynamicResource.cs +++ b/Esiur/Data/IDynamicResource.cs @@ -1,5 +1,5 @@ using Esiur.Core; -using Esiur.Resource.Template; +using Esiur.Data.Types; using System; using System.Collections.Generic; using System.Text; @@ -15,6 +15,6 @@ namespace Esiur.Data public AsyncReply SetResourcePropertyAsync(byte index, object value); public void SetResourceProperty(byte index, object value); - public TypeTemplate ResourceTemplate { get; } + public TypeDef ResourceDefinition { get; } } } diff --git a/Esiur/Data/NullabilityInfoContext.cs b/Esiur/Data/NullabilityInfoContext.cs index 57fc431..1dcf807 100644 --- a/Esiur/Data/NullabilityInfoContext.cs +++ b/Esiur/Data/NullabilityInfoContext.cs @@ -466,9 +466,9 @@ namespace Esiur.Data private static MemberInfo GetMemberMetadataDefinition(MemberInfo member) { Type? type = member.DeclaringType; - if ((type != null) && type.IsGenericType && !type.IsGenericTypeDefinition) + if ((type != null) && type.IsGenericType && !type.IsGenericTypeDef) { - return GetMemberWithSameMetadataDefinitionAs(type.GetGenericTypeDefinition(), member); + return GetMemberWithSameMetadataDefinitionAs(type.GetGenericTypeDef(), member); } return member; @@ -575,20 +575,20 @@ namespace Esiur.Data { Debug.Assert(genericParameter.IsGenericParameter && !IsGenericMethodParameter(genericParameter)); - Type contextTypeDefinition = context.IsGenericType && !context.IsGenericTypeDefinition ? context.GetGenericTypeDefinition() : context; - if (genericParameter.DeclaringType == contextTypeDefinition) + Type contextTypeDef = context.IsGenericType && !context.IsGenericTypeDef ? context.GetGenericTypeDef() : context; + if (genericParameter.DeclaringType == contextTypeDef) { return false; } - Type? baseType = contextTypeDefinition.BaseType; + Type? baseType = contextTypeDef.BaseType; if (baseType is null) { return false; } if (!baseType.IsGenericType - || (baseType.IsGenericTypeDefinition ? baseType : baseType.GetGenericTypeDefinition()) != genericParameter.DeclaringType) + || (baseType.IsGenericTypeDef ? baseType : baseType.GetGenericTypeDef()) != genericParameter.DeclaringType) { return TryUpdateGenericTypeParameterNullabilityFromReflectedType(nullability, genericParameter, baseType, reflectedType); } @@ -600,7 +600,7 @@ namespace Esiur.Data return TryUpdateGenericParameterNullability(nullability, genericArgument, reflectedType); } - NullableAttributeStateParser parser = CreateParser(contextTypeDefinition.GetCustomAttributesData()); + NullableAttributeStateParser parser = CreateParser(contextTypeDef.GetCustomAttributesData()); int nullabilityStateIndex = 1; // start at 1 since index 0 is the type itself for (int i = 0; i < genericParameter.GenericParameterPosition; i++) { diff --git a/Esiur/Data/ResourceJsonConverter.cs b/Esiur/Data/ResourceJsonConverter.cs index b8c7792..9dc601b 100644 --- a/Esiur/Data/ResourceJsonConverter.cs +++ b/Esiur/Data/ResourceJsonConverter.cs @@ -52,7 +52,7 @@ class ResourceJsonConverter : JsonConverter writer.WriteStartObject(); - foreach (var pt in resource.Instance.Template.Properties) + foreach (var pt in resource.Instance.Schema.Properties) { var rt = pt.PropertyInfo.GetValue(resource, null); if (rt != null && rt.GetType().IsGenericType) diff --git a/Esiur/Data/RuntimeCaster.cs b/Esiur/Data/RuntimeCaster.cs index 608ecfe..084aa72 100644 --- a/Esiur/Data/RuntimeCaster.cs +++ b/Esiur/Data/RuntimeCaster.cs @@ -458,7 +458,7 @@ public static class RuntimeCaster [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsListType(Type t) { - return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>); + return t.IsGenericType && t.GetGenericTypeDef() == typeof(List<>); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Esiur/Data/TRU.cs b/Esiur/Data/TRU.cs index ec4adb8..7629976 100644 --- a/Esiur/Data/TRU.cs +++ b/Esiur/Data/TRU.cs @@ -1,7 +1,7 @@ using Esiur.Core; +using Esiur.Data.Types; using Esiur.Net.IIP; using Esiur.Resource; -using Esiur.Resource.Template; using Microsoft.CodeAnalysis; using System; using System.Collections; @@ -168,9 +168,9 @@ namespace Esiur.Data (TRUIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime), (TRUIdentifier.Resource) => typeof(IResource), (TRUIdentifier.Record) => typeof(IRecord), - (TRUIdentifier.TypedRecord) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Record)?.DefinedType, - (TRUIdentifier.TypedResource) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Resource)?.DefinedType, - (TRUIdentifier.Enum) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Enum)?.DefinedType, + (TRUIdentifier.TypedRecord) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Record)?.DefinedType, + (TRUIdentifier.TypedResource) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Resource)?.DefinedType, + (TRUIdentifier.Enum) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Enum)?.DefinedType, _ => null }; @@ -308,7 +308,7 @@ namespace Esiur.Data tru = new TRU( TRUIdentifier.TypedResource, nullable, - TypeTemplate.GetTypeUUID(type) + TypeDef.GetTypeUUID(type) ); } else if (Codec.ImplementsInterface(type, typeof(IRecord))) @@ -316,7 +316,7 @@ namespace Esiur.Data tru = new TRU( TRUIdentifier.TypedRecord, nullable, - TypeTemplate.GetTypeUUID(type) + TypeDef.GetTypeUUID(type) ); } else if (type.IsGenericType) @@ -483,7 +483,7 @@ namespace Esiur.Data } else if (type.IsEnum) { - tru = new TRU(TRUIdentifier.Enum, nullable, TypeTemplate.GetTypeUUID(type)); + tru = new TRU(TRUIdentifier.Enum, nullable, TypeDef.GetTypeUUID(type)); } else if (type.IsInterface) { diff --git a/Esiur/Resource/Template/ArgumentTemplate.cs b/Esiur/Data/Types/ArgumentDef.cs similarity index 90% rename from Esiur/Resource/Template/ArgumentTemplate.cs rename to Esiur/Data/Types/ArgumentDef.cs index 955e93e..8b4d21f 100644 --- a/Esiur/Resource/Template/ArgumentTemplate.cs +++ b/Esiur/Data/Types/ArgumentDef.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.Text; using System.Reflection; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; -public class ArgumentTemplate +public class ArgumentDef { public string Name { get; set; } @@ -20,7 +20,7 @@ public class ArgumentTemplate public Map Annotations { get; set; } - public static (uint, ArgumentTemplate) Parse(byte[] data, uint offset, int index) + public static (uint, ArgumentDef) Parse(byte[] data, uint offset, int index) { var optional = (data[offset] & 0x1) == 0x1; var hasAnnotations = (data[offset++] & 0x2) == 0x2; @@ -46,7 +46,7 @@ public class ArgumentTemplate cs += l; } - return (cs + 2 + size, new ArgumentTemplate() + return (cs + 2 + size, new ArgumentDef() { Name = name, Index = index, @@ -56,7 +56,7 @@ public class ArgumentTemplate }); } - public ArgumentTemplate() + public ArgumentDef() { } diff --git a/Esiur/Resource/Template/AttributeTemplate.cs b/Esiur/Data/Types/AttributeDef.cs similarity index 56% rename from Esiur/Resource/Template/AttributeTemplate.cs rename to Esiur/Data/Types/AttributeDef.cs index 61cdaff..aa6a7ca 100644 --- a/Esiur/Resource/Template/AttributeTemplate.cs +++ b/Esiur/Data/Types/AttributeDef.cs @@ -6,9 +6,9 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; -public class AttributeTemplate : MemberTemplate +public class AttributeDef : MemberDef { public PropertyInfo PropertyInfo @@ -18,14 +18,15 @@ public class AttributeTemplate : MemberTemplate } - public static AttributeTemplate MakeAttributeTemplate(Type type, PropertyInfo pi, byte index, string name, TypeTemplate typeTemplate ) + public static AttributeDef MakeAttributeDef(Type type, PropertyInfo pi, byte index, string name, TypeDef typeDef) { - return new AttributeTemplate() + return new AttributeDef() { Index = index, Inherited = pi.DeclaringType != type, Name = name, - PropertyInfo = pi + PropertyInfo = pi, + Definition = typeDef }; } } diff --git a/Esiur/Resource/Template/ConstantTemplate.cs b/Esiur/Data/Types/ConstantDef.cs similarity index 87% rename from Esiur/Resource/Template/ConstantTemplate.cs rename to Esiur/Data/Types/ConstantDef.cs index 100b3d1..3c06e0a 100644 --- a/Esiur/Resource/Template/ConstantTemplate.cs +++ b/Esiur/Data/Types/ConstantDef.cs @@ -4,10 +4,11 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using Esiur.Data; +using Esiur.Resource; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; -public class ConstantTemplate : MemberTemplate +public class ConstantDef : MemberDef { public object Value { get; set; } @@ -17,7 +18,7 @@ public class ConstantTemplate : MemberTemplate public FieldInfo FieldInfo { get; set; } - public static (uint, ConstantTemplate) Parse(byte[] data, uint offset, byte index, bool inherited) + public static (uint, ConstantDef) Parse(byte[] data, uint offset, byte index, bool inherited) { var oOffset = offset; @@ -47,7 +48,7 @@ public class ConstantTemplate : MemberTemplate offset += len; } - return (offset - oOffset, new ConstantTemplate() + return (offset - oOffset, new ConstantDef() { Index = index, Name = name, @@ -95,7 +96,7 @@ public class ConstantTemplate : MemberTemplate } - public static ConstantTemplate MakeConstantTemplate(Type type, FieldInfo ci, byte index = 0, string customName = null, TypeTemplate typeTemplate = null) + public static ConstantDef MakeConstantDef(Type type, FieldInfo ci, byte index = 0, string customName = null, TypeDef typeDef = null) { var annotationAttrs = ci.GetCustomAttributes(true); @@ -106,7 +107,7 @@ public class ConstantTemplate : MemberTemplate var value = ci.GetValue(null); - if (typeTemplate?.Type == TemplateType.Enum) + if (typeDef?.Type == TypeDefKind.Enum) value = Convert.ChangeType(value, ci.FieldType.GetEnumUnderlyingType()); Map annotations = null; @@ -120,7 +121,7 @@ public class ConstantTemplate : MemberTemplate - return new ConstantTemplate() + return new ConstantDef() { Name = customName, Index = index, diff --git a/Esiur/Data/Types/CustomEventOccurredEvent.cs b/Esiur/Data/Types/CustomEventOccurredEvent.cs new file mode 100644 index 0000000..d9539c8 --- /dev/null +++ b/Esiur/Data/Types/CustomEventOccurredEvent.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Esiur.Data.Types; + +internal class CustomEventOccurredEvent +{ +} diff --git a/Esiur/Resource/Template/TemplateDataType.cs b/Esiur/Data/Types/DefinitionDataType.cs similarity index 100% rename from Esiur/Resource/Template/TemplateDataType.cs rename to Esiur/Data/Types/DefinitionDataType.cs diff --git a/Esiur/Resource/Template/EventTemplate.cs b/Esiur/Data/Types/EventDef.cs similarity index 90% rename from Esiur/Resource/Template/EventTemplate.cs rename to Esiur/Data/Types/EventDef.cs index 8431b05..8642211 100644 --- a/Esiur/Resource/Template/EventTemplate.cs +++ b/Esiur/Data/Types/EventDef.cs @@ -1,5 +1,6 @@ using Esiur.Core; using Esiur.Data; +using Esiur.Resource; using System; using System.Collections.Generic; using System.Linq; @@ -8,9 +9,9 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; -public class EventTemplate : MemberTemplate +public class EventDef : MemberDef { public Map Annotations @@ -31,7 +32,7 @@ public class EventTemplate : MemberTemplate public TRU ArgumentType { get; set; } - public static (uint, EventTemplate) Parse(byte[] data, uint offset, byte index, bool inherited) + public static (uint, EventDef) Parse(byte[] data, uint offset, byte index, bool inherited) { var oOffset = offset; @@ -58,7 +59,7 @@ public class EventTemplate : MemberTemplate offset += len; } - return (offset - oOffset, new EventTemplate() + return (offset - oOffset, new EventDef() { Index = index, Name = name, @@ -102,7 +103,7 @@ public class EventTemplate : MemberTemplate .ToArray(); } - //public EventTemplate(TypeTemplate template, byte index, string name, bool inherited, TRU argumentType, Map annotations = null, bool subscribable = false) + //public EventTemplate(TypeSchema template, byte index, string name, bool inherited, TRU argumentType, Map annotations = null, bool subscribable = false) // : base(template, index, name, inherited) //{ // this.Annotations = annotations; @@ -110,7 +111,7 @@ public class EventTemplate : MemberTemplate // this.ArgumentType = argumentType; //} - public static EventTemplate MakeEventTemplate(Type type, EventInfo ei, byte index, string name, TypeTemplate typeTemplate) + public static EventDef MakeEventDef(Type type, EventInfo ei, byte index, string name, TypeDef schema) { if (!ei.EventHandlerType.IsGenericType) @@ -171,7 +172,7 @@ public class EventTemplate : MemberTemplate } - return new EventTemplate() + return new EventDef() { Name = name, ArgumentType = evtType, diff --git a/Esiur/Resource/Template/FunctionTemplate.cs b/Esiur/Data/Types/FunctionDef.cs similarity index 92% rename from Esiur/Resource/Template/FunctionTemplate.cs rename to Esiur/Data/Types/FunctionDef.cs index 550d4e2..2e817d2 100644 --- a/Esiur/Resource/Template/FunctionTemplate.cs +++ b/Esiur/Data/Types/FunctionDef.cs @@ -1,6 +1,7 @@ using Esiur.Core; using Esiur.Data; using Esiur.Net.IIP; +using Esiur.Resource; using System; using System.Collections.Generic; using System.Linq; @@ -9,9 +10,9 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; -public class FunctionTemplate : MemberTemplate +public class FunctionDef : MemberDef { public Map Annotations @@ -30,7 +31,7 @@ public class FunctionTemplate : MemberTemplate public bool IsStatic { get; set; } - public ArgumentTemplate[] Arguments { get; set; } + public ArgumentDef[] Arguments { get; set; } public MethodInfo MethodInfo { @@ -39,7 +40,7 @@ public class FunctionTemplate : MemberTemplate } - public static (uint, FunctionTemplate) Parse(byte[] data, uint offset, byte index, bool inherited) + public static (uint, FunctionDef) Parse(byte[] data, uint offset, byte index, bool inherited) { var oOffset = offset; @@ -56,11 +57,11 @@ public class FunctionTemplate : MemberTemplate // arguments count var argsCount = data[offset++]; - List arguments = new(); + List arguments = new(); for (var a = 0; a < argsCount; a++) { - var (cs, argType) = ArgumentTemplate.Parse(data, offset, a); + var (cs, argType) = ArgumentDef.Parse(data, offset, a); arguments.Add(argType); offset += cs; } @@ -78,7 +79,7 @@ public class FunctionTemplate : MemberTemplate offset += len; } - return (offset - oOffset, new FunctionTemplate() + return (offset - oOffset, new FunctionDef() { Index = index, Name = name, @@ -117,7 +118,7 @@ public class FunctionTemplate : MemberTemplate return bl.ToArray(); } - //public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, TRU returnType, Map annotations = null) + //public FunctionTemplate(TypeSchema template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, TRU returnType, Map annotations = null) // : base(template, index, name, inherited) //{ // this.Arguments = arguments; @@ -128,7 +129,7 @@ public class FunctionTemplate : MemberTemplate - public static FunctionTemplate MakeFunctionTemplate(Type type, MethodInfo mi, byte index, string name, TypeTemplate typeTemplate) + public static FunctionDef MakeFunctionDef(Type type, MethodInfo mi, byte index, string name, TypeDef schema) { var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null; @@ -262,7 +263,7 @@ public class FunctionTemplate : MemberTemplate argAnn.Add(attr.Key, attr.Value); } - return new ArgumentTemplate() + return new ArgumentDef() { Name = x.Name, Type = argType, @@ -290,7 +291,7 @@ public class FunctionTemplate : MemberTemplate } - return new FunctionTemplate() + return new FunctionDef() { Name = name, Index = index, diff --git a/Esiur/Resource/Template/MemberData.cs b/Esiur/Data/Types/MemberData.cs similarity index 97% rename from Esiur/Resource/Template/MemberData.cs rename to Esiur/Data/Types/MemberData.cs index cb1ea88..a9eab0d 100644 --- a/Esiur/Resource/Template/MemberData.cs +++ b/Esiur/Data/Types/MemberData.cs @@ -1,9 +1,10 @@ -using System; +using Esiur.Resource; +using System; using System.Collections.Generic; using System.Reflection; using System.Text; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; #nullable enable diff --git a/Esiur/Resource/Template/MemberTemplate.cs b/Esiur/Data/Types/MemberDef.cs similarity index 74% rename from Esiur/Resource/Template/MemberTemplate.cs rename to Esiur/Data/Types/MemberDef.cs index 8ff8408..1f4d1f0 100644 --- a/Esiur/Resource/Template/MemberTemplate.cs +++ b/Esiur/Data/Types/MemberDef.cs @@ -5,14 +5,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Esiur.Resource.Template; -public class MemberTemplate +namespace Esiur.Data.Types; +public class MemberDef { public byte Index { get; set; } public string Name { get; set; } public bool Inherited { get; set; } - public TypeTemplate Template { get; set; } + public TypeDef Definition { get; set; } //public MemberTemplate() //{ @@ -22,7 +22,7 @@ public class MemberTemplate // Inherited = inherited; //} - public string Fullname => Template.ClassName + "." + Name; + public string Fullname => Definition.ClassName + "." + Name; //public virtual byte[] Compose() //{ diff --git a/Esiur/Resource/Template/PropertyTemplate.cs b/Esiur/Data/Types/PropertyDef.cs similarity index 92% rename from Esiur/Resource/Template/PropertyTemplate.cs rename to Esiur/Data/Types/PropertyDef.cs index 611c981..7f210f9 100644 --- a/Esiur/Resource/Template/PropertyTemplate.cs +++ b/Esiur/Data/Types/PropertyDef.cs @@ -1,5 +1,6 @@ using Esiur.Data; using Esiur.Net.IIP; +using Esiur.Resource; using System; using System.Collections.Generic; using System.Linq; @@ -8,9 +9,9 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; -public class PropertyTemplate : MemberTemplate +public class PropertyDef : MemberDef { public Map Annotations { get; set; } @@ -79,7 +80,7 @@ public class PropertyTemplate : MemberTemplate return $"{Name}: {ValueType}"; } - public static (uint, PropertyTemplate) Parse(byte[] data, uint offset, byte index, bool inherited) + public static (uint, PropertyDef) Parse(byte[] data, uint offset, byte index, bool inherited) { var oOffset = offset; @@ -109,7 +110,7 @@ public class PropertyTemplate : MemberTemplate offset += len; } - return (offset - oOffset, new PropertyTemplate() + return (offset - oOffset, new PropertyDef() { Index = index, Name = name, @@ -192,7 +193,7 @@ public class PropertyTemplate : MemberTemplate } } - //public PropertyTemplate(TypeTemplate template, byte index, string name, bool inherited, + //public PropertyTemplate(TypeSchema template, byte index, string name, bool inherited, // TRU valueType, string readAnnotation = null, string writeAnnotation = null, bool recordable = false) // : base(template, index, name, inherited) //{ @@ -204,7 +205,7 @@ public class PropertyTemplate : MemberTemplate // this.ValueType = valueType; //} - public static PropertyTemplate MakePropertyTemplate(Type type, PropertyInfo pi, string name, byte index, PropertyPermission permission, TypeTemplate typeTemplate) + public static PropertyDef MakePropertyDef(Type type, PropertyInfo pi, string name, byte index, PropertyPermission permission, TypeDef schema) { var genericPropType = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericTypeDefinition() : null; @@ -265,7 +266,7 @@ public class PropertyTemplate : MemberTemplate } - return new PropertyTemplate() + return new PropertyDef() { Name = name, Index = index, @@ -277,7 +278,7 @@ public class PropertyTemplate : MemberTemplate Annotations = annotations, }; - //var pt = new PropertyTemplate(typeTemplate, index, customName ?? pi.Name, pi.DeclaringType != type, propType); + //var pt = new PropertyTemplate(TypeSchema, index, customName ?? pi.Name, pi.DeclaringType != type, propType); //if (storageAttr != null) // pt.Recordable = storageAttr.Mode == StorageMode.Recordable; diff --git a/Esiur/Resource/Template/TypeTemplate.cs b/Esiur/Data/Types/TypeDef.cs similarity index 83% rename from Esiur/Resource/Template/TypeTemplate.cs rename to Esiur/Data/Types/TypeDef.cs index 991efdf..63c2ab9 100644 --- a/Esiur/Resource/Template/TypeTemplate.cs +++ b/Esiur/Data/Types/TypeDef.cs @@ -10,8 +10,9 @@ using System.Security.Cryptography; using Esiur.Proxy; using Esiur.Net.IIP; using System.Runtime.CompilerServices; +using Esiur.Resource; -namespace Esiur.Resource.Template; +namespace Esiur.Data.Types; //public enum TemplateType //{ @@ -19,27 +20,27 @@ namespace Esiur.Resource.Template; // Record //} -public class TypeTemplate +public class TypeDef { - protected UUID classId; + protected UUID typeId; protected UUID? parentId; public Map Annotations { get; set; } - string className; - List functions = new List(); - List events = new List(); - List properties = new List(); - List attributes = new List(); - List constants = new(); + string typeName; + List functions = new List(); + List events = new List(); + List properties = new List(); + List attributes = new List(); + List constants = new(); int version; - TemplateType templateType; + TypeDefKind typeDefKind; public override string ToString() { - return className; + return typeName; } // protected TemplateType @@ -54,7 +55,7 @@ public class TypeTemplate get { return content; } } - public TemplateType Type => templateType; + public TypeDefKind Kind => typeDefKind; public Type DefinedType { get; set; } @@ -72,7 +73,7 @@ public class TypeTemplate // return null; //} - public EventTemplate GetEventTemplateByName(string eventName) + public EventDef GetEventDefByName(string eventName) { foreach (var i in events) if (i.Name == eventName) @@ -80,7 +81,7 @@ public class TypeTemplate return null; } - public EventTemplate GetEventTemplateByIndex(byte index) + public EventDef GetEventDefByIndex(byte index) { foreach (var i in events) if (i.Index == index) @@ -88,14 +89,14 @@ public class TypeTemplate return null; } - public FunctionTemplate GetFunctionTemplateByName(string functionName) + public FunctionDef GetFunctionDefByName(string functionName) { foreach (var i in functions) if (i.Name == functionName) return i; return null; } - public FunctionTemplate GetFunctionTemplateByIndex(byte index) + public FunctionDef GetFunctionDefByIndex(byte index) { foreach (var i in functions) if (i.Index == index) @@ -103,7 +104,7 @@ public class TypeTemplate return null; } - public PropertyTemplate GetPropertyTemplateByIndex(byte index) + public PropertyDef GetPropertyDefByIndex(byte index) { foreach (var i in properties) if (i.Index == index) @@ -111,7 +112,7 @@ public class TypeTemplate return null; } - public PropertyTemplate GetPropertyTemplateByName(string propertyName) + public PropertyDef GetPropertyDefByName(string propertyName) { foreach (var i in properties) if (i.Name == propertyName) @@ -119,7 +120,7 @@ public class TypeTemplate return null; } - public AttributeTemplate GetAttributeTemplate(string attributeName) + public AttributeDef GetAttributeDef(string attributeName) { foreach (var i in attributes) if (i.Name == attributeName) @@ -127,13 +128,13 @@ public class TypeTemplate return null; } - public UUID ClassId + public UUID Id { - get { return classId; } + get { return typeId; } } - public string ClassName + public string Name { - get { return className; } + get { return typeName; } } //public MemberTemplate[] Methods @@ -141,24 +142,24 @@ public class TypeTemplate // get { return members.ToArray(); } //} - public FunctionTemplate[] Functions + public FunctionDef[] Functions { get { return functions.ToArray(); } } - public EventTemplate[] Events + public EventDef[] Events { get { return events.ToArray(); } } - public PropertyTemplate[] Properties + public PropertyDef[] Properties { get { return properties.ToArray(); } } - public ConstantTemplate[] Constants => constants.ToArray(); + public ConstantDef[] Constants => constants.ToArray(); - public TypeTemplate() + public TypeDef() { } @@ -169,7 +170,7 @@ public class TypeTemplate if (attr != null) return attr.ClassId; - var tn = Encoding.UTF8.GetBytes(GetTypeClassName(type)); + var tn = Encoding.UTF8.GetBytes(GetTypeName(type)); var hash = SHA256.Create().ComputeHash(tn).Clip(0, 16); hash[6] = (byte)((hash[6] & 0xF) | 0x80); hash[8] = (byte)((hash[8] & 0xF) | 0x80); @@ -222,24 +223,24 @@ public class TypeTemplate } - public static TypeTemplate[] GetDependencies(TypeTemplate template, Warehouse warehouse) + public static TypeDef[] GetDependencies(TypeDef schema, Warehouse warehouse) { - var list = new List(); + var list = new List(); // Add self - list.Add(template); + list.Add(schema); - Action> getDependenciesFunc = null; + Action> getDependenciesFunc = null; - getDependenciesFunc = (TypeTemplate tmp, List bag) => + getDependenciesFunc = (TypeDef sch, List bag) => { - if (template.DefinedType == null) + if (schema.DefinedType == null) return; // Add parents - var parentType = tmp.ParentDefinedType; + var parentType = sch.ParentDefinedType; // Get parents while (parentType != null) @@ -253,7 +254,7 @@ public class TypeTemplate } // functions - foreach (var f in tmp.functions) + foreach (var f in sch.functions) { var functionReturnTypes = GetDistributedTypes(f.MethodInfo.ReturnType); //.Select(x => Warehouse.GetTemplateByType(x)) @@ -319,7 +320,7 @@ public class TypeTemplate } // properties - foreach (var p in tmp.properties) + foreach (var p in sch.properties) { var propertyTypes = GetDistributedTypes(p.PropertyInfo.PropertyType); @@ -338,7 +339,7 @@ public class TypeTemplate } // events - foreach (var e in tmp.events) + foreach (var e in sch.events) { var eventTypes = GetDistributedTypes(e.EventInfo.EventHandlerType.GenericTypeArguments[0]); @@ -358,12 +359,12 @@ public class TypeTemplate } }; - getDependenciesFunc(template, list); + getDependenciesFunc(schema, list); return list.Distinct().ToArray(); } - public static string GetTypeClassName(Type type, char separator = '.') + public static string GetTypeName(Type type, char separator = '.') { if (type.IsGenericType) @@ -371,7 +372,7 @@ public class TypeTemplate var index = type.Name.IndexOf("`"); var name = $"{type.Namespace}{separator}{((index > -1) ? type.Name.Substring(0, index) : type.Name)}Of"; foreach (var t in type.GenericTypeArguments) - name += GetTypeClassName(t, '_'); + name += GetTypeName(t, '_'); return name; } @@ -386,14 +387,14 @@ public class TypeTemplate public bool IsWrapper { get; private set; } - public TypeTemplate(Type type, Warehouse warehouse = null) + public TypeDef(Type type, Warehouse warehouse = null) { if (Codec.ImplementsInterface(type, typeof(IResource))) - templateType = TemplateType.Resource; + typeDefKind = TypeDefKind.Resource; else if (Codec.ImplementsInterface(type, typeof(IRecord))) - templateType = TemplateType.Record; + typeDefKind = TypeDefKind.Record; else if (type.IsEnum) - templateType = TemplateType.Enum; + typeDefKind = TypeDefKind.Enum; else throw new Exception("Type must implement IResource, IRecord or inherit from DistributedResource."); @@ -403,13 +404,13 @@ public class TypeTemplate DefinedType = type; - className = GetTypeClassName(type); + typeName = GetTypeName(type); // set guid - classId = GetTypeUUID(type); + typeId = GetTypeUUID(type); if (warehouse != null) - warehouse.PutTemplate(this); + warehouse.RegisterSchema(this); var hierarchy = GetHierarchy(type); @@ -417,7 +418,7 @@ public class TypeTemplate { foreach (var cd in hierarchy[MemberTypes.Field]) { - constants.Add(ConstantTemplate.MakeConstantTemplate + constants.Add(ConstantDef.MakeConstantDef (type, (FieldInfo)cd.GetMemberInfo(), cd.Index, cd.Name, this)); } } @@ -426,18 +427,18 @@ public class TypeTemplate { foreach (var pd in hierarchy[MemberTypes.Property]) { - properties.Add(PropertyTemplate.MakePropertyTemplate + properties.Add(PropertyDef.MakePropertyDef (type, (PropertyInfo)pd.GetMemberInfo(), pd.Name, pd.Index, pd.PropertyPermission, this)); } } - if (templateType == TemplateType.Resource) + if (typeDefKind == TypeDefKind.Resource) { if (hierarchy.ContainsKey(MemberTypes.Method)) { foreach (var fd in hierarchy[MemberTypes.Method]) { - functions.Add(FunctionTemplate.MakeFunctionTemplate + functions.Add(FunctionDef.MakeFunctionDef (type, (MethodInfo)fd.GetMemberInfo(), fd.Index, fd.Name, this)); } } @@ -446,7 +447,7 @@ public class TypeTemplate { foreach (var ed in hierarchy[MemberTypes.Event]) { - events.Add(EventTemplate.MakeEventTemplate + events.Add(EventDef.MakeEventDef (type, (EventInfo)ed.GetMemberInfo(), ed.Index, ed.Name, this)); } } @@ -461,8 +462,8 @@ public class TypeTemplate { var attrAttr = attr.GetCustomAttribute(); - attributes.Add(AttributeTemplate - .MakeAttributeTemplate(type, attr, 0, attrAttr?.Name ?? attr.Name, this)); + attributes.Add(AttributeDef + .MakeAttributeDef(type, attr, 0, attrAttr?.Name ?? attr.Name, this)); } @@ -478,12 +479,12 @@ public class TypeTemplate var hasClassAnnotation = (classAnnotations != null) && (classAnnotations.Count() > 0); - var classNameBytes = DC.ToBytes(className); + var typeNameBytes = DC.ToBytes(typeName); - b.AddUInt8((byte)((hasParent ? 0x80 : 0) | (hasClassAnnotation ? 0x40 : 0x0) | (byte)templateType)) - .AddUUID(classId) - .AddUInt8((byte)classNameBytes.Length) - .AddUInt8Array(classNameBytes); + b.AddUInt8((byte)((hasParent ? 0x80 : 0) | (hasClassAnnotation ? 0x40 : 0x0) | (byte)typeDefKind)) + .AddUUID(typeId) + .AddUInt8((byte)typeNameBytes.Length) + .AddUInt8Array(typeNameBytes); if (hasParent) { @@ -529,7 +530,7 @@ public class TypeTemplate while (parent != null) { - if (parent == typeof(Resource) + if (parent == typeof(Esiur.Resource.Resource) || parent == typeof(Record) || parent == typeof(EntryPoint)) return false; @@ -606,7 +607,7 @@ public class TypeTemplate type = type.BaseType; if (type == null - || type == typeof(Resource) + || type == typeof(Esiur.Resource.Resource) || type == typeof(Record) || type == typeof(EntryPoint)) break; @@ -674,13 +675,13 @@ public class TypeTemplate } - public static TypeTemplate Parse(byte[] data) + public static TypeDef Parse(byte[] data) { return Parse(data, 0, (uint)data.Length); } - public static TypeTemplate Parse(byte[] data, uint offset, uint contentLength) + public static TypeDef Parse(byte[] data, uint offset, uint contentLength) { uint ends = offset + contentLength; @@ -689,17 +690,17 @@ public class TypeTemplate // start parsing... - var od = new TypeTemplate(); + var od = new TypeDef(); od.content = data.Clip(offset, contentLength); var hasParent = (data[offset] & 0x80) > 0; var hasClassAnnotation = (data[offset] & 0x40) > 0; - od.templateType = (TemplateType)(data[offset++] & 0xF); + od.typeDefKind = (TypeDefKind)(data[offset++] & 0xF); - od.classId = data.GetUUID(offset); + od.typeId = data.GetUUID(offset); offset += 16; - od.className = data.GetString(offset + 1, data[offset]); + od.typeName = data.GetString(offset + 1, data[offset]); offset += (uint)data[offset] + 1; @@ -736,27 +737,27 @@ public class TypeTemplate if (type == 0) // function { - var (len, ft) = FunctionTemplate.Parse(data, offset, functionIndex++, inherited); + var (len, ft) = FunctionDef.Parse(data, offset, functionIndex++, inherited); offset += len; od.functions.Add(ft); } else if (type == 1) // property { - var (len, pt) = PropertyTemplate.Parse(data, offset, propertyIndex++, inherited); + var (len, pt) = PropertyDef.Parse(data, offset, propertyIndex++, inherited); offset += len; od.properties.Add(pt); } else if (type == 2) // Event { - var (len, et) = EventTemplate.Parse(data, offset, propertyIndex++, inherited); + var (len, et) = EventDef.Parse(data, offset, propertyIndex++, inherited); offset += len; od.events.Add(et); } // constant else if (type == 3) { - var (len, ct) = ConstantTemplate.Parse(data, offset, propertyIndex++, inherited); + var (len, ct) = ConstantDef.Parse(data, offset, propertyIndex++, inherited); offset += len; od.constants.Add(ct); } @@ -770,7 +771,7 @@ public class TypeTemplate var rt = new Map(); foreach (var kv in properties) { - var pt = GetPropertyTemplateByName(kv.Key); + var pt = GetPropertyDefByName(kv.Key); if (pt == null) continue; rt.Add(pt.Index, kv.Value); } diff --git a/Esiur/Resource/Template/TemplateType.cs b/Esiur/Data/Types/TypeDefKind.cs similarity index 64% rename from Esiur/Resource/Template/TemplateType.cs rename to Esiur/Data/Types/TypeDefKind.cs index b0fc577..360bfe9 100644 --- a/Esiur/Resource/Template/TemplateType.cs +++ b/Esiur/Data/Types/TypeDefKind.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace Esiur.Resource.Template; -public enum TemplateType : byte +namespace Esiur.Data.Types; + +public enum TypeDefKind : byte { Resource, Record, diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 9507c3b..536ee39 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -67,6 +67,8 @@ + + diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs index 77560c6..d25bf61 100644 --- a/Esiur/Net/IIP/DistributedConnection.cs +++ b/Esiur/Net/IIP/DistributedConnection.cs @@ -24,13 +24,13 @@ SOFTWARE. using Esiur.Core; using Esiur.Data; +using Esiur.Data.Schema; using Esiur.Misc; using Esiur.Net.HTTP; using Esiur.Net.Packets; using Esiur.Net.Packets.HTTP; using Esiur.Net.Sockets; using Esiur.Resource; -using Esiur.Resource.Template; using Esiur.Security.Authority; using Esiur.Security.Membership; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -492,19 +492,19 @@ public partial class DistributedConnection : NetworkConnection, IStore IIPRequestUnsubscribe(packet.CallbackId, dt, msg); break; // Inquire - case IIPPacketRequest.TemplateFromClassName: + case IIPPacketRequest.SchemaFromClassName: IIPRequestTemplateFromClassName(packet.CallbackId, dt, msg); break; - case IIPPacketRequest.TemplateFromClassId: + case IIPPacketRequest.SchemaFromClassId: IIPRequestTemplateFromClassId(packet.CallbackId, dt, msg); break; - case IIPPacketRequest.TemplateFromResourceId: + case IIPPacketRequest.SchemaFromResourceId: IIPRequestTemplateFromResourceId(packet.CallbackId, dt, msg); break; case IIPPacketRequest.Query: IIPRequestQueryResources(packet.CallbackId, dt, msg); break; - case IIPPacketRequest.LinkTemplates: + case IIPPacketRequest.LinkSchemas: IIPRequestLinkTemplates(packet.CallbackId, dt, msg); break; case IIPPacketRequest.Token: @@ -1712,7 +1712,7 @@ public partial class DistributedConnection : NetworkConnection, IStore throw new NotImplementedException(); } - public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) + public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) { throw new NotImplementedException(); } diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs index 451b910..2c597ea 100644 --- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs +++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs @@ -24,10 +24,10 @@ SOFTWARE. using Esiur.Core; using Esiur.Data; +using Esiur.Data.Types; using Esiur.Misc; using Esiur.Net.Packets; using Esiur.Resource; -using Esiur.Resource.Template; using Esiur.Security.Authority; using Esiur.Security.Permissions; using System; @@ -50,12 +50,12 @@ partial class DistributedConnection KeyList> suspendedResources = new KeyList>(); KeyList resourceRequests = new KeyList(); - KeyList> templateRequests = new KeyList>(); + KeyList> typeDefsByIdRequests = new KeyList>(); - KeyList> templateByNameRequests = new KeyList>(); + KeyList> typeDefsByNameRequests = new KeyList>(); - Dictionary templates = new Dictionary(); + Dictionary typeDefs = new Dictionary(); KeyList requests = new KeyList(); @@ -455,7 +455,7 @@ partial class DistributedConnection Fetch(rid, null).Then(r => { - var pt = r.Instance.Template.GetPropertyTemplateByIndex(index); + var pt = r.Instance.Definition.GetPropertyDefByIndex(index); if (pt == null) return; @@ -500,7 +500,7 @@ partial class DistributedConnection Fetch(resourceId, null).Then(r => { - var et = r.Instance.Template.GetEventTemplateByIndex(index); + var et = r.Instance.Definition.GetEventDefByIndex(index); if (et == null) // this should never happen return; @@ -561,7 +561,7 @@ partial class DistributedConnection // reply ok SendReply(IIPPacketReply.Completed, callback, - r.Instance.Template.ClassId, + r.Instance.Definition.TypeId, r.Instance.Age, r.Instance.Link, r.Instance.Hops, @@ -608,7 +608,7 @@ partial class DistributedConnection // reply ok SendReply(IIPPacketReply.Completed, callback, - r.Instance.Template.ClassId, + r.Instance.Definition.TypeId, r.Instance.Age, r.Instance.Link, r.Instance.Hops, @@ -666,12 +666,12 @@ partial class DistributedConnection var path = (string)args[0]; - TypeTemplate type = null; + TypeDef type = null; if (args[1] is UUID) - type = Instance.Warehouse.GetTemplateByClassId((UUID)args[1]); + type = Instance.Warehouse.GetTypeDefById((UUID)args[1]); else if (args[1] is string) - type = Instance.Warehouse.GetTemplateByClassName((string)args[1]); + type = Instance.Warehouse.GetTypeByName((string)args[1]); if (type == null) { @@ -814,7 +814,7 @@ partial class DistributedConnection return; } - var templates = TypeTemplate.GetDependencies(r.Instance.Template, Instance.Warehouse); + var templates = TypeDef.GetDependencies(r.Instance.Definition, Instance.Warehouse); // Send SendReply(IIPPacketReply.Completed, callback, templates.Select(x => x.Content).ToArray()); @@ -842,18 +842,18 @@ partial class DistributedConnection else { // reply failed - SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TemplateNotFound); + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TypeDefNotFound); } } - void IIPRequestTemplateFromClassId(uint callback, ParsedTDU dataType, byte[] data) + void IIPRequestTypeDefById(uint callback, ParsedTDU dataType, byte[] data) { var (_, value) = Codec.ParseSync(dataType, Instance.Warehouse); var classId = (UUID)value; - var t = Instance.Warehouse.GetTemplateByClassId(classId); + var t = Instance.Warehouse.GetTypeDefById(classId); if (t != null) { @@ -862,7 +862,7 @@ partial class DistributedConnection else { // reply failed - SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TemplateNotFound); + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TypeDefNotFound); } } @@ -879,7 +879,7 @@ partial class DistributedConnection { if (r != null) { - SendReply(IIPPacketReply.Completed, callback, r.Instance.Template.Content); + SendReply(IIPPacketReply.Completed, callback, r.Instance.Definition.Content); } else { @@ -1046,16 +1046,16 @@ partial class DistributedConnection var index = (byte)args[1]; - var template = Instance.Warehouse.GetTemplateByClassId(classId); + var template = Instance.Warehouse.GetTypeDefById(classId); if (template == null) { - SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TemplateNotFound); + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TypeDefNotFound); return; } - var ft = template.GetFunctionTemplateByIndex(index); + var ft = template.GetFunctionDefByIndex(index); if (ft == null) { @@ -1131,7 +1131,7 @@ partial class DistributedConnection return; } - var ft = r.Instance.Template.GetFunctionTemplateByIndex(index); + var ft = r.Instance.Definition.GetFunctionDefByIndex(index); if (ft == null) { @@ -1221,7 +1221,7 @@ partial class DistributedConnection - void InvokeFunction(FunctionTemplate ft, uint callback, object arguments, IIPPacketRequest actionType, object target = null) + void InvokeFunction(FunctionDef ft, uint callback, object arguments, IIPPacketRequest actionType, object target = null) { // cast arguments @@ -1455,7 +1455,7 @@ partial class DistributedConnection return; } - var et = r.Instance.Template.GetEventTemplateByIndex(index); + var et = r.Instance.Definition.GetEventDefByIndex(index); if (et != null) { @@ -1514,7 +1514,7 @@ partial class DistributedConnection return; } - var et = r.Instance.Template.GetEventTemplateByIndex(index); + var et = r.Instance.Definition.GetEventDefByIndex(index); if (et == null) { @@ -1578,7 +1578,7 @@ partial class DistributedConnection return; } - var pt = r.Instance.Template.GetPropertyTemplateByIndex(index); + var pt = r.Instance.Definition.GetPropertyDefByIndex(index); if (pt != null) { @@ -1686,27 +1686,27 @@ partial class DistributedConnection /// - /// Get the ResourceTemplate for a given class Id. + /// Get the TypeSchema for a given class Id. /// /// Class GUID. - /// ResourceTemplate. - public AsyncReply GetTemplate(UUID classId) + /// TypeSchema. + public AsyncReply GetTypeDefById(UUID classId) { - if (templates.ContainsKey(classId)) - return new AsyncReply(templates[classId]); - else if (templateRequests.ContainsKey(classId)) - return templateRequests[classId]; + if (typeDefs.ContainsKey(classId)) + return new AsyncReply(typeDefs[classId]); + else if (typeDefsByIdRequests.ContainsKey(classId)) + return typeDefsByIdRequests[classId]; - var reply = new AsyncReply(); - templateRequests.Add(classId, reply); + var reply = new AsyncReply(); + typeDefsByIdRequests.Add(classId, reply); - SendRequest(IIPPacketRequest.TemplateFromClassId, classId) + SendRequest(IIPPacketRequest.SchemaFromClassId, classId) .Then((result) => { - var tt = TypeTemplate.Parse((byte[])result); - templateRequests.Remove(classId); - templates.Add(tt.ClassId, tt); - Instance.Warehouse.PutTemplate(tt); + var tt = TypeDef.Parse((byte[])result); + typeDefsByIdRequests.Remove(classId); + typeDefs.Add(tt.ClassId, tt); + Instance.Warehouse.RegisterSchema(tt); reply.Trigger(tt); }).Error((ex) => @@ -1718,27 +1718,27 @@ partial class DistributedConnection } - public AsyncReply GetTemplateByClassName(string className) + public AsyncReply GetTypeDefByClassName(string className) { - var template = templates.Values.FirstOrDefault(x => x.ClassName == className); + var template = typeDefs.Values.FirstOrDefault(x => x.ClassName == className); if (template != null) - return new AsyncReply(template); + return new AsyncReply(template); - if (templateByNameRequests.ContainsKey(className)) - return templateByNameRequests[className]; + if (typeDefsByNameRequests.ContainsKey(className)) + return typeDefsByNameRequests[className]; - var reply = new AsyncReply(); - templateByNameRequests.Add(className, reply); + var reply = new AsyncReply(); + typeDefsByNameRequests.Add(className, reply); - SendRequest(IIPPacketRequest.TemplateFromClassName, className) + SendRequest(IIPPacketRequest.SchemaFromClassName, className) .Then((result) => { - var tt = TypeTemplate.Parse((byte[])result); + var tt = TypeDef.Parse((byte[])result); - templateByNameRequests.Remove(className); - templates.Add(tt.ClassId, tt); - Instance.Warehouse.PutTemplate(tt); + typeDefsByNameRequests.Remove(className); + typeDefs.Add(tt.ClassId, tt); + Instance.Warehouse.RegisterSchema(tt); reply.Trigger(tt); }).Error((ex) => { @@ -1786,23 +1786,23 @@ partial class DistributedConnection } - public AsyncReply GetLinkTemplates(string link) + public AsyncReply GetLinkDefinitions(string link) { - var reply = new AsyncReply(); + var reply = new AsyncReply(); - SendRequest(IIPPacketRequest.LinkTemplates, link) + SendRequest(IIPPacketRequest.LinkSchemas, link) .Then((result) => { - var templates = new List(); + var defs = new List(); - foreach (var template in (byte[][])result) + foreach (var def in (byte[][])result) { - templates.Add(TypeTemplate.Parse(template)); + defs.Add(TypeDef.Parse(def)); } - reply.Trigger(templates.ToArray()); + reply.Trigger(defs.ToArray()); }).Error((ex) => { @@ -1874,7 +1874,7 @@ partial class DistributedConnection // ClassId, Age, Link, Hops, PropertyValue[] var args = (object[])result; - var classId = (UUID)args[0]; + var typeId = (UUID)args[0]; var age = Convert.ToUInt64(args[1]); var link = (string)args[2]; var hops = (byte)args[3]; @@ -1882,20 +1882,20 @@ partial class DistributedConnection DistributedResource dr; - TypeTemplate template = null; + TypeDef typeDef = null; if (resource == null) { - template = Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Resource); - if (template?.DefinedType != null && template.IsWrapper) - dr = Activator.CreateInstance(template.DefinedType, this, id, Convert.ToUInt64(args[1]), (string)args[2]) as DistributedResource; + typeDef = Instance.Warehouse.GetTypeDefByClassId(typeId, TypeDefKind.Resource); + if (typeDef?.DefinedType != null && typeDef.IsWrapper) + dr = Activator.CreateInstance(typeDef.DefinedType, this, id, Convert.ToUInt64(args[1]), (string)args[2]) as DistributedResource; else dr = new DistributedResource(this, id, Convert.ToUInt64(args[1]), (string)args[2]); } else { dr = resource; - template = resource.Instance.Template; + typeDef = resource.Instance.Definition; } @@ -1924,14 +1924,14 @@ partial class DistributedConnection }; - if (template == null) + if (typeDef == null) { - GetTemplate(classId).Then((tmp) => + GetTypeDefById(typeId).Then((tmp) => { // ClassId, ResourceAge, ResourceLink, Content if (resource == null) { - dr.ResourceTemplate = tmp; + dr.ResourceDefinition = tmp; Instance.Warehouse.Put(this.Instance.Link + "/" + id.ToString(), dr) .Then(initResource) @@ -1999,7 +1999,7 @@ partial class DistributedConnection /// Values for the resource properties. /// Resource attributes. /// New resource instance - public AsyncReply Create(string path, TypeTemplate type, Map properties, Map attributes) + public AsyncReply Create(string path, TypeDef type, Map properties, Map attributes) { var reply = new AsyncReply(); @@ -2103,7 +2103,7 @@ partial class DistributedConnection private void Instance_EventOccurred(EventOccurredInfo info) { - if (info.EventTemplate.Subscribable) + if (info.Definition.Subscribable) { lock (subscriptionsLock) { @@ -2111,18 +2111,18 @@ partial class DistributedConnection if (!subscriptions.ContainsKey(info.Resource)) return; - if (!subscriptions[info.Resource].Contains(info.EventTemplate.Index)) + if (!subscriptions[info.Resource].Contains(info.Definition.Index)) return; } } - if (info.Resource.Instance.Applicable(this.session, ActionType.ReceiveEvent, info.EventTemplate, null) == Ruling.Denied) + if (info.Resource.Instance.Applicable(this.session, ActionType.ReceiveEvent, info.Definition, null) == Ruling.Denied) return; // compose the packet SendNotification(IIPPacketNotification.EventOccurred, info.Resource.Instance.Id, - info.EventTemplate.Index, + info.Definition.Index, info.Value); } diff --git a/Esiur/Net/IIP/DistributedResource.cs b/Esiur/Net/IIP/DistributedResource.cs index 9f9725f..dea846f 100644 --- a/Esiur/Net/IIP/DistributedResource.cs +++ b/Esiur/Net/IIP/DistributedResource.cs @@ -40,8 +40,8 @@ using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using Esiur.Resource; -using Esiur.Resource.Template; using Esiur.Net.Packets; +using Esiur.Data.Types; namespace Esiur.Net.IIP; @@ -57,7 +57,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan public event PropertyChangedEventHandler PropertyChanged; uint instanceId; - TypeTemplate template; + TypeDef typeDef; DistributedConnection connection; @@ -163,7 +163,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan this.properties = new object[properties.Length]; - this.events = new DistributedResourceEvent[Instance.Template.Events.Length]; + this.events = new DistributedResourceEvent[Instance.Definition.Events.Length]; for (byte i = 0; i < properties.Length; i++) { @@ -187,7 +187,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan protected internal virtual void _EmitEventByIndex(byte index, object args) { - var et = Instance.Template.GetEventTemplateByIndex(index); + var et = Instance.Definition.GetEventDefByIndex(index); events[index]?.Invoke(this, args); Instance.EmitResourceEvent(et, args); } @@ -200,21 +200,21 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan if (suspended) throw new Exception("Trying to access a suspended object."); - if (index >= Instance.Template.Functions.Length) + if (index >= Instance.Definition.Functions.Length) throw new Exception("Function index is incorrect."); - var ft = Instance.Template.GetFunctionTemplateByIndex(index); + var ft = Instance.Definition.GetFunctionDefByIndex(index); if (ft == null) throw new Exception("Function template not found."); if (ft.IsStatic) - return connection.StaticCall(Instance.Template.ClassId, index, args); + return connection.StaticCall(Instance.Definition.ClassId, index, args); else return connection.SendInvoke(instanceId, index, args); } - public AsyncReply Subscribe(EventTemplate et) + public AsyncReply Subscribe(EventDef et) { if (et == null) return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, "")); @@ -227,13 +227,13 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan public AsyncReply Subscribe(string eventName) { - var et = Instance.Template.GetEventTemplateByName(eventName); + var et = Instance.Definition.GetEventDefByName(eventName); return Subscribe(et); } - public AsyncReply Unsubscribe(EventTemplate et) + public AsyncReply Unsubscribe(EventDef et) { if (et == null) return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, "")); @@ -246,7 +246,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan public AsyncReply Unsubscribe(string eventName) { - var et = Instance.Template.GetEventTemplateByName(eventName); + var et = Instance.Definition.GetEventDefByName(eventName); return Unsubscribe(et); } @@ -260,7 +260,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan if (suspended) throw new Exception("Trying to access a suspended object."); - var ft = Instance.Template.GetFunctionTemplateByName(binder.Name); + var ft = Instance.Definition.GetFunctionDefByName(binder.Name); var reply = new AsyncReply(); @@ -345,7 +345,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan if (!attached) return false; - var pt = Instance.Template.GetPropertyTemplateByName(binder.Name); + var pt = Instance.Definition.GetPropertyDefByName(binder.Name); if (pt != null) { @@ -354,7 +354,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan } else { - var et = Instance.Template.GetEventTemplateByName(binder.Name); + var et = Instance.Definition.GetEventDefByName(binder.Name); if (et == null) return false; @@ -367,7 +367,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan internal void _UpdatePropertyByIndex(byte index, object value) { - var pt = Instance.Template.GetPropertyTemplateByIndex(index); + var pt = Instance.Definition.GetPropertyDefByIndex(index); properties[index] = value; Instance.EmitModification(pt, value); } @@ -403,7 +403,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan if (!attached) return false; - var pt = Instance.Template.GetPropertyTemplateByName(binder.Name); + var pt = Instance.Definition.GetPropertyDefByName(binder.Name); if (pt != null) { @@ -412,7 +412,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan } else { - var et = Instance.Template.GetEventTemplateByName(binder.Name); + var et = Instance.Definition.GetEventDefByName(binder.Name); if (et == null) return false; @@ -433,15 +433,15 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan set; } - public TypeTemplate ResourceTemplate + public TypeDef ResourceDefinition { get { - return template; + return typeDef; } internal set { - template = value; + typeDef = value; } } diff --git a/Esiur/Net/IIP/DistributedServer.cs b/Esiur/Net/IIP/DistributedServer.cs index 66e8f10..2b01aa9 100644 --- a/Esiur/Net/IIP/DistributedServer.cs +++ b/Esiur/Net/IIP/DistributedServer.cs @@ -35,7 +35,7 @@ using System.Net; using Esiur.Resource; using Esiur.Security.Membership; using System.Threading.Tasks; -using Esiur.Resource.Template; +using Esiur.Data.Schema; namespace Esiur.Net.IIP; public class DistributedServer : NetworkServer, IResource @@ -168,13 +168,13 @@ public class DistributedServer : NetworkServer, IResource public struct CallInfo { - public FunctionTemplate Template; + public FunctionDefinition Template; public Delegate Delegate; } public DistributedServer MapCall(string call, Delegate handler) { - var ft = FunctionTemplate.MakeFunctionTemplate(null, handler.Method, 0, call, null); + var ft = FunctionDefinition.MakeFunctionDef(null, handler.Method, 0, call, null); Calls.Add(call, new CallInfo() { Delegate = handler, Template = ft }); return this; } diff --git a/Esiur/Net/IIP/EntryPoint.cs b/Esiur/Net/IIP/EntryPoint.cs index 148534e..122f546 100644 --- a/Esiur/Net/IIP/EntryPoint.cs +++ b/Esiur/Net/IIP/EntryPoint.cs @@ -27,7 +27,7 @@ using System.Text; using Esiur.Core; using Esiur.Data; using Esiur.Resource; -using Esiur.Resource.Template; +using Esiur.Data.Schema; namespace Esiur.Net.IIP; diff --git a/Esiur/Net/Packets/IIPPacketAttachInfo.cs b/Esiur/Net/Packets/IIPPacketAttachInfo.cs index d2a7770..2e746e3 100644 --- a/Esiur/Net/Packets/IIPPacketAttachInfo.cs +++ b/Esiur/Net/Packets/IIPPacketAttachInfo.cs @@ -10,11 +10,11 @@ struct IIPPacketAttachInfo public string Link; public ulong Age; public byte[] Content; - public UUID ClassId; + public UUID TypeId; - public IIPPacketAttachInfo(UUID classId, ulong age, string link, byte[] content) + public IIPPacketAttachInfo(UUID typeId, ulong age, string link, byte[] content) { - ClassId = classId; + TypeId = typeId; Age = age; Content = content; Link = link; diff --git a/Esiur/Net/Packets/IIPPacketRequest.cs b/Esiur/Net/Packets/IIPPacketRequest.cs index 306a67b..73336f4 100644 --- a/Esiur/Net/Packets/IIPPacketRequest.cs +++ b/Esiur/Net/Packets/IIPPacketRequest.cs @@ -13,11 +13,11 @@ namespace Esiur.Net.Packets Unsubscribe = 0x3, // Request Inquire - TemplateFromClassName = 0x8, - TemplateFromClassId = 0x9, - TemplateFromResourceId = 0xA, + SchemaFromClassName = 0x8, + SchemaFromClassId = 0x9, + SchemaFromResourceId = 0xA, Query = 0xB, - LinkTemplates = 0xC, + LinkSchemas = 0xC, Token = 0xD, GetResourceIdByLink = 0xE, diff --git a/Esiur/Proxy/ResourceGenerator.cs b/Esiur/Proxy/ResourceGenerator.cs index cd75b08..837a73f 100644 --- a/Esiur/Proxy/ResourceGenerator.cs +++ b/Esiur/Proxy/ResourceGenerator.cs @@ -4,9 +4,9 @@ // ================================ using Esiur.Core; using Esiur.Data; +using Esiur.Data.Types; using Esiur.Net.IIP; using Esiur.Resource; -using Esiur.Resource.Template; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -57,7 +57,7 @@ namespace Esiur.Proxy var parts = TemplateGenerator.urlRegex.Split(path); var con = Warehouse.Default.Get($"{parts[1]}://{parts[2]}").Wait(20000); - var templates = con.GetLinkTemplates(parts[3]).Wait(60000); + var templates = con.GetLinkDefinitions(parts[3]).Wait(60000); EmitTemplates(spc, templates); } @@ -222,26 +222,26 @@ $@" public partial class {ci.Name} : IResource {{ } // === Emission helpers (ported from your original generator) === - private static void EmitTemplates(SourceProductionContext spc, TypeTemplate[] templates) + private static void EmitTemplates(SourceProductionContext spc, TypeDef[] templates) { foreach (var tmp in templates) { - if (tmp.Type == TemplateType.Resource) + if (tmp.Kind == TypeDefKind.Resource) { var source = TemplateGenerator.GenerateClass(tmp, templates, false); - spc.AddSource(tmp.ClassName + ".g.cs", source); + spc.AddSource(tmp.Name + ".g.cs", source); } - else if (tmp.Type == TemplateType.Record) + else if (tmp.Kind == TypeDefKind.Record) { var source = TemplateGenerator.GenerateRecord(tmp, templates); - spc.AddSource(tmp.ClassName + ".g.cs", source); + spc.AddSource(tmp.Name + ".g.cs", source); } } var typesFile = "using System; \r\n namespace Esiur { public static class Generated { public static Type[] Resources {get;} = new Type[] { " + - string.Join(",", templates.Where(x => x.Type == TemplateType.Resource).Select(x => $"typeof({x.ClassName})")) + string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Resource).Select(x => $"typeof({x.ClassName})")) + " }; \r\n public static Type[] Records { get; } = new Type[] { " + - string.Join(",", templates.Where(x => x.Type == TemplateType.Record).Select(x => $"typeof({x.ClassName})")) + string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Record).Select(x => $"typeof({x.ClassName})")) + " }; " + "\r\n } \r\n}"; diff --git a/Esiur/Proxy/TemplateGenerator.cs b/Esiur/Proxy/TemplateGenerator.cs index a684a78..bf81aa0 100644 --- a/Esiur/Proxy/TemplateGenerator.cs +++ b/Esiur/Proxy/TemplateGenerator.cs @@ -1,5 +1,4 @@ using Esiur.Data; -using Esiur.Resource.Template; using System; using System.Collections.Generic; using System.IO; @@ -9,6 +8,7 @@ using System.Text.RegularExpressions; using Esiur.Resource; using Esiur.Net.IIP; using System.Diagnostics; +using Esiur.Data.Types; namespace Esiur.Proxy; @@ -61,9 +61,9 @@ public static class TemplateGenerator } - internal static string GenerateRecord(TypeTemplate template, TypeTemplate[] templates) + internal static string GenerateRecord(TypeDef typeDef, TypeDef[] templates) { - var cls = template.ClassName.Split('.'); + var cls = typeDef.Name.Split('.'); var nameSpace = string.Join(".", cls.Take(cls.Length - 1)); var className = cls.Last(); @@ -74,19 +74,19 @@ public static class TemplateGenerator rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Net.IIP;"); rt.AppendLine($"namespace {nameSpace} {{"); - if (template.Annotations != null) + if (typeDef.Annotations != null) { - foreach (var ann in template.Annotations) + foreach (var ann in typeDef.Annotations) { rt.AppendLine($"[Annotation({ToLiteral(ann.Key)}, {ToLiteral(ann.Value)})]"); } } - rt.AppendLine($"[ClassId(\"{template.ClassId.Data.ToHex(0, 16, null)}\")]"); + rt.AppendLine($"[ClassId(\"{typeDef.Id.Data.ToHex(0, 16, null)}\")]"); rt.AppendLine($"[Export] public class {className} : IRecord {{"); - foreach (var p in template.Properties) + foreach (var p in typeDef.Properties) { var ptTypeName = GetTypeName(p.ValueType, templates); @@ -109,9 +109,9 @@ public static class TemplateGenerator return rt.ToString(); } - internal static string GenerateEnum(TypeTemplate template, TypeTemplate[] templates) + internal static string GenerateEnum(TypeDef template, TypeDef[] templates) { - var cls = template.ClassName.Split('.'); + var cls = template.Name.Split('.'); var nameSpace = string.Join(".", cls.Take(cls.Length - 1)); var className = cls.Last(); @@ -129,7 +129,7 @@ public static class TemplateGenerator } } - rt.AppendLine($"[ClassId(\"{template.ClassId.Data.ToHex(0, 16, null)}\")]"); + rt.AppendLine($"[ClassId(\"{template.Id.Data.ToHex(0, 16, null)}\")]"); rt.AppendLine($"[Export] public enum {className} {{"); rt.AppendLine(String.Join(",\r\n", template.Constants.Select(x => $"{x.Name}={x.Value}"))); @@ -140,16 +140,16 @@ public static class TemplateGenerator } - static string GetTypeName(TRU representationType, TypeTemplate[] templates) + static string GetTypeName(TRU representationType, TypeDef[] templates) { string name; if (representationType.Identifier == TRUIdentifier.TypedResource)// == DataType.Resource) - name = templates.First(x => x.ClassId == representationType.UUID && (x.Type == TemplateType.Resource)).ClassName; + name = templates.First(x => x.Id == representationType.UUID && (x.Kind == TypeDefKind.Resource)).Name; else if (representationType.Identifier == TRUIdentifier.TypedRecord) - name = templates.First(x => x.ClassId == representationType.UUID && x.Type == TemplateType.Record).ClassName; + name = templates.First(x => x.Id == representationType.UUID && x.Kind == TypeDefKind.Record).Name; else if (representationType.Identifier == TRUIdentifier.Enum) - name = templates.First(x => x.ClassId == representationType.UUID && x.Type == TemplateType.Enum).ClassName; + name = templates.First(x => x.Id == representationType.UUID && x.Kind == TypeDefKind.Enum).Name; else if (representationType.Identifier == TRUIdentifier.TypedList) name = GetTypeName(representationType.SubTypes[0], templates) + "[]"; else if (representationType.Identifier == TRUIdentifier.TypedMap) @@ -215,7 +215,7 @@ public static class TemplateGenerator if (string.IsNullOrEmpty(dir)) dir = path[2].Replace(":", "_"); - var templates = con.GetLinkTemplates(path[3]).Wait(60000); + var templates = con.GetLinkDefinitions(path[3]).Wait(60000); // no longer needed Warehouse.Default.Remove(con); @@ -233,20 +233,20 @@ public static class TemplateGenerator // make sources foreach (var tmp in templates) { - if (tmp.Type == TemplateType.Resource) + if (tmp.Kind == TypeDefKind.Resource) { var source = GenerateClass(tmp, templates, asyncSetters); - File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".g.cs", source); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.Name + ".g.cs", source); } - else if (tmp.Type == TemplateType.Record) + else if (tmp.Kind == TypeDefKind.Record) { var source = GenerateRecord(tmp, templates); - File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".g.cs", source); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.Name + ".g.cs", source); } - else if (tmp.Type == TemplateType.Enum) + else if (tmp.Kind == TypeDefKind.Enum) { var source = GenerateEnum(tmp, templates); - File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".g.cs", source); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.Name + ".g.cs", source); } } @@ -256,13 +256,13 @@ public static class TemplateGenerator namespace Esiur { public static class Generated { public static Type[] Resources {get;} = new Type[] { " + - string.Join(",", templates.Where(x => x.Type == TemplateType.Resource).Select(x => $"typeof({x.ClassName})")) + string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Resource).Select(x => $"typeof({x.Name})")) + @" }; public static Type[] Records { get; } = new Type[] { " + - string.Join(",", templates.Where(x => x.Type == TemplateType.Record).Select(x => $"typeof({x.ClassName})")) + string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Record).Select(x => $"typeof({x.Name})")) + @" }; public static Type[] Enums { get; } = new Type[] { " + - string.Join(",", templates.Where(x => x.Type == TemplateType.Enum).Select(x => $"typeof({x.ClassName})")) + string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Enum).Select(x => $"typeof({x.Name})")) + @" };" + "\r\n } \r\n}"; @@ -279,9 +279,9 @@ public static class TemplateGenerator } } - internal static string GenerateClass(TypeTemplate template, TypeTemplate[] templates, bool asyncSetters) + internal static string GenerateClass(TypeDef template, TypeDef[] templates, bool asyncSetters) { - var cls = template.ClassName.Split('.'); + var cls = template.Name.Split('.'); var nameSpace = string.Join(".", cls.Take(cls.Length - 1)); var className = cls.Last(); @@ -302,13 +302,13 @@ public static class TemplateGenerator } - rt.AppendLine($"[ClassId(\"{template.ClassId.Data.ToHex(0, 16, null)}\")]"); + rt.AppendLine($"[ClassId(\"{template.Id.Data.ToHex(0, 16, null)}\")]"); // extends if (template.ParentId == null) rt.AppendLine($"public class {className} : DistributedResource {{"); else - rt.AppendLine($"public class {className} : {templates.First(x => x.ClassId == template.ParentId && x.Type == TemplateType.Resource).ClassName} {{"); + rt.AppendLine($"public class {className} : {templates.First(x => x.Id == template.ParentId && x.Kind == TypeDefKind.Resource).Name} {{"); rt.AppendLine($"public {className}(DistributedConnection connection, uint instanceId, ulong age, string link) : base(connection, instanceId, age, link) {{}}"); @@ -378,7 +378,7 @@ public static class TemplateGenerator rt.AppendLine($"var rt = new AsyncReply<{rtTypeName}>();"); if (f.IsStatic) - rt.AppendLine($"connection.StaticCall(Guid.Parse(\"{template.ClassId.ToString()}\"), {f.Index}, args)"); + rt.AppendLine($"connection.StaticCall(Guid.Parse(\"{template.Id.ToString()}\"), {f.Index}, args)"); else rt.AppendLine($"_Invoke({f.Index}, args)"); diff --git a/Esiur/Resource/CustomEventOccurredInfo.cs b/Esiur/Resource/CustomEventOccurredInfo.cs index 3857bf9..a72b796 100644 --- a/Esiur/Resource/CustomEventOccurredInfo.cs +++ b/Esiur/Resource/CustomEventOccurredInfo.cs @@ -1,4 +1,4 @@ -using Esiur.Resource.Template; +using Esiur.Data.Types; using Esiur.Security.Authority; using System; using System.Collections.Generic; @@ -8,7 +8,7 @@ namespace Esiur.Resource; public class CustomEventOccurredInfo { - public readonly EventTemplate EventTemplate; + public readonly EventDef EventTemplate; public readonly IResource Resource; public readonly object Value; public readonly object Issuer; @@ -16,7 +16,7 @@ public class CustomEventOccurredInfo public string Name => EventTemplate.Name; - public CustomEventOccurredInfo(IResource resource, EventTemplate eventTemplate, Func receivers, object issuer, object value) + public CustomEventOccurredInfo(IResource resource, EventDef eventTemplate, Func receivers, object issuer, object value) { Resource = resource; EventTemplate = eventTemplate; diff --git a/Esiur/Resource/EventOccurredInfo.cs b/Esiur/Resource/EventOccurredInfo.cs index 4ad931e..f2ebfc2 100644 --- a/Esiur/Resource/EventOccurredInfo.cs +++ b/Esiur/Resource/EventOccurredInfo.cs @@ -1,4 +1,4 @@ -using Esiur.Resource.Template; +using Esiur.Data.Types; using System; using System.Collections.Generic; using System.Text; @@ -9,18 +9,18 @@ namespace Esiur.Resource public class EventOccurredInfo { - public readonly EventTemplate EventTemplate; + public readonly EventDef Definition; - public string Name => EventTemplate.Name; + public string Name => Definition.Name; public readonly IResource Resource; public readonly object Value; - public EventOccurredInfo(IResource resource, EventTemplate eventTemplate, object value) + public EventOccurredInfo(IResource resource, EventDef eventDef, object value) { Resource = resource; Value = value; - EventTemplate = eventTemplate; + Definition = eventDef; } } } diff --git a/Esiur/Resource/ExportAttribute.cs b/Esiur/Resource/ExportAttribute.cs index a8331d9..97436d2 100644 --- a/Esiur/Resource/ExportAttribute.cs +++ b/Esiur/Resource/ExportAttribute.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Text; using System.Xml.Linq; -using static Esiur.Resource.Template.PropertyTemplate; namespace Esiur.Resource; diff --git a/Esiur/Resource/IStore.cs b/Esiur/Resource/IStore.cs index 4fd70e0..f149306 100644 --- a/Esiur/Resource/IStore.cs +++ b/Esiur/Resource/IStore.cs @@ -24,7 +24,6 @@ SOFTWARE. using Esiur.Data; using Esiur.Core; -using Esiur.Resource.Template; using System; using System.Collections.Generic; using System.Linq; @@ -32,6 +31,7 @@ using System.Text; using System.Threading.Tasks; using Esiur.Security.Permissions; using Esiur.Security.Authority; +using Esiur.Data.Schema; namespace Esiur.Resource; public interface IStore : IResource @@ -73,5 +73,5 @@ public interface IStore : IResource //AsyncReply> GetRecord(IResource resource, ulong fromAge, ulong toAge); // AsyncReply> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate); - AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate); + AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate); } diff --git a/Esiur/Resource/Instance.cs b/Esiur/Resource/Instance.cs index f6edf74..2f41deb 100644 --- a/Esiur/Resource/Instance.cs +++ b/Esiur/Resource/Instance.cs @@ -9,13 +9,13 @@ using System.Reflection; using Esiur.Net.IIP; using Esiur.Misc; using Esiur.Security.Permissions; -using Esiur.Resource.Template; using Esiur.Security.Authority; using Esiur.Proxy; using Esiur.Core; using System.Text.Json; using System.ComponentModel.DataAnnotations.Schema; using System.Reflection.Emit; +using Esiur.Data.Types; namespace Esiur.Resource; @@ -29,7 +29,7 @@ public class Instance WeakReference resource; IStore store; - TypeTemplate template; + TypeDef definition; AutoList managers; @@ -107,7 +107,7 @@ public class Instance { for (var i = 0; i < attributes.Length; i++) { - var at = template.GetAttributeTemplate(attributes[i]); + var at = definition.GetAttributeDef(attributes[i]); if (at != null) { @@ -128,7 +128,7 @@ public class Instance { foreach (var kv in attributes) { - var at = template.GetAttributeTemplate(kv.Key); + var at = definition.GetAttributeDef(kv.Key); if (at != null) if (at.PropertyInfo.CanWrite) @@ -287,7 +287,7 @@ public class Instance if (!resource.TryGetTarget(out res)) return false; - var pt = template.GetPropertyTemplateByName(name); + var pt = definition.GetPropertyDefByName(name); if (pt == null) return false; @@ -376,7 +376,7 @@ public class Instance { for (byte i = 0; i < properties.Length; i++) { - var pt = this.template.GetPropertyTemplateByIndex(i); + var pt = this.definition.GetPropertyDefByIndex(i); if (pt != null) { var pv = properties[i]; @@ -413,7 +413,7 @@ public class Instance var props = new List(); - foreach (var pt in template.Properties) + foreach (var pt in definition.Properties) { var rt = pt.PropertyInfo.GetValue(res, null); props.Add(new PropertyValue(rt, ages[pt.Index], modificationDates[pt.Index])); @@ -438,7 +438,7 @@ public class Instance var props = new Map(); - foreach (var pt in template.Properties) + foreach (var pt in definition.Properties) { if (res.Instance.GetAge(pt.Index) > age) { @@ -470,7 +470,7 @@ public class Instance } - internal void EmitModification(PropertyTemplate pt, object value) + internal void EmitModification(PropertyDef pt, object value) { IResource res; @@ -511,7 +511,7 @@ public class Instance object value; if (TryGetPropertyValue(propertyName, out value)) { - var pt = template.GetPropertyTemplateByName(propertyName); + var pt = definition.GetPropertyDefByName(propertyName); EmitModification(pt, value); } } @@ -520,21 +520,21 @@ public class Instance // internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args) - internal void EmitCustomResourceEvent(object issuer, Func receivers, EventTemplate eventTemplate, object value) + internal void EmitCustomResourceEvent(object issuer, Func receivers, EventDef eventDef, object value) { IResource res; if (this.resource.TryGetTarget(out res)) { - CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventTemplate, receivers, issuer, value)); + CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventDef, receivers, issuer, value)); } } - internal void EmitResourceEvent(EventTemplate eventTemplate, object value) + internal void EmitResourceEvent(EventDef eventDef, object value) { IResource res; if (this.resource.TryGetTarget(out res)) { - EventOccurred?.Invoke(new EventOccurredInfo(res, eventTemplate, value)); + EventOccurred?.Invoke(new EventOccurredInfo(res, eventDef, value)); } } @@ -543,8 +543,8 @@ public class Instance IResource res; if (this.resource.TryGetTarget(out res)) { - var eventTemplate = template.GetEventTemplateByIndex(eventIndex); - EventOccurred?.Invoke(new EventOccurredInfo(res, eventTemplate, value)); + var eventDef = definition.GetEventDefByIndex(eventIndex); + EventOccurred?.Invoke(new EventOccurredInfo(res, eventDef, value)); } } @@ -553,8 +553,8 @@ public class Instance IResource res; if (this.resource.TryGetTarget(out res)) { - var eventTemplate = template.GetEventTemplateByIndex(eventIndex); - CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventTemplate, receivers, issuer, value)); + var eventDef = definition.GetEventDefByIndex(eventIndex); + CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventDef, receivers, issuer, value)); } } @@ -567,7 +567,7 @@ public class Instance /// True, if the resource has the property. public bool TryGetPropertyValue(string name, out object value) { - var pt = template.GetPropertyTemplateByName(name); + var pt = definition.GetPropertyDefByName(name); IResource res; if (resource.TryGetTarget(out res)) @@ -680,9 +680,9 @@ public class Instance /// /// Resource template describes the properties, functions and events of the resource. /// - public TypeTemplate Template + public TypeDef Definition { - get { return template; } + get { return definition; } /* internal set @@ -707,7 +707,7 @@ public class Instance /// Function, property or event to check for permission. /// Permission inquirer. /// Ruling. - public Ruling Applicable(Session session, ActionType action, MemberTemplate member, object inquirer = null) + public Ruling Applicable(Session session, ActionType action, MemberDef member, object inquirer = null) { IResource res; if (this.resource.TryGetTarget(out res)) @@ -762,15 +762,15 @@ public class Instance if (resource is IDynamicResource dynamicResource) { - this.template = dynamicResource.ResourceTemplate; + this.definition = dynamicResource.ResourceDefinition; } else { - this.template = Warehouse.GetTemplateByType(resource.GetType()); + this.definition = Warehouse.GetTemplateByType(resource.GetType()); } // set ages - for (byte i = 0; i < template.Properties.Length; i++) + for (byte i = 0; i < definition.Properties.Length; i++) { ages.Add(0); modificationDates.Add(DateTime.MinValue); @@ -788,7 +788,7 @@ public class Instance var emitEventByIndexMethod = GetType().GetMethod("EmitResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic); var emitCustomEventByIndexMethod = GetType().GetMethod("EmitCustomResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic); - foreach (var evt in template.Events) + foreach (var evt in definition.Events) { if (evt.EventInfo == null) diff --git a/Esiur/Resource/PropertyModificationInfo.cs b/Esiur/Resource/PropertyModificationInfo.cs index 6c31b71..3be52ac 100644 --- a/Esiur/Resource/PropertyModificationInfo.cs +++ b/Esiur/Resource/PropertyModificationInfo.cs @@ -1,20 +1,20 @@ using System; using System.Collections.Generic; using System.Text; +using Esiur.Data.Types; using Esiur.Resource; -using Esiur.Resource.Template; namespace Esiur.Resource; public struct PropertyModificationInfo { public readonly IResource Resource; - public readonly PropertyTemplate PropertyTemplate; + public readonly PropertyDef PropertyTemplate; public string Name => PropertyTemplate.Name; public readonly ulong Age; public object Value; - public PropertyModificationInfo(IResource resource, PropertyTemplate propertyTemplate, object value, ulong age) + public PropertyModificationInfo(IResource resource, PropertyDef propertyTemplate, object value, ulong age) { Resource = resource; PropertyTemplate = propertyTemplate; diff --git a/Esiur/Resource/StoreGeneric.cs b/Esiur/Resource/StoreGeneric.cs index 8dad38c..0fcfb5a 100644 --- a/Esiur/Resource/StoreGeneric.cs +++ b/Esiur/Resource/StoreGeneric.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using Esiur.Core; using Esiur.Data; -using Esiur.Resource.Template; +using Esiur.Data.Schema; namespace Esiur.Resource; public abstract class Store : IStore where T : IResource @@ -23,7 +23,7 @@ public abstract class Store : IStore where T : IResource public abstract AsyncReply Get(string path); - public abstract AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate); + public abstract AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate); public abstract string Link(IResource resource); diff --git a/Esiur/Resource/Template/CustomEventOccurredEvent.cs b/Esiur/Resource/Template/CustomEventOccurredEvent.cs deleted file mode 100644 index b0da4f7..0000000 --- a/Esiur/Resource/Template/CustomEventOccurredEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Esiur.Resource.Template -{ - internal class CustomEventOccurredEvent - { - } -} diff --git a/Esiur/Resource/Warehouse.cs b/Esiur/Resource/Warehouse.cs index 38e6c88..233ec9d 100644 --- a/Esiur/Resource/Warehouse.cs +++ b/Esiur/Resource/Warehouse.cs @@ -24,11 +24,11 @@ SOFTWARE. using Esiur.Core; using Esiur.Data; +using Esiur.Data.Types; using Esiur.Misc; using Esiur.Net.IIP; using Esiur.Net.Packets; using Esiur.Proxy; -using Esiur.Resource.Template; using Esiur.Security.Permissions; using System; using System.Collections; @@ -36,6 +36,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -58,14 +59,14 @@ public class Warehouse uint resourceCounter = 0; - KeyList> templates - = new KeyList>() + KeyList> schemas + = new KeyList>() { - //[TemplateType.Unspecified] = new KeyList(), - [TemplateType.Resource] = new KeyList(), - [TemplateType.Record] = new KeyList(), - //[TemplateType.Wrapper] = new KeyList(), - [TemplateType.Enum] = new KeyList(), + //[TemplateType.Unspecified] = new KeyList(), + [TypeDefKind.Resource] = new KeyList(), + [TypeDefKind.Record] = new KeyList(), + //[TemplateType.Wrapper] = new KeyList(), + [TypeDefKind.Enum] = new KeyList(), }; bool warehouseIsOpen = false; @@ -87,10 +88,10 @@ public class Warehouse async (name, attributes) => await New(name, null, attributes)); - new TypeTemplate(typeof(IIPAuthPacketIAuthHeader), this); + new TypeDef(typeof(IIPAuthPacketIAuthHeader), this); - new TypeTemplate(typeof(IIPAuthPacketIAuthDestination), this); - new TypeTemplate(typeof(IIPAuthPacketIAuthFormat), this); + new TypeDef(typeof(IIPAuthPacketIAuthDestination), this); + new TypeDef(typeof(IIPAuthPacketIAuthFormat), this); } @@ -138,19 +139,19 @@ public class Warehouse var resourceTypes = (Type[])generatedType.GetProperty("Resources").GetValue(null); foreach (var t in resourceTypes) { - PutTemplate(new TypeTemplate(t)); + RegisterSchema(new TypeDef(t)); } var recordTypes = (Type[])generatedType.GetProperty("Records").GetValue(null); foreach (var t in recordTypes) { - PutTemplate(new TypeTemplate(t)); + RegisterSchema(new TypeDef(t)); } var enumsTypes = (Type[])generatedType.GetProperty("Enums").GetValue(null); foreach (var t in enumsTypes) { - PutTemplate(new TypeTemplate(t)); + RegisterSchema(new TypeDef(t)); } } } @@ -192,7 +193,7 @@ public class Warehouse if (!rt) { - Global.Log("Warehouse", LogType.Warning, $"Resource failed at Initialize {r.Instance.Name} [{r.Instance.Template.ClassName}]"); + Global.Log("Warehouse", LogType.Warning, $"Resource failed at Initialize {r.Instance.Name} [{r.Instance.Definition.Name}]"); } //} } @@ -202,7 +203,7 @@ public class Warehouse var rt = await r.Trigger(ResourceTrigger.SystemInitialized); if (!rt) { - Global.Log("Warehouse", LogType.Warning, $"Resource failed at SystemInitialized {r.Instance.Name} [{r.Instance.Template.ClassName}]"); + Global.Log("Warehouse", LogType.Warning, $"Resource failed at SystemInitialized {r.Instance.Name} [{r.Instance.Definition.Name}]"); } } @@ -345,7 +346,7 @@ public class Warehouse /// Resource instance. /// IStore that manages the resource. Can be null if the resource is a store. /// Parent resource. if not presented the store becomes the parent for the resource. - //public async AsyncReply Put(string instanceName, T resource, IStore store, TypeTemplate customTemplate = null, ulong age = 0, IPermissionsManager manager = null, object attributes = null) where T : IResource + //public async AsyncReply Put(string instanceName, T resource, IStore store, TypeSchema customTemplate = null, ulong age = 0, IPermissionsManager manager = null, object attributes = null) where T : IResource //{ // if (resource.Instance != null) // throw new Exception("Resource has a store."); @@ -526,7 +527,7 @@ public class Warehouse { var template = GetTemplateByType(type); foreach (var kvp in map) - template.GetPropertyTemplateByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value); + template.GetPropertyDefByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value); } else { @@ -584,15 +585,15 @@ public class Warehouse } /// - /// Put a resource template in the templates warehouse. + /// Put a resource schema in the schemas warehouse. /// - /// Resource template. - public void PutTemplate(TypeTemplate template) + /// Resource schema. + public void RegisterSchema(TypeDef typeDef) { - if (templates[template.Type].ContainsKey(template.ClassId)) - throw new Exception($"Template with same class Id already exists. {templates[template.Type][template.ClassId].ClassName} -> {template.ClassName}"); + if (schemas[typeDef.Kind].ContainsKey(typeDef.Id)) + throw new Exception($"Template with same class Id already exists. {schemas[typeDef.Kind][typeDef.Id].Name} -> {typeDef.Name}"); - templates[template.Type][template.ClassId] = template; + schemas[typeDef.Kind][typeDef.Id] = typeDef; } @@ -601,7 +602,7 @@ public class Warehouse /// /// .Net type. /// Resource template. - public TypeTemplate GetTemplateByType(Type type) + public TypeDef GetTemplateByType(Type type) { if (!(type.IsClass || type.IsEnum)) return null; @@ -612,48 +613,48 @@ public class Warehouse || baseType == typeof(IRecord)) return null; - TemplateType templateType; + TypeDefKind schemaKind; if (Codec.ImplementsInterface(type, typeof(IResource))) - templateType = TemplateType.Resource; + schemaKind = TypeDefKind.Resource; else if (Codec.ImplementsInterface(type, typeof(IRecord))) - templateType = TemplateType.Record; + schemaKind = TypeDefKind.Record; else if (type.IsEnum) - templateType = TemplateType.Enum; + schemaKind = TypeDefKind.Enum; else return null; - var template = templates[templateType].Values.FirstOrDefault(x => x.DefinedType == baseType); - if (template != null) - return template; + var schema = schemas[schemaKind].Values.FirstOrDefault(x => x.DefinedType == baseType); + if (schema != null) + return schema; // create new template for type - template = new TypeTemplate(baseType, this); - TypeTemplate.GetDependencies(template, this); + schema = new TypeDef(baseType, this); + TypeDef.GetDependencies(schema, this); - return template; + return schema; } /// - /// Get a template by class Id from the templates warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse. + /// Get a schema by class Id from the templates warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse. /// /// Class Id. /// Resource template. - public TypeTemplate GetTemplateByClassId(UUID classId, TemplateType? templateType = null) + public TypeDef GetTypeDefById(UUID typeId, TypeDefKind? templateType = null) { if (templateType == null) { // look into resources - var template = templates[TemplateType.Resource][classId]; + var template = schemas[TypeDefKind.Resource][typeId]; if (template != null) return template; // look into records - template = templates[TemplateType.Record][classId]; + template = schemas[TypeDefKind.Record][typeId]; if (template != null) return template; // look into enums - template = templates[TemplateType.Enum][classId]; + template = schemas[TypeDefKind.Enum][typeId]; return template; //if (template != null) @@ -663,7 +664,7 @@ public class Warehouse //return template; } else - return templates[templateType.Value][classId]; + return schemas[templateType.Value][typeId]; } @@ -672,22 +673,22 @@ public class Warehouse /// /// Class name. /// Resource template. - public TypeTemplate GetTemplateByClassName(string className, TemplateType? templateType = null) + public TypeDef GetTypeDfByName(string typeName, TypeDefKind? templateType = null) { if (templateType == null) { // look into resources - var template = templates[TemplateType.Resource].Values.FirstOrDefault(x => x.ClassName == className); + var template = schemas[TypeDefKind.Resource].Values.FirstOrDefault(x => x.Name == typeName); if (template != null) return template; // look into records - template = templates[TemplateType.Record].Values.FirstOrDefault(x => x.ClassName == className); + template = schemas[TypeDefKind.Record].Values.FirstOrDefault(x => x.Name == typeName); if (template != null) return template; // look into enums - template = templates[TemplateType.Enum].Values.FirstOrDefault(x => x.ClassName == className); + template = schemas[TypeDefKind.Enum].Values.FirstOrDefault(x => x.Name == typeName); //if (template != null) return template; @@ -697,7 +698,7 @@ public class Warehouse } else { - return templates[templateType.Value].Values.FirstOrDefault(x => x.ClassName == className); + return schemas[templateType.Value].Values.FirstOrDefault(x => x.Name == typeName); } } diff --git a/Esiur/Security/Permissions/IPermissionsManager.cs b/Esiur/Security/Permissions/IPermissionsManager.cs index b4ede30..a7dec3e 100644 --- a/Esiur/Security/Permissions/IPermissionsManager.cs +++ b/Esiur/Security/Permissions/IPermissionsManager.cs @@ -26,13 +26,13 @@ using Esiur.Data; using Esiur.Core; using Esiur.Net; using Esiur.Resource; -using Esiur.Resource.Template; using Esiur.Security.Authority; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Esiur.Data.Types; namespace Esiur.Security.Permissions; @@ -47,7 +47,7 @@ public interface IPermissionsManager /// Function, property or event to check for permission. /// Permission inquirer object. /// Allowed or denined. - Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer = null); + Ruling Applicable(IResource resource, Session session, ActionType action, MemberDef member, object inquirer = null); bool Initialize(Map settings, IResource resource); diff --git a/Esiur/Security/Permissions/StorePermissionsManager.cs b/Esiur/Security/Permissions/StorePermissionsManager.cs index 4bec070..2de2350 100644 --- a/Esiur/Security/Permissions/StorePermissionsManager.cs +++ b/Esiur/Security/Permissions/StorePermissionsManager.cs @@ -28,8 +28,8 @@ using System.Text; using Esiur.Data; using Esiur.Core; using Esiur.Resource; -using Esiur.Resource.Template; using Esiur.Security.Authority; +using Esiur.Data.Schema; namespace Esiur.Security.Permissions; @@ -39,7 +39,7 @@ public class StorePermissionsManager : IPermissionsManager public Map Settings => settings; - public Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer = null) + public Ruling Applicable(IResource resource, Session session, ActionType action, MemberDefinition member, object inquirer = null) { return resource.Instance.Store.Instance.Applicable(session, action, member, inquirer); } diff --git a/Esiur/Security/Permissions/UserPermissionsManager.cs b/Esiur/Security/Permissions/UserPermissionsManager.cs index c3e4082..fa8ed64 100644 --- a/Esiur/Security/Permissions/UserPermissionsManager.cs +++ b/Esiur/Security/Permissions/UserPermissionsManager.cs @@ -28,8 +28,8 @@ using System.Text; using Esiur.Data; using Esiur.Core; using Esiur.Resource; -using Esiur.Resource.Template; using Esiur.Security.Authority; +using Esiur.Data.Schema; namespace Esiur.Security.Permissions; @@ -40,7 +40,7 @@ public class UserPermissionsManager : IPermissionsManager public Map Settings => settings; - public Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer) + public Ruling Applicable(IResource resource, Session session, ActionType action, MemberDefinition member, object inquirer) { Map userPermissions = null; diff --git a/Esiur/Stores/MemoryStore.cs b/Esiur/Stores/MemoryStore.cs index a65b093..d561620 100644 --- a/Esiur/Stores/MemoryStore.cs +++ b/Esiur/Stores/MemoryStore.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using Esiur.Core; using Esiur.Data; -using Esiur.Resource.Template; +using Esiur.Data.Schema; namespace Esiur.Stores; @@ -78,7 +78,7 @@ public class MemoryStore : IStore throw new NotImplementedException(); } - public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) + public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) { throw new NotImplementedException(); } diff --git a/Esiur/Stores/TemporaryStore.cs b/Esiur/Stores/TemporaryStore.cs index 2c433f9..495b62c 100644 --- a/Esiur/Stores/TemporaryStore.cs +++ b/Esiur/Stores/TemporaryStore.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using Esiur.Core; using Esiur.Data; -using Esiur.Resource.Template; +using Esiur.Data.Schema; namespace Esiur.Stores; public class TemporaryStore : IStore @@ -69,7 +69,7 @@ public class TemporaryStore : IStore throw new NotImplementedException(); } - public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) + public AsyncReply> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) { throw new NotImplementedException(); } diff --git a/Test/Program.cs b/Test/Program.cs index 396f62a..d0a28af 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -36,7 +36,7 @@ using System.Threading.Tasks; using Esiur.Security.Integrity; using System.Linq; -using Esiur.Resource.Template; +using Esiur.Data.Types; using System.Collections; using System.Runtime.CompilerServices; using Esiur.Proxy; @@ -298,7 +298,7 @@ namespace Test static void TestObjectProps(IResource local, DistributedResource remote) { - foreach (var pt in local.Instance.Template.Properties) + foreach (var pt in local.Instance.Definition.Properties) { var lv = pt.PropertyInfo.GetValue(local);