mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-09-13 20:43:19 +00:00
.Net 6 Upgrade
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2,26 +2,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
namespace Esiur.Net.IIP;
|
||||
public class DistributedPropertyContext
|
||||
{
|
||||
public class DistributedPropertyContext
|
||||
public object Value { get; private set; }
|
||||
public DistributedConnection Connection { get; private set; }
|
||||
public Func<DistributedConnection, object> Method { get; private set; }
|
||||
|
||||
public DistributedPropertyContext(DistributedConnection connection, object value)
|
||||
{
|
||||
public object Value { get; private set; }
|
||||
public DistributedConnection Connection { get; private set; }
|
||||
public Func<DistributedConnection, object> Method { get; private set; }
|
||||
|
||||
public DistributedPropertyContext(DistributedConnection connection, object value)
|
||||
{
|
||||
this.Value = value;
|
||||
this.Connection = connection;
|
||||
}
|
||||
|
||||
public DistributedPropertyContext(Func<DistributedConnection, object> method)
|
||||
{
|
||||
this.Method = method;
|
||||
}
|
||||
|
||||
public static implicit operator DistributedPropertyContext(Func<DistributedConnection, object> method)
|
||||
=> new DistributedPropertyContext(method);
|
||||
this.Value = value;
|
||||
this.Connection = connection;
|
||||
}
|
||||
|
||||
public DistributedPropertyContext(Func<DistributedConnection, object> method)
|
||||
{
|
||||
this.Method = method;
|
||||
}
|
||||
|
||||
public static implicit operator DistributedPropertyContext(Func<DistributedConnection, object> method)
|
||||
=> new DistributedPropertyContext(method);
|
||||
}
|
||||
|
@@ -42,465 +42,463 @@ using System.Threading.Tasks;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Resource.Template;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
namespace Esiur.Net.IIP;
|
||||
|
||||
//[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public class DistributedResource : DynamicObject, IResource
|
||||
{
|
||||
|
||||
//[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public class DistributedResource : DynamicObject, IResource
|
||||
/// <summary>
|
||||
/// Raised when the distributed resource is destroyed.
|
||||
/// </summary>
|
||||
public event DestroyedEvent OnDestroy;
|
||||
public event Instance.ResourceModifiedEvent OnModified;
|
||||
uint instanceId;
|
||||
DistributedConnection connection;
|
||||
|
||||
|
||||
bool attached = false;
|
||||
bool destroyed = false;
|
||||
bool suspended = false;
|
||||
|
||||
//Structure properties = new Structure();
|
||||
|
||||
string link;
|
||||
//ulong age;
|
||||
//ulong[] ages;
|
||||
protected object[] properties;
|
||||
internal List<DistributedResource> parents = new List<DistributedResource>();
|
||||
internal List<DistributedResource> children = new List<DistributedResource>();
|
||||
|
||||
DistributedResourceEvent[] events;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource template for the remotely located resource.
|
||||
/// </summary>
|
||||
//public ResourceTemplate Template
|
||||
//{
|
||||
// get { return template; }
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Connection responsible for the distributed resource.
|
||||
/// </summary>
|
||||
public DistributedConnection Connection
|
||||
{
|
||||
get { return connection; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resource link
|
||||
/// </summary>
|
||||
public string Link
|
||||
{
|
||||
get { return link; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instance Id given by the other end.
|
||||
/// </summary>
|
||||
public uint Id
|
||||
{
|
||||
get { return instanceId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IDestructible interface.
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
{
|
||||
destroyed = true;
|
||||
attached = false;
|
||||
connection.SendDetachRequest(instanceId);
|
||||
OnDestroy?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspend resource
|
||||
/// </summary>
|
||||
|
||||
internal void Suspend()
|
||||
{
|
||||
suspended = true;
|
||||
attached = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource is attached when all its properties are received.
|
||||
/// </summary>
|
||||
internal bool Attached => attached;
|
||||
|
||||
internal bool Suspended => suspended;
|
||||
|
||||
|
||||
// public DistributedResourceStack Stack
|
||||
//{
|
||||
// get { return stack; }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new distributed resource.
|
||||
/// </summary>
|
||||
/// <param name="connection">Connection responsible for the distributed resource.</param>
|
||||
/// <param name="template">Resource template.</param>
|
||||
/// <param name="instanceId">Instance Id given by the other end.</param>
|
||||
/// <param name="age">Resource age.</param>
|
||||
public DistributedResource(DistributedConnection connection, uint instanceId, ulong age, string link)
|
||||
{
|
||||
this.link = link;
|
||||
this.connection = connection;
|
||||
this.instanceId = instanceId;
|
||||
|
||||
//this.Instance.Template = template;
|
||||
//this.Instance.Age = age;
|
||||
//this.template = template;
|
||||
//this.age = age;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export all properties with ResourceProperty attributed as bytes array.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal PropertyValue[] _Serialize()
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the distributed resource is destroyed.
|
||||
/// </summary>
|
||||
public event DestroyedEvent OnDestroy;
|
||||
public event Instance.ResourceModifiedEvent OnModified;
|
||||
uint instanceId;
|
||||
DistributedConnection connection;
|
||||
var props = new PropertyValue[properties.Length];
|
||||
|
||||
|
||||
bool attached = false;
|
||||
bool destroyed = false;
|
||||
bool suspended = false;
|
||||
for (byte i = 0; i < properties.Length; i++)
|
||||
props[i] = new PropertyValue(properties[i], Instance.GetAge(i), Instance.GetModificationDate(i));
|
||||
|
||||
//Structure properties = new Structure();
|
||||
return props;
|
||||
}
|
||||
|
||||
string link;
|
||||
//ulong age;
|
||||
//ulong[] ages;
|
||||
protected object[] properties;
|
||||
internal List<DistributedResource> parents = new List<DistributedResource>();
|
||||
internal List<DistributedResource> children = new List<DistributedResource>();
|
||||
|
||||
DistributedResourceEvent[] events;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource template for the remotely located resource.
|
||||
/// </summary>
|
||||
//public ResourceTemplate Template
|
||||
//{
|
||||
// get { return template; }
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Connection responsible for the distributed resource.
|
||||
/// </summary>
|
||||
public DistributedConnection Connection
|
||||
internal bool _Attach(PropertyValue[] properties)
|
||||
{
|
||||
if (attached)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
get { return connection; }
|
||||
}
|
||||
suspended = false;
|
||||
|
||||
/// <summary>
|
||||
/// Resource link
|
||||
/// </summary>
|
||||
public string Link
|
||||
{
|
||||
get { return link; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instance Id given by the other end.
|
||||
/// </summary>
|
||||
public uint Id
|
||||
{
|
||||
get { return instanceId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IDestructible interface.
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
{
|
||||
destroyed = true;
|
||||
attached = false;
|
||||
connection.SendDetachRequest(instanceId);
|
||||
OnDestroy?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspend resource
|
||||
/// </summary>
|
||||
|
||||
internal void Suspend()
|
||||
{
|
||||
suspended = true;
|
||||
attached = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource is attached when all its properties are received.
|
||||
/// </summary>
|
||||
internal bool Attached => attached;
|
||||
|
||||
internal bool Suspended => suspended;
|
||||
|
||||
|
||||
// public DistributedResourceStack Stack
|
||||
//{
|
||||
// get { return stack; }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new distributed resource.
|
||||
/// </summary>
|
||||
/// <param name="connection">Connection responsible for the distributed resource.</param>
|
||||
/// <param name="template">Resource template.</param>
|
||||
/// <param name="instanceId">Instance Id given by the other end.</param>
|
||||
/// <param name="age">Resource age.</param>
|
||||
public DistributedResource(DistributedConnection connection, uint instanceId, ulong age, string link)
|
||||
{
|
||||
this.link = link;
|
||||
this.connection = connection;
|
||||
this.instanceId = instanceId;
|
||||
|
||||
//this.Instance.Template = template;
|
||||
//this.Instance.Age = age;
|
||||
//this.template = template;
|
||||
//this.age = age;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export all properties with ResourceProperty attributed as bytes array.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal PropertyValue[] _Serialize()
|
||||
{
|
||||
|
||||
var props = new PropertyValue[properties.Length];
|
||||
this.properties = new object[properties.Length];
|
||||
|
||||
this.events = new DistributedResourceEvent[Instance.Template.Events.Length];
|
||||
|
||||
for (byte i = 0; i < properties.Length; i++)
|
||||
props[i] = new PropertyValue(properties[i], Instance.GetAge(i), Instance.GetModificationDate(i));
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
internal bool _Attach(PropertyValue[] properties)
|
||||
{
|
||||
if (attached)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
suspended = false;
|
||||
|
||||
this.properties = new object[properties.Length];
|
||||
|
||||
this.events = new DistributedResourceEvent[Instance.Template.Events.Length];
|
||||
|
||||
for (byte i = 0; i < properties.Length; i++)
|
||||
{
|
||||
Instance.SetAge(i, properties[i].Age);
|
||||
Instance.SetModificationDate(i, properties[i].Date);
|
||||
this.properties[i] = properties[i].Value;
|
||||
}
|
||||
|
||||
// trigger holded events/property updates.
|
||||
//foreach (var r in afterAttachmentTriggers)
|
||||
// r.Key.Trigger(r.Value);
|
||||
|
||||
//afterAttachmentTriggers.Clear();
|
||||
|
||||
attached = true;
|
||||
|
||||
Instance.SetAge(i, properties[i].Age);
|
||||
Instance.SetModificationDate(i, properties[i].Date);
|
||||
this.properties[i] = properties[i].Value;
|
||||
}
|
||||
return true;
|
||||
|
||||
// trigger holded events/property updates.
|
||||
//foreach (var r in afterAttachmentTriggers)
|
||||
// r.Key.Trigger(r.Value);
|
||||
|
||||
//afterAttachmentTriggers.Clear();
|
||||
|
||||
attached = true;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected internal virtual void _EmitEventByIndex(byte index, object args)
|
||||
protected internal virtual void _EmitEventByIndex(byte index, object args)
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByIndex(index);
|
||||
events[index]?.Invoke(this, args);
|
||||
Instance.EmitResourceEvent(et.Name, args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public AsyncReply<object> _InvokeByNamedArguments(byte index, Structure namedArgs)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (index >= Instance.Template.Functions.Length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
|
||||
return connection.SendInvokeByNamedArguments(instanceId, index, namedArgs);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply<object> _InvokeByArrayArguments(byte index, object[] args)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (index >= Instance.Template.Functions.Length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
|
||||
return connection.SendInvokeByArrayArguments(instanceId, index, args);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply Listen(EventTemplate et)
|
||||
{
|
||||
if (et == null)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, ""));
|
||||
|
||||
if (!et.Listenable)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.NotListenable, ""));
|
||||
|
||||
return connection.SendListenRequest(instanceId, et.Index);
|
||||
}
|
||||
|
||||
public AsyncReply Listen(string eventName)
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(eventName);
|
||||
|
||||
return Listen(et);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply Unlisten(EventTemplate et)
|
||||
{
|
||||
if (et == null)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, ""));
|
||||
|
||||
if (!et.Listenable)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.NotListenable, ""));
|
||||
|
||||
return connection.SendUnlistenRequest(instanceId, et.Index);
|
||||
}
|
||||
|
||||
public AsyncReply Unlisten(string eventName)
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(eventName);
|
||||
|
||||
return Unlisten(et);
|
||||
}
|
||||
|
||||
|
||||
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
|
||||
{
|
||||
var ft = Instance.Template.GetFunctionTemplateByName(binder.Name);
|
||||
|
||||
var reply = new AsyncReply<object>();
|
||||
|
||||
if (attached && ft != null)
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByIndex(index);
|
||||
events[index]?.Invoke(this, args);
|
||||
Instance.EmitResourceEvent(et.Name, args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public AsyncReply<object> _InvokeByNamedArguments(byte index, Structure namedArgs)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (index >= Instance.Template.Functions.Length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
|
||||
return connection.SendInvokeByNamedArguments(instanceId, index, namedArgs);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply<object> _InvokeByArrayArguments(byte index, object[] args)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (index >= Instance.Template.Functions.Length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
|
||||
return connection.SendInvokeByArrayArguments(instanceId, index, args);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply Listen(EventTemplate et)
|
||||
{
|
||||
if (et == null)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, ""));
|
||||
|
||||
if (!et.Listenable)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.NotListenable, ""));
|
||||
|
||||
return connection.SendListenRequest(instanceId, et.Index);
|
||||
}
|
||||
|
||||
public AsyncReply Listen(string eventName)
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(eventName);
|
||||
|
||||
return Listen(et);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply Unlisten(EventTemplate et)
|
||||
{
|
||||
if (et == null)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, ""));
|
||||
|
||||
if (!et.Listenable)
|
||||
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.NotListenable, ""));
|
||||
|
||||
return connection.SendUnlistenRequest(instanceId, et.Index);
|
||||
}
|
||||
|
||||
public AsyncReply Unlisten(string eventName)
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(eventName);
|
||||
|
||||
return Unlisten(et);
|
||||
}
|
||||
|
||||
|
||||
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
|
||||
{
|
||||
var ft = Instance.Template.GetFunctionTemplateByName(binder.Name);
|
||||
|
||||
var reply = new AsyncReply<object>();
|
||||
|
||||
if (attached && ft != null)
|
||||
if (args.Length == 1)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
// Detect anonymous types
|
||||
var type = args[0].GetType();
|
||||
if (Codec.IsAnonymous(type))
|
||||
{
|
||||
// Detect anonymous types
|
||||
var type = args[0].GetType();
|
||||
if (Codec.IsAnonymous(type))
|
||||
{
|
||||
var namedArgs = new Structure();
|
||||
|
||||
var pi = type.GetTypeInfo().GetProperties();
|
||||
foreach (var p in pi)
|
||||
namedArgs[p.Name] = p.GetValue(args[0]);
|
||||
result = _InvokeByNamedArguments(ft.Index, namedArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _InvokeByArrayArguments(ft.Index, args);
|
||||
}
|
||||
var namedArgs = new Structure();
|
||||
|
||||
var pi = type.GetTypeInfo().GetProperties();
|
||||
foreach (var p in pi)
|
||||
namedArgs[p.Name] = p.GetValue(args[0]);
|
||||
result = _InvokeByNamedArguments(ft.Index, namedArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _InvokeByArrayArguments(ft.Index, args);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
result = _InvokeByArrayArguments(ft.Index, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a property value.
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <returns>Value</returns>
|
||||
protected internal object _Get(byte index)
|
||||
else
|
||||
{
|
||||
if (index >= properties.Length)
|
||||
return null;
|
||||
return properties[index];
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!attached)
|
||||
/// <summary>
|
||||
/// Get a property value.
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <returns>Value</returns>
|
||||
protected internal object _Get(byte index)
|
||||
{
|
||||
if (index >= properties.Length)
|
||||
return null;
|
||||
return properties[index];
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
|
||||
result = null;
|
||||
|
||||
if (!attached)
|
||||
return false;
|
||||
|
||||
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
|
||||
|
||||
if (pt != null)
|
||||
{
|
||||
result = properties[pt.Index];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(binder.Name);
|
||||
if (et == null)
|
||||
return false;
|
||||
|
||||
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
|
||||
result = events[et.Index];
|
||||
|
||||
if (pt != null)
|
||||
{
|
||||
result = properties[pt.Index];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(binder.Name);
|
||||
if (et == null)
|
||||
return false;
|
||||
|
||||
result = events[et.Index];
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void _UpdatePropertyByIndex(byte index, object value)
|
||||
{
|
||||
var pt = Instance.Template.GetPropertyTemplateByIndex(index);
|
||||
properties[index] = value;
|
||||
Instance.EmitModification(pt, value);
|
||||
}
|
||||
internal void _UpdatePropertyByIndex(byte index, object value)
|
||||
{
|
||||
var pt = Instance.Template.GetPropertyTemplateByIndex(index);
|
||||
properties[index] = value;
|
||||
Instance.EmitModification(pt, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set property value.
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <param name="value">Value</param>
|
||||
/// <returns>Indicator when the property is set.</returns>
|
||||
protected internal AsyncReply<object> _Set(byte index, object value)
|
||||
{
|
||||
if (index >= properties.Length)
|
||||
return null;
|
||||
/// <summary>
|
||||
/// Set property value.
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <param name="value">Value</param>
|
||||
/// <returns>Indicator when the property is set.</returns>
|
||||
protected internal AsyncReply<object> _Set(byte index, object value)
|
||||
{
|
||||
if (index >= properties.Length)
|
||||
return null;
|
||||
|
||||
var reply = new AsyncReply<object>();
|
||||
var reply = new AsyncReply<object>();
|
||||
|
||||
var parameters = Codec.Compose(value, connection);
|
||||
connection.SendRequest(Packets.IIPPacket.IIPPacketAction.SetProperty)
|
||||
.AddUInt32(instanceId)
|
||||
.AddUInt8(index)
|
||||
.AddUInt8Array(parameters)
|
||||
.Done()
|
||||
.Then((res) =>
|
||||
{
|
||||
var parameters = Codec.Compose(value, connection);
|
||||
connection.SendRequest(Packets.IIPPacket.IIPPacketAction.SetProperty)
|
||||
.AddUInt32(instanceId)
|
||||
.AddUInt8(index)
|
||||
.AddUInt8Array(parameters)
|
||||
.Done()
|
||||
.Then((res) =>
|
||||
{
|
||||
// not really needed, server will always send property modified,
|
||||
// this only happens if the programmer forgot to emit in property setter
|
||||
properties[index] = value;
|
||||
reply.Trigger(null);
|
||||
});
|
||||
reply.Trigger(null);
|
||||
});
|
||||
|
||||
return reply;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override bool TrySetMember(SetMemberBinder binder, object value)
|
||||
public override bool TrySetMember(SetMemberBinder binder, object value)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (!attached)
|
||||
return false;
|
||||
|
||||
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
|
||||
|
||||
if (pt != null)
|
||||
{
|
||||
if (destroyed)
|
||||
throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (suspended)
|
||||
throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (!attached)
|
||||
_Set(pt.Index, value);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(binder.Name);
|
||||
if (et == null)
|
||||
return false;
|
||||
|
||||
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
|
||||
|
||||
if (pt != null)
|
||||
{
|
||||
_Set(pt.Index, value);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var et = Instance.Template.GetEventTemplateByName(binder.Name);
|
||||
if (et == null)
|
||||
return false;
|
||||
|
||||
events[et.Index] = (DistributedResourceEvent)value;
|
||||
|
||||
return true;
|
||||
}
|
||||
events[et.Index] = (DistributedResourceEvent)value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
public async void InvokeMethod(byte index, object[] arguments, DistributedConnection sender)
|
||||
{
|
||||
// get function parameters
|
||||
Type t = this.GetType();
|
||||
}
|
||||
|
||||
MethodInfo mi = t.GetMethod(GetFunctionName(index), BindingFlags.DeclaredOnly |
|
||||
BindingFlags.Public |
|
||||
BindingFlags.Instance | BindingFlags.InvokeMethod);
|
||||
if (mi != null)
|
||||
/*
|
||||
public async void InvokeMethod(byte index, object[] arguments, DistributedConnection sender)
|
||||
{
|
||||
// get function parameters
|
||||
Type t = this.GetType();
|
||||
|
||||
MethodInfo mi = t.GetMethod(GetFunctionName(index), BindingFlags.DeclaredOnly |
|
||||
BindingFlags.Public |
|
||||
BindingFlags.Instance | BindingFlags.InvokeMethod);
|
||||
if (mi != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = await invokeMethod(mi, arguments, sender);
|
||||
object rt = Codec.Compose(res);
|
||||
sender.SendParams((byte)0x80, instanceId, index, rt);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var msg = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
|
||||
sender.SendParams((byte)0x8E, instanceId, index, Codec.Compose(msg));
|
||||
}
|
||||
var res = await invokeMethod(mi, arguments, sender);
|
||||
object rt = Codec.Compose(res);
|
||||
sender.SendParams((byte)0x80, instanceId, index, rt);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var msg = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
|
||||
sender.SendParams((byte)0x8E, instanceId, index, Codec.Compose(msg));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource interface.
|
||||
/// </summary>
|
||||
public Instance Instance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// Resource interface.
|
||||
/// </summary>
|
||||
public Instance Instance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of distributed resource.
|
||||
/// </summary>
|
||||
public DistributedResource()
|
||||
{
|
||||
//stack = new DistributedResourceStack(this);
|
||||
//this.Instance.ResourceModified += this.OnModified;
|
||||
/// <summary>
|
||||
/// Create a new instance of distributed resource.
|
||||
/// </summary>
|
||||
public DistributedResource()
|
||||
{
|
||||
//stack = new DistributedResourceStack(this);
|
||||
//this.Instance.ResourceModified += this.OnModified;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resource interface.
|
||||
/// </summary>
|
||||
/// <param name="trigger"></param>
|
||||
/// <returns></returns>
|
||||
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
/// <summary>
|
||||
/// Resource interface.
|
||||
/// </summary>
|
||||
/// <param name="trigger"></param>
|
||||
/// <returns></returns>
|
||||
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
this.Instance.ResourceModified += this.OnModified;
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
this.Instance.ResourceModified += this.OnModified;
|
||||
|
||||
// do nothing.
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
// do nothing.
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
}
|
@@ -28,7 +28,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
{
|
||||
public delegate void DistributedResourceEvent(DistributedResource sender, object argument);
|
||||
}
|
||||
namespace Esiur.Net.IIP;
|
||||
|
||||
public delegate void DistributedResourceEvent(DistributedResource sender, object argument);
|
||||
|
@@ -28,46 +28,44 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
namespace Esiur.Net.IIP;
|
||||
public class DistributedResourceQueueItem
|
||||
{
|
||||
public class DistributedResourceQueueItem
|
||||
public enum DistributedResourceQueueItemType
|
||||
{
|
||||
public enum DistributedResourceQueueItemType
|
||||
{
|
||||
Propery,
|
||||
Event
|
||||
}
|
||||
Propery,
|
||||
Event
|
||||
}
|
||||
|
||||
DistributedResourceQueueItemType type;
|
||||
byte index;
|
||||
object value;
|
||||
DistributedResource resource;
|
||||
DistributedResourceQueueItemType type;
|
||||
byte index;
|
||||
object value;
|
||||
DistributedResource resource;
|
||||
|
||||
public DistributedResourceQueueItem(DistributedResource resource, DistributedResourceQueueItemType type, object value, byte index)
|
||||
{
|
||||
this.resource = resource;
|
||||
this.index = index;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
public DistributedResourceQueueItem(DistributedResource resource, DistributedResourceQueueItemType type, object value, byte index)
|
||||
{
|
||||
this.resource = resource;
|
||||
this.index = index;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public DistributedResource Resource
|
||||
{
|
||||
get { return resource; }
|
||||
}
|
||||
public DistributedResourceQueueItemType Type
|
||||
{
|
||||
get { return type; }
|
||||
}
|
||||
public DistributedResource Resource
|
||||
{
|
||||
get { return resource; }
|
||||
}
|
||||
public DistributedResourceQueueItemType Type
|
||||
{
|
||||
get { return type; }
|
||||
}
|
||||
|
||||
public byte Index
|
||||
{
|
||||
get { return index; }
|
||||
}
|
||||
public byte Index
|
||||
{
|
||||
get { return index; }
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return value; }
|
||||
}
|
||||
public object Value
|
||||
{
|
||||
get { return value; }
|
||||
}
|
||||
}
|
||||
|
@@ -35,143 +35,141 @@ using System.Net;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Membership;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
namespace Esiur.Net.IIP;
|
||||
public class DistributedServer : NetworkServer<DistributedConnection>, IResource
|
||||
{
|
||||
public class DistributedServer : NetworkServer<DistributedConnection>, IResource
|
||||
[Attribute]
|
||||
public string IP
|
||||
{
|
||||
[Attribute]
|
||||
public string IP
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public IMembership Membership
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public EntryPoint EntryPoint
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public ushort Port
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = 10518;
|
||||
|
||||
|
||||
[Attribute]
|
||||
public ExceptionLevel ExceptionLevel { get; set; }
|
||||
= ExceptionLevel.Code
|
||||
| ExceptionLevel.Source
|
||||
| ExceptionLevel.Message
|
||||
| ExceptionLevel.Trace;
|
||||
|
||||
|
||||
public Instance Instance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
{
|
||||
TCPSocket listener;
|
||||
|
||||
if (IP != null)
|
||||
listener = new TCPSocket(new IPEndPoint(IPAddress.Parse(IP), Port));
|
||||
else
|
||||
listener = new TCPSocket(new IPEndPoint(IPAddress.Any, Port));
|
||||
|
||||
Start(listener);
|
||||
}
|
||||
else if (trigger == ResourceTrigger.Terminate)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
else if (trigger == ResourceTrigger.SystemReload)
|
||||
{
|
||||
Trigger(ResourceTrigger.Terminate);
|
||||
Trigger(ResourceTrigger.Initialize);
|
||||
}
|
||||
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//protected override void DataReceived(DistributedConnection sender, NetworkBuffer data)
|
||||
//{
|
||||
// //throw new NotImplementedException();
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//protected override void ClientConnected(DistributedConnection sender)
|
||||
//{
|
||||
// //Console.WriteLine("DistributedConnection Client Connected");
|
||||
//}
|
||||
|
||||
//private void ConnectionReadyEventReceiver(DistributedConnection sender)
|
||||
//{
|
||||
// sender.OnReady -= ConnectionReadyEventReceiver;
|
||||
// Warehouse.Put(sender, sender.LocalUsername, null, this);
|
||||
//}
|
||||
|
||||
|
||||
//public override void RemoveConnection(DistributedConnection connection)
|
||||
//{
|
||||
// connection.OnReady -= Sender_OnReady;
|
||||
// //connection.Server = null;
|
||||
// base.RemoveConnection(connection);
|
||||
//}
|
||||
|
||||
//public override void AddConnection(DistributedConnection connection)
|
||||
//{
|
||||
// connection.OnReady += Sender_OnReady;
|
||||
// connection.Server = this;
|
||||
// base.AddConnection(connection);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
protected override void ClientConnected(DistributedConnection connection)
|
||||
{
|
||||
//connection.OnReady += ConnectionReadyEventReceiver;
|
||||
}
|
||||
|
||||
public override void Add(DistributedConnection connection)
|
||||
{
|
||||
connection.Server = this;
|
||||
connection.ExceptionLevel = ExceptionLevel;
|
||||
base.Add(connection);
|
||||
}
|
||||
|
||||
public override void Remove(DistributedConnection connection)
|
||||
{
|
||||
connection.Server = null;
|
||||
base.Remove(connection);
|
||||
}
|
||||
|
||||
protected override void ClientDisconnected(DistributedConnection connection)
|
||||
{
|
||||
//connection.OnReady -= ConnectionReadyEventReceiver;
|
||||
//Warehouse.Remove(connection);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public IMembership Membership
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public EntryPoint EntryPoint
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public ushort Port
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = 10518;
|
||||
|
||||
|
||||
[Attribute]
|
||||
public ExceptionLevel ExceptionLevel { get; set; }
|
||||
= ExceptionLevel.Code
|
||||
| ExceptionLevel.Source
|
||||
| ExceptionLevel.Message
|
||||
| ExceptionLevel.Trace;
|
||||
|
||||
|
||||
public Instance Instance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
{
|
||||
TCPSocket listener;
|
||||
|
||||
if (IP != null)
|
||||
listener = new TCPSocket(new IPEndPoint(IPAddress.Parse(IP), Port));
|
||||
else
|
||||
listener = new TCPSocket(new IPEndPoint(IPAddress.Any, Port));
|
||||
|
||||
Start(listener);
|
||||
}
|
||||
else if (trigger == ResourceTrigger.Terminate)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
else if (trigger == ResourceTrigger.SystemReload)
|
||||
{
|
||||
Trigger(ResourceTrigger.Terminate);
|
||||
Trigger(ResourceTrigger.Initialize);
|
||||
}
|
||||
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//protected override void DataReceived(DistributedConnection sender, NetworkBuffer data)
|
||||
//{
|
||||
// //throw new NotImplementedException();
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//protected override void ClientConnected(DistributedConnection sender)
|
||||
//{
|
||||
// //Console.WriteLine("DistributedConnection Client Connected");
|
||||
//}
|
||||
|
||||
//private void ConnectionReadyEventReceiver(DistributedConnection sender)
|
||||
//{
|
||||
// sender.OnReady -= ConnectionReadyEventReceiver;
|
||||
// Warehouse.Put(sender, sender.LocalUsername, null, this);
|
||||
//}
|
||||
|
||||
|
||||
//public override void RemoveConnection(DistributedConnection connection)
|
||||
//{
|
||||
// connection.OnReady -= Sender_OnReady;
|
||||
// //connection.Server = null;
|
||||
// base.RemoveConnection(connection);
|
||||
//}
|
||||
|
||||
//public override void AddConnection(DistributedConnection connection)
|
||||
//{
|
||||
// connection.OnReady += Sender_OnReady;
|
||||
// connection.Server = this;
|
||||
// base.AddConnection(connection);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
protected override void ClientConnected(DistributedConnection connection)
|
||||
{
|
||||
//connection.OnReady += ConnectionReadyEventReceiver;
|
||||
}
|
||||
|
||||
public override void Add(DistributedConnection connection)
|
||||
{
|
||||
connection.Server = this;
|
||||
connection.ExceptionLevel = ExceptionLevel;
|
||||
base.Add(connection);
|
||||
}
|
||||
|
||||
public override void Remove(DistributedConnection connection)
|
||||
{
|
||||
connection.Server = null;
|
||||
base.Remove(connection);
|
||||
}
|
||||
|
||||
protected override void ClientDisconnected(DistributedConnection connection)
|
||||
{
|
||||
//connection.OnReady -= ConnectionReadyEventReceiver;
|
||||
//Warehouse.Remove(connection);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -28,11 +28,9 @@ using System.Text;
|
||||
using Esiur.Net.Sockets;
|
||||
using Esiur.Security.Authority;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
namespace Esiur.Net.IIP;
|
||||
public class DistributedSession : NetworkSession
|
||||
{
|
||||
public class DistributedSession : NetworkSession
|
||||
{
|
||||
public Source Source { get; set; }
|
||||
public Authentication Authentication { get; set; }
|
||||
}
|
||||
public Source Source { get; set; }
|
||||
public Authentication Authentication { get; set; }
|
||||
}
|
||||
|
@@ -29,12 +29,11 @@ using Esiur.Data;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Resource.Template;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
{
|
||||
public abstract class EntryPoint : Esiur.Resource.Resource
|
||||
{
|
||||
namespace Esiur.Net.IIP;
|
||||
|
||||
public abstract AsyncReply<IResource[]> Query(string path, DistributedConnection sender);
|
||||
protected abstract override bool Create();
|
||||
}
|
||||
public abstract class EntryPoint : Esiur.Resource.Resource
|
||||
{
|
||||
|
||||
public abstract AsyncReply<IResource[]> Query(string path, DistributedConnection sender);
|
||||
protected abstract override bool Create();
|
||||
}
|
||||
|
Reference in New Issue
Block a user