mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-03-31 18:38:22 +00:00
No templates anymore
This commit is contained in:
@@ -1,131 +1 @@
|
||||
//using Esiur.Data;
|
||||
//using System;
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Dynamic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
|
||||
//namespace Esiur.Resource.Template;
|
||||
//public struct TemplateDataType
|
||||
//{
|
||||
// public DataType Type { get; set; }
|
||||
// //public string TypeName { get; set; }
|
||||
// public TypeTemplate TypeTemplate => TypeGuid == null ? null : Warehouse.GetTemplateByClassId((Guid)TypeGuid);
|
||||
|
||||
// public Guid? TypeGuid { get; set; }
|
||||
|
||||
// public bool IsNullable { get; set; }
|
||||
// //public TemplateDataType(DataType type, string typeName)
|
||||
// //{
|
||||
// // Type = type;
|
||||
// // TypeName = typeName;
|
||||
// //}
|
||||
|
||||
|
||||
|
||||
// public static TemplateDataType FromType(Type type)
|
||||
// {
|
||||
|
||||
|
||||
// bool isList = typeof(ICollection).IsAssignableFrom(type);
|
||||
|
||||
// var t = type switch
|
||||
// {
|
||||
|
||||
// { IsArray: true } => type.GetElementType(),
|
||||
// { IsEnum: true } => type.GetEnumUnderlyingType(),
|
||||
// _ when isList => Codec.GetGenericListType(type),
|
||||
// (_) => type
|
||||
// };
|
||||
|
||||
// DataType dt = t switch
|
||||
// {
|
||||
// _ when t == typeof(bool) => DataType.Bool,
|
||||
// _ when t == typeof(char) => DataType.Char,
|
||||
// _ when t == typeof(byte) => DataType.UInt8,
|
||||
// _ when t == typeof(sbyte) => DataType.Int8,
|
||||
// _ when t == typeof(short) => DataType.Int16,
|
||||
// _ when t == typeof(ushort) => DataType.UInt16,
|
||||
// _ when t == typeof(int) => DataType.Int32,
|
||||
// _ when t == typeof(uint) => DataType.UInt32,
|
||||
// _ when t == typeof(long) => DataType.Int64,
|
||||
// _ when t == typeof(ulong) => DataType.UInt64,
|
||||
// _ when t == typeof(float) => DataType.Float32,
|
||||
// _ when t == typeof(double) => DataType.Float64,
|
||||
// _ when t == typeof(decimal) => DataType.Decimal,
|
||||
// _ when t == typeof(string) => DataType.String,
|
||||
// _ when t == typeof(DateTime) => DataType.DateTime,
|
||||
// _ when t == typeof(IResource) => DataType.Void, // Dynamic resource (unspecified type)
|
||||
// _ when t == typeof(IRecord) => DataType.Void, // Dynamic record (unspecified type)
|
||||
// _ when typeof(Structure).IsAssignableFrom(t) || t == typeof(ExpandoObject) => DataType.Structure,
|
||||
// _ when Codec.ImplementsInterface(t, typeof(IResource)) => DataType.Resource,
|
||||
// _ when Codec.ImplementsInterface(t, typeof(IRecord)) => DataType.Record,
|
||||
// _ => DataType.Void
|
||||
// };
|
||||
|
||||
|
||||
// Guid? typeGuid = null;
|
||||
|
||||
// if (dt == DataType.Resource || dt == DataType.Record)
|
||||
// typeGuid = TypeTemplate.GetTypeGuid(t);
|
||||
|
||||
// if (type.IsArray || isList)
|
||||
// dt = (DataType)((byte)dt | 0x80);
|
||||
|
||||
|
||||
// return new TemplateDataType()
|
||||
// {
|
||||
// Type = dt,
|
||||
// TypeGuid = typeGuid,
|
||||
// IsNullable = Nullable.GetUnderlyingType(type) != null
|
||||
// };
|
||||
// }
|
||||
|
||||
// public byte[] Compose()
|
||||
// {
|
||||
// if (Type == DataType.Resource ||
|
||||
// Type == DataType.ResourceArray ||
|
||||
// Type == DataType.Record ||
|
||||
// Type == DataType.RecordArray)
|
||||
// {
|
||||
// var guid = DC.ToBytes((Guid)TypeGuid);
|
||||
// if (IsNullable)
|
||||
// {
|
||||
// return new BinaryList()
|
||||
// .AddUInt8((byte)((byte)Type | 0x40))
|
||||
// .AddUInt8Array(guid).ToArray();
|
||||
// } else
|
||||
// {
|
||||
// return new BinaryList()
|
||||
// .AddUInt8((byte)Type)
|
||||
// .AddUInt8Array(guid).ToArray();
|
||||
// }
|
||||
// }
|
||||
// else if (IsNullable)
|
||||
// return new byte[] { (byte)((byte)Type | 0x40) };
|
||||
// else
|
||||
// return new byte[] { (byte)Type };
|
||||
// }
|
||||
|
||||
// public override string ToString() => Type.ToString() + (IsNullable ? "?":"" )
|
||||
// + TypeTemplate != null ? "<" + TypeTemplate.ClassName + ">" : "";
|
||||
|
||||
|
||||
// public static (uint, TemplateDataType) Parse(byte[] data, uint offset)
|
||||
// {
|
||||
// bool isNullable = (data[offset] & 0x40) > 0;
|
||||
// var type = (DataType)(data[offset++] & 0xBF);
|
||||
|
||||
// if (type == DataType.Resource ||
|
||||
// type == DataType.ResourceArray ||
|
||||
// type == DataType.Record ||
|
||||
// type == DataType.RecordArray)
|
||||
// {
|
||||
// var guid = data.GetGuid(offset);
|
||||
// return (17, new TemplateDataType() { Type = type, TypeGuid = guid , IsNullable = isNullable});
|
||||
// }
|
||||
// else
|
||||
// return (1, new TemplateDataType() { Type = type, IsNullable = isNullable });
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -103,13 +103,6 @@ public class EventDef : MemberDef
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
//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)
|
||||
//{
|
||||
// this.Annotations = annotations;
|
||||
// this.Subscribable = subscribable;
|
||||
// this.ArgumentType = argumentType;
|
||||
//}
|
||||
|
||||
public static EventDef MakeEventDef(Type type, EventInfo ei, byte index, string name, TypeDef schema)
|
||||
{
|
||||
|
||||
@@ -118,16 +118,6 @@ public class FunctionDef : MemberDef
|
||||
return bl.ToArray();
|
||||
}
|
||||
|
||||
//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)
|
||||
//{
|
||||
// this.Arguments = arguments;
|
||||
// this.ReturnType = returnType;
|
||||
// this.Annotations = annotations;
|
||||
// this.IsStatic = isStatic;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
public static FunctionDef MakeFunctionDef(Type type, MethodInfo mi, byte index, string name, TypeDef schema)
|
||||
{
|
||||
|
||||
@@ -13,20 +13,9 @@ public class MemberDef
|
||||
public string Name { get; set; }
|
||||
public bool Inherited { get; set; }
|
||||
public TypeDef Definition { get; set; }
|
||||
|
||||
//public MemberTemplate()
|
||||
//{
|
||||
// Template = template;
|
||||
// Index = index;
|
||||
// Name = name;
|
||||
// Inherited = inherited;
|
||||
//}
|
||||
|
||||
|
||||
public string Fullname => Definition.Name + "." + Name;
|
||||
|
||||
//public virtual byte[] Compose()
|
||||
//{
|
||||
// return DC.ToBytes(Name);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,6 @@ using Esiur.Protocol;
|
||||
|
||||
namespace Esiur.Data.Types;
|
||||
|
||||
//public enum TemplateType
|
||||
//{
|
||||
// Resource,
|
||||
// Record
|
||||
//}
|
||||
|
||||
public class TypeDef
|
||||
{
|
||||
@@ -43,8 +38,6 @@ public class TypeDef
|
||||
return typeName;
|
||||
}
|
||||
|
||||
// protected TemplateType
|
||||
//bool isReady;
|
||||
|
||||
protected byte[] content;
|
||||
|
||||
@@ -61,17 +54,6 @@ public class TypeDef
|
||||
public Type DefinedType { get; set; }
|
||||
public Type ParentDefinedType { get; set; }
|
||||
|
||||
//public MemberTemplate GetMemberTemplate(MemberInfo member)
|
||||
//{
|
||||
// if (member is MethodInfo)
|
||||
// return GetFunctionTemplateByName(member.Name);
|
||||
// else if (member is EventInfo)
|
||||
// return GetEventTemplateByName(member.Name);
|
||||
// else if (member is PropertyInfo)
|
||||
// return GetPropertyTemplateByName(member.Name);
|
||||
// else
|
||||
// return null;
|
||||
//}
|
||||
|
||||
public EventDef GetEventDefByName(string eventName)
|
||||
{
|
||||
@@ -137,10 +119,6 @@ public class TypeDef
|
||||
get { return typeName; }
|
||||
}
|
||||
|
||||
//public MemberTemplate[] Methods
|
||||
//{
|
||||
// get { return members.ToArray(); }
|
||||
//}
|
||||
|
||||
public FunctionDef[] Functions
|
||||
{
|
||||
@@ -166,9 +144,9 @@ public class TypeDef
|
||||
|
||||
public static UUID GetTypeUUID(Type type)
|
||||
{
|
||||
var attr = type.GetCustomAttribute<ClassIdAttribute>();
|
||||
var attr = type.GetCustomAttribute<TypeIdAttribute>();
|
||||
if (attr != null)
|
||||
return attr.ClassId;
|
||||
return attr.Id;
|
||||
|
||||
var tn = Encoding.UTF8.GetBytes(GetTypeName(type));
|
||||
var hash = SHA256.Create().ComputeHash(tn).Clip(0, 16);
|
||||
@@ -245,11 +223,11 @@ public class TypeDef
|
||||
// Get parents
|
||||
while (parentType != null)
|
||||
{
|
||||
var parentTemplate = warehouse.GetTypeDefByType(parentType);
|
||||
if (parentTemplate != null)
|
||||
var parentTypeDef = warehouse.GetTypeDefByType(parentType);
|
||||
if (parentTypeDef != null)
|
||||
{
|
||||
list.Add(parentTemplate);
|
||||
parentType = parentTemplate.ParentDefinedType;
|
||||
list.Add(parentTypeDef);
|
||||
parentType = parentTypeDef.ParentDefinedType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,18 +235,16 @@ public class TypeDef
|
||||
foreach (var f in sch.functions)
|
||||
{
|
||||
var functionReturnTypes = GetDistributedTypes(f.MethodInfo.ReturnType);
|
||||
//.Select(x => Warehouse.GetTemplateByType(x))
|
||||
//.Where(x => x != null && !bag.Contains(x))
|
||||
|
||||
foreach (var functionReturnType in functionReturnTypes)
|
||||
{
|
||||
var functionReturnTemplate = warehouse.GetTypeDefByType(functionReturnType);
|
||||
if (functionReturnTemplate != null)
|
||||
var functionReturnTypeDef = warehouse.GetTypeDefByType(functionReturnType);
|
||||
if (functionReturnTypeDef != null)
|
||||
{
|
||||
if (!bag.Contains(functionReturnTemplate))
|
||||
if (!bag.Contains(functionReturnTypeDef))
|
||||
{
|
||||
list.Add(functionReturnTemplate);
|
||||
getDependenciesFunc(functionReturnTemplate, bag);
|
||||
list.Add(functionReturnTypeDef);
|
||||
getDependenciesFunc(functionReturnTypeDef, bag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -326,13 +302,13 @@ public class TypeDef
|
||||
|
||||
foreach (var propertyType in propertyTypes)
|
||||
{
|
||||
var propertyTemplate = warehouse.GetTypeDefByType(propertyType);
|
||||
if (propertyTemplate != null)
|
||||
var propertyTypeDef = warehouse.GetTypeDefByType(propertyType);
|
||||
if (propertyTypeDef != null)
|
||||
{
|
||||
if (!bag.Contains(propertyTemplate))
|
||||
if (!bag.Contains(propertyTypeDef))
|
||||
{
|
||||
bag.Add(propertyTemplate);
|
||||
getDependenciesFunc(propertyTemplate, bag);
|
||||
bag.Add(propertyTypeDef);
|
||||
getDependenciesFunc(propertyTypeDef, bag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,14 +321,14 @@ public class TypeDef
|
||||
|
||||
foreach (var eventType in eventTypes)
|
||||
{
|
||||
var eventTemplate = warehouse.GetTypeDefByType(eventType);
|
||||
var eventTypeDef = warehouse.GetTypeDefByType(eventType);
|
||||
|
||||
if (eventTemplate != null)
|
||||
if (eventTypeDef != null)
|
||||
{
|
||||
if (!bag.Contains(eventTemplate))
|
||||
if (!bag.Contains(eventTypeDef))
|
||||
{
|
||||
bag.Add(eventTemplate);
|
||||
getDependenciesFunc(eventTemplate, bag);
|
||||
bag.Add(eventTypeDef);
|
||||
getDependenciesFunc(eventTypeDef, bag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user