2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-03-31 10:28:21 +00:00
This commit is contained in:
2026-03-17 19:10:20 +03:00
parent 3f7e3992c1
commit 8fc07d6350
50 changed files with 443 additions and 434 deletions

View File

@@ -25,7 +25,6 @@ SOFTWARE.
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -35,6 +34,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using System.Reflection; using System.Reflection;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using System.Collections; using System.Collections;
using Esiur.Data.Schema;
namespace Esiur.Stores.EntityCore; namespace Esiur.Stores.EntityCore;
public class EntityStore : IStore public class EntityStore : IStore
@@ -216,7 +216,7 @@ public class EntityStore : IStore
throw new NotImplementedException(); throw new NotImplementedException();
} }
public AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -131,7 +131,7 @@ public static class EsiurExtensions
var id = store.TypesByType[typeof(T)].PrimaryKey.GetValue(resource); 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; return (T)res;
} }

View File

@@ -71,7 +71,7 @@ public class EsiurProxyRewrite : IModelFinalizingConvention
// check if the object exists // check if the object exists
var obj = options.Warehouse.Create(entityType.ClrType) as IResource; var obj = options.Warehouse.Create(entityType.ClrType) as IResource;
options.Store.TypesByType[entityType.ClrType].PrimaryKey.SetValue(obj, id); 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; return obj;
} }
else else

View File

@@ -32,10 +32,10 @@ using Esiur.Data;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Resource.Template;
using System.Linq; using System.Linq;
using Esiur.Security.Permissions; using Esiur.Security.Permissions;
using Esiur.Proxy; using Esiur.Proxy;
using Esiur.Data.Schema;
namespace Esiur.Stores.MongoDB; namespace Esiur.Stores.MongoDB;
@@ -342,7 +342,7 @@ public class MongoDBStore : IStore
var parents = new BsonArray(); var parents = new BsonArray();
var children = new BsonArray(); var children = new BsonArray();
var template = resource.Instance.Template; var schema = resource.Instance.Schema;
// setup attributes // setup attributes
resource.Instance.Variables["children"] = new string[0]; resource.Instance.Variables["children"] = new string[0];
@@ -381,7 +381,7 @@ public class MongoDBStore : IStore
var values = new BsonDocument(); var values = new BsonDocument();
foreach (var pt in template.Properties) foreach (var pt in schema.Properties)
{ {
var rt = pt.PropertyInfo.GetValue(resource, null); var rt = pt.PropertyInfo.GetValue(resource, null);
@@ -594,7 +594,7 @@ public class MongoDBStore : IStore
var parents = new BsonArray(); var parents = new BsonArray();
var children = new BsonArray(); var children = new BsonArray();
var template = resource.Instance.Template; var schema = resource.Instance.Schema;
//foreach (IResource c in resource.Instance.Children) //foreach (IResource c in resource.Instance.Children)
// children.Add(c.Instance.Link); // children.Add(c.Instance.Link);
@@ -607,7 +607,7 @@ public class MongoDBStore : IStore
var values = new BsonDocument(); var values = new BsonDocument();
foreach (var pt in template.Properties) foreach (var pt in schema.Properties)
{ {
/* /*
#if NETSTANDARD1_5 #if NETSTANDARD1_5
@@ -728,11 +728,11 @@ public class MongoDBStore : IStore
return reply; return reply;
} }
AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecordByAge(IResource resource, ulong fromAge, ulong toAge) AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> 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<KeyList<PropertyTemplate, PropertyValue[]>>(); var reply = new AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>>();
AsyncBag<PropertyValue[]> bag = new AsyncBag<PropertyValue[]>(); AsyncBag<PropertyValue[]> bag = new AsyncBag<PropertyValue[]>();
@@ -743,7 +743,7 @@ public class MongoDBStore : IStore
bag.Then(x => bag.Then(x =>
{ {
var list = new KeyList<PropertyTemplate, PropertyValue[]>(); var list = new KeyList<PropertyDefinition, PropertyValue[]>();
for (var i = 0; i < x.Length; i++) for (var i = 0; i < x.Length; i++)
list.Add(properties[i], x[i]); list.Add(properties[i], x[i]);
@@ -754,11 +754,11 @@ public class MongoDBStore : IStore
return reply; return reply;
} }
public AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> 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<KeyList<PropertyTemplate, PropertyValue[]>>(); var reply = new AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>>();
AsyncBag<PropertyValue[]> bag = new AsyncBag<PropertyValue[]>(); AsyncBag<PropertyValue[]> bag = new AsyncBag<PropertyValue[]>();
@@ -769,7 +769,7 @@ public class MongoDBStore : IStore
bag.Then(x => bag.Then(x =>
{ {
var list = new KeyList<PropertyTemplate, PropertyValue[]>(); var list = new KeyList<PropertyDefinition, PropertyValue[]>();
for (var i = 0; i < x.Length; i++) for (var i = 0; i < x.Length; i++)
list.Add(properties[i], x[i]); list.Add(properties[i], x[i]);

View File

@@ -29,7 +29,7 @@ public enum ExceptionCode : ushort
UpdateAttributeFailed, UpdateAttributeFailed,
GetAttributesFailed, GetAttributesFailed,
ClearAttributesFailed, ClearAttributesFailed,
TemplateNotFound, TypeDefNotFound,
RenameDenied, RenameDenied,
ClassNotFound, ClassNotFound,
MethodNotFound, MethodNotFound,

View File

@@ -165,7 +165,7 @@ public static class DataDeserializer
var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Record); var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Record);
var initRecord = (TypeTemplate template) => var initRecord = (TypeSchema template) =>
{ {
ListParser(data, offset, length, connection, requestSequence).Then(r => ListParser(data, offset, length, connection, requestSequence).Then(r =>
{ {

View File

@@ -1,10 +1,10 @@
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Data.GVWIE; using Esiur.Data.GVWIE;
using Esiur.Data.Schema;
using Esiur.Misc; using Esiur.Misc;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using System; using System;
using System.Collections; using System.Collections;
@@ -397,7 +397,7 @@ public static class DataDeserializer
{ {
var classId = tdu.Metadata.GetUUID(0); var classId = tdu.Metadata.GetUUID(0);
var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, var template = connection.Instance.Warehouse.GetTemplateByClassId(classId,
TemplateType.Record); TypeDefKind.Record);
var rt = new AsyncReply<IRecord>(); var rt = new AsyncReply<IRecord>();
@@ -410,7 +410,7 @@ public static class DataDeserializer
var length = tdu.ContentLength; var length = tdu.ContentLength;
var ends = offset + (uint)length; var ends = offset + (uint)length;
var initRecord = (TypeTemplate template) => var initRecord = (TypeDef template) =>
{ {
for (var i = 0; i < template.Properties.Length; i++) 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 template = connection.Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Record);
//var initRecord = (TypeTemplate template) => //var initRecord = (TypeSchema template) =>
//{ //{
// ListParserAsync(tdu, connection, requestSequence).Then(r => // ListParserAsync(tdu, connection, requestSequence).Then(r =>
// { // {
@@ -585,12 +585,12 @@ public static class DataDeserializer
public static unsafe object RecordParser(ParsedTDU tdu, Warehouse warehouse) public static unsafe object RecordParser(ParsedTDU tdu, Warehouse warehouse)
{ {
var classId = tdu.Metadata.GetUUID(0); var classId = tdu.Metadata.GetUUID(0);
var template = warehouse.GetTemplateByClassId(classId, TemplateType.Record); var template = warehouse.GetTypeDefByClassId(classId, TypeDefKind.Record);
if (template == null) if (template == null)
{ {
// @TODO: add parse if no template settings // @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."); "Template not found for record.");
} }
@@ -691,7 +691,7 @@ public static class DataDeserializer
var index = tdu.Data[tdu.Offset]; var index = tdu.Data[tdu.Offset];
var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, var template = connection.Instance.Warehouse.GetTemplateByClassId(classId,
TemplateType.Enum); TypeDefKind.Enum);
if (template != null) if (template != null)
{ {
@@ -717,7 +717,7 @@ public static class DataDeserializer
var index = tdu.Data[tdu.Offset]; var index = tdu.Data[tdu.Offset];
var template = warehouse.GetTemplateByClassId(classId, TemplateType.Enum); var template = warehouse.GetTemplateByClassId(classId, TypeDefKind.Enum);
if (template != null) if (template != null)
{ {
@@ -725,7 +725,7 @@ public static class DataDeserializer
} }
else else
{ {
throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TemplateNotFound, throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.SchemaNotFound,
"Template not found for enum."); "Template not found for enum.");
} }
} }
@@ -1625,13 +1625,13 @@ public static class DataDeserializer
return (16 + valueSize, reply); return (16 + valueSize, reply);
} }
public static AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> HistoryParserAsync(byte[] data, uint offset, uint length, IResource resource, DistributedConnection connection, uint[] requestSequence) public static AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> HistoryParserAsync(byte[] data, uint offset, uint length, IResource resource, DistributedConnection connection, uint[] requestSequence)
{ {
//var count = (int)toAge - (int)fromAge; //var count = (int)toAge - (int)fromAge;
var list = new KeyList<PropertyTemplate, PropertyValue[]>(); var list = new KeyList<PropertyDefinition, PropertyValue[]>();
var reply = new AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>>(); var reply = new AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>>();
var bagOfBags = new AsyncBag<PropertyValue[]>(); var bagOfBags = new AsyncBag<PropertyValue[]>();
@@ -1639,7 +1639,7 @@ public static class DataDeserializer
while (offset < ends) while (offset < ends)
{ {
var index = data[offset++]; var index = data[offset++];
var pt = resource.Instance.Template.GetPropertyTemplateByIndex(index); var pt = resource.Instance.Schema.GetPropertyDefByIndex(index);
list.Add(pt, null); list.Add(pt, null);
var cs = data.GetUInt32(offset, Endian.Little); var cs = data.GetUInt32(offset, Endian.Little);
offset += 4; offset += 4;

View File

@@ -1,8 +1,8 @@
using Esiur.Core; using Esiur.Core;
using Esiur.Data.GVWIE; using Esiur.Data.GVWIE;
using Esiur.Data.Schema;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using System; using System;
using System.Buffers.Binary; using System.Buffers.Binary;
@@ -943,7 +943,7 @@ public static class DataSerializer
template.ClassId.Data); template.ClassId.Data);
} }
public static byte[] HistoryComposer(KeyList<PropertyTemplate, PropertyValue[]> history, Warehouse warehouse, public static byte[] HistoryComposer(KeyList<PropertyDefinition, PropertyValue[]> history, Warehouse warehouse,
DistributedConnection connection, bool prependLength = false) DistributedConnection connection, bool prependLength = false)
{ {
//@TODO:Test //@TODO:Test

View File

@@ -1,5 +1,5 @@
using Esiur.Core; using Esiur.Core;
using Esiur.Resource.Template; using Esiur.Data.Types;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
@@ -15,6 +15,6 @@ namespace Esiur.Data
public AsyncReply SetResourcePropertyAsync(byte index, object value); public AsyncReply SetResourcePropertyAsync(byte index, object value);
public void SetResourceProperty(byte index, object value); public void SetResourceProperty(byte index, object value);
public TypeTemplate ResourceTemplate { get; } public TypeDef ResourceDefinition { get; }
} }
} }

View File

@@ -466,9 +466,9 @@ namespace Esiur.Data
private static MemberInfo GetMemberMetadataDefinition(MemberInfo member) private static MemberInfo GetMemberMetadataDefinition(MemberInfo member)
{ {
Type? type = member.DeclaringType; 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; return member;
@@ -575,20 +575,20 @@ namespace Esiur.Data
{ {
Debug.Assert(genericParameter.IsGenericParameter && !IsGenericMethodParameter(genericParameter)); Debug.Assert(genericParameter.IsGenericParameter && !IsGenericMethodParameter(genericParameter));
Type contextTypeDefinition = context.IsGenericType && !context.IsGenericTypeDefinition ? context.GetGenericTypeDefinition() : context; Type contextTypeDef = context.IsGenericType && !context.IsGenericTypeDef ? context.GetGenericTypeDef() : context;
if (genericParameter.DeclaringType == contextTypeDefinition) if (genericParameter.DeclaringType == contextTypeDef)
{ {
return false; return false;
} }
Type? baseType = contextTypeDefinition.BaseType; Type? baseType = contextTypeDef.BaseType;
if (baseType is null) if (baseType is null)
{ {
return false; return false;
} }
if (!baseType.IsGenericType if (!baseType.IsGenericType
|| (baseType.IsGenericTypeDefinition ? baseType : baseType.GetGenericTypeDefinition()) != genericParameter.DeclaringType) || (baseType.IsGenericTypeDef ? baseType : baseType.GetGenericTypeDef()) != genericParameter.DeclaringType)
{ {
return TryUpdateGenericTypeParameterNullabilityFromReflectedType(nullability, genericParameter, baseType, reflectedType); return TryUpdateGenericTypeParameterNullabilityFromReflectedType(nullability, genericParameter, baseType, reflectedType);
} }
@@ -600,7 +600,7 @@ namespace Esiur.Data
return TryUpdateGenericParameterNullability(nullability, genericArgument, reflectedType); 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 int nullabilityStateIndex = 1; // start at 1 since index 0 is the type itself
for (int i = 0; i < genericParameter.GenericParameterPosition; i++) for (int i = 0; i < genericParameter.GenericParameterPosition; i++)
{ {

View File

@@ -52,7 +52,7 @@ class ResourceJsonConverter : JsonConverter<IResource>
writer.WriteStartObject(); 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); var rt = pt.PropertyInfo.GetValue(resource, null);
if (rt != null && rt.GetType().IsGenericType) if (rt != null && rt.GetType().IsGenericType)

View File

@@ -458,7 +458,7 @@ public static class RuntimeCaster
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsListType(Type t) private static bool IsListType(Type t)
{ {
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>); return t.IsGenericType && t.GetGenericTypeDef() == typeof(List<>);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]

View File

@@ -1,7 +1,7 @@
using Esiur.Core; using Esiur.Core;
using Esiur.Data.Types;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using System; using System;
using System.Collections; using System.Collections;
@@ -168,9 +168,9 @@ namespace Esiur.Data
(TRUIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime), (TRUIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime),
(TRUIdentifier.Resource) => typeof(IResource), (TRUIdentifier.Resource) => typeof(IResource),
(TRUIdentifier.Record) => typeof(IRecord), (TRUIdentifier.Record) => typeof(IRecord),
(TRUIdentifier.TypedRecord) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Record)?.DefinedType, (TRUIdentifier.TypedRecord) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Record)?.DefinedType,
(TRUIdentifier.TypedResource) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Resource)?.DefinedType, (TRUIdentifier.TypedResource) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Resource)?.DefinedType,
(TRUIdentifier.Enum) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Enum)?.DefinedType, (TRUIdentifier.Enum) => warehouse.GetTypeDefById((UUID)UUID!, TypeDefKind.Enum)?.DefinedType,
_ => null _ => null
}; };
@@ -308,7 +308,7 @@ namespace Esiur.Data
tru = new TRU( tru = new TRU(
TRUIdentifier.TypedResource, TRUIdentifier.TypedResource,
nullable, nullable,
TypeTemplate.GetTypeUUID(type) TypeDef.GetTypeUUID(type)
); );
} }
else if (Codec.ImplementsInterface(type, typeof(IRecord))) else if (Codec.ImplementsInterface(type, typeof(IRecord)))
@@ -316,7 +316,7 @@ namespace Esiur.Data
tru = new TRU( tru = new TRU(
TRUIdentifier.TypedRecord, TRUIdentifier.TypedRecord,
nullable, nullable,
TypeTemplate.GetTypeUUID(type) TypeDef.GetTypeUUID(type)
); );
} }
else if (type.IsGenericType) else if (type.IsGenericType)
@@ -483,7 +483,7 @@ namespace Esiur.Data
} }
else if (type.IsEnum) 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) else if (type.IsInterface)
{ {

View File

@@ -4,9 +4,9 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Reflection; using System.Reflection;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public class ArgumentTemplate public class ArgumentDef
{ {
public string Name { get; set; } public string Name { get; set; }
@@ -20,7 +20,7 @@ public class ArgumentTemplate
public Map<string, string> Annotations { get; set; } public Map<string, string> 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 optional = (data[offset] & 0x1) == 0x1;
var hasAnnotations = (data[offset++] & 0x2) == 0x2; var hasAnnotations = (data[offset++] & 0x2) == 0x2;
@@ -46,7 +46,7 @@ public class ArgumentTemplate
cs += l; cs += l;
} }
return (cs + 2 + size, new ArgumentTemplate() return (cs + 2 + size, new ArgumentDef()
{ {
Name = name, Name = name,
Index = index, Index = index,
@@ -56,7 +56,7 @@ public class ArgumentTemplate
}); });
} }
public ArgumentTemplate() public ArgumentDef()
{ {
} }

View File

@@ -6,9 +6,9 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public class AttributeTemplate : MemberTemplate public class AttributeDef : MemberDef
{ {
public PropertyInfo PropertyInfo 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, Index = index,
Inherited = pi.DeclaringType != type, Inherited = pi.DeclaringType != type,
Name = name, Name = name,
PropertyInfo = pi PropertyInfo = pi,
Definition = typeDef
}; };
} }
} }

View File

@@ -4,10 +4,11 @@ using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using Esiur.Data; 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; } public object Value { get; set; }
@@ -17,7 +18,7 @@ public class ConstantTemplate : MemberTemplate
public FieldInfo FieldInfo { get; set; } 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; var oOffset = offset;
@@ -47,7 +48,7 @@ public class ConstantTemplate : MemberTemplate
offset += len; offset += len;
} }
return (offset - oOffset, new ConstantTemplate() return (offset - oOffset, new ConstantDef()
{ {
Index = index, Index = index,
Name = name, 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<AnnotationAttribute>(true); var annotationAttrs = ci.GetCustomAttributes<AnnotationAttribute>(true);
@@ -106,7 +107,7 @@ public class ConstantTemplate : MemberTemplate
var value = ci.GetValue(null); var value = ci.GetValue(null);
if (typeTemplate?.Type == TemplateType.Enum) if (typeDef?.Type == TypeDefKind.Enum)
value = Convert.ChangeType(value, ci.FieldType.GetEnumUnderlyingType()); value = Convert.ChangeType(value, ci.FieldType.GetEnumUnderlyingType());
Map<string, string> annotations = null; Map<string, string> annotations = null;
@@ -120,7 +121,7 @@ public class ConstantTemplate : MemberTemplate
return new ConstantTemplate() return new ConstantDef()
{ {
Name = customName, Name = customName,
Index = index, Index = index,

View File

@@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Data.Types;
internal class CustomEventOccurredEvent
{
}

View File

@@ -1,5 +1,6 @@
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Resource;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -8,9 +9,9 @@ using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public class EventTemplate : MemberTemplate public class EventDef : MemberDef
{ {
public Map<string, string> Annotations public Map<string, string> Annotations
@@ -31,7 +32,7 @@ public class EventTemplate : MemberTemplate
public TRU ArgumentType { get; set; } 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; var oOffset = offset;
@@ -58,7 +59,7 @@ public class EventTemplate : MemberTemplate
offset += len; offset += len;
} }
return (offset - oOffset, new EventTemplate() return (offset - oOffset, new EventDef()
{ {
Index = index, Index = index,
Name = name, Name = name,
@@ -102,7 +103,7 @@ public class EventTemplate : MemberTemplate
.ToArray(); .ToArray();
} }
//public EventTemplate(TypeTemplate template, byte index, string name, bool inherited, TRU argumentType, Map<string, string> annotations = null, bool subscribable = false) //public EventTemplate(TypeSchema template, byte index, string name, bool inherited, TRU argumentType, Map<string, string> annotations = null, bool subscribable = false)
// : base(template, index, name, inherited) // : base(template, index, name, inherited)
//{ //{
// this.Annotations = annotations; // this.Annotations = annotations;
@@ -110,7 +111,7 @@ public class EventTemplate : MemberTemplate
// this.ArgumentType = argumentType; // 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) if (!ei.EventHandlerType.IsGenericType)
@@ -171,7 +172,7 @@ public class EventTemplate : MemberTemplate
} }
return new EventTemplate() return new EventDef()
{ {
Name = name, Name = name,
ArgumentType = evtType, ArgumentType = evtType,

View File

@@ -1,6 +1,7 @@
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Resource;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -9,9 +10,9 @@ using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public class FunctionTemplate : MemberTemplate public class FunctionDef : MemberDef
{ {
public Map<string, string> Annotations public Map<string, string> Annotations
@@ -30,7 +31,7 @@ public class FunctionTemplate : MemberTemplate
public bool IsStatic { get; set; } public bool IsStatic { get; set; }
public ArgumentTemplate[] Arguments { get; set; } public ArgumentDef[] Arguments { get; set; }
public MethodInfo MethodInfo 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; var oOffset = offset;
@@ -56,11 +57,11 @@ public class FunctionTemplate : MemberTemplate
// arguments count // arguments count
var argsCount = data[offset++]; var argsCount = data[offset++];
List<ArgumentTemplate> arguments = new(); List<ArgumentDef> arguments = new();
for (var a = 0; a < argsCount; a++) 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); arguments.Add(argType);
offset += cs; offset += cs;
} }
@@ -78,7 +79,7 @@ public class FunctionTemplate : MemberTemplate
offset += len; offset += len;
} }
return (offset - oOffset, new FunctionTemplate() return (offset - oOffset, new FunctionDef()
{ {
Index = index, Index = index,
Name = name, Name = name,
@@ -117,7 +118,7 @@ public class FunctionTemplate : MemberTemplate
return bl.ToArray(); return bl.ToArray();
} }
//public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, TRU returnType, Map<string, string> annotations = null) //public FunctionTemplate(TypeSchema template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, TRU returnType, Map<string, string> annotations = null)
// : base(template, index, name, inherited) // : base(template, index, name, inherited)
//{ //{
// this.Arguments = arguments; // 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; var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null;
@@ -262,7 +263,7 @@ public class FunctionTemplate : MemberTemplate
argAnn.Add(attr.Key, attr.Value); argAnn.Add(attr.Key, attr.Value);
} }
return new ArgumentTemplate() return new ArgumentDef()
{ {
Name = x.Name, Name = x.Name,
Type = argType, Type = argType,
@@ -290,7 +291,7 @@ public class FunctionTemplate : MemberTemplate
} }
return new FunctionTemplate() return new FunctionDef()
{ {
Name = name, Name = name,
Index = index, Index = index,

View File

@@ -1,9 +1,10 @@
using System; using Esiur.Resource;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
#nullable enable #nullable enable

View File

@@ -5,14 +5,14 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public class MemberTemplate public class MemberDef
{ {
public byte Index { get; set; } public byte Index { get; set; }
public string Name { get; set; } public string Name { get; set; }
public bool Inherited { get; set; } public bool Inherited { get; set; }
public TypeTemplate Template { get; set; } public TypeDef Definition { get; set; }
//public MemberTemplate() //public MemberTemplate()
//{ //{
@@ -22,7 +22,7 @@ public class MemberTemplate
// Inherited = inherited; // Inherited = inherited;
//} //}
public string Fullname => Template.ClassName + "." + Name; public string Fullname => Definition.ClassName + "." + Name;
//public virtual byte[] Compose() //public virtual byte[] Compose()
//{ //{

View File

@@ -1,5 +1,6 @@
using Esiur.Data; using Esiur.Data;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Resource;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -8,9 +9,9 @@ using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public class PropertyTemplate : MemberTemplate public class PropertyDef : MemberDef
{ {
public Map<string, string> Annotations { get; set; } public Map<string, string> Annotations { get; set; }
@@ -79,7 +80,7 @@ public class PropertyTemplate : MemberTemplate
return $"{Name}: {ValueType}"; 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; var oOffset = offset;
@@ -109,7 +110,7 @@ public class PropertyTemplate : MemberTemplate
offset += len; offset += len;
} }
return (offset - oOffset, new PropertyTemplate() return (offset - oOffset, new PropertyDef()
{ {
Index = index, Index = index,
Name = name, 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) // TRU valueType, string readAnnotation = null, string writeAnnotation = null, bool recordable = false)
// : base(template, index, name, inherited) // : base(template, index, name, inherited)
//{ //{
@@ -204,7 +205,7 @@ public class PropertyTemplate : MemberTemplate
// this.ValueType = valueType; // 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; 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, Name = name,
Index = index, Index = index,
@@ -277,7 +278,7 @@ public class PropertyTemplate : MemberTemplate
Annotations = annotations, 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) //if (storageAttr != null)
// pt.Recordable = storageAttr.Mode == StorageMode.Recordable; // pt.Recordable = storageAttr.Mode == StorageMode.Recordable;

View File

@@ -10,8 +10,9 @@ using System.Security.Cryptography;
using Esiur.Proxy; using Esiur.Proxy;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Esiur.Resource;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
//public enum TemplateType //public enum TemplateType
//{ //{
@@ -19,27 +20,27 @@ namespace Esiur.Resource.Template;
// Record // Record
//} //}
public class TypeTemplate public class TypeDef
{ {
protected UUID classId; protected UUID typeId;
protected UUID? parentId; protected UUID? parentId;
public Map<string, string> Annotations { get; set; } public Map<string, string> Annotations { get; set; }
string className; string typeName;
List<FunctionTemplate> functions = new List<FunctionTemplate>(); List<FunctionDef> functions = new List<FunctionDef>();
List<EventTemplate> events = new List<EventTemplate>(); List<EventDef> events = new List<EventDef>();
List<PropertyTemplate> properties = new List<PropertyTemplate>(); List<PropertyDef> properties = new List<PropertyDef>();
List<AttributeTemplate> attributes = new List<AttributeTemplate>(); List<AttributeDef> attributes = new List<AttributeDef>();
List<ConstantTemplate> constants = new(); List<ConstantDef> constants = new();
int version; int version;
TemplateType templateType; TypeDefKind typeDefKind;
public override string ToString() public override string ToString()
{ {
return className; return typeName;
} }
// protected TemplateType // protected TemplateType
@@ -54,7 +55,7 @@ public class TypeTemplate
get { return content; } get { return content; }
} }
public TemplateType Type => templateType; public TypeDefKind Kind => typeDefKind;
public Type DefinedType { get; set; } public Type DefinedType { get; set; }
@@ -72,7 +73,7 @@ public class TypeTemplate
// return null; // return null;
//} //}
public EventTemplate GetEventTemplateByName(string eventName) public EventDef GetEventDefByName(string eventName)
{ {
foreach (var i in events) foreach (var i in events)
if (i.Name == eventName) if (i.Name == eventName)
@@ -80,7 +81,7 @@ public class TypeTemplate
return null; return null;
} }
public EventTemplate GetEventTemplateByIndex(byte index) public EventDef GetEventDefByIndex(byte index)
{ {
foreach (var i in events) foreach (var i in events)
if (i.Index == index) if (i.Index == index)
@@ -88,14 +89,14 @@ public class TypeTemplate
return null; return null;
} }
public FunctionTemplate GetFunctionTemplateByName(string functionName) public FunctionDef GetFunctionDefByName(string functionName)
{ {
foreach (var i in functions) foreach (var i in functions)
if (i.Name == functionName) if (i.Name == functionName)
return i; return i;
return null; return null;
} }
public FunctionTemplate GetFunctionTemplateByIndex(byte index) public FunctionDef GetFunctionDefByIndex(byte index)
{ {
foreach (var i in functions) foreach (var i in functions)
if (i.Index == index) if (i.Index == index)
@@ -103,7 +104,7 @@ public class TypeTemplate
return null; return null;
} }
public PropertyTemplate GetPropertyTemplateByIndex(byte index) public PropertyDef GetPropertyDefByIndex(byte index)
{ {
foreach (var i in properties) foreach (var i in properties)
if (i.Index == index) if (i.Index == index)
@@ -111,7 +112,7 @@ public class TypeTemplate
return null; return null;
} }
public PropertyTemplate GetPropertyTemplateByName(string propertyName) public PropertyDef GetPropertyDefByName(string propertyName)
{ {
foreach (var i in properties) foreach (var i in properties)
if (i.Name == propertyName) if (i.Name == propertyName)
@@ -119,7 +120,7 @@ public class TypeTemplate
return null; return null;
} }
public AttributeTemplate GetAttributeTemplate(string attributeName) public AttributeDef GetAttributeDef(string attributeName)
{ {
foreach (var i in attributes) foreach (var i in attributes)
if (i.Name == attributeName) if (i.Name == attributeName)
@@ -127,13 +128,13 @@ public class TypeTemplate
return null; 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 //public MemberTemplate[] Methods
@@ -141,24 +142,24 @@ public class TypeTemplate
// get { return members.ToArray(); } // get { return members.ToArray(); }
//} //}
public FunctionTemplate[] Functions public FunctionDef[] Functions
{ {
get { return functions.ToArray(); } get { return functions.ToArray(); }
} }
public EventTemplate[] Events public EventDef[] Events
{ {
get { return events.ToArray(); } get { return events.ToArray(); }
} }
public PropertyTemplate[] Properties public PropertyDef[] Properties
{ {
get { return properties.ToArray(); } 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) if (attr != null)
return attr.ClassId; 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); var hash = SHA256.Create().ComputeHash(tn).Clip(0, 16);
hash[6] = (byte)((hash[6] & 0xF) | 0x80); hash[6] = (byte)((hash[6] & 0xF) | 0x80);
hash[8] = (byte)((hash[8] & 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<TypeTemplate>(); var list = new List<TypeDef>();
// Add self // Add self
list.Add(template); list.Add(schema);
Action<TypeTemplate, List<TypeTemplate>> getDependenciesFunc = null; Action<TypeDef, List<TypeDef>> getDependenciesFunc = null;
getDependenciesFunc = (TypeTemplate tmp, List<TypeTemplate> bag) => getDependenciesFunc = (TypeDef sch, List<TypeDef> bag) =>
{ {
if (template.DefinedType == null) if (schema.DefinedType == null)
return; return;
// Add parents // Add parents
var parentType = tmp.ParentDefinedType; var parentType = sch.ParentDefinedType;
// Get parents // Get parents
while (parentType != null) while (parentType != null)
@@ -253,7 +254,7 @@ public class TypeTemplate
} }
// functions // functions
foreach (var f in tmp.functions) foreach (var f in sch.functions)
{ {
var functionReturnTypes = GetDistributedTypes(f.MethodInfo.ReturnType); var functionReturnTypes = GetDistributedTypes(f.MethodInfo.ReturnType);
//.Select(x => Warehouse.GetTemplateByType(x)) //.Select(x => Warehouse.GetTemplateByType(x))
@@ -319,7 +320,7 @@ public class TypeTemplate
} }
// properties // properties
foreach (var p in tmp.properties) foreach (var p in sch.properties)
{ {
var propertyTypes = GetDistributedTypes(p.PropertyInfo.PropertyType); var propertyTypes = GetDistributedTypes(p.PropertyInfo.PropertyType);
@@ -338,7 +339,7 @@ public class TypeTemplate
} }
// events // events
foreach (var e in tmp.events) foreach (var e in sch.events)
{ {
var eventTypes = GetDistributedTypes(e.EventInfo.EventHandlerType.GenericTypeArguments[0]); 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(); return list.Distinct().ToArray();
} }
public static string GetTypeClassName(Type type, char separator = '.') public static string GetTypeName(Type type, char separator = '.')
{ {
if (type.IsGenericType) if (type.IsGenericType)
@@ -371,7 +372,7 @@ public class TypeTemplate
var index = type.Name.IndexOf("`"); var index = type.Name.IndexOf("`");
var name = $"{type.Namespace}{separator}{((index > -1) ? type.Name.Substring(0, index) : type.Name)}Of"; var name = $"{type.Namespace}{separator}{((index > -1) ? type.Name.Substring(0, index) : type.Name)}Of";
foreach (var t in type.GenericTypeArguments) foreach (var t in type.GenericTypeArguments)
name += GetTypeClassName(t, '_'); name += GetTypeName(t, '_');
return name; return name;
} }
@@ -386,14 +387,14 @@ public class TypeTemplate
public bool IsWrapper { get; private set; } 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))) if (Codec.ImplementsInterface(type, typeof(IResource)))
templateType = TemplateType.Resource; typeDefKind = TypeDefKind.Resource;
else if (Codec.ImplementsInterface(type, typeof(IRecord))) else if (Codec.ImplementsInterface(type, typeof(IRecord)))
templateType = TemplateType.Record; typeDefKind = TypeDefKind.Record;
else if (type.IsEnum) else if (type.IsEnum)
templateType = TemplateType.Enum; typeDefKind = TypeDefKind.Enum;
else else
throw new Exception("Type must implement IResource, IRecord or inherit from DistributedResource."); throw new Exception("Type must implement IResource, IRecord or inherit from DistributedResource.");
@@ -403,13 +404,13 @@ public class TypeTemplate
DefinedType = type; DefinedType = type;
className = GetTypeClassName(type); typeName = GetTypeName(type);
// set guid // set guid
classId = GetTypeUUID(type); typeId = GetTypeUUID(type);
if (warehouse != null) if (warehouse != null)
warehouse.PutTemplate(this); warehouse.RegisterSchema(this);
var hierarchy = GetHierarchy(type); var hierarchy = GetHierarchy(type);
@@ -417,7 +418,7 @@ public class TypeTemplate
{ {
foreach (var cd in hierarchy[MemberTypes.Field]) foreach (var cd in hierarchy[MemberTypes.Field])
{ {
constants.Add(ConstantTemplate.MakeConstantTemplate constants.Add(ConstantDef.MakeConstantDef
(type, (FieldInfo)cd.GetMemberInfo(), cd.Index, cd.Name, this)); (type, (FieldInfo)cd.GetMemberInfo(), cd.Index, cd.Name, this));
} }
} }
@@ -426,18 +427,18 @@ public class TypeTemplate
{ {
foreach (var pd in hierarchy[MemberTypes.Property]) 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)); (type, (PropertyInfo)pd.GetMemberInfo(), pd.Name, pd.Index, pd.PropertyPermission, this));
} }
} }
if (templateType == TemplateType.Resource) if (typeDefKind == TypeDefKind.Resource)
{ {
if (hierarchy.ContainsKey(MemberTypes.Method)) if (hierarchy.ContainsKey(MemberTypes.Method))
{ {
foreach (var fd in hierarchy[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)); (type, (MethodInfo)fd.GetMemberInfo(), fd.Index, fd.Name, this));
} }
} }
@@ -446,7 +447,7 @@ public class TypeTemplate
{ {
foreach (var ed in hierarchy[MemberTypes.Event]) foreach (var ed in hierarchy[MemberTypes.Event])
{ {
events.Add(EventTemplate.MakeEventTemplate events.Add(EventDef.MakeEventDef
(type, (EventInfo)ed.GetMemberInfo(), ed.Index, ed.Name, this)); (type, (EventInfo)ed.GetMemberInfo(), ed.Index, ed.Name, this));
} }
} }
@@ -461,8 +462,8 @@ public class TypeTemplate
{ {
var attrAttr = attr.GetCustomAttribute<AttributeAttribute>(); var attrAttr = attr.GetCustomAttribute<AttributeAttribute>();
attributes.Add(AttributeTemplate attributes.Add(AttributeDef
.MakeAttributeTemplate(type, attr, 0, attrAttr?.Name ?? attr.Name, this)); .MakeAttributeDef(type, attr, 0, attrAttr?.Name ?? attr.Name, this));
} }
@@ -478,12 +479,12 @@ public class TypeTemplate
var hasClassAnnotation = (classAnnotations != null) && (classAnnotations.Count() > 0); 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)) b.AddUInt8((byte)((hasParent ? 0x80 : 0) | (hasClassAnnotation ? 0x40 : 0x0) | (byte)typeDefKind))
.AddUUID(classId) .AddUUID(typeId)
.AddUInt8((byte)classNameBytes.Length) .AddUInt8((byte)typeNameBytes.Length)
.AddUInt8Array(classNameBytes); .AddUInt8Array(typeNameBytes);
if (hasParent) if (hasParent)
{ {
@@ -529,7 +530,7 @@ public class TypeTemplate
while (parent != null) while (parent != null)
{ {
if (parent == typeof(Resource) if (parent == typeof(Esiur.Resource.Resource)
|| parent == typeof(Record) || parent == typeof(Record)
|| parent == typeof(EntryPoint)) || parent == typeof(EntryPoint))
return false; return false;
@@ -606,7 +607,7 @@ public class TypeTemplate
type = type.BaseType; type = type.BaseType;
if (type == null if (type == null
|| type == typeof(Resource) || type == typeof(Esiur.Resource.Resource)
|| type == typeof(Record) || type == typeof(Record)
|| type == typeof(EntryPoint)) || type == typeof(EntryPoint))
break; 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); 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; uint ends = offset + contentLength;
@@ -689,17 +690,17 @@ public class TypeTemplate
// start parsing... // start parsing...
var od = new TypeTemplate(); var od = new TypeDef();
od.content = data.Clip(offset, contentLength); od.content = data.Clip(offset, contentLength);
var hasParent = (data[offset] & 0x80) > 0; var hasParent = (data[offset] & 0x80) > 0;
var hasClassAnnotation = (data[offset] & 0x40) > 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; offset += 16;
od.className = data.GetString(offset + 1, data[offset]); od.typeName = data.GetString(offset + 1, data[offset]);
offset += (uint)data[offset] + 1; offset += (uint)data[offset] + 1;
@@ -736,27 +737,27 @@ public class TypeTemplate
if (type == 0) // function if (type == 0) // function
{ {
var (len, ft) = FunctionTemplate.Parse(data, offset, functionIndex++, inherited); var (len, ft) = FunctionDef.Parse(data, offset, functionIndex++, inherited);
offset += len; offset += len;
od.functions.Add(ft); od.functions.Add(ft);
} }
else if (type == 1) // property 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; offset += len;
od.properties.Add(pt); od.properties.Add(pt);
} }
else if (type == 2) // Event 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; offset += len;
od.events.Add(et); od.events.Add(et);
} }
// constant // constant
else if (type == 3) else if (type == 3)
{ {
var (len, ct) = ConstantTemplate.Parse(data, offset, propertyIndex++, inherited); var (len, ct) = ConstantDef.Parse(data, offset, propertyIndex++, inherited);
offset += len; offset += len;
od.constants.Add(ct); od.constants.Add(ct);
} }
@@ -770,7 +771,7 @@ public class TypeTemplate
var rt = new Map<byte, object>(); var rt = new Map<byte, object>();
foreach (var kv in properties) foreach (var kv in properties)
{ {
var pt = GetPropertyTemplateByName(kv.Key); var pt = GetPropertyDefByName(kv.Key);
if (pt == null) continue; if (pt == null) continue;
rt.Add(pt.Index, kv.Value); rt.Add(pt.Index, kv.Value);
} }

View File

@@ -2,8 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace Esiur.Resource.Template; namespace Esiur.Data.Types;
public enum TemplateType : byte
public enum TypeDefKind : byte
{ {
Resource, Resource,
Record, Record,

View File

@@ -67,6 +67,8 @@
<None Include="Data\DataDeserializer - Copy.cs" /> <None Include="Data\DataDeserializer - Copy.cs" />
<None Include="Data\NullabilityInfo.cs" /> <None Include="Data\NullabilityInfo.cs" />
<None Include="Data\NullabilityInfoContext.cs" /> <None Include="Data\NullabilityInfoContext.cs" />
<None Include="Data\Types\ArgumentDef.cs" />
<None Include="Data\Types\AttributeDef.cs" />
<None Include="LICENSE" Pack="true" PackagePath=""></None> <None Include="LICENSE" Pack="true" PackagePath=""></None>
<None Include="README.md" Pack="true" PackagePath="" /> <None Include="README.md" Pack="true" PackagePath="" />
</ItemGroup> </ItemGroup>

View File

@@ -24,13 +24,13 @@ SOFTWARE.
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Data.Schema;
using Esiur.Misc; using Esiur.Misc;
using Esiur.Net.HTTP; using Esiur.Net.HTTP;
using Esiur.Net.Packets; using Esiur.Net.Packets;
using Esiur.Net.Packets.HTTP; using Esiur.Net.Packets.HTTP;
using Esiur.Net.Sockets; using Esiur.Net.Sockets;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using Esiur.Security.Membership; using Esiur.Security.Membership;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -492,19 +492,19 @@ public partial class DistributedConnection : NetworkConnection, IStore
IIPRequestUnsubscribe(packet.CallbackId, dt, msg); IIPRequestUnsubscribe(packet.CallbackId, dt, msg);
break; break;
// Inquire // Inquire
case IIPPacketRequest.TemplateFromClassName: case IIPPacketRequest.SchemaFromClassName:
IIPRequestTemplateFromClassName(packet.CallbackId, dt, msg); IIPRequestTemplateFromClassName(packet.CallbackId, dt, msg);
break; break;
case IIPPacketRequest.TemplateFromClassId: case IIPPacketRequest.SchemaFromClassId:
IIPRequestTemplateFromClassId(packet.CallbackId, dt, msg); IIPRequestTemplateFromClassId(packet.CallbackId, dt, msg);
break; break;
case IIPPacketRequest.TemplateFromResourceId: case IIPPacketRequest.SchemaFromResourceId:
IIPRequestTemplateFromResourceId(packet.CallbackId, dt, msg); IIPRequestTemplateFromResourceId(packet.CallbackId, dt, msg);
break; break;
case IIPPacketRequest.Query: case IIPPacketRequest.Query:
IIPRequestQueryResources(packet.CallbackId, dt, msg); IIPRequestQueryResources(packet.CallbackId, dt, msg);
break; break;
case IIPPacketRequest.LinkTemplates: case IIPPacketRequest.LinkSchemas:
IIPRequestLinkTemplates(packet.CallbackId, dt, msg); IIPRequestLinkTemplates(packet.CallbackId, dt, msg);
break; break;
case IIPPacketRequest.Token: case IIPPacketRequest.Token:
@@ -1712,7 +1712,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
throw new NotImplementedException(); throw new NotImplementedException();
} }
public AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -24,10 +24,10 @@ SOFTWARE.
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Data.Types;
using Esiur.Misc; using Esiur.Misc;
using Esiur.Net.Packets; using Esiur.Net.Packets;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using Esiur.Security.Permissions; using Esiur.Security.Permissions;
using System; using System;
@@ -50,12 +50,12 @@ partial class DistributedConnection
KeyList<uint, WeakReference<DistributedResource>> suspendedResources = new KeyList<uint, WeakReference<DistributedResource>>(); KeyList<uint, WeakReference<DistributedResource>> suspendedResources = new KeyList<uint, WeakReference<DistributedResource>>();
KeyList<uint, DistributedResourceAttachRequestInfo> resourceRequests = new KeyList<uint, DistributedResourceAttachRequestInfo>(); KeyList<uint, DistributedResourceAttachRequestInfo> resourceRequests = new KeyList<uint, DistributedResourceAttachRequestInfo>();
KeyList<UUID, AsyncReply<TypeTemplate>> templateRequests = new KeyList<UUID, AsyncReply<TypeTemplate>>(); KeyList<UUID, AsyncReply<TypeDef>> typeDefsByIdRequests = new KeyList<UUID, AsyncReply<TypeDef>>();
KeyList<string, AsyncReply<TypeTemplate>> templateByNameRequests = new KeyList<string, AsyncReply<TypeTemplate>>(); KeyList<string, AsyncReply<TypeDef>> typeDefsByNameRequests = new KeyList<string, AsyncReply<TypeDef>>();
Dictionary<UUID, TypeTemplate> templates = new Dictionary<UUID, TypeTemplate>(); Dictionary<UUID, TypeDef> typeDefs = new Dictionary<UUID, TypeDef>();
KeyList<uint, AsyncReply> requests = new KeyList<uint, AsyncReply>(); KeyList<uint, AsyncReply> requests = new KeyList<uint, AsyncReply>();
@@ -455,7 +455,7 @@ partial class DistributedConnection
Fetch(rid, null).Then(r => Fetch(rid, null).Then(r =>
{ {
var pt = r.Instance.Template.GetPropertyTemplateByIndex(index); var pt = r.Instance.Definition.GetPropertyDefByIndex(index);
if (pt == null) if (pt == null)
return; return;
@@ -500,7 +500,7 @@ partial class DistributedConnection
Fetch(resourceId, null).Then(r => 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 if (et == null) // this should never happen
return; return;
@@ -561,7 +561,7 @@ partial class DistributedConnection
// reply ok // reply ok
SendReply(IIPPacketReply.Completed, callback, SendReply(IIPPacketReply.Completed, callback,
r.Instance.Template.ClassId, r.Instance.Definition.TypeId,
r.Instance.Age, r.Instance.Age,
r.Instance.Link, r.Instance.Link,
r.Instance.Hops, r.Instance.Hops,
@@ -608,7 +608,7 @@ partial class DistributedConnection
// reply ok // reply ok
SendReply(IIPPacketReply.Completed, callback, SendReply(IIPPacketReply.Completed, callback,
r.Instance.Template.ClassId, r.Instance.Definition.TypeId,
r.Instance.Age, r.Instance.Age,
r.Instance.Link, r.Instance.Link,
r.Instance.Hops, r.Instance.Hops,
@@ -666,12 +666,12 @@ partial class DistributedConnection
var path = (string)args[0]; var path = (string)args[0];
TypeTemplate type = null; TypeDef type = null;
if (args[1] is UUID) 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) else if (args[1] is string)
type = Instance.Warehouse.GetTemplateByClassName((string)args[1]); type = Instance.Warehouse.GetTypeByName((string)args[1]);
if (type == null) if (type == null)
{ {
@@ -814,7 +814,7 @@ partial class DistributedConnection
return; return;
} }
var templates = TypeTemplate.GetDependencies(r.Instance.Template, Instance.Warehouse); var templates = TypeDef.GetDependencies(r.Instance.Definition, Instance.Warehouse);
// Send // Send
SendReply(IIPPacketReply.Completed, callback, templates.Select(x => x.Content).ToArray()); SendReply(IIPPacketReply.Completed, callback, templates.Select(x => x.Content).ToArray());
@@ -842,18 +842,18 @@ partial class DistributedConnection
else else
{ {
// reply failed // 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 (_, value) = Codec.ParseSync(dataType, Instance.Warehouse);
var classId = (UUID)value; var classId = (UUID)value;
var t = Instance.Warehouse.GetTemplateByClassId(classId); var t = Instance.Warehouse.GetTypeDefById(classId);
if (t != null) if (t != null)
{ {
@@ -862,7 +862,7 @@ partial class DistributedConnection
else else
{ {
// reply failed // 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) if (r != null)
{ {
SendReply(IIPPacketReply.Completed, callback, r.Instance.Template.Content); SendReply(IIPPacketReply.Completed, callback, r.Instance.Definition.Content);
} }
else else
{ {
@@ -1046,16 +1046,16 @@ partial class DistributedConnection
var index = (byte)args[1]; var index = (byte)args[1];
var template = Instance.Warehouse.GetTemplateByClassId(classId); var template = Instance.Warehouse.GetTypeDefById(classId);
if (template == null) if (template == null)
{ {
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TemplateNotFound); SendError(ErrorType.Management, callback, (ushort)ExceptionCode.TypeDefNotFound);
return; return;
} }
var ft = template.GetFunctionTemplateByIndex(index); var ft = template.GetFunctionDefByIndex(index);
if (ft == null) if (ft == null)
{ {
@@ -1131,7 +1131,7 @@ partial class DistributedConnection
return; return;
} }
var ft = r.Instance.Template.GetFunctionTemplateByIndex(index); var ft = r.Instance.Definition.GetFunctionDefByIndex(index);
if (ft == null) 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 // cast arguments
@@ -1455,7 +1455,7 @@ partial class DistributedConnection
return; return;
} }
var et = r.Instance.Template.GetEventTemplateByIndex(index); var et = r.Instance.Definition.GetEventDefByIndex(index);
if (et != null) if (et != null)
{ {
@@ -1514,7 +1514,7 @@ partial class DistributedConnection
return; return;
} }
var et = r.Instance.Template.GetEventTemplateByIndex(index); var et = r.Instance.Definition.GetEventDefByIndex(index);
if (et == null) if (et == null)
{ {
@@ -1578,7 +1578,7 @@ partial class DistributedConnection
return; return;
} }
var pt = r.Instance.Template.GetPropertyTemplateByIndex(index); var pt = r.Instance.Definition.GetPropertyDefByIndex(index);
if (pt != null) if (pt != null)
{ {
@@ -1686,27 +1686,27 @@ partial class DistributedConnection
/// <summary> /// <summary>
/// Get the ResourceTemplate for a given class Id. /// Get the TypeSchema for a given class Id.
/// </summary> /// </summary>
/// <param name="classId">Class GUID.</param> /// <param name="classId">Class GUID.</param>
/// <returns>ResourceTemplate.</returns> /// <returns>TypeSchema.</returns>
public AsyncReply<TypeTemplate> GetTemplate(UUID classId) public AsyncReply<TypeDef> GetTypeDefById(UUID classId)
{ {
if (templates.ContainsKey(classId)) if (typeDefs.ContainsKey(classId))
return new AsyncReply<TypeTemplate>(templates[classId]); return new AsyncReply<TypeDef>(typeDefs[classId]);
else if (templateRequests.ContainsKey(classId)) else if (typeDefsByIdRequests.ContainsKey(classId))
return templateRequests[classId]; return typeDefsByIdRequests[classId];
var reply = new AsyncReply<TypeTemplate>(); var reply = new AsyncReply<TypeDef>();
templateRequests.Add(classId, reply); typeDefsByIdRequests.Add(classId, reply);
SendRequest(IIPPacketRequest.TemplateFromClassId, classId) SendRequest(IIPPacketRequest.SchemaFromClassId, classId)
.Then((result) => .Then((result) =>
{ {
var tt = TypeTemplate.Parse((byte[])result); var tt = TypeDef.Parse((byte[])result);
templateRequests.Remove(classId); typeDefsByIdRequests.Remove(classId);
templates.Add(tt.ClassId, tt); typeDefs.Add(tt.ClassId, tt);
Instance.Warehouse.PutTemplate(tt); Instance.Warehouse.RegisterSchema(tt);
reply.Trigger(tt); reply.Trigger(tt);
}).Error((ex) => }).Error((ex) =>
@@ -1718,27 +1718,27 @@ partial class DistributedConnection
} }
public AsyncReply<TypeTemplate> GetTemplateByClassName(string className) public AsyncReply<TypeDef> GetTypeDefByClassName(string className)
{ {
var template = templates.Values.FirstOrDefault(x => x.ClassName == className); var template = typeDefs.Values.FirstOrDefault(x => x.ClassName == className);
if (template != null) if (template != null)
return new AsyncReply<TypeTemplate>(template); return new AsyncReply<TypeDef>(template);
if (templateByNameRequests.ContainsKey(className)) if (typeDefsByNameRequests.ContainsKey(className))
return templateByNameRequests[className]; return typeDefsByNameRequests[className];
var reply = new AsyncReply<TypeTemplate>(); var reply = new AsyncReply<TypeDef>();
templateByNameRequests.Add(className, reply); typeDefsByNameRequests.Add(className, reply);
SendRequest(IIPPacketRequest.TemplateFromClassName, className) SendRequest(IIPPacketRequest.SchemaFromClassName, className)
.Then((result) => .Then((result) =>
{ {
var tt = TypeTemplate.Parse((byte[])result); var tt = TypeDef.Parse((byte[])result);
templateByNameRequests.Remove(className); typeDefsByNameRequests.Remove(className);
templates.Add(tt.ClassId, tt); typeDefs.Add(tt.ClassId, tt);
Instance.Warehouse.PutTemplate(tt); Instance.Warehouse.RegisterSchema(tt);
reply.Trigger(tt); reply.Trigger(tt);
}).Error((ex) => }).Error((ex) =>
{ {
@@ -1786,23 +1786,23 @@ partial class DistributedConnection
} }
public AsyncReply<TypeTemplate[]> GetLinkTemplates(string link) public AsyncReply<TypeDef[]> GetLinkDefinitions(string link)
{ {
var reply = new AsyncReply<TypeTemplate[]>(); var reply = new AsyncReply<TypeDef[]>();
SendRequest(IIPPacketRequest.LinkTemplates, link) SendRequest(IIPPacketRequest.LinkSchemas, link)
.Then((result) => .Then((result) =>
{ {
var templates = new List<TypeTemplate>(); var defs = new List<TypeDef>();
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) => }).Error((ex) =>
{ {
@@ -1874,7 +1874,7 @@ partial class DistributedConnection
// ClassId, Age, Link, Hops, PropertyValue[] // ClassId, Age, Link, Hops, PropertyValue[]
var args = (object[])result; var args = (object[])result;
var classId = (UUID)args[0]; var typeId = (UUID)args[0];
var age = Convert.ToUInt64(args[1]); var age = Convert.ToUInt64(args[1]);
var link = (string)args[2]; var link = (string)args[2];
var hops = (byte)args[3]; var hops = (byte)args[3];
@@ -1882,20 +1882,20 @@ partial class DistributedConnection
DistributedResource dr; DistributedResource dr;
TypeTemplate template = null; TypeDef typeDef = null;
if (resource == null) if (resource == null)
{ {
template = Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Resource); typeDef = Instance.Warehouse.GetTypeDefByClassId(typeId, TypeDefKind.Resource);
if (template?.DefinedType != null && template.IsWrapper) if (typeDef?.DefinedType != null && typeDef.IsWrapper)
dr = Activator.CreateInstance(template.DefinedType, this, id, Convert.ToUInt64(args[1]), (string)args[2]) as DistributedResource; dr = Activator.CreateInstance(typeDef.DefinedType, this, id, Convert.ToUInt64(args[1]), (string)args[2]) as DistributedResource;
else else
dr = new DistributedResource(this, id, Convert.ToUInt64(args[1]), (string)args[2]); dr = new DistributedResource(this, id, Convert.ToUInt64(args[1]), (string)args[2]);
} }
else else
{ {
dr = resource; 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 // ClassId, ResourceAge, ResourceLink, Content
if (resource == null) if (resource == null)
{ {
dr.ResourceTemplate = tmp; dr.ResourceDefinition = tmp;
Instance.Warehouse.Put(this.Instance.Link + "/" + id.ToString(), dr) Instance.Warehouse.Put(this.Instance.Link + "/" + id.ToString(), dr)
.Then(initResource) .Then(initResource)
@@ -1999,7 +1999,7 @@ partial class DistributedConnection
/// <param name="properties">Values for the resource properties.</param> /// <param name="properties">Values for the resource properties.</param>
/// <param name="attributes">Resource attributes.</param> /// <param name="attributes">Resource attributes.</param>
/// <returns>New resource instance</returns> /// <returns>New resource instance</returns>
public AsyncReply<DistributedResource> Create(string path, TypeTemplate type, Map<string, object> properties, Map<string, object> attributes) public AsyncReply<DistributedResource> Create(string path, TypeDef type, Map<string, object> properties, Map<string, object> attributes)
{ {
var reply = new AsyncReply<DistributedResource>(); var reply = new AsyncReply<DistributedResource>();
@@ -2103,7 +2103,7 @@ partial class DistributedConnection
private void Instance_EventOccurred(EventOccurredInfo info) private void Instance_EventOccurred(EventOccurredInfo info)
{ {
if (info.EventTemplate.Subscribable) if (info.Definition.Subscribable)
{ {
lock (subscriptionsLock) lock (subscriptionsLock)
{ {
@@ -2111,18 +2111,18 @@ partial class DistributedConnection
if (!subscriptions.ContainsKey(info.Resource)) if (!subscriptions.ContainsKey(info.Resource))
return; return;
if (!subscriptions[info.Resource].Contains(info.EventTemplate.Index)) if (!subscriptions[info.Resource].Contains(info.Definition.Index))
return; 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; return;
// compose the packet // compose the packet
SendNotification(IIPPacketNotification.EventOccurred, SendNotification(IIPPacketNotification.EventOccurred,
info.Resource.Instance.Id, info.Resource.Instance.Id,
info.EventTemplate.Index, info.Definition.Index,
info.Value); info.Value);
} }

View File

@@ -40,8 +40,8 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Net.Packets; using Esiur.Net.Packets;
using Esiur.Data.Types;
namespace Esiur.Net.IIP; namespace Esiur.Net.IIP;
@@ -57,7 +57,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
uint instanceId; uint instanceId;
TypeTemplate template; TypeDef typeDef;
DistributedConnection connection; DistributedConnection connection;
@@ -163,7 +163,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
this.properties = new object[properties.Length]; 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++) 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) 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); events[index]?.Invoke(this, args);
Instance.EmitResourceEvent(et, args); Instance.EmitResourceEvent(et, args);
} }
@@ -200,21 +200,21 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
if (suspended) if (suspended)
throw new Exception("Trying to access a suspended object."); 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."); throw new Exception("Function index is incorrect.");
var ft = Instance.Template.GetFunctionTemplateByIndex(index); var ft = Instance.Definition.GetFunctionDefByIndex(index);
if (ft == null) if (ft == null)
throw new Exception("Function template not found."); throw new Exception("Function template not found.");
if (ft.IsStatic) if (ft.IsStatic)
return connection.StaticCall(Instance.Template.ClassId, index, args); return connection.StaticCall(Instance.Definition.ClassId, index, args);
else else
return connection.SendInvoke(instanceId, index, args); return connection.SendInvoke(instanceId, index, args);
} }
public AsyncReply Subscribe(EventTemplate et) public AsyncReply Subscribe(EventDef et)
{ {
if (et == null) if (et == null)
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, "")); 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) public AsyncReply Subscribe(string eventName)
{ {
var et = Instance.Template.GetEventTemplateByName(eventName); var et = Instance.Definition.GetEventDefByName(eventName);
return Subscribe(et); return Subscribe(et);
} }
public AsyncReply Unsubscribe(EventTemplate et) public AsyncReply Unsubscribe(EventDef et)
{ {
if (et == null) if (et == null)
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, "")); 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) public AsyncReply Unsubscribe(string eventName)
{ {
var et = Instance.Template.GetEventTemplateByName(eventName); var et = Instance.Definition.GetEventDefByName(eventName);
return Unsubscribe(et); return Unsubscribe(et);
} }
@@ -260,7 +260,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
if (suspended) if (suspended)
throw new Exception("Trying to access a suspended object."); 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<object>(); var reply = new AsyncReply<object>();
@@ -345,7 +345,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
if (!attached) if (!attached)
return false; return false;
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name); var pt = Instance.Definition.GetPropertyDefByName(binder.Name);
if (pt != null) if (pt != null)
{ {
@@ -354,7 +354,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
} }
else else
{ {
var et = Instance.Template.GetEventTemplateByName(binder.Name); var et = Instance.Definition.GetEventDefByName(binder.Name);
if (et == null) if (et == null)
return false; return false;
@@ -367,7 +367,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
internal void _UpdatePropertyByIndex(byte index, object value) internal void _UpdatePropertyByIndex(byte index, object value)
{ {
var pt = Instance.Template.GetPropertyTemplateByIndex(index); var pt = Instance.Definition.GetPropertyDefByIndex(index);
properties[index] = value; properties[index] = value;
Instance.EmitModification(pt, value); Instance.EmitModification(pt, value);
} }
@@ -403,7 +403,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
if (!attached) if (!attached)
return false; return false;
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name); var pt = Instance.Definition.GetPropertyDefByName(binder.Name);
if (pt != null) if (pt != null)
{ {
@@ -412,7 +412,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
} }
else else
{ {
var et = Instance.Template.GetEventTemplateByName(binder.Name); var et = Instance.Definition.GetEventDefByName(binder.Name);
if (et == null) if (et == null)
return false; return false;
@@ -433,15 +433,15 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
set; set;
} }
public TypeTemplate ResourceTemplate public TypeDef ResourceDefinition
{ {
get get
{ {
return template; return typeDef;
} }
internal set internal set
{ {
template = value; typeDef = value;
} }
} }

View File

@@ -35,7 +35,7 @@ using System.Net;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Security.Membership; using Esiur.Security.Membership;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Resource.Template; using Esiur.Data.Schema;
namespace Esiur.Net.IIP; namespace Esiur.Net.IIP;
public class DistributedServer : NetworkServer<DistributedConnection>, IResource public class DistributedServer : NetworkServer<DistributedConnection>, IResource
@@ -168,13 +168,13 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
public struct CallInfo public struct CallInfo
{ {
public FunctionTemplate Template; public FunctionDefinition Template;
public Delegate Delegate; public Delegate Delegate;
} }
public DistributedServer MapCall(string call, Delegate handler) 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 }); Calls.Add(call, new CallInfo() { Delegate = handler, Template = ft });
return this; return this;
} }

View File

@@ -27,7 +27,7 @@ using System.Text;
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template; using Esiur.Data.Schema;
namespace Esiur.Net.IIP; namespace Esiur.Net.IIP;

View File

@@ -10,11 +10,11 @@ struct IIPPacketAttachInfo
public string Link; public string Link;
public ulong Age; public ulong Age;
public byte[] Content; 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; Age = age;
Content = content; Content = content;
Link = link; Link = link;

View File

@@ -13,11 +13,11 @@ namespace Esiur.Net.Packets
Unsubscribe = 0x3, Unsubscribe = 0x3,
// Request Inquire // Request Inquire
TemplateFromClassName = 0x8, SchemaFromClassName = 0x8,
TemplateFromClassId = 0x9, SchemaFromClassId = 0x9,
TemplateFromResourceId = 0xA, SchemaFromResourceId = 0xA,
Query = 0xB, Query = 0xB,
LinkTemplates = 0xC, LinkSchemas = 0xC,
Token = 0xD, Token = 0xD,
GetResourceIdByLink = 0xE, GetResourceIdByLink = 0xE,

View File

@@ -4,9 +4,9 @@
// ================================ // ================================
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Data.Types;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -57,7 +57,7 @@ namespace Esiur.Proxy
var parts = TemplateGenerator.urlRegex.Split(path); var parts = TemplateGenerator.urlRegex.Split(path);
var con = Warehouse.Default.Get<DistributedConnection>($"{parts[1]}://{parts[2]}").Wait(20000); var con = Warehouse.Default.Get<DistributedConnection>($"{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); EmitTemplates(spc, templates);
} }
@@ -222,26 +222,26 @@ $@" public partial class {ci.Name} : IResource {{
} }
// === Emission helpers (ported from your original generator) === // === 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) foreach (var tmp in templates)
{ {
if (tmp.Type == TemplateType.Resource) if (tmp.Kind == TypeDefKind.Resource)
{ {
var source = TemplateGenerator.GenerateClass(tmp, templates, false); 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); 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[] { " + 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[] { " + + " }; \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}"; "\r\n } \r\n}";

View File

@@ -1,5 +1,4 @@
using Esiur.Data; using Esiur.Data;
using Esiur.Resource.Template;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -9,6 +8,7 @@ using System.Text.RegularExpressions;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using System.Diagnostics; using System.Diagnostics;
using Esiur.Data.Types;
namespace Esiur.Proxy; 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 nameSpace = string.Join(".", cls.Take(cls.Length - 1));
var className = cls.Last(); 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("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Net.IIP;");
rt.AppendLine($"namespace {nameSpace} {{"); 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($"[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 {{"); 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); var ptTypeName = GetTypeName(p.ValueType, templates);
@@ -109,9 +109,9 @@ public static class TemplateGenerator
return rt.ToString(); 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 nameSpace = string.Join(".", cls.Take(cls.Length - 1));
var className = cls.Last(); 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($"[Export] public enum {className} {{");
rt.AppendLine(String.Join(",\r\n", template.Constants.Select(x => $"{x.Name}={x.Value}"))); 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; string name;
if (representationType.Identifier == TRUIdentifier.TypedResource)// == DataType.Resource) 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) 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) 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) else if (representationType.Identifier == TRUIdentifier.TypedList)
name = GetTypeName(representationType.SubTypes[0], templates) + "[]"; name = GetTypeName(representationType.SubTypes[0], templates) + "[]";
else if (representationType.Identifier == TRUIdentifier.TypedMap) else if (representationType.Identifier == TRUIdentifier.TypedMap)
@@ -215,7 +215,7 @@ public static class TemplateGenerator
if (string.IsNullOrEmpty(dir)) if (string.IsNullOrEmpty(dir))
dir = path[2].Replace(":", "_"); dir = path[2].Replace(":", "_");
var templates = con.GetLinkTemplates(path[3]).Wait(60000); var templates = con.GetLinkDefinitions(path[3]).Wait(60000);
// no longer needed // no longer needed
Warehouse.Default.Remove(con); Warehouse.Default.Remove(con);
@@ -233,20 +233,20 @@ public static class TemplateGenerator
// make sources // make sources
foreach (var tmp in templates) foreach (var tmp in templates)
{ {
if (tmp.Type == TemplateType.Resource) if (tmp.Kind == TypeDefKind.Resource)
{ {
var source = GenerateClass(tmp, templates, asyncSetters); 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); 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); 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 { namespace Esiur {
public static class Generated { public static class Generated {
public static Type[] Resources {get;} = new Type[] { " + 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[] { " + 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[] { " + 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}"; "\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 nameSpace = string.Join(".", cls.Take(cls.Length - 1));
var className = cls.Last(); 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 // extends
if (template.ParentId == null) if (template.ParentId == null)
rt.AppendLine($"public class {className} : DistributedResource {{"); rt.AppendLine($"public class {className} : DistributedResource {{");
else 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) {{}}"); 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}>();"); rt.AppendLine($"var rt = new AsyncReply<{rtTypeName}>();");
if (f.IsStatic) 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 else
rt.AppendLine($"_Invoke({f.Index}, args)"); rt.AppendLine($"_Invoke({f.Index}, args)");

View File

@@ -1,4 +1,4 @@
using Esiur.Resource.Template; using Esiur.Data.Types;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -8,7 +8,7 @@ namespace Esiur.Resource;
public class CustomEventOccurredInfo public class CustomEventOccurredInfo
{ {
public readonly EventTemplate EventTemplate; public readonly EventDef EventTemplate;
public readonly IResource Resource; public readonly IResource Resource;
public readonly object Value; public readonly object Value;
public readonly object Issuer; public readonly object Issuer;
@@ -16,7 +16,7 @@ public class CustomEventOccurredInfo
public string Name => EventTemplate.Name; public string Name => EventTemplate.Name;
public CustomEventOccurredInfo(IResource resource, EventTemplate eventTemplate, Func<Session, bool> receivers, object issuer, object value) public CustomEventOccurredInfo(IResource resource, EventDef eventTemplate, Func<Session, bool> receivers, object issuer, object value)
{ {
Resource = resource; Resource = resource;
EventTemplate = eventTemplate; EventTemplate = eventTemplate;

View File

@@ -1,4 +1,4 @@
using Esiur.Resource.Template; using Esiur.Data.Types;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
@@ -9,18 +9,18 @@ namespace Esiur.Resource
public class EventOccurredInfo 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 IResource Resource;
public readonly object Value; public readonly object Value;
public EventOccurredInfo(IResource resource, EventTemplate eventTemplate, object value) public EventOccurredInfo(IResource resource, EventDef eventDef, object value)
{ {
Resource = resource; Resource = resource;
Value = value; Value = value;
EventTemplate = eventTemplate; Definition = eventDef;
} }
} }
} }

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using static Esiur.Resource.Template.PropertyTemplate;
namespace Esiur.Resource; namespace Esiur.Resource;

View File

@@ -24,7 +24,6 @@ SOFTWARE.
using Esiur.Data; using Esiur.Data;
using Esiur.Core; using Esiur.Core;
using Esiur.Resource.Template;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -32,6 +31,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Security.Permissions; using Esiur.Security.Permissions;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using Esiur.Data.Schema;
namespace Esiur.Resource; namespace Esiur.Resource;
public interface IStore : IResource public interface IStore : IResource
@@ -73,5 +73,5 @@ public interface IStore : IResource
//AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, ulong fromAge, ulong toAge); //AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, ulong fromAge, ulong toAge);
// AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate); // AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate);
AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate); AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
} }

View File

@@ -9,13 +9,13 @@ using System.Reflection;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Misc; using Esiur.Misc;
using Esiur.Security.Permissions; using Esiur.Security.Permissions;
using Esiur.Resource.Template;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using Esiur.Proxy; using Esiur.Proxy;
using Esiur.Core; using Esiur.Core;
using System.Text.Json; using System.Text.Json;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection.Emit; using System.Reflection.Emit;
using Esiur.Data.Types;
namespace Esiur.Resource; namespace Esiur.Resource;
@@ -29,7 +29,7 @@ public class Instance
WeakReference<IResource> resource; WeakReference<IResource> resource;
IStore store; IStore store;
TypeTemplate template; TypeDef definition;
AutoList<IPermissionsManager, Instance> managers; AutoList<IPermissionsManager, Instance> managers;
@@ -107,7 +107,7 @@ public class Instance
{ {
for (var i = 0; i < attributes.Length; i++) for (var i = 0; i < attributes.Length; i++)
{ {
var at = template.GetAttributeTemplate(attributes[i]); var at = definition.GetAttributeDef(attributes[i]);
if (at != null) if (at != null)
{ {
@@ -128,7 +128,7 @@ public class Instance
{ {
foreach (var kv in attributes) foreach (var kv in attributes)
{ {
var at = template.GetAttributeTemplate(kv.Key); var at = definition.GetAttributeDef(kv.Key);
if (at != null) if (at != null)
if (at.PropertyInfo.CanWrite) if (at.PropertyInfo.CanWrite)
@@ -287,7 +287,7 @@ public class Instance
if (!resource.TryGetTarget(out res)) if (!resource.TryGetTarget(out res))
return false; return false;
var pt = template.GetPropertyTemplateByName(name); var pt = definition.GetPropertyDefByName(name);
if (pt == null) if (pt == null)
return false; return false;
@@ -376,7 +376,7 @@ public class Instance
{ {
for (byte i = 0; i < properties.Length; i++) for (byte i = 0; i < properties.Length; i++)
{ {
var pt = this.template.GetPropertyTemplateByIndex(i); var pt = this.definition.GetPropertyDefByIndex(i);
if (pt != null) if (pt != null)
{ {
var pv = properties[i]; var pv = properties[i];
@@ -413,7 +413,7 @@ public class Instance
var props = new List<PropertyValue>(); var props = new List<PropertyValue>();
foreach (var pt in template.Properties) foreach (var pt in definition.Properties)
{ {
var rt = pt.PropertyInfo.GetValue(res, null); var rt = pt.PropertyInfo.GetValue(res, null);
props.Add(new PropertyValue(rt, ages[pt.Index], modificationDates[pt.Index])); props.Add(new PropertyValue(rt, ages[pt.Index], modificationDates[pt.Index]));
@@ -438,7 +438,7 @@ public class Instance
var props = new Map<byte, PropertyValue>(); var props = new Map<byte, PropertyValue>();
foreach (var pt in template.Properties) foreach (var pt in definition.Properties)
{ {
if (res.Instance.GetAge(pt.Index) > age) 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; IResource res;
@@ -511,7 +511,7 @@ public class Instance
object value; object value;
if (TryGetPropertyValue(propertyName, out value)) if (TryGetPropertyValue(propertyName, out value))
{ {
var pt = template.GetPropertyTemplateByName(propertyName); var pt = definition.GetPropertyDefByName(propertyName);
EmitModification(pt, value); EmitModification(pt, value);
} }
} }
@@ -520,21 +520,21 @@ public class Instance
// internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args) // internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args)
internal void EmitCustomResourceEvent(object issuer, Func<Session, bool> receivers, EventTemplate eventTemplate, object value) internal void EmitCustomResourceEvent(object issuer, Func<Session, bool> receivers, EventDef eventDef, object value)
{ {
IResource res; IResource res;
if (this.resource.TryGetTarget(out 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; IResource res;
if (this.resource.TryGetTarget(out 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; IResource res;
if (this.resource.TryGetTarget(out res)) if (this.resource.TryGetTarget(out res))
{ {
var eventTemplate = template.GetEventTemplateByIndex(eventIndex); var eventDef = definition.GetEventDefByIndex(eventIndex);
EventOccurred?.Invoke(new EventOccurredInfo(res, eventTemplate, value)); EventOccurred?.Invoke(new EventOccurredInfo(res, eventDef, value));
} }
} }
@@ -553,8 +553,8 @@ public class Instance
IResource res; IResource res;
if (this.resource.TryGetTarget(out res)) if (this.resource.TryGetTarget(out res))
{ {
var eventTemplate = template.GetEventTemplateByIndex(eventIndex); var eventDef = definition.GetEventDefByIndex(eventIndex);
CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventTemplate, receivers, issuer, value)); CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventDef, receivers, issuer, value));
} }
} }
@@ -567,7 +567,7 @@ public class Instance
/// <returns>True, if the resource has the property.</returns> /// <returns>True, if the resource has the property.</returns>
public bool TryGetPropertyValue(string name, out object value) public bool TryGetPropertyValue(string name, out object value)
{ {
var pt = template.GetPropertyTemplateByName(name); var pt = definition.GetPropertyDefByName(name);
IResource res; IResource res;
if (resource.TryGetTarget(out res)) if (resource.TryGetTarget(out res))
@@ -680,9 +680,9 @@ public class Instance
/// <summary> /// <summary>
/// Resource template describes the properties, functions and events of the resource. /// Resource template describes the properties, functions and events of the resource.
/// </summary> /// </summary>
public TypeTemplate Template public TypeDef Definition
{ {
get { return template; } get { return definition; }
/* /*
internal set internal set
@@ -707,7 +707,7 @@ public class Instance
/// <param name="member">Function, property or event to check for permission.</param> /// <param name="member">Function, property or event to check for permission.</param>
/// <param name="inquirer">Permission inquirer.</param> /// <param name="inquirer">Permission inquirer.</param>
/// <returns>Ruling.</returns> /// <returns>Ruling.</returns>
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; IResource res;
if (this.resource.TryGetTarget(out res)) if (this.resource.TryGetTarget(out res))
@@ -762,15 +762,15 @@ public class Instance
if (resource is IDynamicResource dynamicResource) if (resource is IDynamicResource dynamicResource)
{ {
this.template = dynamicResource.ResourceTemplate; this.definition = dynamicResource.ResourceDefinition;
} }
else else
{ {
this.template = Warehouse.GetTemplateByType(resource.GetType()); this.definition = Warehouse.GetTemplateByType(resource.GetType());
} }
// set ages // set ages
for (byte i = 0; i < template.Properties.Length; i++) for (byte i = 0; i < definition.Properties.Length; i++)
{ {
ages.Add(0); ages.Add(0);
modificationDates.Add(DateTime.MinValue); modificationDates.Add(DateTime.MinValue);
@@ -788,7 +788,7 @@ public class Instance
var emitEventByIndexMethod = GetType().GetMethod("EmitResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic); var emitEventByIndexMethod = GetType().GetMethod("EmitResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic);
var emitCustomEventByIndexMethod = GetType().GetMethod("EmitCustomResourceEventByIndex", 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) if (evt.EventInfo == null)

View File

@@ -1,20 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Esiur.Data.Types;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
namespace Esiur.Resource; namespace Esiur.Resource;
public struct PropertyModificationInfo public struct PropertyModificationInfo
{ {
public readonly IResource Resource; public readonly IResource Resource;
public readonly PropertyTemplate PropertyTemplate; public readonly PropertyDef PropertyTemplate;
public string Name => PropertyTemplate.Name; public string Name => PropertyTemplate.Name;
public readonly ulong Age; public readonly ulong Age;
public object Value; 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; Resource = resource;
PropertyTemplate = propertyTemplate; PropertyTemplate = propertyTemplate;

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Resource.Template; using Esiur.Data.Schema;
namespace Esiur.Resource; namespace Esiur.Resource;
public abstract class Store<T> : IStore where T : IResource public abstract class Store<T> : IStore where T : IResource
@@ -23,7 +23,7 @@ public abstract class Store<T> : IStore where T : IResource
public abstract AsyncReply<IResource> Get(string path); public abstract AsyncReply<IResource> Get(string path);
public abstract AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate); public abstract AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
public abstract string Link(IResource resource); public abstract string Link(IResource resource);

View File

@@ -1,10 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Resource.Template
{
internal class CustomEventOccurredEvent
{
}
}

View File

@@ -24,11 +24,11 @@ SOFTWARE.
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Data.Types;
using Esiur.Misc; using Esiur.Misc;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Net.Packets; using Esiur.Net.Packets;
using Esiur.Proxy; using Esiur.Proxy;
using Esiur.Resource.Template;
using Esiur.Security.Permissions; using Esiur.Security.Permissions;
using System; using System;
using System.Collections; using System.Collections;
@@ -36,6 +36,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Reflection.Metadata;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -58,14 +59,14 @@ public class Warehouse
uint resourceCounter = 0; uint resourceCounter = 0;
KeyList<TemplateType, KeyList<UUID, TypeTemplate>> templates KeyList<TypeDefKind, KeyList<UUID, TypeDef>> schemas
= new KeyList<TemplateType, KeyList<UUID, TypeTemplate>>() = new KeyList<TypeDefKind, KeyList<UUID, TypeDef>>()
{ {
//[TemplateType.Unspecified] = new KeyList<Guid, TypeTemplate>(), //[TemplateType.Unspecified] = new KeyList<Guid, TypeSchema>(),
[TemplateType.Resource] = new KeyList<UUID, TypeTemplate>(), [TypeDefKind.Resource] = new KeyList<UUID, TypeDef>(),
[TemplateType.Record] = new KeyList<UUID, TypeTemplate>(), [TypeDefKind.Record] = new KeyList<UUID, TypeDef>(),
//[TemplateType.Wrapper] = new KeyList<Guid, TypeTemplate>(), //[TemplateType.Wrapper] = new KeyList<Guid, TypeSchema>(),
[TemplateType.Enum] = new KeyList<UUID, TypeTemplate>(), [TypeDefKind.Enum] = new KeyList<UUID, TypeDef>(),
}; };
bool warehouseIsOpen = false; bool warehouseIsOpen = false;
@@ -87,10 +88,10 @@ public class Warehouse
async (name, attributes) async (name, attributes)
=> await New<DistributedConnection>(name, null, attributes)); => await New<DistributedConnection>(name, null, attributes));
new TypeTemplate(typeof(IIPAuthPacketIAuthHeader), this); new TypeDef(typeof(IIPAuthPacketIAuthHeader), this);
new TypeTemplate(typeof(IIPAuthPacketIAuthDestination), this); new TypeDef(typeof(IIPAuthPacketIAuthDestination), this);
new TypeTemplate(typeof(IIPAuthPacketIAuthFormat), this); new TypeDef(typeof(IIPAuthPacketIAuthFormat), this);
} }
@@ -138,19 +139,19 @@ public class Warehouse
var resourceTypes = (Type[])generatedType.GetProperty("Resources").GetValue(null); var resourceTypes = (Type[])generatedType.GetProperty("Resources").GetValue(null);
foreach (var t in resourceTypes) foreach (var t in resourceTypes)
{ {
PutTemplate(new TypeTemplate(t)); RegisterSchema(new TypeDef(t));
} }
var recordTypes = (Type[])generatedType.GetProperty("Records").GetValue(null); var recordTypes = (Type[])generatedType.GetProperty("Records").GetValue(null);
foreach (var t in recordTypes) foreach (var t in recordTypes)
{ {
PutTemplate(new TypeTemplate(t)); RegisterSchema(new TypeDef(t));
} }
var enumsTypes = (Type[])generatedType.GetProperty("Enums").GetValue(null); var enumsTypes = (Type[])generatedType.GetProperty("Enums").GetValue(null);
foreach (var t in enumsTypes) foreach (var t in enumsTypes)
{ {
PutTemplate(new TypeTemplate(t)); RegisterSchema(new TypeDef(t));
} }
} }
} }
@@ -192,7 +193,7 @@ public class Warehouse
if (!rt) 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); var rt = await r.Trigger(ResourceTrigger.SystemInitialized);
if (!rt) 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
/// <param name="resource">Resource instance.</param> /// <param name="resource">Resource instance.</param>
/// <param name="store">IStore that manages the resource. Can be null if the resource is a store.</param> /// <param name="store">IStore that manages the resource. Can be null if the resource is a store.</param>
/// <param name="parent">Parent resource. if not presented the store becomes the parent for the resource.</param> /// <param name="parent">Parent resource. if not presented the store becomes the parent for the resource.</param>
//public async AsyncReply<T> Put<T>(string instanceName, T resource, IStore store, TypeTemplate customTemplate = null, ulong age = 0, IPermissionsManager manager = null, object attributes = null) where T : IResource //public async AsyncReply<T> Put<T>(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) // if (resource.Instance != null)
// throw new Exception("Resource has a store."); // throw new Exception("Resource has a store.");
@@ -526,7 +527,7 @@ public class Warehouse
{ {
var template = GetTemplateByType(type); var template = GetTemplateByType(type);
foreach (var kvp in map) foreach (var kvp in map)
template.GetPropertyTemplateByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value); template.GetPropertyDefByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value);
} }
else else
{ {
@@ -584,15 +585,15 @@ public class Warehouse
} }
/// <summary> /// <summary>
/// Put a resource template in the templates warehouse. /// Put a resource schema in the schemas warehouse.
/// </summary> /// </summary>
/// <param name="template">Resource template.</param> /// <param name="schema">Resource schema.</param>
public void PutTemplate(TypeTemplate template) public void RegisterSchema(TypeDef typeDef)
{ {
if (templates[template.Type].ContainsKey(template.ClassId)) if (schemas[typeDef.Kind].ContainsKey(typeDef.Id))
throw new Exception($"Template with same class Id already exists. {templates[template.Type][template.ClassId].ClassName} -> {template.ClassName}"); 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
/// </summary> /// </summary>
/// <param name="type">.Net type.</param> /// <param name="type">.Net type.</param>
/// <returns>Resource template.</returns> /// <returns>Resource template.</returns>
public TypeTemplate GetTemplateByType(Type type) public TypeDef GetTemplateByType(Type type)
{ {
if (!(type.IsClass || type.IsEnum)) if (!(type.IsClass || type.IsEnum))
return null; return null;
@@ -612,48 +613,48 @@ public class Warehouse
|| baseType == typeof(IRecord)) || baseType == typeof(IRecord))
return null; return null;
TemplateType templateType; TypeDefKind schemaKind;
if (Codec.ImplementsInterface(type, typeof(IResource))) if (Codec.ImplementsInterface(type, typeof(IResource)))
templateType = TemplateType.Resource; schemaKind = TypeDefKind.Resource;
else if (Codec.ImplementsInterface(type, typeof(IRecord))) else if (Codec.ImplementsInterface(type, typeof(IRecord)))
templateType = TemplateType.Record; schemaKind = TypeDefKind.Record;
else if (type.IsEnum) else if (type.IsEnum)
templateType = TemplateType.Enum; schemaKind = TypeDefKind.Enum;
else else
return null; return null;
var template = templates[templateType].Values.FirstOrDefault(x => x.DefinedType == baseType); var schema = schemas[schemaKind].Values.FirstOrDefault(x => x.DefinedType == baseType);
if (template != null) if (schema != null)
return template; return schema;
// create new template for type // create new template for type
template = new TypeTemplate(baseType, this); schema = new TypeDef(baseType, this);
TypeTemplate.GetDependencies(template, this); TypeDef.GetDependencies(schema, this);
return template; return schema;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <param name="classId">Class Id.</param> /// <param name="classId">Class Id.</param>
/// <returns>Resource template.</returns> /// <returns>Resource template.</returns>
public TypeTemplate GetTemplateByClassId(UUID classId, TemplateType? templateType = null) public TypeDef GetTypeDefById(UUID typeId, TypeDefKind? templateType = null)
{ {
if (templateType == null) if (templateType == null)
{ {
// look into resources // look into resources
var template = templates[TemplateType.Resource][classId]; var template = schemas[TypeDefKind.Resource][typeId];
if (template != null) if (template != null)
return template; return template;
// look into records // look into records
template = templates[TemplateType.Record][classId]; template = schemas[TypeDefKind.Record][typeId];
if (template != null) if (template != null)
return template; return template;
// look into enums // look into enums
template = templates[TemplateType.Enum][classId]; template = schemas[TypeDefKind.Enum][typeId];
return template; return template;
//if (template != null) //if (template != null)
@@ -663,7 +664,7 @@ public class Warehouse
//return template; //return template;
} }
else else
return templates[templateType.Value][classId]; return schemas[templateType.Value][typeId];
} }
@@ -672,22 +673,22 @@ public class Warehouse
/// </summary> /// </summary>
/// <param name="className">Class name.</param> /// <param name="className">Class name.</param>
/// <returns>Resource template.</returns> /// <returns>Resource template.</returns>
public TypeTemplate GetTemplateByClassName(string className, TemplateType? templateType = null) public TypeDef GetTypeDfByName(string typeName, TypeDefKind? templateType = null)
{ {
if (templateType == null) if (templateType == null)
{ {
// look into resources // 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) if (template != null)
return template; return template;
// look into records // 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) if (template != null)
return template; return template;
// look into enums // 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) //if (template != null)
return template; return template;
@@ -697,7 +698,7 @@ public class Warehouse
} }
else else
{ {
return templates[templateType.Value].Values.FirstOrDefault(x => x.ClassName == className); return schemas[templateType.Value].Values.FirstOrDefault(x => x.Name == typeName);
} }
} }

View File

@@ -26,13 +26,13 @@ using Esiur.Data;
using Esiur.Core; using Esiur.Core;
using Esiur.Net; using Esiur.Net;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Data.Types;
namespace Esiur.Security.Permissions; namespace Esiur.Security.Permissions;
@@ -47,7 +47,7 @@ public interface IPermissionsManager
/// <param name="member">Function, property or event to check for permission.</param> /// <param name="member">Function, property or event to check for permission.</param>
/// <param name="inquirer">Permission inquirer object.</param> /// <param name="inquirer">Permission inquirer object.</param>
/// <returns>Allowed or denined.</returns> /// <returns>Allowed or denined.</returns>
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<string, object> settings, IResource resource); bool Initialize(Map<string, object> settings, IResource resource);

View File

@@ -28,8 +28,8 @@ using System.Text;
using Esiur.Data; using Esiur.Data;
using Esiur.Core; using Esiur.Core;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using Esiur.Data.Schema;
namespace Esiur.Security.Permissions; namespace Esiur.Security.Permissions;
@@ -39,7 +39,7 @@ public class StorePermissionsManager : IPermissionsManager
public Map<string,object> Settings => settings; public Map<string,object> 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); return resource.Instance.Store.Instance.Applicable(session, action, member, inquirer);
} }

View File

@@ -28,8 +28,8 @@ using System.Text;
using Esiur.Data; using Esiur.Data;
using Esiur.Core; using Esiur.Core;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Resource.Template;
using Esiur.Security.Authority; using Esiur.Security.Authority;
using Esiur.Data.Schema;
namespace Esiur.Security.Permissions; namespace Esiur.Security.Permissions;
@@ -40,7 +40,7 @@ public class UserPermissionsManager : IPermissionsManager
public Map<string,object> Settings => settings; public Map<string,object> 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<string,object> userPermissions = null; Map<string,object> userPermissions = null;

View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Resource.Template; using Esiur.Data.Schema;
namespace Esiur.Stores; namespace Esiur.Stores;
@@ -78,7 +78,7 @@ public class MemoryStore : IStore
throw new NotImplementedException(); throw new NotImplementedException();
} }
public AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Esiur.Core; using Esiur.Core;
using Esiur.Data; using Esiur.Data;
using Esiur.Resource.Template; using Esiur.Data.Schema;
namespace Esiur.Stores; namespace Esiur.Stores;
public class TemporaryStore : IStore public class TemporaryStore : IStore
@@ -69,7 +69,7 @@ public class TemporaryStore : IStore
throw new NotImplementedException(); throw new NotImplementedException();
} }
public AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate) public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -36,7 +36,7 @@ using System.Threading.Tasks;
using Esiur.Security.Integrity; using Esiur.Security.Integrity;
using System.Linq; using System.Linq;
using Esiur.Resource.Template; using Esiur.Data.Types;
using System.Collections; using System.Collections;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Esiur.Proxy; using Esiur.Proxy;
@@ -298,7 +298,7 @@ namespace Test
static void TestObjectProps(IResource local, DistributedResource remote) 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); var lv = pt.PropertyInfo.GetValue(local);