mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 03:32:57 +00:00
invoke
This commit is contained in:
parent
2bccebd419
commit
ebc80b08cf
12
Esiur/Core/AsyncChunk.cs
Normal file
12
Esiur/Core/AsyncChunk.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Core
|
||||
{
|
||||
// This interface is used to provide return type for templates and support chunk callbacks using IAsyncEnumerable feature of C# 8
|
||||
public interface IAsyncChunk<T> : IAsyncEnumerable<object>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
31
Esiur/Core/InvocationContext.cs
Normal file
31
Esiur/Core/InvocationContext.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Esiur.Net.IIP;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Core
|
||||
{
|
||||
public class InvocationContext
|
||||
{
|
||||
private uint CallbackId;
|
||||
|
||||
public void Chunk(object value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Progress(int value) {
|
||||
|
||||
}
|
||||
|
||||
public DistributedConnection Connection { get; internal set; }
|
||||
|
||||
|
||||
internal InvocationContext(DistributedConnection connection, uint callbackId)
|
||||
{
|
||||
Connection = connection;
|
||||
CallbackId = callbackId;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1552,11 +1552,8 @@ partial class DistributedConnection
|
||||
.Done();
|
||||
});
|
||||
|
||||
//await t;
|
||||
//SendParams((byte)0x90, callback, Codec.Compose(res, this));
|
||||
}
|
||||
else if (rt is AsyncReply)// Codec.ImplementsInterface(rt.GetType(), typeof(IAsyncReply<>)))// rt.GetType().GetTypeInfo().IsGenericType
|
||||
//&& rt.GetType().GetGenericTypeDefinition() == typeof(IAsyncReply<>))
|
||||
else if (rt is AsyncReply)
|
||||
{
|
||||
(rt as AsyncReply).Then(res =>
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Esiur.Resource;
|
||||
|
||||
@ -8,10 +9,29 @@ namespace Esiur.Resource;
|
||||
|
||||
public class ExportAttribute : Attribute
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Name { get; private set; } = null;
|
||||
public Type ReturnType { get; private set; } = null;
|
||||
|
||||
public ExportAttribute(string name = null)
|
||||
public ExportAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ExportAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public ExportAttribute(Type returnType)
|
||||
{
|
||||
ReturnType = returnType;
|
||||
}
|
||||
|
||||
public ExportAttribute(string name, Type returnType)
|
||||
{
|
||||
Name = name;
|
||||
ReturnType = returnType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -82,9 +82,25 @@ public class FunctionTemplate : MemberTemplate
|
||||
|
||||
var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null;
|
||||
|
||||
var rtType = genericRtType == typeof(AsyncReply<>) ?
|
||||
RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]) :
|
||||
RepresentationType.FromType(mi.ReturnType);
|
||||
RepresentationType rtType;
|
||||
|
||||
if (genericRtType == typeof(AsyncReply<>))
|
||||
{
|
||||
rtType = RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]);
|
||||
}
|
||||
else if (genericRtType == typeof(IEnumerable<>) || genericRtType == typeof(IAsyncEnumerable<>))
|
||||
{
|
||||
// get export
|
||||
rtType = RepresentationType.FromType(mi.GetCustomAttribute<ExportAttribute>()?.ReturnType ?? typeof(object));
|
||||
}
|
||||
else
|
||||
{
|
||||
rtType = RepresentationType.FromType(mi.ReturnType);
|
||||
}
|
||||
|
||||
//var rtType = genericRtType == typeof(AsyncReply<>) ?
|
||||
// RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]) :
|
||||
// RepresentationType.FromType(mi.ReturnType);
|
||||
|
||||
if (rtType == null)
|
||||
throw new Exception($"Unsupported type `{mi.ReturnType}` in method `{type.Name}.{mi.Name}` return");
|
||||
|
@ -16,10 +16,14 @@ public class MemberData
|
||||
public MemberData? Parent;
|
||||
public MemberData? Child;
|
||||
public byte Index;
|
||||
//public ExportAttribute ExportAttribute;
|
||||
|
||||
public MemberData(string name, MemberInfo info, int order)
|
||||
|
||||
//public string Name => ExportAttribute?.Name ?? Info.Name;
|
||||
|
||||
public MemberData(MemberInfo info, int order)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Name = info.GetCustomAttribute<ExportAttribute>()?.Name ?? info.Name;
|
||||
this.Info = info;
|
||||
this.Order = order;
|
||||
}
|
||||
|
@ -611,7 +611,6 @@ public class TypeTemplate
|
||||
)
|
||||
))
|
||||
.Select(x => new MemberData(
|
||||
name: x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
|
||||
info: x,
|
||||
order: order
|
||||
))
|
||||
@ -631,7 +630,6 @@ public class TypeTemplate
|
||||
.Where(x => x.GetCustomAttribute<ExportAttribute>() != null)
|
||||
.Where(x => !(x is MethodInfo m && m.IsSpecialName))
|
||||
.Select(x => new MemberData (
|
||||
name : x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
|
||||
info : x,
|
||||
order : order
|
||||
))
|
||||
|
Loading…
x
Reference in New Issue
Block a user