mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
.Net 6 Upgrade
This commit is contained in:
@ -2,17 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event)]
|
||||
public class AnnotationAttribute : Attribute
|
||||
{
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event)]
|
||||
public class AnnotationAttribute : Attribute
|
||||
public string Annotation { get; set; }
|
||||
public AnnotationAttribute(string annotation)
|
||||
{
|
||||
|
||||
public string Annotation { get; set; }
|
||||
public AnnotationAttribute(string annotation)
|
||||
{
|
||||
this.Annotation = annotation;
|
||||
}
|
||||
this.Annotation = annotation;
|
||||
}
|
||||
}
|
||||
|
@ -27,16 +27,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AttributeAttribute : System.Attribute
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AttributeAttribute : System.Attribute
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public AttributeAttribute(string name = null)
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public AttributeAttribute(string name = null)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
this.Name = name;
|
||||
}
|
||||
}
|
||||
|
@ -32,24 +32,23 @@ using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
public delegate bool QueryFilter<T>(T value);
|
||||
|
||||
//[JsonConverter(typeof(ResourceJsonConverter))]
|
||||
|
||||
public interface IResource : IDestructible///, INotifyPropertyChanged
|
||||
{
|
||||
public delegate bool QueryFilter<T>(T value);
|
||||
|
||||
//[JsonConverter(typeof(ResourceJsonConverter))]
|
||||
AsyncReply<bool> Trigger(ResourceTrigger trigger);
|
||||
|
||||
public interface IResource : IDestructible///, INotifyPropertyChanged
|
||||
[NotMapped]
|
||||
Instance Instance
|
||||
{
|
||||
|
||||
AsyncReply<bool> Trigger(ResourceTrigger trigger);
|
||||
|
||||
[NotMapped]
|
||||
Instance Instance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -33,44 +33,42 @@ using System.Threading.Tasks;
|
||||
using Esiur.Security.Permissions;
|
||||
using Esiur.Security.Authority;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
public interface IStore : IResource
|
||||
{
|
||||
public interface IStore:IResource
|
||||
{
|
||||
AsyncReply<IResource> Get(string path);//, Func<IResource, bool> filter = null);
|
||||
//AsyncReply<IResource> Retrieve(uint iid);
|
||||
AsyncReply<bool> Put(IResource resource);
|
||||
string Link(IResource resource);
|
||||
bool Record(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
bool Modify(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
bool Remove(IResource resource);
|
||||
AsyncReply<IResource> Get(string path);//, Func<IResource, bool> filter = null);
|
||||
//AsyncReply<IResource> Retrieve(uint iid);
|
||||
AsyncReply<bool> Put(IResource resource);
|
||||
string Link(IResource resource);
|
||||
bool Record(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
bool Modify(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
bool Remove(IResource resource);
|
||||
|
||||
//bool RemoveAttributes(IResource resource, string[] attributes = null);
|
||||
//bool RemoveAttributes(IResource resource, string[] attributes = null);
|
||||
|
||||
//Structure GetAttributes(IResource resource, string[] attributes = null);
|
||||
//Structure GetAttributes(IResource resource, string[] attributes = null);
|
||||
|
||||
//bool SetAttributes(IResource resource, Structure attributes, bool clearAttributes = false);
|
||||
|
||||
|
||||
|
||||
AsyncReply<bool> AddChild(IResource parent, IResource child);
|
||||
AsyncReply<bool> RemoveChild(IResource parent, IResource child);
|
||||
|
||||
AsyncReply<bool> AddParent(IResource child, IResource parent);
|
||||
AsyncReply<bool> RemoveParent(IResource child, IResource parent);
|
||||
|
||||
|
||||
AsyncBag<T> Children<T>(IResource resource, string name) where T : IResource;
|
||||
AsyncBag<T> Parents<T>(IResource resource, string name) where T : IResource;
|
||||
//bool SetAttributes(IResource resource, Structure attributes, bool clearAttributes = false);
|
||||
|
||||
|
||||
|
||||
//AsyncReply<PropertyValue[]> GetPropertyRecord(IResource resource, string propertyName, ulong fromAge, ulong toAge);
|
||||
//AsyncReply<PropertyValue[]> GetPropertyRecordByDate(IResource resource, string propertyName, DateTime fromDate, DateTime toDate);
|
||||
AsyncReply<bool> AddChild(IResource parent, IResource child);
|
||||
AsyncReply<bool> RemoveChild(IResource parent, IResource child);
|
||||
|
||||
//AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, ulong fromAge, ulong toAge);
|
||||
// AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
AsyncReply<bool> AddParent(IResource child, IResource parent);
|
||||
AsyncReply<bool> RemoveParent(IResource child, IResource parent);
|
||||
|
||||
AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
}
|
||||
|
||||
AsyncBag<T> Children<T>(IResource resource, string name) where T : IResource;
|
||||
AsyncBag<T> Parents<T>(IResource resource, string name) where T : IResource;
|
||||
|
||||
|
||||
|
||||
//AsyncReply<PropertyValue[]> GetPropertyRecord(IResource resource, string propertyName, ulong fromAge, ulong toAge);
|
||||
//AsyncReply<PropertyValue[]> GetPropertyRecordByDate(IResource resource, string propertyName, DateTime fromDate, DateTime toDate);
|
||||
|
||||
//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[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
}
|
||||
|
@ -2,14 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ImportAttribute:Attribute
|
||||
{
|
||||
public ImportAttribute(string url)
|
||||
{
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ImportAttribute : Attribute
|
||||
{
|
||||
public ImportAttribute(string url)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -27,16 +27,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Event)]
|
||||
public class ListenableAttribute : System.Attribute
|
||||
{
|
||||
|
||||
[AttributeUsage(AttributeTargets.Event)]
|
||||
public class ListenableAttribute : System.Attribute
|
||||
public ListenableAttribute()
|
||||
{
|
||||
|
||||
public ListenableAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
public class PrivateAttribute : Attribute
|
||||
{
|
||||
public class PrivateAttribute:Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event | AttributeTargets.Class)]
|
||||
|
||||
public class PublicAttribute : Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event | AttributeTargets.Class)]
|
||||
public string Name { get; set; }
|
||||
|
||||
public class PublicAttribute : Attribute
|
||||
public PublicAttribute(string name = null)
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public PublicAttribute(string name = null)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
@ -26,36 +26,34 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Esiur.Core;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
public class Resource : IResource
|
||||
{
|
||||
public class Resource : IResource
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
public event DestroyedEvent OnDestroy;
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
public Instance Instance { get; set; }
|
||||
OnDestroy?.Invoke(this);
|
||||
}
|
||||
|
||||
public event DestroyedEvent OnDestroy;
|
||||
public virtual AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
return new AsyncReply<bool>(this.Create());
|
||||
else
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
OnDestroy?.Invoke(this);
|
||||
}
|
||||
|
||||
public virtual AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
return new AsyncReply<bool>(this.Create());
|
||||
else
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
protected virtual bool Create()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected virtual bool Create()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
~Resource()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
~Resource()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public class ResourceAttribute : Attribute
|
||||
{
|
||||
public ResourceAttribute()
|
||||
{
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public class ResourceAttribute : Attribute
|
||||
{
|
||||
public ResourceAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,27 +27,25 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Event)]
|
||||
public class ResourceEvent : System.Attribute
|
||||
{
|
||||
|
||||
[AttributeUsage(AttributeTargets.Event)]
|
||||
public class ResourceEvent : System.Attribute
|
||||
string expansion;
|
||||
|
||||
public string Expansion
|
||||
{
|
||||
|
||||
string expansion;
|
||||
|
||||
public string Expansion
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
return expansion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ResourceEvent(string expansion = null)
|
||||
{
|
||||
this.expansion = expansion;
|
||||
return expansion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ResourceEvent(string expansion = null)
|
||||
{
|
||||
this.expansion = expansion;
|
||||
}
|
||||
}
|
||||
|
@ -31,17 +31,16 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
public delegate R DCovariant<out R>();
|
||||
namespace Esiur.Resource;
|
||||
|
||||
public delegate void ResourceEventHandler<in T>(T argument);
|
||||
// public delegate void CustomUsersEventHanlder(string[] usernames, params object[] args);
|
||||
//public delegate void CustomReceiversEventHanlder(DistributedConnection[] connections, params object[] args);
|
||||
//public delegate void CustomInquirerEventHanlder(object inquirer, params object[] args);
|
||||
public delegate R DCovariant<out R>();
|
||||
|
||||
public delegate void CustomResourceEventHandler<in T>(object issuer, Func<Session, bool> receivers, T argument);// object issuer, Session[] receivers, params object[] args);
|
||||
public delegate void ResourceEventHandler<in T>(T argument);
|
||||
// public delegate void CustomUsersEventHanlder(string[] usernames, params object[] args);
|
||||
//public delegate void CustomReceiversEventHanlder(DistributedConnection[] connections, params object[] args);
|
||||
//public delegate void CustomInquirerEventHanlder(object inquirer, params object[] args);
|
||||
|
||||
// public delegate void CustomReceiversEventHanlder(string[] usernames, DistributedConnection[] connections, params object[] args);
|
||||
public delegate void CustomResourceEventHandler<in T>(object issuer, Func<Session, bool> receivers, T argument);// object issuer, Session[] receivers, params object[] args);
|
||||
|
||||
// public delegate void CustomReceiversEventHanlder(string[] usernames, DistributedConnection[] connections, params object[] args);
|
||||
|
||||
}
|
||||
|
@ -28,25 +28,24 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class ResourceFunction : System.Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class ResourceFunction : System.Attribute
|
||||
private string expansion = null;
|
||||
|
||||
public string Expansion
|
||||
{
|
||||
private string expansion = null;
|
||||
|
||||
public string Expansion
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
return expansion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ResourceFunction(string expansion = null)
|
||||
{
|
||||
this.expansion = expansion;
|
||||
return expansion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ResourceFunction(string expansion = null)
|
||||
{
|
||||
this.expansion = expansion;
|
||||
}
|
||||
}
|
||||
|
@ -29,49 +29,47 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ResourceProperty : System.Attribute
|
||||
{
|
||||
bool serialize;
|
||||
string readExpansion;
|
||||
string writeExpansion;
|
||||
// bool recordable;
|
||||
//bool storable;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ResourceProperty : System.Attribute
|
||||
//public bool Recordable => recordable;
|
||||
|
||||
//public bool Storable => storable;
|
||||
StorageMode storage;
|
||||
|
||||
public StorageMode Storage => storage;
|
||||
|
||||
public bool Serialize => serialize;
|
||||
|
||||
public string ReadExpansion
|
||||
{
|
||||
bool serialize;
|
||||
string readExpansion;
|
||||
string writeExpansion;
|
||||
// bool recordable;
|
||||
//bool storable;
|
||||
|
||||
//public bool Recordable => recordable;
|
||||
|
||||
//public bool Storable => storable;
|
||||
StorageMode storage;
|
||||
|
||||
public StorageMode Storage => storage;
|
||||
|
||||
public bool Serialize => serialize;
|
||||
|
||||
public string ReadExpansion
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
return readExpansion;
|
||||
}
|
||||
}
|
||||
|
||||
public string WriteExpansion
|
||||
{
|
||||
get
|
||||
{
|
||||
return writeExpansion;
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, bool serialize = true, string readExpansion = null, string writeExpansion = null)
|
||||
{
|
||||
this.readExpansion = readExpansion;
|
||||
this.writeExpansion = writeExpansion;
|
||||
this.storage = storage;
|
||||
this.serialize = serialize;
|
||||
return readExpansion;
|
||||
}
|
||||
}
|
||||
|
||||
public string WriteExpansion
|
||||
{
|
||||
get
|
||||
{
|
||||
return writeExpansion;
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, bool serialize = true, string readExpansion = null, string writeExpansion = null)
|
||||
{
|
||||
this.readExpansion = readExpansion;
|
||||
this.writeExpansion = writeExpansion;
|
||||
this.storage = storage;
|
||||
this.serialize = serialize;
|
||||
}
|
||||
}
|
||||
|
@ -5,24 +5,23 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
public class ResourceQuery : IQueryable<IResource>
|
||||
{
|
||||
public class ResourceQuery : IQueryable<IResource>
|
||||
public Type ElementType => throw new NotImplementedException();
|
||||
|
||||
public Expression Expression => throw new NotImplementedException();
|
||||
|
||||
public IQueryProvider Provider => throw new NotImplementedException();
|
||||
|
||||
public IEnumerator<IResource> GetEnumerator()
|
||||
{
|
||||
public Type ElementType => throw new NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Expression Expression => throw new NotImplementedException();
|
||||
|
||||
public IQueryProvider Provider => throw new NotImplementedException();
|
||||
|
||||
public IEnumerator<IResource> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -28,16 +28,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
public enum ResourceTrigger : int
|
||||
{
|
||||
public enum ResourceTrigger : int
|
||||
{
|
||||
Open = 0,
|
||||
Initialize,
|
||||
Terminate,
|
||||
Configure,
|
||||
SystemInitialized,
|
||||
SystemTerminated,
|
||||
SystemReload,
|
||||
}
|
||||
Open = 0,
|
||||
Initialize,
|
||||
Terminate,
|
||||
Configure,
|
||||
SystemInitialized,
|
||||
SystemTerminated,
|
||||
SystemReload,
|
||||
}
|
||||
|
@ -30,43 +30,42 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
public class Storable : global::System.Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
public class Storable : global::System.Attribute
|
||||
public delegate object SerializerFunction(object value);
|
||||
public delegate object DeserializerFunction(object data);
|
||||
|
||||
SerializerFunction serializer;
|
||||
DeserializerFunction deserializer;
|
||||
DataType type;
|
||||
|
||||
public Storable()
|
||||
{
|
||||
public delegate object SerializerFunction(object value);
|
||||
public delegate object DeserializerFunction(object data);
|
||||
type = DataType.Void;
|
||||
}
|
||||
|
||||
SerializerFunction serializer;
|
||||
DeserializerFunction deserializer;
|
||||
DataType type;
|
||||
public DeserializerFunction Deserializer
|
||||
{
|
||||
get { return deserializer; }
|
||||
}
|
||||
|
||||
public Storable()
|
||||
{
|
||||
type = DataType.Void;
|
||||
}
|
||||
public SerializerFunction Serializer
|
||||
{
|
||||
get { return serializer; }
|
||||
}
|
||||
|
||||
public DeserializerFunction Deserializer
|
||||
{
|
||||
get { return deserializer; }
|
||||
}
|
||||
public Storable(DataType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public SerializerFunction Serializer
|
||||
{
|
||||
get { return serializer; }
|
||||
}
|
||||
|
||||
public Storable(DataType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Storable(DataType type, SerializerFunction serializer, DeserializerFunction deserializer)
|
||||
{
|
||||
this.type = type;
|
||||
this.serializer = serializer;
|
||||
this.deserializer = deserializer;
|
||||
}
|
||||
public Storable(DataType type, SerializerFunction serializer, DeserializerFunction deserializer)
|
||||
{
|
||||
this.type = type;
|
||||
this.serializer = serializer;
|
||||
this.deserializer = deserializer;
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class StorageAttribute : Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class StorageAttribute:Attribute
|
||||
public StorageMode Mode { get; set; }
|
||||
public StorageAttribute(StorageMode mode)
|
||||
{
|
||||
public StorageMode Mode { get; set; }
|
||||
public StorageAttribute(StorageMode mode)
|
||||
{
|
||||
Mode = mode;
|
||||
}
|
||||
Mode = mode;
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
public enum StorageMode : byte
|
||||
{
|
||||
public enum StorageMode : byte
|
||||
{
|
||||
NonVolatile,
|
||||
Volatile,
|
||||
Recordable
|
||||
}
|
||||
NonVolatile,
|
||||
Volatile,
|
||||
Recordable
|
||||
}
|
||||
|
@ -5,53 +5,52 @@ using Esiur.Core;
|
||||
using Esiur.Data;
|
||||
using Esiur.Resource.Template;
|
||||
|
||||
namespace Esiur.Resource
|
||||
namespace Esiur.Resource;
|
||||
public abstract class Store<T> : IStore where T : IResource
|
||||
{
|
||||
public abstract class Store<T> : IStore where T:IResource
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
public event DestroyedEvent OnDestroy;
|
||||
|
||||
public abstract AsyncReply<bool> AddChild(IResource parent, IResource child);
|
||||
|
||||
public abstract AsyncReply<bool> AddParent(IResource child, IResource parent);
|
||||
|
||||
public abstract AsyncBag<T1> Children<T1>(IResource resource, string name) where T1 : IResource;
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
public Instance Instance { get; set; }
|
||||
OnDestroy?.Invoke(this);
|
||||
}
|
||||
|
||||
public event DestroyedEvent OnDestroy;
|
||||
public abstract AsyncReply<IResource> Get(string path);
|
||||
|
||||
public abstract AsyncReply<bool> AddChild(IResource parent, IResource child);
|
||||
|
||||
public abstract AsyncReply<bool> AddParent(IResource child, IResource parent);
|
||||
|
||||
public abstract AsyncBag<T1> Children<T1>(IResource resource, string name) where T1 : IResource;
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
OnDestroy?.Invoke(this);
|
||||
}
|
||||
|
||||
public abstract AsyncReply<IResource> Get(string path);
|
||||
|
||||
public abstract AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
public abstract AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
|
||||
|
||||
public abstract string Link(IResource resource);
|
||||
public abstract string Link(IResource resource);
|
||||
|
||||
public abstract bool Modify(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
public abstract bool Modify(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
|
||||
public abstract AsyncBag<T1> Parents<T1>(IResource resource, string name) where T1 : IResource;
|
||||
public abstract AsyncBag<T1> Parents<T1>(IResource resource, string name) where T1 : IResource;
|
||||
|
||||
public abstract AsyncReply<bool> Put(IResource resource);
|
||||
public abstract AsyncReply<bool> Put(IResource resource);
|
||||
|
||||
public abstract bool Record(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
public abstract bool Record(IResource resource, string propertyName, object value, ulong age, DateTime dateTime);
|
||||
|
||||
public abstract bool Remove(IResource resource);
|
||||
public abstract bool Remove(IResource resource);
|
||||
|
||||
public abstract AsyncReply<bool> RemoveChild(IResource parent, IResource child);
|
||||
public abstract AsyncReply<bool> RemoveChild(IResource parent, IResource child);
|
||||
|
||||
public abstract AsyncReply<bool> RemoveParent(IResource child, IResource parent);
|
||||
public abstract AsyncReply<bool> RemoveParent(IResource child, IResource parent);
|
||||
|
||||
public abstract AsyncReply<bool> Trigger(ResourceTrigger trigger);
|
||||
public abstract AsyncReply<bool> Trigger(ResourceTrigger trigger);
|
||||
|
||||
public async AsyncReply<T> New(string name = null, object attributes = null, object properties = null)
|
||||
{
|
||||
var resource = await Warehouse.New<T>(name, this, null, null, attributes, properties);
|
||||
resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray());
|
||||
return resource;
|
||||
}
|
||||
public async AsyncReply<T> New(string name = null, object attributes = null, object properties = null)
|
||||
{
|
||||
var resource = await Warehouse.New<T>(name, this, null, null, attributes, properties);
|
||||
resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray());
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,46 +4,44 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class ArgumentTemplate
|
||||
{
|
||||
public class ArgumentTemplate
|
||||
public string Name { get; set; }
|
||||
|
||||
public TemplateDataType Type { get; set; }
|
||||
|
||||
public ParameterInfo ParameterInfo { get; set; }
|
||||
|
||||
public static (uint, ArgumentTemplate) Parse(byte[] data, uint offset)
|
||||
{
|
||||
public string Name { get; set; }
|
||||
var cs = (uint)data[offset++];
|
||||
var name = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
var (size, type) = TemplateDataType.Parse(data, offset);
|
||||
|
||||
public TemplateDataType Type { get; set; }
|
||||
return (cs + 1 + size, new ArgumentTemplate(name, type));
|
||||
}
|
||||
|
||||
public ParameterInfo ParameterInfo { get; set; }
|
||||
public ArgumentTemplate()
|
||||
{
|
||||
|
||||
public static (uint, ArgumentTemplate) Parse(byte[] data, uint offset)
|
||||
{
|
||||
var cs = (uint)data[offset++];
|
||||
var name = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
var (size, type) = TemplateDataType.Parse(data, offset);
|
||||
}
|
||||
|
||||
return (cs + 1 + size, new ArgumentTemplate(name, type));
|
||||
}
|
||||
public ArgumentTemplate(string name, TemplateDataType type)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public ArgumentTemplate()
|
||||
{
|
||||
public byte[] Compose()
|
||||
{
|
||||
var name = DC.ToBytes(Name);
|
||||
|
||||
}
|
||||
|
||||
public ArgumentTemplate(string name, TemplateDataType type)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public byte[] Compose()
|
||||
{
|
||||
var name = DC.ToBytes(Name);
|
||||
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(Type.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(Type.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,19 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class AttributeTemplate : MemberTemplate
|
||||
{
|
||||
public class AttributeTemplate : MemberTemplate
|
||||
public PropertyInfo PropertyInfo
|
||||
{
|
||||
public PropertyInfo PropertyInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public AttributeTemplate(TypeTemplate template, byte index, string name)
|
||||
: base(template, MemberType.Attribute, index, name)
|
||||
{
|
||||
public AttributeTemplate(TypeTemplate template, byte index, string name)
|
||||
: base(template, MemberType.Attribute, index, name)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,54 +6,52 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
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 Expansion
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool Listenable { get; set; }
|
||||
|
||||
public EventInfo EventInfo { get; set; }
|
||||
|
||||
public TemplateDataType ArgumentType { get; set; }
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool Listenable { get; set; }
|
||||
|
||||
public EventInfo EventInfo { get; set; }
|
||||
|
||||
public TemplateDataType ArgumentType { get; set; }
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte) 0x58 : (byte) 0x50)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte) 0x48 : (byte) 0x40)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.ToArray();
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte)0x58 : (byte)0x50)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte)0x48 : (byte)0x40)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public EventTemplate(TypeTemplate template, byte index, string name, TemplateDataType argumentType, string expansion = null, bool listenable=false)
|
||||
:base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Expansion = expansion;
|
||||
this.Listenable = listenable;
|
||||
this.ArgumentType = argumentType;
|
||||
}
|
||||
public EventTemplate(TypeTemplate template, byte index, string name, TemplateDataType argumentType, string expansion = null, bool listenable = false)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Expansion = expansion;
|
||||
this.Listenable = listenable;
|
||||
this.ArgumentType = argumentType;
|
||||
}
|
||||
}
|
||||
|
@ -6,71 +6,69 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class FunctionTemplate : MemberTemplate
|
||||
{
|
||||
public class FunctionTemplate : MemberTemplate
|
||||
|
||||
public string Expansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
//public bool IsVoid
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
public TemplateDataType ReturnType { get; set; }
|
||||
|
||||
public ArgumentTemplate[] Arguments { get; set; }
|
||||
|
||||
public MethodInfo MethodInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
|
||||
public string Expansion
|
||||
var name = base.Compose();
|
||||
|
||||
var bl = new BinaryList()
|
||||
//.AddUInt8(Expansion != null ? (byte)0x10 : (byte)0)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ReturnType.Compose())
|
||||
.AddUInt8((byte)Arguments.Length);
|
||||
|
||||
for (var i = 0; i < Arguments.Length; i++)
|
||||
bl.AddUInt8Array(Arguments[i].Compose());
|
||||
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
bl.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp);
|
||||
bl.InsertUInt8(0, 0x10);
|
||||
}
|
||||
else
|
||||
bl.InsertUInt8(0, 0x0);
|
||||
|
||||
//public bool IsVoid
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
public TemplateDataType ReturnType { get; set; }
|
||||
|
||||
public ArgumentTemplate[] Arguments { get; set; }
|
||||
|
||||
public MethodInfo MethodInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
return bl.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
|
||||
var name = base.Compose();
|
||||
|
||||
var bl = new BinaryList()
|
||||
//.AddUInt8(Expansion != null ? (byte)0x10 : (byte)0)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ReturnType.Compose())
|
||||
.AddUInt8((byte)Arguments.Length);
|
||||
|
||||
for (var i = 0; i < Arguments.Length; i++)
|
||||
bl.AddUInt8Array(Arguments[i].Compose());
|
||||
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
bl.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp);
|
||||
bl.InsertUInt8(0, 0x10);
|
||||
}
|
||||
else
|
||||
bl.InsertUInt8(0, 0x0);
|
||||
|
||||
return bl.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public FunctionTemplate(TypeTemplate template, byte index, string name, ArgumentTemplate[] arguments, TemplateDataType returnType, string expansion = null)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
//this.IsVoid = isVoid;
|
||||
this.Arguments = arguments;
|
||||
this.ReturnType = returnType;
|
||||
this.Expansion = expansion;
|
||||
}
|
||||
public FunctionTemplate(TypeTemplate template, byte index, string name, ArgumentTemplate[] arguments, TemplateDataType returnType, string expansion = null)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
//this.IsVoid = isVoid;
|
||||
this.Arguments = arguments;
|
||||
this.ReturnType = returnType;
|
||||
this.Expansion = expansion;
|
||||
}
|
||||
}
|
||||
|
@ -5,43 +5,41 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class MemberTemplate
|
||||
{
|
||||
public class MemberTemplate
|
||||
public enum MemberType
|
||||
{
|
||||
public enum MemberType
|
||||
{
|
||||
Function = 0,
|
||||
Property = 1,
|
||||
Event = 2,
|
||||
Attribute = 3
|
||||
}
|
||||
|
||||
public byte Index => index;
|
||||
public string Name => name;
|
||||
public MemberType Type => type;
|
||||
|
||||
TypeTemplate template;
|
||||
string name;
|
||||
MemberType type;
|
||||
byte index;
|
||||
|
||||
public TypeTemplate Template => template;
|
||||
|
||||
public MemberTemplate(TypeTemplate template, MemberType type, byte index, string name)
|
||||
{
|
||||
this.template = template;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public string Fullname => template.ClassName + "." + Name;
|
||||
|
||||
public virtual byte[] Compose()
|
||||
{
|
||||
return DC.ToBytes(Name);
|
||||
}
|
||||
Function = 0,
|
||||
Property = 1,
|
||||
Event = 2,
|
||||
Attribute = 3
|
||||
}
|
||||
|
||||
public byte Index => index;
|
||||
public string Name => name;
|
||||
public MemberType Type => type;
|
||||
|
||||
TypeTemplate template;
|
||||
string name;
|
||||
MemberType type;
|
||||
byte index;
|
||||
|
||||
public TypeTemplate Template => template;
|
||||
|
||||
public MemberTemplate(TypeTemplate template, MemberType type, byte index, string name)
|
||||
{
|
||||
this.template = template;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public string Fullname => template.ClassName + "." + Name;
|
||||
|
||||
public virtual byte[] Compose()
|
||||
{
|
||||
return DC.ToBytes(Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,138 +6,136 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class PropertyTemplate : MemberTemplate
|
||||
{
|
||||
public class PropertyTemplate : MemberTemplate
|
||||
public enum PropertyPermission : byte
|
||||
{
|
||||
public enum PropertyPermission : byte
|
||||
Read = 1,
|
||||
Write,
|
||||
ReadWrite
|
||||
}
|
||||
|
||||
|
||||
public PropertyInfo PropertyInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public TemplateDataType ValueType { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
public bool Serilize
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
*/
|
||||
//bool ReadOnly;
|
||||
//IIPTypes::DataType ReturnType;
|
||||
public PropertyPermission Permission
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public bool Recordable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public PropertyType Mode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
public string ReadExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string WriteExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public bool Storable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
var pv = ((byte)(Permission) << 1) | (Recordable ? 1 : 0);
|
||||
|
||||
if (WriteExpansion != null && ReadExpansion != null)
|
||||
{
|
||||
Read = 1,
|
||||
Write,
|
||||
ReadWrite
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x38 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public PropertyInfo PropertyInfo
|
||||
else if (WriteExpansion != null)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x30 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public TemplateDataType ValueType { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
public bool Serilize
|
||||
else if (ReadExpansion != null)
|
||||
{
|
||||
get;set;
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x28 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
*/
|
||||
//bool ReadOnly;
|
||||
//IIPTypes::DataType ReturnType;
|
||||
public PropertyPermission Permission
|
||||
else
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public bool Recordable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public PropertyType Mode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
public string ReadExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string WriteExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public bool Storable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
var pv = ((byte)(Permission) << 1) | (Recordable ? 1 : 0);
|
||||
|
||||
if (WriteExpansion != null && ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x38 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
else if (WriteExpansion != null)
|
||||
{
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x30 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.ToArray();
|
||||
}
|
||||
else if (ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x28 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x20 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyTemplate(TypeTemplate template, byte index, string name, TemplateDataType valueType, string read = null, string write = null, bool recordable = false)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Recordable = recordable;
|
||||
//this.Storage = storage;
|
||||
this.ReadExpansion = read;
|
||||
this.WriteExpansion = write;
|
||||
this.ValueType = valueType;
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x20 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyTemplate(TypeTemplate template, byte index, string name, TemplateDataType valueType, string read = null, string write = null, bool recordable = false)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Recordable = recordable;
|
||||
//this.Storage = storage;
|
||||
this.ReadExpansion = read;
|
||||
this.WriteExpansion = write;
|
||||
this.ValueType = valueType;
|
||||
}
|
||||
}
|
||||
|
@ -4,106 +4,104 @@ using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public struct TemplateDataType
|
||||
{
|
||||
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 TemplateDataType(DataType type, string typeName)
|
||||
//{
|
||||
// Type = type;
|
||||
// TypeName = typeName;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
public static TemplateDataType FromType(Type type)
|
||||
{
|
||||
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 TemplateDataType(DataType type, string typeName)
|
||||
//{
|
||||
// Type = type;
|
||||
// TypeName = typeName;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
public static TemplateDataType FromType(Type type)
|
||||
var t = type switch
|
||||
{
|
||||
{ IsArray: true } => type.GetElementType(),
|
||||
{ IsEnum: true } => type.GetEnumUnderlyingType(),
|
||||
(_) => type
|
||||
};
|
||||
|
||||
var t = type switch
|
||||
{
|
||||
{ IsArray: true } => type.GetElementType(),
|
||||
{ IsEnum: true } => type.GetEnumUnderlyingType(),
|
||||
(_) => 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)
|
||||
dt = (DataType)((byte)dt | 0x80);
|
||||
|
||||
return new TemplateDataType()
|
||||
{
|
||||
Type = dt,
|
||||
TypeGuid = typeGuid
|
||||
};
|
||||
}
|
||||
|
||||
public byte[] Compose()
|
||||
DataType dt = t switch
|
||||
{
|
||||
if (Type == DataType.Resource ||
|
||||
Type == DataType.ResourceArray ||
|
||||
Type == DataType.Record ||
|
||||
Type == DataType.RecordArray)
|
||||
{
|
||||
var guid = DC.ToBytes((Guid)TypeGuid);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)Type)
|
||||
.AddUInt8Array(guid).ToArray();
|
||||
}
|
||||
else
|
||||
return new byte[] { (byte)Type };
|
||||
}
|
||||
|
||||
public override string ToString() => Type.ToString() + TypeTemplate != null ? "<" + TypeTemplate.ClassName + ">" : "";
|
||||
_ 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
|
||||
};
|
||||
|
||||
|
||||
public static (uint, TemplateDataType) Parse(byte[] data, uint offset)
|
||||
Guid? typeGuid = null;
|
||||
|
||||
if (dt == DataType.Resource || dt == DataType.Record)
|
||||
typeGuid = TypeTemplate.GetTypeGuid(t);
|
||||
|
||||
if (type.IsArray)
|
||||
dt = (DataType)((byte)dt | 0x80);
|
||||
|
||||
return new TemplateDataType()
|
||||
{
|
||||
var type = (DataType)data[offset++];
|
||||
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 });
|
||||
}
|
||||
else
|
||||
return (1, new TemplateDataType() { Type = type });
|
||||
Type = dt,
|
||||
TypeGuid = typeGuid
|
||||
};
|
||||
}
|
||||
|
||||
public byte[] Compose()
|
||||
{
|
||||
if (Type == DataType.Resource ||
|
||||
Type == DataType.ResourceArray ||
|
||||
Type == DataType.Record ||
|
||||
Type == DataType.RecordArray)
|
||||
{
|
||||
var guid = DC.ToBytes((Guid)TypeGuid);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)Type)
|
||||
.AddUInt8Array(guid).ToArray();
|
||||
}
|
||||
else
|
||||
return new byte[] { (byte)Type };
|
||||
}
|
||||
|
||||
public override string ToString() => Type.ToString() + TypeTemplate != null ? "<" + TypeTemplate.ClassName + ">" : "";
|
||||
|
||||
|
||||
public static (uint, TemplateDataType) Parse(byte[] data, uint offset)
|
||||
{
|
||||
var type = (DataType)data[offset++];
|
||||
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 });
|
||||
}
|
||||
else
|
||||
return (1, new TemplateDataType() { Type = type });
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public enum TemplateType : byte
|
||||
{
|
||||
public enum TemplateType:byte
|
||||
{
|
||||
Unspecified,
|
||||
Resource,
|
||||
Record,
|
||||
Wrapper,
|
||||
}
|
||||
Unspecified,
|
||||
Resource,
|
||||
Record,
|
||||
Wrapper,
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user