diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs index 9eb8c8a..e138d22 100644 --- a/Esiur/Net/IIP/DistributedConnection.cs +++ b/Esiur/Net/IIP/DistributedConnection.cs @@ -292,7 +292,7 @@ namespace Esiur.Net.IIP queue.Then((x) => { if (x.Type == DistributedResourceQueueItem.DistributedResourceQueueItemType.Event) - x.Resource._EmitEventByIndex(x.Index, (object[])x.Value); + x.Resource._EmitEventByIndex(x.Index, x.Value); else x.Resource._UpdatePropertyByIndex(x.Index, x.Value); }); @@ -895,7 +895,7 @@ namespace Esiur.Net.IIP } finally { - this.Socket.Unhold(); + this.Socket?.Unhold(); } } diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs index 4a73833..0889d0d 100644 --- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs +++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs @@ -344,7 +344,7 @@ namespace Esiur.Net.IIP var item = new AsyncReply(); queue.Add(item); - Codec.ParseVarArray(content, this).Then((arguments) => + Codec.Parse(content, 0, this).Then((arguments) => { var et = r.Instance.Template.GetEventTemplateByIndex(index); if (et != null) @@ -1286,18 +1286,21 @@ namespace Esiur.Net.IIP else { // ft found, fi not found, this should never happen + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound); } } } else { // no function at this index + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound); } }); } else { // no resource with this id + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.ResourceNotFound); } }); } @@ -1424,16 +1427,16 @@ namespace Esiur.Net.IIP .AddUInt8Array(Codec.Compose(res, this)) .Done(); - }).Error(ex => - { - SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message); - }).Progress((pt, pv, pm) => - { - SendProgress(callback, pv, pm); - }).Chunk(v => - { - SendChunk(callback, v); - }); + }).Error(ex => + { + SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message); + }).Progress((pt, pv, pm) => + { + SendProgress(callback, pv, pm); + }).Chunk(v => + { + SendChunk(callback, v); + }); } else { @@ -1445,18 +1448,23 @@ namespace Esiur.Net.IIP else { // ft found, fi not found, this should never happen + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound); + } } } else { // no function at this index + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound); + } }); } else { // no resource with this id + SendError(ErrorType.Management, callback, (ushort)ExceptionCode.ResourceNotFound); } }); } @@ -2298,7 +2306,7 @@ namespace Esiur.Net.IIP // private void Instance_EventOccurred(IResource resource, string name, string[] users, DistributedConnection[] connections, object[] args) - private void Instance_CustomEventOccurred(IResource resource, object issuer, Func receivers, string name, object[] args) + private void Instance_CustomEventOccurred(IResource resource, object issuer, Func receivers, string name, object args) { var et = resource.Instance.Template.GetEventTemplateByName(name); @@ -2315,11 +2323,11 @@ namespace Esiur.Net.IIP SendEvent(IIPPacket.IIPPacketEvent.EventOccurred) .AddUInt32(resource.Instance.Id) .AddUInt8((byte)et.Index) - .AddUInt8Array(Codec.ComposeVarArray(args, this, true)) + .AddUInt8Array(Codec.Compose(args, this, true)) .Done(); } - private void Instance_EventOccurred(IResource resource, string name, object[] args) + private void Instance_EventOccurred(IResource resource, string name, object args) { var et = resource.Instance.Template.GetEventTemplateByName(name); @@ -2334,7 +2342,7 @@ namespace Esiur.Net.IIP SendEvent(IIPPacket.IIPPacketEvent.EventOccurred) .AddUInt32(resource.Instance.Id) .AddUInt8((byte)et.Index) - .AddUInt8Array(Codec.ComposeVarArray(args, this, true)) + .AddUInt8Array(Codec.Compose(args, this, true)) .Done(); } } diff --git a/Esiur/Net/IIP/DistributedResource.cs b/Esiur/Net/IIP/DistributedResource.cs index df4c076..1c9d3c3 100644 --- a/Esiur/Net/IIP/DistributedResource.cs +++ b/Esiur/Net/IIP/DistributedResource.cs @@ -210,7 +210,7 @@ namespace Esiur.Net.IIP return true; } - internal void _EmitEventByIndex(byte index, object[] args) + internal void _EmitEventByIndex(byte index, object args) { var et = Instance.Template.GetEventTemplateByIndex(index); events[index]?.Invoke(this, args); diff --git a/Esiur/Net/IIP/DistributedResourceEvent.cs b/Esiur/Net/IIP/DistributedResourceEvent.cs index 8241d15..5a03bf7 100644 --- a/Esiur/Net/IIP/DistributedResourceEvent.cs +++ b/Esiur/Net/IIP/DistributedResourceEvent.cs @@ -30,5 +30,5 @@ using System.Threading.Tasks; namespace Esiur.Net.IIP { - public delegate void DistributedResourceEvent(DistributedResource sender, params object[] arguments); + public delegate void DistributedResourceEvent(DistributedResource sender, object arguments); } diff --git a/Esiur/Net/Packets/IIPPacket.cs b/Esiur/Net/Packets/IIPPacket.cs index b1a9e98..b65f1cf 100644 --- a/Esiur/Net/Packets/IIPPacket.cs +++ b/Esiur/Net/Packets/IIPPacket.cs @@ -300,7 +300,8 @@ namespace Esiur.Net.Packets offset += cl; } - else if (Event == IIPPacketEvent.PropertyUpdated) + else if (Event == IIPPacketEvent.PropertyUpdated + || Event == IIPPacketEvent.EventOccurred) { if (NotEnough(offset, ends, 2)) return -dataLengthNeeded; @@ -333,23 +334,23 @@ namespace Esiur.Net.Packets offset += (uint)size; } } - else if (Event == IIPPacketEvent.EventOccurred) - { - if (NotEnough(offset, ends, 5)) - return -dataLengthNeeded; + //else if (Event == IIPPacketEvent.EventOccurred) + //{ + // if (NotEnough(offset, ends, 5)) + // return -dataLengthNeeded; - MethodIndex = data[offset++]; + // MethodIndex = data[offset++]; - var cl = data.GetUInt32(offset); - offset += 4; + // var cl = data.GetUInt32(offset); + // offset += 4; - if (NotEnough(offset, ends, cl)) - return -dataLengthNeeded; + // if (NotEnough(offset, ends, cl)) + // return -dataLengthNeeded; - Content = data.Clip(offset, cl); - offset += cl; + // Content = data.Clip(offset, cl); + // offset += cl; - } + //} // Attribute else if (Event == IIPPacketEvent.AttributesUpdated) { diff --git a/Esiur/Resource/Instance.cs b/Esiur/Resource/Instance.cs index dff37b6..376ed99 100644 --- a/Esiur/Resource/Instance.cs +++ b/Esiur/Resource/Instance.cs @@ -31,9 +31,9 @@ namespace Esiur.Resource public delegate void ResourceModifiedEvent(IResource resource, string propertyName, object newValue); - public delegate void ResourceEventOccurredEvent(IResource resource, string eventName, object[] args); + public delegate void ResourceEventOccurredEvent(IResource resource, string eventName, object args); - public delegate void CustomResourceEventOccurredEvent(IResource resource, object issuer, Func receivers, string eventName, object[] args); + public delegate void CustomResourceEventOccurredEvent(IResource resource, object issuer, Func receivers, string eventName, object args); public delegate void ResourceDestroyedEvent(IResource resource); @@ -589,7 +589,7 @@ namespace Esiur.Resource // internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args) - internal void EmitCustomResourceEvent(object issuer, Func receivers, string name, object[] args) + internal void EmitCustomResourceEvent(object issuer, Func receivers, string name, object args) { IResource res; if (this.resource.TryGetTarget(out res)) @@ -598,7 +598,7 @@ namespace Esiur.Resource } } - internal void EmitResourceEvent(string name, object[] args) + internal void EmitResourceEvent(string name, object args) { IResource res; if (this.resource.TryGetTarget(out res)) diff --git a/Esiur/Resource/ResourceEventHandler.cs b/Esiur/Resource/ResourceEventHandler.cs index b917d19..fa80565 100644 --- a/Esiur/Resource/ResourceEventHandler.cs +++ b/Esiur/Resource/ResourceEventHandler.cs @@ -33,12 +33,12 @@ using System.Threading.Tasks; namespace Esiur.Resource { - public delegate void ResourceEventHanlder(params object[] args); + public delegate void ResourceEventHanlder(object args); // 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 CustomResourceEventHanlder(object issuer, Func receivers, params object[] args);// object issuer, Session[] receivers, params object[] args); + public delegate void CustomResourceEventHanlder(object issuer, Func receivers, object args);// object issuer, Session[] receivers, params object[] args); // public delegate void CustomReceiversEventHanlder(string[] usernames, DistributedConnection[] connections, params object[] args); diff --git a/Esiur/Resource/Template/EventTemplate.cs b/Esiur/Resource/Template/EventTemplate.cs index 9d7372e..a8ab2b5 100644 --- a/Esiur/Resource/Template/EventTemplate.cs +++ b/Esiur/Resource/Template/EventTemplate.cs @@ -27,10 +27,10 @@ namespace Esiur.Resource.Template var exp = DC.ToBytes(Expansion); return new BinaryList() .AddUInt8(0x50) - .AddInt32(exp.Length) - .AddUInt8Array(exp) .AddUInt8((byte)name.Length) .AddUInt8Array(name) + .AddInt32(exp.Length) + .AddUInt8Array(exp) .ToArray(); } else