2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00
This commit is contained in:
2020-02-26 03:14:22 +03:00
parent 7a21f6a928
commit fde1b1d8ad
39 changed files with 1108 additions and 502 deletions

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -15,6 +16,8 @@ namespace Esyur.Resource.Template
set;
}
public EventInfo Info { get; set; }
public override byte[] Compose()
{
var name = base.Compose();
@ -39,7 +42,7 @@ namespace Esyur.Resource.Template
}
public EventTemplate(ResourceTemplate template, byte index, string name, string expansion)
public EventTemplate(ResourceTemplate template, byte index, string name, string expansion = null)
:base(template, MemberType.Property, index, name)
{
this.Expansion = expansion;

View File

@ -45,7 +45,7 @@ namespace Esyur.Resource.Template
}
public FunctionTemplate(ResourceTemplate template, byte index, string name,bool isVoid, string expansion)
public FunctionTemplate(ResourceTemplate template, byte index, string name,bool isVoid, string expansion = null)
:base(template, MemberType.Property, index, name)
{
this.IsVoid = isVoid;

View File

@ -24,10 +24,12 @@ namespace Esyur.Resource.Template
set;
}
/*
public bool Serilize
{
get;set;
}
*/
//bool ReadOnly;
//IIPTypes::DataType ReturnType;
public PropertyPermission Permission {
@ -35,18 +37,19 @@ namespace Esyur.Resource.Template
set;
}
/*
public bool Recordable
{
get;
set;
}*/
}
public StorageMode Storage
/*
public PropertyType Mode
{
get;
set;
}
}*/
public string ReadExpansion
{
@ -71,7 +74,7 @@ namespace Esyur.Resource.Template
public override byte[] Compose()
{
var name = base.Compose();
var pv = ((byte)(Permission) << 1) | (Storage == StorageMode.Recordable ? 1 : 0);
var pv = ((byte)(Permission) << 1) | (Recordable ? 1 : 0);
if (WriteExpansion != null && ReadExpansion != null)
{
@ -117,11 +120,11 @@ namespace Esyur.Resource.Template
.ToArray();
}
public PropertyTemplate(ResourceTemplate template, byte index, string name, string read, string write, StorageMode storage)
public PropertyTemplate(ResourceTemplate template, byte index, string name, string read = null, string write = null, bool recordable = false)
:base(template, MemberType.Property, index, name)
{
//this.Recordable = recordable;
this.Storage = storage;
this.Recordable = recordable;
//this.Storage = storage;
this.ReadExpansion = read;
this.WriteExpansion = write;
}

View File

@ -8,6 +8,7 @@ using Esyur.Data;
using Esyur.Core;
using System.Security.Cryptography;
using Esyur.Proxy;
using Esyur.Net.IIP;
namespace Esyur.Resource.Template
{
@ -159,52 +160,87 @@ namespace Esyur.Resource.Template
MethodInfo[] methodsInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
#endif
//byte currentIndex = 0;
bool classIsPublic = type.GetCustomAttribute<PublicAttribute>() != null;
byte i = 0;
foreach (var pi in propsInfo)
if (classIsPublic)
{
var rp = pi.GetCustomAttribute<ResourceProperty>(true);
if (rp != null)
{
var pt = new PropertyTemplate(this, i++, pi.Name, rp.ReadExpansion, rp.WriteExpansion, rp.Storage);
pt.Info = pi;
pt.Serilize = rp.Serialize;
properties.Add(pt);
}
var ra = pi.GetCustomAttribute<ResourceAttribute>(true);
if (ra != null)
{
var at = new AttributeTemplate(this, i++, pi.Name);
at.Info = pi;
attributes.Add(at);
}
}
i = 0;
foreach (var ei in eventsInfo)
else
{
var es = ei.GetCustomAttributes<ResourceEvent>(true).ToArray();
if (es.Length > 0)
foreach (var pi in propsInfo)
{
var et = new EventTemplate(this, i++, ei.Name, es[0].Expansion);
events.Add(et);
var publicAttr = pi.GetCustomAttribute<PublicAttribute>(true);
if (publicAttr != null)
{
var annotationAttr = pi.GetCustomAttribute<AnnotationAttribute>(true);
var storageAttr = pi.GetCustomAttribute<StorageAttribute>(true);
var pt = new PropertyTemplate(this, i++, pi.Name);//, rp.ReadExpansion, rp.WriteExpansion, rp.Storage);
if (storageAttr != null)
pt.Recordable = storageAttr.Mode == StorageMode.Recordable;
if (annotationAttr != null)
pt.ReadExpansion = annotationAttr.Annotation;
else
pt.ReadExpansion = pi.PropertyType.Name;
pt.Info = pi;
//pt.Serilize = publicAttr.Serialize;
properties.Add(pt);
}
else
{
var attributeAttr = pi.GetCustomAttribute<AttributeAttribute>(true);
if (attributeAttr != null)
{
var at = new AttributeTemplate(this, 0, pi.Name);
at.Info = pi;
attributes.Add(at);
}
}
}
}
i = 0;
foreach (MethodInfo mi in methodsInfo)
{
var fs = mi.GetCustomAttributes<ResourceFunction>(true).ToArray();
if (fs.Length > 0)
i = 0;
foreach (var ei in eventsInfo)
{
var ft = new FunctionTemplate(this, i++, mi.Name, mi.ReturnType == typeof(void), fs[0].Expansion);
functions.Add(ft);
var publicAttr = ei.GetCustomAttribute<PublicAttribute>(true);
if (publicAttr != null)
{
var annotationAttr = ei.GetCustomAttribute<AnnotationAttribute>(true);
var et = new EventTemplate(this, i++, ei.Name);
et.Info = ei;
if (annotationAttr != null)
et.Expansion = annotationAttr.Annotation;
events.Add(et);
}
}
i = 0;
foreach (MethodInfo mi in methodsInfo)
{
var publicAttr = mi.GetCustomAttribute<PublicAttribute>(true);
if (publicAttr != null)
{
var annotationAttr = mi.GetCustomAttribute<AnnotationAttribute>(true);
var ft = new FunctionTemplate(this, i++, mi.Name, mi.ReturnType == typeof(void));
if (annotationAttr != null)
ft.Expansion = annotationAttr.Annotation;
else
ft.Expansion = "(" + String.Join(",", mi.GetParameters().Where(x=>x.ParameterType != typeof(DistributedConnection)).Select(x=> "[" + x.ParameterType.Name + "] " + x.Name)) + ") -> " + mi.ReturnType.Name;
functions.Add(ft);
}
}
}
@ -323,7 +359,7 @@ namespace Esyur.Resource.Template
offset += cs;
}
var pt = new PropertyTemplate(od, propertyIndex++, name, readExpansion, writeExpansion, recordable ? StorageMode.Recordable : StorageMode.Volatile);
var pt = new PropertyTemplate(od, propertyIndex++, name, readExpansion, writeExpansion, recordable);
od.properties.Add(pt);
}