2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 03:32:57 +00:00
This commit is contained in:
Ahmed Zamil 2021-02-22 01:58:49 +03:00
parent 4cfad2a242
commit e790fe18e5
8 changed files with 49 additions and 40 deletions

View File

@ -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();
}
}

View File

@ -344,7 +344,7 @@ namespace Esiur.Net.IIP
var item = new AsyncReply<DistributedResourceQueueItem>();
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<Session, bool> receivers, string name, object[] args)
private void Instance_CustomEventOccurred(IResource resource, object issuer, Func<Session, bool> 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();
}
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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<Session, bool> receivers, string eventName, object[] args);
public delegate void CustomResourceEventOccurredEvent(IResource resource, object issuer, Func<Session, bool> 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<Session, bool> receivers, string name, object[] args)
internal void EmitCustomResourceEvent(object issuer, Func<Session, bool> 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))

View File

@ -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<Session, bool> receivers, params object[] args);// object issuer, Session[] receivers, params object[] args);
public delegate void CustomResourceEventHanlder(object issuer, Func<Session, bool> receivers, object args);// object issuer, Session[] receivers, params object[] args);
// public delegate void CustomReceiversEventHanlder(string[] usernames, DistributedConnection[] connections, params object[] args);

View File

@ -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