mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-03-31 10:28:21 +00:00
No templates anymore
This commit is contained in:
@@ -1,562 +0,0 @@
|
||||
using Esiur.Core;
|
||||
using Esiur.Net.EP;
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Esiur.Data;
|
||||
using Esiur.Resource.Template;
|
||||
using System.Linq;
|
||||
using Esiur.Misc;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace Esiur.Data;
|
||||
|
||||
public static class DataDeserializer
|
||||
{
|
||||
public static AsyncReply NullParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply(null);
|
||||
}
|
||||
|
||||
public static AsyncReply BooleanTrueParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
public static AsyncReply BooleanFalseParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<bool>(false);
|
||||
}
|
||||
|
||||
public static AsyncReply NotModifiedParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<NotModified>(new NotModified());
|
||||
}
|
||||
|
||||
public static AsyncReply ByteParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<byte>(data[offset]);
|
||||
}
|
||||
public static AsyncReply SByteParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<sbyte>((sbyte)data[offset]);
|
||||
}
|
||||
public static unsafe AsyncReply Char16Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<char>(*(char*)ptr);
|
||||
}
|
||||
|
||||
public static AsyncReply Char8Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<char>((char)data[offset]);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe AsyncReply Int16Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<short>(*(short*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply UInt16Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<ushort>(*(ushort*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply Int32Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<int>(*(int*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply UInt32Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<uint>(*(uint*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply Float32Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<float>(*(float*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply Float64Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<double>(*(double*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply Float128Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<decimal>(*(decimal*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply Int128Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<decimal>(*(decimal*)ptr);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe AsyncReply UInt128Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<decimal>(*(decimal*)ptr);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe AsyncReply Int64Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<long>(*(long*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply UInt64Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<ulong>(*(ulong*)ptr);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply DateTimeParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return new AsyncReply<DateTime>(new DateTime(*(long*)ptr, DateTimeKind.Utc));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static unsafe AsyncReply ResourceParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return connection.Fetch(*(uint*)ptr, requestSequence);
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply LocalResourceParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
fixed (byte* ptr = &data[offset])
|
||||
return Warehouse.GetById(*(uint*)ptr);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe AsyncReply RawDataParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<byte[]>(data.Clip(offset, length));
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply StringParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
return new AsyncReply<string>(data.GetString(offset, length));
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply RecordParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
|
||||
var reply = new AsyncReply<IRecord>();
|
||||
|
||||
var classId = data.GetUUID(offset);
|
||||
offset += 16;
|
||||
length -= 16;
|
||||
|
||||
|
||||
var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Record);
|
||||
|
||||
var initRecord = (TypeSchema template) =>
|
||||
{
|
||||
ListParser(data, offset, length, connection, requestSequence).Then(r =>
|
||||
{
|
||||
var ar = (object[])r;
|
||||
|
||||
if (template == null)
|
||||
{
|
||||
// @TODO: add parse if no template settings
|
||||
reply.TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TemplateNotFound,
|
||||
"Template not found for record."));
|
||||
}
|
||||
else if (template.DefinedType != null)
|
||||
{
|
||||
var record = Activator.CreateInstance(template.DefinedType) as IRecord;
|
||||
for (var i = 0; i < template.Properties.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
//var v = Convert.ChangeType(ar[i], template.Properties[i].PropertyInfo.PropertyType);
|
||||
var v = DC.CastConvert(ar[i], template.Properties[i].PropertyInfo.PropertyType);
|
||||
template.Properties[i].PropertyInfo.SetValue(record, v);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Global.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
reply.Trigger(record);
|
||||
}
|
||||
else
|
||||
{
|
||||
var record = new Record();
|
||||
|
||||
for (var i = 0; i < template.Properties.Length; i++)
|
||||
record.Add(template.Properties[i].Name, ar[i]);
|
||||
|
||||
reply.Trigger(record);
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
if (template != null)
|
||||
{
|
||||
initRecord(template);
|
||||
}
|
||||
else if (connection != null)
|
||||
{
|
||||
// try to get the template from the other end
|
||||
connection.GetTemplate(classId).Then(tmp =>
|
||||
{
|
||||
initRecord(tmp);
|
||||
}).Error(x => reply.TriggerError(x));
|
||||
}
|
||||
else
|
||||
{
|
||||
initRecord(null);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply ConstantParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe AsyncReply EnumParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
|
||||
var classId = data.GetUUID(offset);
|
||||
offset += 16;
|
||||
var index = data[offset++];
|
||||
|
||||
var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Enum);
|
||||
|
||||
if (template != null)
|
||||
{
|
||||
return new AsyncReply(template.Constants[index].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var reply = new AsyncReply();
|
||||
|
||||
connection.GetTemplate(classId).Then(tmp =>
|
||||
{
|
||||
reply.Trigger(tmp.Constants[index].Value);
|
||||
}).Error(x => reply.TriggerError(x));
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static AsyncReply RecordListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var rt = new AsyncBag<IRecord>();
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
var (cs, reply) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
rt.Add(reply);
|
||||
|
||||
if (cs > 0)
|
||||
{
|
||||
offset += (uint)cs;
|
||||
length -= (uint)cs;
|
||||
}
|
||||
else
|
||||
throw new Exception("Error while parsing structured data");
|
||||
|
||||
}
|
||||
|
||||
rt.Seal();
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static AsyncReply ResourceListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var rt = new AsyncBag<IResource>();
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
var (cs, reply) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
rt.Add(reply);
|
||||
|
||||
if (cs > 0)
|
||||
{
|
||||
offset += (uint)cs;
|
||||
length -= (uint)cs;
|
||||
}
|
||||
else
|
||||
throw new Exception("Error while parsing structured data");
|
||||
|
||||
}
|
||||
|
||||
rt.Seal();
|
||||
return rt;
|
||||
}
|
||||
|
||||
|
||||
public static AsyncBag<object> ListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var rt = new AsyncBag<object>();
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
var (cs, reply) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
rt.Add(reply);
|
||||
|
||||
if (cs > 0)
|
||||
{
|
||||
offset += (uint)cs;
|
||||
length -= (uint)cs;
|
||||
}
|
||||
else
|
||||
throw new Exception("Error while parsing structured data");
|
||||
|
||||
}
|
||||
|
||||
rt.Seal();
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static AsyncReply TypedMapParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
// get key type
|
||||
var (keyCs, keyRepType) = RepresentationType.Parse(data, offset);
|
||||
offset += keyCs;
|
||||
length -= keyCs;
|
||||
|
||||
var (valueCs, valueRepType) = RepresentationType.Parse(data, offset);
|
||||
offset += valueCs;
|
||||
length -= valueCs;
|
||||
|
||||
var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(keyRepType.GetRuntimeType(), valueRepType.GetRuntimeType()));
|
||||
|
||||
var rt = new AsyncReply();
|
||||
|
||||
var results = new AsyncBag<object>();
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
var (cs, reply) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
|
||||
results.Add(reply);
|
||||
|
||||
if (cs > 0)
|
||||
{
|
||||
offset += (uint)cs;
|
||||
length -= (uint)cs;
|
||||
}
|
||||
else
|
||||
throw new Exception("Error while parsing structured data");
|
||||
|
||||
}
|
||||
|
||||
results.Seal();
|
||||
|
||||
results.Then(ar =>
|
||||
{
|
||||
for (var i = 0; i < ar.Length; i += 2)
|
||||
map.Add(ar[i], ar[i + 1]);
|
||||
|
||||
rt.Trigger(map);
|
||||
});
|
||||
|
||||
|
||||
return rt;
|
||||
|
||||
}
|
||||
|
||||
public static AsyncReply TupleParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var results = new AsyncBag<object>();
|
||||
var rt = new AsyncReply();
|
||||
|
||||
var tupleSize = data[offset++];
|
||||
length--;
|
||||
|
||||
var types = new List<Type>();
|
||||
|
||||
for (var i = 0; i < tupleSize; i++)
|
||||
{
|
||||
var (cs, rep) = RepresentationType.Parse(data, offset);
|
||||
types.Add(rep.GetRuntimeType());
|
||||
offset += cs;
|
||||
length -= cs;
|
||||
}
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
var (cs, reply) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
results.Add(reply);
|
||||
|
||||
if (cs > 0)
|
||||
{
|
||||
offset += (uint)cs;
|
||||
length -= (uint)cs;
|
||||
}
|
||||
else
|
||||
throw new Exception("Error while parsing structured data");
|
||||
|
||||
}
|
||||
|
||||
results.Seal();
|
||||
|
||||
|
||||
results.Then(ar =>
|
||||
{
|
||||
if (ar.Length == 2)
|
||||
{
|
||||
var type = typeof(ValueTuple<,>).MakeGenericType(types.ToArray());
|
||||
rt.Trigger(Activator.CreateInstance(type, ar[0], ar[1]));
|
||||
}
|
||||
else if (ar.Length == 3)
|
||||
{
|
||||
var type = typeof(ValueTuple<,,>).MakeGenericType(types.ToArray());
|
||||
rt.Trigger(Activator.CreateInstance(type, ar[0], ar[1], ar[2]));
|
||||
}
|
||||
else if (ar.Length == 4)
|
||||
{
|
||||
var type = typeof(ValueTuple<,,,>).MakeGenericType(types.ToArray());
|
||||
rt.Trigger(Activator.CreateInstance(type, ar[0], ar[1], ar[2], ar[3]));
|
||||
}
|
||||
});
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static AsyncReply TypedListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
var rt = new AsyncBag<object>();
|
||||
|
||||
// get the type
|
||||
var (hdrCs, rep) = RepresentationType.Parse(data, offset);
|
||||
|
||||
offset += hdrCs;
|
||||
length -= hdrCs;
|
||||
|
||||
var runtimeType = rep.GetRuntimeType();
|
||||
|
||||
rt.ArrayType = runtimeType;
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
var (cs, reply) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
rt.Add(reply);
|
||||
|
||||
if (cs > 0)
|
||||
{
|
||||
offset += (uint)cs;
|
||||
length -= (uint)cs;
|
||||
}
|
||||
else
|
||||
throw new Exception("Error while parsing structured data");
|
||||
|
||||
}
|
||||
|
||||
rt.Seal();
|
||||
return rt;
|
||||
}
|
||||
|
||||
|
||||
public static AsyncBag<PropertyValue> PropertyValueArrayParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
|
||||
{
|
||||
var rt = new AsyncBag<PropertyValue>();
|
||||
|
||||
|
||||
ListParser(data, offset, length, connection, requestSequence).Then(x =>
|
||||
{
|
||||
var ar = (object[])x;
|
||||
var pvs = new List<PropertyValue>();
|
||||
|
||||
for (var i = 0; i < ar.Length; i += 3)
|
||||
pvs.Add(new PropertyValue(ar[2], (ulong?)ar[0], (DateTime?)ar[1]));
|
||||
|
||||
|
||||
rt.Trigger(pvs.ToArray());
|
||||
});
|
||||
|
||||
return rt;
|
||||
|
||||
}
|
||||
|
||||
public static (uint, AsyncReply<PropertyValue>) PropertyValueParser(byte[] data, uint offset, EpConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
|
||||
{
|
||||
var reply = new AsyncReply<PropertyValue>();
|
||||
|
||||
var age = data.GetUInt64(offset, Endian.Little);
|
||||
offset += 8;
|
||||
|
||||
DateTime date = data.GetDateTime(offset, Endian.Little);
|
||||
offset += 8;
|
||||
|
||||
|
||||
var (valueSize, results) = Codec.Parse(data, offset, connection, requestSequence);
|
||||
|
||||
results.Then(value =>
|
||||
{
|
||||
reply.Trigger(new PropertyValue(value, age, date));
|
||||
});
|
||||
|
||||
return (16 + valueSize, reply);
|
||||
}
|
||||
|
||||
public static AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> HistoryParser(byte[] data, uint offset, uint length, IResource resource, EpConnection connection, uint[] requestSequence)
|
||||
{
|
||||
//var count = (int)toAge - (int)fromAge;
|
||||
|
||||
var list = new KeyList<PropertyTemplate, PropertyValue[]>();
|
||||
|
||||
var reply = new AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>>();
|
||||
|
||||
var bagOfBags = new AsyncBag<PropertyValue[]>();
|
||||
|
||||
var ends = offset + length;
|
||||
while (offset < ends)
|
||||
{
|
||||
var index = data[offset++];
|
||||
var pt = resource.Instance.Template.GetPropertyTemplateByIndex(index);
|
||||
list.Add(pt, null);
|
||||
var cs = data.GetUInt32(offset, Endian.Little);
|
||||
offset += 4;
|
||||
|
||||
var (len, pv) = PropertyValueParser(data, offset, connection, requestSequence);
|
||||
|
||||
bagOfBags.Add(pv);// ParsePropertyValueArray(data, offset, cs, connection));
|
||||
offset += len;
|
||||
}
|
||||
|
||||
bagOfBags.Seal();
|
||||
|
||||
bagOfBags.Then(x =>
|
||||
{
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
list[list.Keys.ElementAt(i)] = x[i];
|
||||
|
||||
reply.Trigger(list);
|
||||
});
|
||||
|
||||
return reply;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -517,8 +517,8 @@ public static class DataDeserializer
|
||||
|
||||
public static unsafe object RecordParser(ParsedTDU tdu, Warehouse warehouse)
|
||||
{
|
||||
var classId = tdu.Metadata.GetUUID(0);
|
||||
var typeDef = warehouse.GetTypeDefById(classId, TypeDefKind.Record);
|
||||
var typeId = tdu.Metadata.GetUUID(0);
|
||||
var typeDef = warehouse.GetTypeDefById(typeId, TypeDefKind.Record);
|
||||
|
||||
if (typeDef == null)
|
||||
{
|
||||
|
||||
@@ -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