mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
1.6.1
This commit is contained in:
@ -197,11 +197,20 @@ namespace Esiur.Net.IIP
|
||||
|
||||
if (socket.State == SocketState.Established &&
|
||||
session.LocalAuthentication.Type == AuthenticationType.Client)
|
||||
{
|
||||
Declare();
|
||||
}
|
||||
}
|
||||
|
||||
private void Declare()
|
||||
{
|
||||
var dmn = DC.ToBytes(session.LocalAuthentication.Domain);// domain);
|
||||
|
||||
if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials)
|
||||
{
|
||||
// declare (Credentials -> No Auth, No Enctypt)
|
||||
|
||||
var un = DC.ToBytes(session.LocalAuthentication.Username);
|
||||
var dmn = DC.ToBytes(session.LocalAuthentication.Domain);// domain);
|
||||
|
||||
SendParams()
|
||||
.AddUInt8(0x60)
|
||||
@ -212,8 +221,27 @@ namespace Esiur.Net.IIP
|
||||
.AddUInt8Array(un)
|
||||
.Done();//, dmn, localNonce, (byte)un.Length, un);
|
||||
}
|
||||
}
|
||||
else if (session.LocalAuthentication.Method == AuthenticationMethod.Token)
|
||||
{
|
||||
|
||||
SendParams()
|
||||
.AddUInt8(0x70)
|
||||
.AddUInt8((byte)dmn.Length)
|
||||
.AddUInt8Array(dmn)
|
||||
.AddUInt8Array(localNonce)
|
||||
.AddUInt64(session.LocalAuthentication.TokenIndex)
|
||||
.Done();//, dmn, localNonce, token
|
||||
|
||||
}
|
||||
else if (session.LocalAuthentication.Method == AuthenticationMethod.None)
|
||||
{
|
||||
SendParams()
|
||||
.AddUInt8(0x40)
|
||||
.AddUInt8((byte)dmn.Length)
|
||||
.AddUInt8Array(dmn)
|
||||
.Done();//, dmn, localNonce, token
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new distributed connection.
|
||||
@ -451,12 +479,21 @@ namespace Esiur.Net.IIP
|
||||
IIPRequestInvokeFunctionNamedArguments(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.Content);
|
||||
break;
|
||||
|
||||
case IIPPacket.IIPPacketAction.GetProperty:
|
||||
IIPRequestGetProperty(packet.CallbackId, packet.ResourceId, packet.MethodIndex);
|
||||
//case IIPPacket.IIPPacketAction.GetProperty:
|
||||
// IIPRequestGetProperty(packet.CallbackId, packet.ResourceId, packet.MethodIndex);
|
||||
// break;
|
||||
//case IIPPacket.IIPPacketAction.GetPropertyIfModified:
|
||||
// IIPRequestGetPropertyIfModifiedSince(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.ResourceAge);
|
||||
// break;
|
||||
|
||||
case IIPPacket.IIPPacketAction.Listen:
|
||||
IIPRequestListen(packet.CallbackId, packet.ResourceId, packet.MethodIndex);
|
||||
break;
|
||||
case IIPPacket.IIPPacketAction.GetPropertyIfModified:
|
||||
IIPRequestGetPropertyIfModifiedSince(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.ResourceAge);
|
||||
|
||||
case IIPPacket.IIPPacketAction.Unlisten:
|
||||
IIPRequestUnlisten(packet.CallbackId, packet.ResourceId, packet.MethodIndex);
|
||||
break;
|
||||
|
||||
case IIPPacket.IIPPacketAction.SetProperty:
|
||||
IIPRequestSetProperty(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.Content);
|
||||
break;
|
||||
@ -531,14 +568,17 @@ namespace Esiur.Net.IIP
|
||||
IIPReplyInvoke(packet.CallbackId, packet.Content);
|
||||
break;
|
||||
|
||||
case IIPPacket.IIPPacketAction.GetProperty:
|
||||
IIPReply(packet.CallbackId, packet.Content);
|
||||
break;
|
||||
//case IIPPacket.IIPPacketAction.GetProperty:
|
||||
// IIPReply(packet.CallbackId, packet.Content);
|
||||
// break;
|
||||
|
||||
case IIPPacket.IIPPacketAction.GetPropertyIfModified:
|
||||
IIPReply(packet.CallbackId, packet.Content);
|
||||
break;
|
||||
case IIPPacket.IIPPacketAction.SetProperty:
|
||||
//case IIPPacket.IIPPacketAction.GetPropertyIfModified:
|
||||
// IIPReply(packet.CallbackId, packet.Content);
|
||||
// break;
|
||||
|
||||
case IIPPacketAction.Listen:
|
||||
case IIPPacketAction.Unlisten:
|
||||
case IIPPacketAction.SetProperty:
|
||||
IIPReply(packet.CallbackId);
|
||||
break;
|
||||
|
||||
@ -753,24 +793,34 @@ namespace Esiur.Net.IIP
|
||||
session.Id = new byte[32];
|
||||
r.NextBytes(session.Id);
|
||||
//SendParams((byte)0x28, session.Id);
|
||||
SendParams()
|
||||
.AddUInt8(0x28)
|
||||
.AddUInt8Array(session.Id)
|
||||
.Done();
|
||||
SendParams().AddUInt8(0x28)
|
||||
.AddUInt8Array(session.Id)
|
||||
.Done();
|
||||
|
||||
ready = true;
|
||||
Warehouse.Put(this, this.LocalUsername, null, Server).Then(x =>
|
||||
if (this.Instance == null)
|
||||
{
|
||||
Warehouse.Put(this.RemoteUsername, this, null, Server).Then(x =>
|
||||
{
|
||||
|
||||
ready = true;
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
Server?.Membership.Login(session);
|
||||
loginDate = DateTime.Now;
|
||||
|
||||
}).Error(x =>
|
||||
{
|
||||
openReply?.TriggerError(x);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ready = true;
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
Server?.Membership.Login(session);
|
||||
|
||||
}).Error(x=>
|
||||
{
|
||||
openReply?.TriggerError(x);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH");
|
||||
|
||||
@ -841,13 +891,21 @@ namespace Esiur.Net.IIP
|
||||
|
||||
ready = true;
|
||||
// put it in the warehouse
|
||||
Warehouse.Put(this, this.LocalUsername, null, Server).Then(x =>
|
||||
|
||||
if (this.Instance == null)
|
||||
{
|
||||
Warehouse.Put(this.LocalUsername, this, null, Server).Then(x =>
|
||||
{
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
}).Error(x => openReply?.TriggerError(x));
|
||||
}
|
||||
else
|
||||
{
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
}).Error(x=> openReply?.TriggerError(x));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (authPacket.Command == IIPAuthPacket.IIPAuthPacketCommand.Error)
|
||||
@ -957,28 +1015,7 @@ namespace Esiur.Net.IIP
|
||||
}
|
||||
|
||||
|
||||
protected void NetworkClose()
|
||||
{
|
||||
// clean up
|
||||
ready = false;
|
||||
readyToEstablish = false;
|
||||
|
||||
foreach (var x in requests.Values)
|
||||
x.TriggerError(new AsyncException(ErrorType.Management, 0, "Connection closed"));
|
||||
|
||||
foreach (var x in resourceRequests.Values)
|
||||
x.TriggerError(new AsyncException(ErrorType.Management, 0, "Connection closed"));
|
||||
|
||||
foreach (var x in templateRequests.Values)
|
||||
x.TriggerError(new AsyncException(ErrorType.Management, 0, "Connection closed"));
|
||||
|
||||
requests.Clear();
|
||||
resourceRequests.Clear();
|
||||
templateRequests.Clear();
|
||||
|
||||
foreach (var x in resources.Values)
|
||||
x.Suspend();
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Connect(AuthenticationMethod method = AuthenticationMethod.Certificate, Sockets.ISocket socket = null, string hostname = null, ushort port = 0, string username = null, ulong tokenIndex = 0, byte[] passwordOrToken = null, string domain = null)
|
||||
{
|
||||
@ -1128,32 +1165,38 @@ namespace Esiur.Net.IIP
|
||||
protected override void Connected()
|
||||
{
|
||||
if (session.LocalAuthentication.Type == AuthenticationType.Client)
|
||||
{
|
||||
// declare (Credentials -> No Auth, No Enctypt)
|
||||
|
||||
var un = DC.ToBytes(session.LocalAuthentication.Username);
|
||||
var dmn = DC.ToBytes(session.LocalAuthentication.Domain);// domain);
|
||||
|
||||
SendParams()
|
||||
.AddUInt8(0x60)
|
||||
.AddUInt8((byte)dmn.Length)
|
||||
.AddUInt8Array(dmn)
|
||||
.AddUInt8Array(localNonce)
|
||||
.AddUInt8((byte)un.Length)
|
||||
.AddUInt8Array(un)
|
||||
.Done();
|
||||
}
|
||||
Declare();
|
||||
}
|
||||
|
||||
protected override void Disconencted()
|
||||
{
|
||||
// clean up
|
||||
readyToEstablish = false;
|
||||
|
||||
foreach (var x in requests.Values)
|
||||
x.TriggerError(new AsyncException(ErrorType.Management, 0, "Connection closed"));
|
||||
|
||||
foreach (var x in resourceRequests.Values)
|
||||
x.TriggerError(new AsyncException(ErrorType.Management, 0, "Connection closed"));
|
||||
|
||||
foreach (var x in templateRequests.Values)
|
||||
x.TriggerError(new AsyncException(ErrorType.Management, 0, "Connection closed"));
|
||||
|
||||
requests.Clear();
|
||||
resourceRequests.Clear();
|
||||
templateRequests.Clear();
|
||||
|
||||
foreach (var x in resources.Values)
|
||||
x.Suspend();
|
||||
|
||||
UnsubscribeAll();
|
||||
|
||||
Warehouse.Remove(this);
|
||||
|
||||
if (ready)
|
||||
{
|
||||
Server?.Membership.Logout(session);
|
||||
Warehouse.Remove(this);
|
||||
ready = false;
|
||||
UnsubscribeAll();
|
||||
}
|
||||
|
||||
ready = false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -36,6 +36,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
{
|
||||
@ -54,7 +55,9 @@ namespace Esiur.Net.IIP
|
||||
|
||||
volatile uint callbackCounter = 0;
|
||||
|
||||
List<IResource> subscriptions = new List<IResource>();
|
||||
//List<IResource> subscriptions = new List<IResource>();
|
||||
Dictionary<IResource, List<byte>> subscriptions = new Dictionary<IResource, List<byte>>();// new List<IResource>();
|
||||
|
||||
object subscriptionsLock = new object();
|
||||
|
||||
AsyncQueue<DistributedResourceQueueItem> queue = new AsyncQueue<DistributedResourceQueueItem>();
|
||||
@ -108,13 +111,40 @@ namespace Esiur.Net.IIP
|
||||
|
||||
internal SendList SendEvent(IIPPacket.IIPPacketEvent evt)
|
||||
{
|
||||
//var bl = new BinaryList((byte)(evt));
|
||||
//bl.AddRange(args);
|
||||
//Send(bl.ToArray());
|
||||
|
||||
return (SendList)SendParams().AddUInt8((byte)(evt));
|
||||
}
|
||||
|
||||
internal AsyncReply SendListenRequest(uint instanceId, byte index)
|
||||
{
|
||||
var reply = new AsyncReply<object>();
|
||||
var c = callbackCounter++;
|
||||
requests.Add(c, reply);
|
||||
|
||||
SendParams().AddUInt8((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.Listen))
|
||||
.AddUInt32(c)
|
||||
.AddUInt32(instanceId)
|
||||
.AddUInt8(index)
|
||||
.Done();
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
internal AsyncReply SendUnlistenRequest(uint instanceId, byte index)
|
||||
{
|
||||
var reply = new AsyncReply<object>();
|
||||
var c = callbackCounter++;
|
||||
requests.Add(c, reply);
|
||||
|
||||
SendParams().AddUInt8((byte)(0x40 | (byte)Packets.IIPPacket.IIPPacketAction.Unlisten))
|
||||
.AddUInt32(c)
|
||||
.AddUInt32(instanceId)
|
||||
.AddUInt8(index)
|
||||
.Done();
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
internal AsyncReply<object> SendInvokeByArrayArguments(uint instanceId, byte index, object[] parameters)
|
||||
{
|
||||
var pb = Codec.ComposeVarArray(parameters, this, true);
|
||||
@ -593,6 +623,7 @@ namespace Esiur.Net.IIP
|
||||
var r = res as IResource;
|
||||
// unsubscribe
|
||||
Unsubscribe(r);
|
||||
Subscribe(r);
|
||||
|
||||
//r.Instance.ResourceEventOccurred -= Instance_EventOccurred;
|
||||
//r.Instance.CustomResourceEventOccurred -= Instance_CustomEventOccurred;
|
||||
@ -610,7 +641,6 @@ namespace Esiur.Net.IIP
|
||||
//r.Instance.ResourceModified += Instance_PropertyModified;
|
||||
//r.Instance.ResourceDestroyed += Instance_ResourceDestroyed;
|
||||
|
||||
Subscribe(r);
|
||||
//r.Instance.Children.OnAdd += Children_OnAdd;
|
||||
//r.Instance.Children.OnRemoved += Children_OnRemoved;
|
||||
|
||||
@ -770,7 +800,7 @@ namespace Esiur.Net.IIP
|
||||
// create the resource
|
||||
var resource = Activator.CreateInstance(type, args) as IResource;
|
||||
|
||||
Warehouse.Put(resource, name, store as IStore, parent).Then(ok =>
|
||||
Warehouse.Put( name, resource, store as IStore, parent).Then(ok =>
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.CreateResource, callback)
|
||||
.AddUInt32(resource.Instance.Id)
|
||||
@ -1126,7 +1156,7 @@ namespace Esiur.Net.IIP
|
||||
if (Server?.EntryPoint != null)
|
||||
Server.EntryPoint.Query(resourceLink, this).Then(queryCallback);
|
||||
else
|
||||
Warehouse.Query(resourceLink).Then(x => queryCallback(x));
|
||||
Warehouse.Query(resourceLink).Then(queryCallback);
|
||||
}
|
||||
|
||||
void IIPRequestResourceAttribute(uint callback, uint resourceId)
|
||||
@ -1469,53 +1499,161 @@ namespace Esiur.Net.IIP
|
||||
});
|
||||
}
|
||||
|
||||
void IIPRequestGetProperty(uint callback, uint resourceId, byte index)
|
||||
void IIPRequestListen(uint callback, uint resourceId, byte index)
|
||||
{
|
||||
Warehouse.GetById(resourceId).Then((r) =>
|
||||
{
|
||||
if (r != null)
|
||||
{
|
||||
var pt = r.Instance.Template.GetFunctionTemplateByIndex(index);
|
||||
if (pt != null)
|
||||
var et = r.Instance.Template.GetEventTemplateByIndex(index);
|
||||
|
||||
if (et != null)
|
||||
{
|
||||
if (r is DistributedResource)
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.GetProperty, callback)
|
||||
.AddUInt8Array(Codec.Compose((r as DistributedResource)._Get(pt.Index), this))
|
||||
.Done();
|
||||
(r as DistributedResource).Listen(et).Then(x =>
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.Listen, callback).Done();
|
||||
}).Error(x => SendError(ErrorType.Exception, callback, (ushort)ExceptionCode.GeneralFailure));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NETSTANDARD
|
||||
var pi = r.GetType().GetTypeInfo().GetProperty(pt.Name);
|
||||
#else
|
||||
var pi = r.GetType().GetProperty(pt.Name);
|
||||
#endif
|
||||
lock(subscriptionsLock)
|
||||
{
|
||||
if (!subscriptions.ContainsKey(r))
|
||||
{
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.NotAttached);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pi != null)
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.GetProperty, callback)
|
||||
.AddUInt8Array(Codec.Compose(pi.GetValue(r), this))
|
||||
.Done();
|
||||
}
|
||||
else
|
||||
{
|
||||
// pt found, pi not found, this should never happen
|
||||
if (subscriptions[r].Contains(index))
|
||||
{
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.AlreadyListened);
|
||||
return;
|
||||
}
|
||||
|
||||
subscriptions[r].Add(index);
|
||||
|
||||
SendReply(IIPPacket.IIPPacketAction.Listen, callback).Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// pt not found
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// resource not found
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.ResourceNotFound);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void IIPRequestUnlisten(uint callback, uint resourceId, byte index)
|
||||
{
|
||||
Warehouse.GetById(resourceId).Then((r) =>
|
||||
{
|
||||
if (r != null)
|
||||
{
|
||||
var et = r.Instance.Template.GetEventTemplateByIndex(index);
|
||||
|
||||
if (et != null)
|
||||
{
|
||||
if (r is DistributedResource)
|
||||
{
|
||||
(r as DistributedResource).Unlisten(et).Then(x =>
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.Unlisten, callback).Done();
|
||||
}).Error(x => SendError(ErrorType.Exception, callback, (ushort)ExceptionCode.GeneralFailure));
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (subscriptionsLock)
|
||||
{
|
||||
if (!subscriptions.ContainsKey(r))
|
||||
{
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.NotAttached);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subscriptions[r].Contains(index))
|
||||
{
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.AlreadyUnlistened);
|
||||
return;
|
||||
}
|
||||
|
||||
subscriptions[r].Remove(index);
|
||||
|
||||
SendReply(IIPPacket.IIPPacketAction.Unlisten, callback).Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// pt not found
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// resource not found
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.ResourceNotFound);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// void IIPRequestGetProperty(uint callback, uint resourceId, byte index)
|
||||
// {
|
||||
// Warehouse.GetById(resourceId).Then((r) =>
|
||||
// {
|
||||
// if (r != null)
|
||||
// {
|
||||
// var pt = r.Instance.Template.GetPropertyTemplateByIndex(index);
|
||||
// if (pt != null)
|
||||
// {
|
||||
// if (r is DistributedResource)
|
||||
// {
|
||||
// SendReply(IIPPacket.IIPPacketAction.GetProperty, callback)
|
||||
// .AddUInt8Array(Codec.Compose((r as DistributedResource)._Get(pt.Index), this))
|
||||
// .Done();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
//#if NETSTANDARD
|
||||
// var pi = r.GetType().GetTypeInfo().GetProperty(pt.Name);
|
||||
//#else
|
||||
// var pi = r.GetType().GetProperty(pt.Name);
|
||||
//#endif
|
||||
|
||||
// if (pi != null)
|
||||
// {
|
||||
// SendReply(IIPPacket.IIPPacketAction.GetProperty, callback)
|
||||
// .AddUInt8Array(Codec.Compose(pi.GetValue(r), this))
|
||||
// .Done();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // pt found, pi not found, this should never happen
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // pt not found
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // resource not found
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
void IIPRequestInquireResourceHistory(uint callback, uint resourceId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
Warehouse.GetById(resourceId).Then((r) =>
|
||||
@ -1552,51 +1690,51 @@ namespace Esiur.Net.IIP
|
||||
});
|
||||
}
|
||||
|
||||
void IIPRequestGetPropertyIfModifiedSince(uint callback, uint resourceId, byte index, ulong age)
|
||||
{
|
||||
Warehouse.GetById(resourceId).Then((r) =>
|
||||
{
|
||||
if (r != null)
|
||||
{
|
||||
var pt = r.Instance.Template.GetFunctionTemplateByIndex(index);
|
||||
if (pt != null)
|
||||
{
|
||||
if (r.Instance.GetAge(index) > age)
|
||||
{
|
||||
#if NETSTANDARD
|
||||
var pi = r.GetType().GetTypeInfo().GetProperty(pt.Name);
|
||||
#else
|
||||
var pi = r.GetType().GetProperty(pt.Name);
|
||||
#endif
|
||||
if (pi != null)
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback)
|
||||
.AddUInt8Array(Codec.Compose(pi.GetValue(r), this))
|
||||
.Done();
|
||||
}
|
||||
else
|
||||
{
|
||||
// pt found, pi not found, this should never happen
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback)
|
||||
.AddUInt8((byte)DataType.NotModified)
|
||||
.Done();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// pt not found
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// resource not found
|
||||
}
|
||||
});
|
||||
}
|
||||
// void IIPRequestGetPropertyIfModifiedSince(uint callback, uint resourceId, byte index, ulong age)
|
||||
// {
|
||||
// Warehouse.GetById(resourceId).Then((r) =>
|
||||
// {
|
||||
// if (r != null)
|
||||
// {
|
||||
// var pt = r.Instance.Template.GetFunctionTemplateByIndex(index);
|
||||
// if (pt != null)
|
||||
// {
|
||||
// if (r.Instance.GetAge(index) > age)
|
||||
// {
|
||||
//#if NETSTANDARD
|
||||
// var pi = r.GetType().GetTypeInfo().GetProperty(pt.Name);
|
||||
//#else
|
||||
// var pi = r.GetType().GetProperty(pt.Name);
|
||||
//#endif
|
||||
// if (pi != null)
|
||||
// {
|
||||
// SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback)
|
||||
// .AddUInt8Array(Codec.Compose(pi.GetValue(r), this))
|
||||
// .Done();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // pt found, pi not found, this should never happen
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SendReply(IIPPacket.IIPPacketAction.GetPropertyIfModified, callback)
|
||||
// .AddUInt8((byte)DataType.NotModified)
|
||||
// .Done();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // pt not found
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // resource not found
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
void IIPRequestSetProperty(uint callback, uint resourceId, byte index, byte[] content)
|
||||
{
|
||||
@ -1973,7 +2111,7 @@ namespace Esiur.Net.IIP
|
||||
// ClassId, ResourceAge, ResourceLink, Content
|
||||
if (resource == null)
|
||||
{
|
||||
Warehouse.Put(dr, id.ToString(), this, null, tmp).Then((ok) =>
|
||||
Warehouse.Put(id.ToString(), dr, this, null, tmp).Then((ok) =>
|
||||
{
|
||||
Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) =>
|
||||
{
|
||||
@ -2242,7 +2380,7 @@ namespace Esiur.Net.IIP
|
||||
resource.Instance.ResourceModified += Instance_PropertyModified;
|
||||
resource.Instance.ResourceDestroyed += Instance_ResourceDestroyed;
|
||||
|
||||
subscriptions.Add(resource);
|
||||
subscriptions.Add(resource, new List<byte>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2265,7 +2403,7 @@ namespace Esiur.Net.IIP
|
||||
{
|
||||
lock(subscriptionsLock)
|
||||
{
|
||||
foreach(var resource in subscriptions)
|
||||
foreach(var resource in subscriptions.Keys)
|
||||
{
|
||||
resource.Instance.ResourceEventOccurred -= Instance_EventOccurred;
|
||||
resource.Instance.CustomResourceEventOccurred -= Instance_CustomEventOccurred;
|
||||
@ -2313,12 +2451,26 @@ namespace Esiur.Net.IIP
|
||||
if (et == null)
|
||||
return;
|
||||
|
||||
if (et.Listenable)
|
||||
{
|
||||
lock (subscriptionsLock)
|
||||
{
|
||||
// check the client requested listen
|
||||
if (!subscriptions.ContainsKey(resource))
|
||||
return;
|
||||
|
||||
if (!subscriptions[resource].Contains(et.Index))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!receivers(this.session))
|
||||
return;
|
||||
|
||||
if (resource.Instance.Applicable(this.session, ActionType.ReceiveEvent, et, issuer) == Ruling.Denied)
|
||||
return;
|
||||
|
||||
|
||||
// compose the packet
|
||||
SendEvent(IIPPacket.IIPPacketEvent.EventOccurred)
|
||||
.AddUInt32(resource.Instance.Id)
|
||||
@ -2334,6 +2486,18 @@ namespace Esiur.Net.IIP
|
||||
if (et == null)
|
||||
return;
|
||||
|
||||
if (et.Listenable)
|
||||
{
|
||||
lock (subscriptionsLock)
|
||||
{
|
||||
// check the client requested listen
|
||||
if (!subscriptions.ContainsKey(resource))
|
||||
return;
|
||||
|
||||
if (!subscriptions[resource].Contains(et.Index))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (resource.Instance.Applicable(this.session, ActionType.ReceiveEvent, et, null) == Ruling.Denied)
|
||||
return;
|
||||
|
@ -44,7 +44,7 @@ using Esiur.Resource.Template;
|
||||
|
||||
namespace Esiur.Net.IIP
|
||||
{
|
||||
|
||||
|
||||
//[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public class DistributedResource : DynamicObject, IResource
|
||||
{
|
||||
@ -73,7 +73,7 @@ namespace Esiur.Net.IIP
|
||||
|
||||
DistributedResourceEvent[] events;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource template for the remotely located resource.
|
||||
@ -105,7 +105,7 @@ namespace Esiur.Net.IIP
|
||||
/// </summary>
|
||||
public uint Id
|
||||
{
|
||||
get { return instanceId; }
|
||||
get { return instanceId; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -136,20 +136,20 @@ namespace Esiur.Net.IIP
|
||||
internal bool Attached => attached;
|
||||
|
||||
internal bool Suspended => suspended;
|
||||
|
||||
|
||||
// public DistributedResourceStack Stack
|
||||
|
||||
// public DistributedResourceStack Stack
|
||||
//{
|
||||
// get { return 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>
|
||||
/// <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;
|
||||
@ -207,7 +207,7 @@ namespace Esiur.Net.IIP
|
||||
attached = true;
|
||||
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void _EmitEventByIndex(byte index, object args)
|
||||
@ -232,6 +232,7 @@ namespace Esiur.Net.IIP
|
||||
return connection.SendInvokeByNamedArguments(instanceId, index, namedArgs);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply<object> _InvokeByArrayArguments(byte index, object[] args)
|
||||
{
|
||||
if (destroyed)
|
||||
@ -247,14 +248,52 @@ namespace Esiur.Net.IIP
|
||||
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 (attached && ft != null)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
@ -273,7 +312,7 @@ namespace Esiur.Net.IIP
|
||||
{
|
||||
result = _InvokeByArrayArguments(ft.Index, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -380,7 +419,7 @@ namespace Esiur.Net.IIP
|
||||
return false;
|
||||
|
||||
var pt = Instance.Template.GetPropertyTemplateByName(binder.Name);
|
||||
|
||||
|
||||
if (pt != null)
|
||||
{
|
||||
_Set(pt.Index, value);
|
||||
@ -397,7 +436,7 @@ namespace Esiur.Net.IIP
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public async void InvokeMethod(byte index, object[] arguments, DistributedConnection sender)
|
||||
@ -426,10 +465,10 @@ namespace Esiur.Net.IIP
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource interface.
|
||||
/// </summary>
|
||||
|
||||
/// <summary>
|
||||
/// Resource interface.
|
||||
/// </summary>
|
||||
public Instance Instance
|
||||
{
|
||||
get;
|
||||
|
@ -32,7 +32,7 @@ namespace Esiur.Net.IIP
|
||||
{
|
||||
public class DistributedSession : NetworkSession
|
||||
{
|
||||
Source Source { get; }
|
||||
Authentication Authentication;
|
||||
public Source Source { get; set; }
|
||||
public Authentication Authentication { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user