2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00

AutoReconnect

This commit is contained in:
2022-08-11 21:28:16 +03:00
parent af94ce318a
commit 21a2061fc4
12 changed files with 355 additions and 154 deletions

View File

@ -108,6 +108,7 @@ public class DistributedResource : DynamicObject, IResource
public uint Id
{
get { return instanceId; }
internal set { instanceId = value; }
}
/// <summary>
@ -117,7 +118,7 @@ public class DistributedResource : DynamicObject, IResource
{
destroyed = true;
attached = false;
connection.SendDetachRequest(instanceId);
connection.DetachResource(instanceId);
OnDestroy?.Invoke(this);
}
@ -223,13 +224,13 @@ public class DistributedResource : DynamicObject, IResource
public AsyncReply<object> _Invoke(byte index, Map<byte, object> args)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object");
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access suspended object");
throw new Exception("Trying to access a suspended object.");
if (index >= Instance.Template.Functions.Length)
throw new Exception("Function index is incorrect");
throw new Exception("Function index is incorrect.");
var ft = Instance.Template.GetFunctionTemplateByIndex(index);
@ -282,6 +283,12 @@ public class DistributedResource : DynamicObject, IResource
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access a suspended object.");
var ft = Instance.Template.GetFunctionTemplateByName(binder.Name);
var reply = new AsyncReply<object>();
@ -361,7 +368,7 @@ public class DistributedResource : DynamicObject, IResource
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (destroyed)
throw new Exception("Trying to access destroyed object");
throw new Exception("Trying to access a destroyed object.");
result = null;
@ -430,10 +437,10 @@ public class DistributedResource : DynamicObject, IResource
public override bool TrySetMember(SetMemberBinder binder, object value)
{
if (destroyed)
throw new Exception("Trying to access destroyed object");
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access suspended object");
throw new Exception("Trying to access a suspended object.");
if (!attached)
return false;
@ -519,4 +526,9 @@ public class DistributedResource : DynamicObject, IResource
// do nothing.
return new AsyncReply<bool>(true);
}
~DistributedResource()
{
Destroy();
}
}