mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
fix generator
This commit is contained in:
parent
80922a13ee
commit
f5e61d4b86
@ -168,6 +168,12 @@ namespace Esiur.Data
|
|||||||
|
|
||||||
public RepresentationType?[] SubTypes = new RepresentationType[3];
|
public RepresentationType?[] SubTypes = new RepresentationType[3];
|
||||||
|
|
||||||
|
|
||||||
|
public RepresentationType ToNullable()
|
||||||
|
{
|
||||||
|
return new RepresentationType(Identifier, true, GUID, SubTypes);
|
||||||
|
}
|
||||||
|
|
||||||
public static RepresentationType? FromType(Type type)
|
public static RepresentationType? FromType(Type type)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ partial class DistributedConnection
|
|||||||
KeyList<uint, AsyncReply<DistributedResource>> resourceRequests = new KeyList<uint, AsyncReply<DistributedResource>>();
|
KeyList<uint, AsyncReply<DistributedResource>> resourceRequests = new KeyList<uint, AsyncReply<DistributedResource>>();
|
||||||
KeyList<Guid, AsyncReply<TypeTemplate>> templateRequests = new KeyList<Guid, AsyncReply<TypeTemplate>>();
|
KeyList<Guid, AsyncReply<TypeTemplate>> templateRequests = new KeyList<Guid, AsyncReply<TypeTemplate>>();
|
||||||
|
|
||||||
|
KeyList<string, AsyncReply<TypeTemplate>> templateByNameRequests = new KeyList<string, AsyncReply<TypeTemplate>>();
|
||||||
|
|
||||||
|
|
||||||
KeyList<string, AsyncReply<IResource>> pathRequests = new KeyList<string, AsyncReply<IResource>>();
|
KeyList<string, AsyncReply<IResource>> pathRequests = new KeyList<string, AsyncReply<IResource>>();
|
||||||
|
|
||||||
@ -1888,6 +1890,39 @@ partial class DistributedConnection
|
|||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AsyncReply<TypeTemplate> GetTemplateByClassName(string className)
|
||||||
|
{
|
||||||
|
var template = templates.Values.FirstOrDefault(x => x.ClassName == className);
|
||||||
|
if (template != null)
|
||||||
|
return new AsyncReply<TypeTemplate>(template);
|
||||||
|
|
||||||
|
if (templateByNameRequests.ContainsKey(className))
|
||||||
|
return templateByNameRequests[className];
|
||||||
|
|
||||||
|
var reply = new AsyncReply<TypeTemplate>();
|
||||||
|
templateByNameRequests.Add(className, reply);
|
||||||
|
|
||||||
|
var classNameBytes = DC.ToBytes(className);
|
||||||
|
|
||||||
|
SendRequest(IIPPacket.IIPPacketAction.TemplateFromClassName)
|
||||||
|
.AddUInt8((byte)classNameBytes.Length)
|
||||||
|
.AddUInt8Array(classNameBytes)
|
||||||
|
.Done()
|
||||||
|
.Then((rt) =>
|
||||||
|
{
|
||||||
|
templateByNameRequests.Remove(className);
|
||||||
|
templates.Add(((TypeTemplate)rt[0]).ClassId, (TypeTemplate)rt[0]);
|
||||||
|
Warehouse.PutTemplate(rt[0] as TypeTemplate);
|
||||||
|
reply.Trigger(rt[0]);
|
||||||
|
}).Error((ex) =>
|
||||||
|
{
|
||||||
|
reply.TriggerError(ex);
|
||||||
|
});
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
// IStore interface
|
// IStore interface
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a resource by its path.
|
/// Get a resource by its path.
|
||||||
|
@ -222,6 +222,7 @@ public class DistributedResource : DynamicObject, IResource
|
|||||||
|
|
||||||
public AsyncReply<object> _Invoke(byte index, Map<byte, object> args)
|
public AsyncReply<object> _Invoke(byte index, Map<byte, object> args)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (destroyed)
|
if (destroyed)
|
||||||
throw new Exception("Trying to access destroyed object");
|
throw new Exception("Trying to access destroyed object");
|
||||||
|
|
||||||
|
@ -284,12 +284,42 @@ public static class TemplateGenerator
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var rtTypeName = GetTypeName(f.ReturnType, templates);
|
var rtTypeName = GetTypeName(f.ReturnType, templates);
|
||||||
|
|
||||||
|
var positionalArgs = f.Arguments.Where((x) => !x.Optional).ToArray();
|
||||||
|
var optionalArgs = f.Arguments.Where((x) => x.Optional).ToArray();
|
||||||
|
|
||||||
|
|
||||||
rt.Append($"public AsyncReply<{rtTypeName}> {f.Name}(");
|
rt.Append($"public AsyncReply<{rtTypeName}> {f.Name}(");
|
||||||
rt.Append(string.Join(",", f.Arguments.Select(x => GetTypeName(x.Type, templates) + " " + x.Name)));
|
|
||||||
|
|
||||||
|
if (positionalArgs.Length > 0)
|
||||||
|
rt.Append(
|
||||||
|
String.Join(", ", positionalArgs.Select((a) => GetTypeName(a.Type, templates) + " " + a.Name)));
|
||||||
|
|
||||||
|
if (optionalArgs.Length > 0)
|
||||||
|
{
|
||||||
|
if (positionalArgs.Length > 0) rt.Append(",");
|
||||||
|
|
||||||
|
rt.Append(
|
||||||
|
String.Join(", ", optionalArgs.Select((a) => GetTypeName(a.Type.ToNullable(), templates) + " " + a.Name + " = null")));
|
||||||
|
}
|
||||||
|
|
||||||
|
//rt.Append(string.Join(",", f.Arguments.Select(x => GetTypeName(x.Type, templates) + " " + x.Name)));
|
||||||
|
|
||||||
rt.AppendLine(") {");
|
rt.AppendLine(") {");
|
||||||
|
|
||||||
|
rt.AppendLine(
|
||||||
|
$"var args = new Map<byte, object>(){{{ String.Join(", ", positionalArgs.Select((e) => "[" + e.Index + "] = " + e.Name))}}};");
|
||||||
|
|
||||||
|
foreach(var a in optionalArgs) {
|
||||||
|
rt.AppendLine(
|
||||||
|
$"if ({a.Name} != null) args[{a.Index}] = {a.Name};");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
rt.AppendLine($"var rt = new AsyncReply<{rtTypeName}>();");
|
rt.AppendLine($"var rt = new AsyncReply<{rtTypeName}>();");
|
||||||
rt.AppendLine($"_InvokeByArrayArguments({f.Index}, new object[] {{ { string.Join(", ", f.Arguments.Select(x => x.Name)) } }})");
|
//rt.AppendLine($"_Invoke({f.Index}, new Map<byte, object>[] {{ { string.Join(", ", f.Arguments.Select(x => x.Name)) } }})");
|
||||||
|
rt.AppendLine($"_Invoke({f.Index}, args)");
|
||||||
rt.AppendLine($".Then(x => rt.Trigger(({rtTypeName})x))");
|
rt.AppendLine($".Then(x => rt.Trigger(({rtTypeName})x))");
|
||||||
rt.AppendLine($".Error(x => rt.TriggerError(x))");
|
rt.AppendLine($".Error(x => rt.TriggerError(x))");
|
||||||
rt.AppendLine($".Chunk(x => rt.TriggerChunk(x));");
|
rt.AppendLine($".Chunk(x => rt.TriggerChunk(x));");
|
||||||
|
@ -33,19 +33,19 @@ namespace Esiur.Resource;
|
|||||||
public class ResourceEvent : System.Attribute
|
public class ResourceEvent : System.Attribute
|
||||||
{
|
{
|
||||||
|
|
||||||
string expansion;
|
string annotation;
|
||||||
|
|
||||||
public string Expansion
|
public readonly string Annotation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return expansion;
|
return annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ResourceEvent(string expansion = null)
|
public ResourceEvent(string annotation = null)
|
||||||
{
|
{
|
||||||
this.expansion = expansion;
|
this.annotation = annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,19 +33,19 @@ namespace Esiur.Resource;
|
|||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public class ResourceFunction : System.Attribute
|
public class ResourceFunction : System.Attribute
|
||||||
{
|
{
|
||||||
private string expansion = null;
|
private string annotation = null;
|
||||||
|
|
||||||
public string Expansion
|
public string Annotation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return expansion;
|
return annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ResourceFunction(string expansion = null)
|
public ResourceFunction(string annotation = null)
|
||||||
{
|
{
|
||||||
this.expansion = expansion;
|
this.annotation = annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,15 +39,15 @@ public class ResourceProperty : System.Attribute
|
|||||||
public readonly bool Nullable;
|
public readonly bool Nullable;
|
||||||
public readonly StorageMode Storage;
|
public readonly StorageMode Storage;
|
||||||
public readonly bool Serialize;
|
public readonly bool Serialize;
|
||||||
public readonly string ReadExpansion;
|
public readonly string ReadAnnotation;
|
||||||
public readonly string WriteExpansion;
|
public readonly string WriteAnnotation;
|
||||||
|
|
||||||
|
|
||||||
public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, bool serialize = true,
|
public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, bool serialize = true,
|
||||||
string readExpansion = null, string writeExpansion = null)
|
string readAnnotation = null, string writeAnnotation = null)
|
||||||
{
|
{
|
||||||
this.ReadExpansion = readExpansion;
|
this.ReadAnnotation = readAnnotation;
|
||||||
this.WriteExpansion = writeExpansion;
|
this.WriteAnnotation = writeAnnotation;
|
||||||
this.Storage = storage;
|
this.Storage = storage;
|
||||||
this.Serialize = serialize;
|
this.Serialize = serialize;
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ public class ConstantTemplate : MemberTemplate
|
|||||||
{
|
{
|
||||||
public readonly object Value;
|
public readonly object Value;
|
||||||
//public readonly byte[] ValueData;
|
//public readonly byte[] ValueData;
|
||||||
public readonly string Expansion;
|
public readonly string Annotation;
|
||||||
public readonly RepresentationType ValueType;
|
public readonly RepresentationType ValueType;
|
||||||
|
|
||||||
public ConstantTemplate(TypeTemplate template, byte index, string name, bool inherited, RepresentationType valueType, object value, string expansion)
|
public ConstantTemplate(TypeTemplate template, byte index, string name, bool inherited, RepresentationType valueType, object value, string annotation)
|
||||||
: base(template, index, name, inherited)
|
: base(template, index, name, inherited)
|
||||||
{
|
{
|
||||||
Expansion = expansion;
|
Annotation = annotation;
|
||||||
ValueType = valueType;
|
ValueType = valueType;
|
||||||
Value = value;
|
Value = value;
|
||||||
//try
|
//try
|
||||||
@ -36,9 +36,9 @@ public class ConstantTemplate : MemberTemplate
|
|||||||
var hdr = Inherited ? (byte)0x80 : (byte)0;
|
var hdr = Inherited ? (byte)0x80 : (byte)0;
|
||||||
|
|
||||||
|
|
||||||
if (Expansion != null)
|
if (Annotation != null)
|
||||||
{
|
{
|
||||||
var exp = DC.ToBytes(Expansion);
|
var exp = DC.ToBytes(Annotation);
|
||||||
hdr |= 0x70;
|
hdr |= 0x70;
|
||||||
return new BinaryList()
|
return new BinaryList()
|
||||||
.AddUInt8(hdr)
|
.AddUInt8(hdr)
|
||||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Esiur.Resource.Template;
|
namespace Esiur.Resource.Template;
|
||||||
public class EventTemplate : MemberTemplate
|
public class EventTemplate : MemberTemplate
|
||||||
{
|
{
|
||||||
public string Expansion
|
public string Annotation
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
@ -30,9 +30,9 @@ public class EventTemplate : MemberTemplate
|
|||||||
if (Listenable)
|
if (Listenable)
|
||||||
hdr |= 0x8;
|
hdr |= 0x8;
|
||||||
|
|
||||||
if (Expansion != null)
|
if (Annotation != null)
|
||||||
{
|
{
|
||||||
var exp = DC.ToBytes(Expansion);
|
var exp = DC.ToBytes(Annotation);
|
||||||
hdr |= 0x50;
|
hdr |= 0x50;
|
||||||
return new BinaryList()
|
return new BinaryList()
|
||||||
.AddUInt8(hdr)
|
.AddUInt8(hdr)
|
||||||
@ -53,10 +53,10 @@ public class EventTemplate : MemberTemplate
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventTemplate(TypeTemplate template, byte index, string name,bool inherited, RepresentationType argumentType, string expansion = null, bool listenable = false)
|
public EventTemplate(TypeTemplate template, byte index, string name,bool inherited, RepresentationType argumentType, string annotation = null, bool listenable = false)
|
||||||
: base(template, index, name, inherited)
|
: base(template, index, name, inherited)
|
||||||
{
|
{
|
||||||
this.Expansion = expansion;
|
this.Annotation = annotation;
|
||||||
this.Listenable = listenable;
|
this.Listenable = listenable;
|
||||||
this.ArgumentType = argumentType;
|
this.ArgumentType = argumentType;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace Esiur.Resource.Template;
|
|||||||
public class FunctionTemplate : MemberTemplate
|
public class FunctionTemplate : MemberTemplate
|
||||||
{
|
{
|
||||||
|
|
||||||
public string Expansion
|
public string Annotation
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
@ -39,7 +39,6 @@ public class FunctionTemplate : MemberTemplate
|
|||||||
var name = base.Compose();
|
var name = base.Compose();
|
||||||
|
|
||||||
var bl = new BinaryList()
|
var bl = new BinaryList()
|
||||||
//.AddUInt8(Expansion != null ? (byte)0x10 : (byte)0)
|
|
||||||
.AddUInt8((byte)name.Length)
|
.AddUInt8((byte)name.Length)
|
||||||
.AddUInt8Array(name)
|
.AddUInt8Array(name)
|
||||||
.AddUInt8Array(ReturnType.Compose())
|
.AddUInt8Array(ReturnType.Compose())
|
||||||
@ -49,9 +48,9 @@ public class FunctionTemplate : MemberTemplate
|
|||||||
bl.AddUInt8Array(Arguments[i].Compose());
|
bl.AddUInt8Array(Arguments[i].Compose());
|
||||||
|
|
||||||
|
|
||||||
if (Expansion != null)
|
if (Annotation != null)
|
||||||
{
|
{
|
||||||
var exp = DC.ToBytes(Expansion);
|
var exp = DC.ToBytes(Annotation);
|
||||||
bl.AddInt32(exp.Length)
|
bl.AddInt32(exp.Length)
|
||||||
.AddUInt8Array(exp);
|
.AddUInt8Array(exp);
|
||||||
bl.InsertUInt8(0, Inherited ? (byte)0x90 : (byte)0x10);
|
bl.InsertUInt8(0, Inherited ? (byte)0x90 : (byte)0x10);
|
||||||
@ -62,12 +61,12 @@ public class FunctionTemplate : MemberTemplate
|
|||||||
return bl.ToArray();
|
return bl.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, ArgumentTemplate[] arguments, RepresentationType returnType, string expansion = null)
|
public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, ArgumentTemplate[] arguments, RepresentationType returnType, string annotation = null)
|
||||||
: base(template, index, name, inherited)
|
: base(template, index, name, inherited)
|
||||||
{
|
{
|
||||||
//this.IsVoid = isVoid;
|
//this.IsVoid = isVoid;
|
||||||
this.Arguments = arguments;
|
this.Arguments = arguments;
|
||||||
this.ReturnType = returnType;
|
this.ReturnType = returnType;
|
||||||
this.Expansion = expansion;
|
this.Annotation = annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,13 +55,13 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
set;
|
set;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public string ReadExpansion
|
public string ReadAnnotation
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string WriteExpansion
|
public string WriteAnnotation
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
@ -83,10 +83,10 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
if (Inherited)
|
if (Inherited)
|
||||||
pv |= 0x80;
|
pv |= 0x80;
|
||||||
|
|
||||||
if (WriteExpansion != null && ReadExpansion != null)
|
if (WriteAnnotation != null && ReadAnnotation != null)
|
||||||
{
|
{
|
||||||
var rexp = DC.ToBytes(ReadExpansion);
|
var rexp = DC.ToBytes(ReadAnnotation);
|
||||||
var wexp = DC.ToBytes(WriteExpansion);
|
var wexp = DC.ToBytes(WriteAnnotation);
|
||||||
return new BinaryList()
|
return new BinaryList()
|
||||||
.AddUInt8((byte)(0x38 | pv))
|
.AddUInt8((byte)(0x38 | pv))
|
||||||
.AddUInt8((byte)name.Length)
|
.AddUInt8((byte)name.Length)
|
||||||
@ -98,9 +98,9 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
.AddUInt8Array(rexp)
|
.AddUInt8Array(rexp)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
else if (WriteExpansion != null)
|
else if (WriteAnnotation != null)
|
||||||
{
|
{
|
||||||
var wexp = DC.ToBytes(WriteExpansion);
|
var wexp = DC.ToBytes(WriteAnnotation);
|
||||||
return new BinaryList()
|
return new BinaryList()
|
||||||
.AddUInt8((byte)(0x30 | pv))
|
.AddUInt8((byte)(0x30 | pv))
|
||||||
.AddUInt8((byte)name.Length)
|
.AddUInt8((byte)name.Length)
|
||||||
@ -110,9 +110,9 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
.AddUInt8Array(wexp)
|
.AddUInt8Array(wexp)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
else if (ReadExpansion != null)
|
else if (ReadAnnotation != null)
|
||||||
{
|
{
|
||||||
var rexp = DC.ToBytes(ReadExpansion);
|
var rexp = DC.ToBytes(ReadAnnotation);
|
||||||
return new BinaryList()
|
return new BinaryList()
|
||||||
.AddUInt8((byte)(0x28 | pv))
|
.AddUInt8((byte)(0x28 | pv))
|
||||||
.AddUInt8((byte)name.Length)
|
.AddUInt8((byte)name.Length)
|
||||||
@ -134,14 +134,14 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PropertyTemplate(TypeTemplate template, byte index, string name, bool inherited,
|
public PropertyTemplate(TypeTemplate template, byte index, string name, bool inherited,
|
||||||
RepresentationType valueType, string read = null, string write = null, bool recordable = false)
|
RepresentationType valueType, string readAnnotation = null, string writeAnnotation = null, bool recordable = false)
|
||||||
: base(template, index, name, inherited)
|
: base(template, index, name, inherited)
|
||||||
{
|
{
|
||||||
this.Recordable = recordable;
|
this.Recordable = recordable;
|
||||||
//this.Storage = storage;
|
//this.Storage = storage;
|
||||||
if (read != null)
|
if (readAnnotation != null)
|
||||||
this.ReadExpansion = read;
|
this.ReadAnnotation = readAnnotation;
|
||||||
this.WriteExpansion = write;
|
this.WriteAnnotation = writeAnnotation;
|
||||||
this.ValueType = valueType;
|
this.ValueType = valueType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,9 +470,9 @@ public class TypeTemplate
|
|||||||
pt.Recordable = storageAttr.Mode == StorageMode.Recordable;
|
pt.Recordable = storageAttr.Mode == StorageMode.Recordable;
|
||||||
|
|
||||||
if (annotationAttr != null)
|
if (annotationAttr != null)
|
||||||
pt.ReadExpansion = annotationAttr.Annotation;
|
pt.ReadAnnotation = annotationAttr.Annotation;
|
||||||
else
|
else
|
||||||
pt.ReadExpansion = GetTypeAnnotationName(pi.PropertyType);
|
pt.ReadAnnotation = GetTypeAnnotationName(pi.PropertyType);
|
||||||
|
|
||||||
pt.PropertyInfo = pi;
|
pt.PropertyInfo = pi;
|
||||||
|
|
||||||
@ -518,7 +518,7 @@ public class TypeTemplate
|
|||||||
et.EventInfo = ei;
|
et.EventInfo = ei;
|
||||||
|
|
||||||
if (annotationAttr != null)
|
if (annotationAttr != null)
|
||||||
et.Expansion = annotationAttr.Annotation;
|
et.Annotation = annotationAttr.Annotation;
|
||||||
|
|
||||||
if (listenableAttr != null)
|
if (listenableAttr != null)
|
||||||
et.Listenable = true;
|
et.Listenable = true;
|
||||||
@ -627,9 +627,9 @@ public class TypeTemplate
|
|||||||
var ft = new FunctionTemplate(this, (byte)functions.Count, fn, mi.DeclaringType != type, arguments, rtType);
|
var ft = new FunctionTemplate(this, (byte)functions.Count, fn, mi.DeclaringType != type, arguments, rtType);
|
||||||
|
|
||||||
if (annotationAttr != null)
|
if (annotationAttr != null)
|
||||||
ft.Expansion = annotationAttr.Annotation;
|
ft.Annotation = annotationAttr.Annotation;
|
||||||
else
|
else
|
||||||
ft.Expansion = "(" + String.Join(",", mi.GetParameters().Where(x => x.ParameterType != typeof(DistributedConnection)).Select(x => "[" + x.ParameterType.Name + "] " + x.Name)) + ") -> " + mi.ReturnType.Name;
|
ft.Annotation = "(" + String.Join(",", mi.GetParameters().Where(x => x.ParameterType != typeof(DistributedConnection)).Select(x => "[" + x.ParameterType.Name + "] " + x.Name)) + ") -> " + mi.ReturnType.Name;
|
||||||
|
|
||||||
ft.MethodInfo = mi;
|
ft.MethodInfo = mi;
|
||||||
functions.Add(ft);
|
functions.Add(ft);
|
||||||
@ -776,11 +776,11 @@ public class TypeTemplate
|
|||||||
|
|
||||||
var hasParent = HasParent(type);
|
var hasParent = HasParent(type);
|
||||||
var classAnnotation = type.GetCustomAttribute<AnnotationAttribute>(false);
|
var classAnnotation = type.GetCustomAttribute<AnnotationAttribute>(false);
|
||||||
var hasAnnotation = classAnnotation != null && classAnnotation.Annotation != null;
|
var hasClassAnnotation = classAnnotation != null && classAnnotation.Annotation != null;
|
||||||
|
|
||||||
var classNameBytes = DC.ToBytes(className);
|
var classNameBytes = DC.ToBytes(className);
|
||||||
|
|
||||||
b.AddUInt8((byte)((hasParent ? 0x80 : 0) | (hasAnnotation ? 0x40 : 0x0) | (byte)templateType))
|
b.AddUInt8((byte)((hasParent ? 0x80 : 0) | (hasClassAnnotation ? 0x40 : 0x0) | (byte)templateType))
|
||||||
.AddGuid(classId)
|
.AddGuid(classId)
|
||||||
.AddUInt8((byte)classNameBytes.Length)
|
.AddUInt8((byte)classNameBytes.Length)
|
||||||
.AddUInt8Array(classNameBytes);
|
.AddUInt8Array(classNameBytes);
|
||||||
@ -793,7 +793,7 @@ public class TypeTemplate
|
|||||||
b.AddGuid(parentId);
|
b.AddGuid(parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAnnotation)
|
if (hasClassAnnotation)
|
||||||
{
|
{
|
||||||
var classAnnotationBytes = DC.ToBytes(classAnnotation.Annotation);
|
var classAnnotationBytes = DC.ToBytes(classAnnotation.Annotation);
|
||||||
b.AddUInt16((ushort)classAnnotationBytes.Length)
|
b.AddUInt16((ushort)classAnnotationBytes.Length)
|
||||||
@ -856,7 +856,7 @@ public class TypeTemplate
|
|||||||
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 hasAnnotation = (data[offset] & 0x40) > 0;
|
var hasClassAnnotation = (data[offset] & 0x40) > 0;
|
||||||
|
|
||||||
od.templateType = (TemplateType)(data[offset++] & 0xF);
|
od.templateType = (TemplateType)(data[offset++] & 0xF);
|
||||||
|
|
||||||
@ -872,7 +872,7 @@ public class TypeTemplate
|
|||||||
offset += 16;
|
offset += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAnnotation)
|
if (hasClassAnnotation)
|
||||||
{
|
{
|
||||||
var len = data.GetUInt16(offset, Endian.Little);
|
var len = data.GetUInt16(offset, Endian.Little);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
@ -897,8 +897,8 @@ public class TypeTemplate
|
|||||||
|
|
||||||
if (type == 0) // function
|
if (type == 0) // function
|
||||||
{
|
{
|
||||||
string expansion = null;
|
string annotation = null;
|
||||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
var hasAnnotation = ((data[offset++] & 0x10) == 0x10);
|
||||||
|
|
||||||
var name = data.GetString(offset + 1, data[offset]);
|
var name = data.GetString(offset + 1, data[offset]);
|
||||||
offset += (uint)data[offset] + 1;
|
offset += (uint)data[offset] + 1;
|
||||||
@ -919,25 +919,25 @@ public class TypeTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// arguments
|
// arguments
|
||||||
if (hasExpansion) // expansion ?
|
if (hasAnnotation) // Annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.GetUInt32(offset, Endian.Little);
|
var cs = data.GetUInt32(offset, Endian.Little);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
expansion = data.GetString(offset, cs);
|
annotation = data.GetString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ft = new FunctionTemplate(od, functionIndex++, name, inherited, arguments.ToArray(), returnType, expansion);
|
var ft = new FunctionTemplate(od, functionIndex++, name, inherited, arguments.ToArray(), returnType, annotation);
|
||||||
|
|
||||||
od.functions.Add(ft);
|
od.functions.Add(ft);
|
||||||
}
|
}
|
||||||
else if (type == 1) // property
|
else if (type == 1) // property
|
||||||
{
|
{
|
||||||
|
|
||||||
string readExpansion = null, writeExpansion = null;
|
string readAnnotation = null, writeAnnotation= null;
|
||||||
|
|
||||||
var hasReadExpansion = ((data[offset] & 0x8) == 0x8);
|
var hasReadAnnotation = ((data[offset] & 0x8) == 0x8);
|
||||||
var hasWriteExpansion = ((data[offset] & 0x10) == 0x10);
|
var hasWriteAnnotation = ((data[offset] & 0x10) == 0x10);
|
||||||
var recordable = ((data[offset] & 1) == 1);
|
var recordable = ((data[offset] & 1) == 1);
|
||||||
var permission = (PropertyTemplate.PropertyPermission)((data[offset++] >> 1) & 0x3);
|
var permission = (PropertyTemplate.PropertyPermission)((data[offset++] >> 1) & 0x3);
|
||||||
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, data[offset]);
|
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, data[offset]);
|
||||||
@ -948,31 +948,31 @@ public class TypeTemplate
|
|||||||
|
|
||||||
offset += dts;
|
offset += dts;
|
||||||
|
|
||||||
if (hasReadExpansion) // expansion ?
|
if (hasReadAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.GetUInt32(offset, Endian.Little);
|
var cs = data.GetUInt32(offset, Endian.Little);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
readExpansion = data.GetString(offset, cs);
|
readAnnotation = data.GetString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasWriteExpansion) // expansion ?
|
if (hasWriteAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.GetUInt32(offset, Endian.Little);
|
var cs = data.GetUInt32(offset, Endian.Little);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
writeExpansion = data.GetString(offset, cs);
|
writeAnnotation = data.GetString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pt = new PropertyTemplate(od, propertyIndex++, name, inherited, valueType, readExpansion, writeExpansion, recordable);
|
var pt = new PropertyTemplate(od, propertyIndex++, name, inherited, valueType, readAnnotation, writeAnnotation, recordable);
|
||||||
|
|
||||||
od.properties.Add(pt);
|
od.properties.Add(pt);
|
||||||
}
|
}
|
||||||
else if (type == 2) // Event
|
else if (type == 2) // Event
|
||||||
{
|
{
|
||||||
|
|
||||||
string expansion = null;
|
string annotation = null;
|
||||||
var hasExpansion = ((data[offset] & 0x10) == 0x10);
|
var hasAnnotation = ((data[offset] & 0x10) == 0x10);
|
||||||
var listenable = ((data[offset++] & 0x8) == 0x8);
|
var listenable = ((data[offset++] & 0x8) == 0x8);
|
||||||
|
|
||||||
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, (int)data[offset]);
|
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, (int)data[offset]);
|
||||||
@ -982,15 +982,15 @@ public class TypeTemplate
|
|||||||
|
|
||||||
offset += dts;
|
offset += dts;
|
||||||
|
|
||||||
if (hasExpansion) // expansion ?
|
if (hasAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.GetUInt32(offset, Endian.Little);
|
var cs = data.GetUInt32(offset, Endian.Little);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
expansion = data.GetString(offset, cs);
|
annotation = data.GetString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var et = new EventTemplate(od, eventIndex++, name, inherited, argType, expansion, listenable);
|
var et = new EventTemplate(od, eventIndex++, name, inherited, argType, annotation, listenable);
|
||||||
|
|
||||||
od.events.Add(et);
|
od.events.Add(et);
|
||||||
|
|
||||||
@ -998,8 +998,8 @@ public class TypeTemplate
|
|||||||
// constant
|
// constant
|
||||||
else if (type == 3)
|
else if (type == 3)
|
||||||
{
|
{
|
||||||
string expansion = null;
|
string annotation = null;
|
||||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
var hasAnnotation = ((data[offset++] & 0x10) == 0x10);
|
||||||
|
|
||||||
var name = data.GetString(offset + 1, data[offset]);
|
var name = data.GetString(offset + 1, data[offset]);
|
||||||
offset += (uint)data[offset] + 1;
|
offset += (uint)data[offset] + 1;
|
||||||
@ -1012,15 +1012,15 @@ public class TypeTemplate
|
|||||||
|
|
||||||
offset += dts;
|
offset += dts;
|
||||||
|
|
||||||
if (hasExpansion) // expansion ?
|
if (hasAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.GetUInt32(offset, Endian.Little);
|
var cs = data.GetUInt32(offset, Endian.Little);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
expansion = data.GetString(offset, cs);
|
annotation = data.GetString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ct = new ConstantTemplate(od, eventIndex++, name, inherited, valueType, value.Result, expansion);
|
var ct = new ConstantTemplate(od, eventIndex++, name, inherited, valueType, value.Result, annotation);
|
||||||
|
|
||||||
od.constants.Add(ct);
|
od.constants.Add(ct);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Test
|
|||||||
[Annotation("A", "B", "C", "D")]
|
[Annotation("A", "B", "C", "D")]
|
||||||
public partial class MyResource
|
public partial class MyResource
|
||||||
{
|
{
|
||||||
[Public] string description;
|
[Public][Annotation("Comment")] string description;
|
||||||
[Public] int categoryId;
|
[Public] int categoryId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,10 @@ namespace Test
|
|||||||
{
|
{
|
||||||
dynamic remote = await Warehouse.Get<IResource>("iip://localhost/mem/service");
|
dynamic remote = await Warehouse.Get<IResource>("iip://localhost/mem/service");
|
||||||
|
|
||||||
|
var con = remote.Connection as DistributedConnection;
|
||||||
|
var template = await con.GetTemplateByClassName("Test.MyResource");
|
||||||
|
|
||||||
|
|
||||||
TestObjectProps(local, remote);
|
TestObjectProps(local, remote);
|
||||||
|
|
||||||
var gr = await remote.GetGenericRecord();
|
var gr = await remote.GetGenericRecord();
|
||||||
@ -184,5 +188,9 @@ namespace Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user