mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 21:13:13 +00:00
1.2.7
This commit is contained in:
@ -27,7 +27,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using Esiur.Resource.Template;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -11,6 +11,7 @@ using Esiur.Misc;
|
||||
using Esiur.Security.Permissions;
|
||||
using Esiur.Resource.Template;
|
||||
using Esiur.Security.Authority;
|
||||
using Esiur.Proxy;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
@ -265,7 +266,7 @@ namespace Esiur.Resource
|
||||
/// <returns></returns>
|
||||
public bool LoadProperty(string name, ulong age, DateTime modificationDate, object value)
|
||||
{
|
||||
var pt = template.GetPropertyTemplate(name);
|
||||
var pt = template.GetPropertyTemplateByName(name);
|
||||
|
||||
if (pt == null)
|
||||
return false;
|
||||
@ -336,7 +337,7 @@ namespace Esiur.Resource
|
||||
{
|
||||
for (byte i = 0; i < properties.Length; i++)
|
||||
{
|
||||
var pt = this.template.GetPropertyTemplate(i);
|
||||
var pt = this.template.GetPropertyTemplateByIndex(i);
|
||||
if (pt != null)
|
||||
{
|
||||
var pv = properties[i];
|
||||
@ -486,7 +487,7 @@ namespace Esiur.Resource
|
||||
object value;
|
||||
if (GetPropertyValue(propertyName, out value))
|
||||
{
|
||||
var pt = template.GetPropertyTemplate(propertyName);
|
||||
var pt = template.GetPropertyTemplateByName(propertyName);
|
||||
EmitModification(pt, value);
|
||||
}
|
||||
}
|
||||
@ -515,7 +516,7 @@ namespace Esiur.Resource
|
||||
#endif
|
||||
*/
|
||||
|
||||
var pt = template.GetPropertyTemplate(name);
|
||||
var pt = template.GetPropertyTemplateByName(name);
|
||||
|
||||
if (pt != null && pt.Info != null)
|
||||
{
|
||||
@ -712,7 +713,7 @@ namespace Esiur.Resource
|
||||
}
|
||||
|
||||
// connect events
|
||||
Type t = resource.GetType();
|
||||
Type t = ResourceProxy.GetBaseType(resource);
|
||||
|
||||
#if NETSTANDARD1_5
|
||||
var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
|
@ -24,7 +24,7 @@ SOFTWARE.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ SOFTWARE.
|
||||
|
||||
*/
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using Esiur.Net.IIP;
|
||||
using Esiur.Security.Authority;
|
||||
using System;
|
||||
|
@ -63,7 +63,7 @@ namespace Esiur.Resource
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceProperty(StorageMode storage = StorageMode.Volatile, string readExpansion = null, string writeExpansion = null)
|
||||
public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, string readExpansion = null, string writeExpansion = null)
|
||||
{
|
||||
this.readExpansion = readExpansion;
|
||||
this.writeExpansion = writeExpansion;
|
||||
|
@ -32,7 +32,7 @@ namespace Esiur.Resource
|
||||
{
|
||||
public enum ResourceTrigger : int
|
||||
{
|
||||
Loaded = 0,
|
||||
Open = 0,
|
||||
Initialize,
|
||||
Terminate,
|
||||
Configure,
|
||||
|
@ -23,7 +23,7 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -6,8 +6,8 @@ namespace Esiur.Resource
|
||||
{
|
||||
public enum StorageMode : byte
|
||||
{
|
||||
Volatile = 0,
|
||||
NonVolatile,
|
||||
Volatile,
|
||||
Recordable
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,20 @@ namespace Esiur.Resource.Template
|
||||
if (Expansion != null)
|
||||
{
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
return BinaryList.ToBytes((byte)0x50, exp.Length, exp, (byte)name.Length, name);
|
||||
return new BinaryList()
|
||||
.AddUInt8(0x50)
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return BinaryList.ToBytes((byte)0x40, (byte)name.Length, name);
|
||||
return new BinaryList()
|
||||
.AddUInt8(0x40)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,10 +30,18 @@ namespace Esiur.Resource.Template
|
||||
if (Expansion != null)
|
||||
{
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
return BinaryList.ToBytes((byte)(0x10 | (IsVoid ? 0x8 : 0x0)), (byte)name.Length, name, exp.Length, exp);
|
||||
return new BinaryList().AddUInt8((byte)(0x10 | (IsVoid ? 0x8 : 0x0)))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return BinaryList.ToBytes((byte)(IsVoid ? 0x8 : 0x0), (byte)name.Length, name);
|
||||
return new BinaryList().AddUInt8((byte)(IsVoid ? 0x8 : 0x0))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,20 +73,44 @@ namespace Esiur.Resource.Template
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return BinaryList.ToBytes((byte)(0x38 | pv), (byte)name.Length, name, wexp.Length, wexp, rexp.Length, rexp);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x38 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
else if (WriteExpansion != null)
|
||||
{
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return BinaryList.ToBytes((byte)(0x30 | pv), (byte)name.Length, name, wexp.Length, wexp);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x30 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.ToArray();
|
||||
}
|
||||
else if (ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
return BinaryList.ToBytes((byte)(0x28 | pv), (byte)name.Length, name, rexp.Length, rexp);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x28 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return BinaryList.ToBytes((byte)(0x20 | pv), (byte)name.Length, name);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x20 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public PropertyTemplate(ResourceTemplate template, byte index, string name, string read, string write, StorageMode storage)
|
||||
|
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Reflection;
|
||||
using Esiur.Misc;
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using System.Security.Cryptography;
|
||||
using Esiur.Proxy;
|
||||
|
||||
@ -32,16 +32,16 @@ namespace Esiur.Resource.Template
|
||||
public MemberTemplate GetMemberTemplate(MemberInfo member)
|
||||
{
|
||||
if (member is MethodInfo)
|
||||
return GetFunctionTemplate(member.Name);
|
||||
return GetFunctionTemplateByName(member.Name);
|
||||
else if (member is EventInfo)
|
||||
return GetEventTemplate(member.Name);
|
||||
return GetEventTemplateByName(member.Name);
|
||||
else if (member is PropertyInfo)
|
||||
return GetPropertyTemplate(member.Name);
|
||||
return GetPropertyTemplateByName(member.Name);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public EventTemplate GetEventTemplate(string eventName)
|
||||
public EventTemplate GetEventTemplateByName(string eventName)
|
||||
{
|
||||
foreach (var i in events)
|
||||
if (i.Name == eventName)
|
||||
@ -49,7 +49,7 @@ namespace Esiur.Resource.Template
|
||||
return null;
|
||||
}
|
||||
|
||||
public EventTemplate GetEventTemplate(byte index)
|
||||
public EventTemplate GetEventTemplateByIndex(byte index)
|
||||
{
|
||||
foreach (var i in events)
|
||||
if (i.Index == index)
|
||||
@ -57,14 +57,14 @@ namespace Esiur.Resource.Template
|
||||
return null;
|
||||
}
|
||||
|
||||
public FunctionTemplate GetFunctionTemplate(string functionName)
|
||||
public FunctionTemplate GetFunctionTemplateByName(string functionName)
|
||||
{
|
||||
foreach (var i in functions)
|
||||
if (i.Name == functionName)
|
||||
return i;
|
||||
return null;
|
||||
}
|
||||
public FunctionTemplate GetFunctionTemplate(byte index)
|
||||
public FunctionTemplate GetFunctionTemplateByIndex(byte index)
|
||||
{
|
||||
foreach (var i in functions)
|
||||
if (i.Index == index)
|
||||
@ -72,7 +72,7 @@ namespace Esiur.Resource.Template
|
||||
return null;
|
||||
}
|
||||
|
||||
public PropertyTemplate GetPropertyTemplate(byte index)
|
||||
public PropertyTemplate GetPropertyTemplateByIndex(byte index)
|
||||
{
|
||||
foreach (var i in properties)
|
||||
if (i.Index == index)
|
||||
@ -80,7 +80,7 @@ namespace Esiur.Resource.Template
|
||||
return null;
|
||||
}
|
||||
|
||||
public PropertyTemplate GetPropertyTemplate(string propertyName)
|
||||
public PropertyTemplate GetPropertyTemplateByName(string propertyName)
|
||||
{
|
||||
foreach (var i in properties)
|
||||
if (i.Name == propertyName)
|
||||
@ -200,16 +200,20 @@ namespace Esiur.Resource.Template
|
||||
|
||||
// bake it binarily
|
||||
var b = new BinaryList();
|
||||
b.Append(classId);
|
||||
b.Append((byte)className.Length, className);
|
||||
b.Append(version);
|
||||
b.Append((ushort)members.Count);
|
||||
b.AddGuid(classId)
|
||||
.AddUInt8((byte)className.Length)
|
||||
.AddString(className)
|
||||
.AddInt32(version)
|
||||
.AddUInt16((ushort)members.Count);
|
||||
|
||||
|
||||
foreach (var ft in functions)
|
||||
b.Append(ft.Compose());
|
||||
b.AddUInt8Array(ft.Compose());
|
||||
foreach (var pt in properties)
|
||||
b.Append(pt.Compose());
|
||||
b.AddUInt8Array(pt.Compose());
|
||||
foreach (var et in events)
|
||||
b.Append(et.Compose());
|
||||
b.AddUInt8Array(et.Compose());
|
||||
|
||||
content = b.ToArray();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Core;
|
||||
using Esiur.Proxy;
|
||||
using Esiur.Resource.Template;
|
||||
using Esiur.Security.Permissions;
|
||||
@ -54,7 +54,7 @@ namespace Esiur.Resource
|
||||
public static event StoreConnectedEvent StoreConnected;
|
||||
public static event StoreDisconnectedEvent StoreDisconnected;
|
||||
|
||||
static KeyList<string, IStore> protocols = new KeyList<string, IStore>();
|
||||
public static KeyList<string, Func<IStore>> Protocols { get; } = new KeyList<string, Func<IStore>>();
|
||||
|
||||
/// <summary>
|
||||
/// Get a store by its name.
|
||||
@ -277,15 +277,15 @@ namespace Esiur.Resource
|
||||
|
||||
var rt = new AsyncReply<IResource>();
|
||||
|
||||
if (protocols.ContainsKey(url[0]))
|
||||
if (Protocols.ContainsKey(url[0]))
|
||||
{
|
||||
var handler = protocols[url[0]];
|
||||
var handler = Protocols[url[0]];
|
||||
|
||||
var store = Activator.CreateInstance(handler.GetType()) as IStore;
|
||||
var store = handler();// Activator.CreateInstance(handler.GetType()) as IStore;
|
||||
Put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
|
||||
|
||||
|
||||
store.Trigger(ResourceTrigger.Initialize).Then(x => {
|
||||
store.Trigger(ResourceTrigger.Open).Then(x => {
|
||||
if (pathname.Length > 0 && pathname != "")
|
||||
store.Get(pathname).Then(r => {
|
||||
rt.Trigger(r);
|
||||
@ -345,7 +345,7 @@ namespace Esiur.Resource
|
||||
|
||||
resources.Add(resource.Instance.Id, resource);
|
||||
|
||||
if (!storeIsOpen)
|
||||
if (storeIsOpen)
|
||||
resource.Trigger(ResourceTrigger.Initialize);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user