mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
Make...Template
This commit is contained in:
@ -230,7 +230,7 @@ partial class DistributedConnection
|
||||
|
||||
await SendDetachRequest(instanceId);
|
||||
}
|
||||
catch
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
@ -708,7 +708,7 @@ partial class DistributedConnection
|
||||
{
|
||||
if (res != null)
|
||||
{
|
||||
|
||||
|
||||
// unsubscribe
|
||||
Unsubscribe(res);
|
||||
// remove from cache
|
||||
@ -1302,7 +1302,7 @@ partial class DistributedConnection
|
||||
// return;
|
||||
//}
|
||||
|
||||
InvokeFunction(call.Method, callback, arguments, IIPPacket.IIPPacketAction.ProcedureCall, call.Target);
|
||||
InvokeFunction(call.Value.Template, callback, arguments, IIPPacket.IIPPacketAction.ProcedureCall, call.Value.Delegate.Target);
|
||||
|
||||
}).Error(x =>
|
||||
{
|
||||
@ -1355,7 +1355,7 @@ partial class DistributedConnection
|
||||
// return;
|
||||
//}
|
||||
|
||||
InvokeFunction(fi, callback, arguments, IIPPacket.IIPPacketAction.StaticCall, null);
|
||||
InvokeFunction(ft, callback, arguments, IIPPacket.IIPPacketAction.StaticCall, null);
|
||||
|
||||
}).Error(x =>
|
||||
{
|
||||
@ -1415,14 +1415,14 @@ partial class DistributedConnection
|
||||
else
|
||||
{
|
||||
|
||||
var fi = r.GetType().GetMethod(ft.Name);
|
||||
//var fi = r.GetType().GetMethod(ft.Name);
|
||||
|
||||
if (fi == null)
|
||||
{
|
||||
// ft found, fi not found, this should never happen
|
||||
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound);
|
||||
return;
|
||||
}
|
||||
//if (fi == null)
|
||||
//{
|
||||
// // ft found, fi not found, this should never happen
|
||||
// SendError(ErrorType.Management, callback, (ushort)ExceptionCode.MethodNotFound);
|
||||
// return;
|
||||
//}
|
||||
|
||||
|
||||
if (r.Instance.Applicable(session, ActionType.Execute, ft) == Ruling.Denied)
|
||||
@ -1432,7 +1432,7 @@ partial class DistributedConnection
|
||||
return;
|
||||
}
|
||||
|
||||
InvokeFunction(fi, callback, arguments, IIPPacket.IIPPacketAction.InvokeFunction, r);
|
||||
InvokeFunction(ft, callback, arguments, IIPPacket.IIPPacketAction.InvokeFunction, r);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1440,11 +1440,11 @@ partial class DistributedConnection
|
||||
|
||||
|
||||
|
||||
void InvokeFunction(MethodInfo fi, uint callback, Map<byte, object> arguments, IIPPacket.IIPPacketAction actionType, object target = null)
|
||||
void InvokeFunction(FunctionTemplate ft, uint callback, Map<byte, object> arguments, IIPPacket.IIPPacketAction actionType, object target = null)
|
||||
{
|
||||
|
||||
// cast arguments
|
||||
ParameterInfo[] pis = fi.GetParameters();
|
||||
ParameterInfo[] pis = ft.MethodInfo.GetParameters();
|
||||
|
||||
object[] args = new object[pis.Length];
|
||||
|
||||
@ -1453,15 +1453,30 @@ partial class DistributedConnection
|
||||
if (pis.Last().ParameterType == typeof(DistributedConnection))
|
||||
{
|
||||
for (byte i = 0; i < pis.Length - 1; i++)
|
||||
args[i] = arguments.ContainsKey(i) ?
|
||||
DC.CastConvert(arguments[i], pis[i].ParameterType) : Type.Missing;
|
||||
{
|
||||
if (arguments.ContainsKey(i))
|
||||
args[i] = DC.CastConvert(arguments[i], pis[i].ParameterType);
|
||||
else if (ft.Arguments[i].Type.Nullable)// Nullable.GetUnderlyingType(pis[i].ParameterType) != null)
|
||||
args[i] = null;
|
||||
else
|
||||
args[i] = Type.Missing;
|
||||
|
||||
}
|
||||
//args[i] = arguments.ContainsKey(i) ?
|
||||
// DC.CastConvert(arguments[i], pis[i].ParameterType) : Type.Missing;
|
||||
args[args.Length - 1] = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (byte i = 0; i < pis.Length; i++)
|
||||
args[i] = arguments.ContainsKey(i) ?
|
||||
DC.CastConvert(arguments[i], pis[i].ParameterType) : Type.Missing;
|
||||
{
|
||||
if (arguments.ContainsKey(i))
|
||||
args[i] = DC.CastConvert(arguments[i], pis[i].ParameterType);
|
||||
else if (ft.Arguments[i].Type.Nullable) //Nullable.GetUnderlyingType(pis[i].ParameterType) != null)
|
||||
args[i] = null;
|
||||
else
|
||||
args[i] = Type.Missing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1469,7 +1484,7 @@ partial class DistributedConnection
|
||||
|
||||
try
|
||||
{
|
||||
rt = fi.Invoke(target, args);
|
||||
rt = ft.MethodInfo.Invoke(target, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ using System.Net;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Membership;
|
||||
using System.Threading.Tasks;
|
||||
using Esiur.Resource.Template;
|
||||
|
||||
namespace Esiur.Net.IIP;
|
||||
public class DistributedServer : NetworkServer<DistributedConnection>, IResource
|
||||
@ -183,11 +184,18 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
|
||||
|
||||
}
|
||||
|
||||
public KeyList<string, Delegate> Calls { get; } = new KeyList<string, Delegate>();
|
||||
public KeyList<string, CallInfo?> Calls { get; } = new KeyList<string, CallInfo?>();
|
||||
|
||||
public struct CallInfo
|
||||
{
|
||||
public FunctionTemplate Template;
|
||||
public Delegate Delegate;
|
||||
}
|
||||
|
||||
public DistributedServer MapCall(string call, Delegate handler)
|
||||
{
|
||||
Calls.Add(call, handler);
|
||||
var ft = FunctionTemplate.MakeFunctionTemplate(null, handler.Method);
|
||||
Calls.Add(call, new CallInfo(){ Delegate = handler, Template = ft});
|
||||
return this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user