-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interceptors.cs
67 lines (59 loc) · 2.64 KB
/
Interceptors.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Reflection;
using WampSharp.V2;
using WampSharp.V2.Core.Contracts;
namespace net.vieapps.Services
{
/// <summary>
/// Presents an interceptor for registering a service
/// </summary>
public class RegistrationInterceptor : CalleeRegistrationInterceptor
{
readonly string _name;
/// <summary>
/// Initializes an interceptor for registering a service
/// </summary>
/// <param name="name">The string that presents name of the service (for registering with right URI)</param>
/// <param name="options">The options for registering (default is round robin)</param>
public RegistrationInterceptor(string name = null, RegisterOptions options = null)
: base(options ?? new RegisterOptions { Invoke = WampInvokePolicy.Roundrobin })
=> this._name = name;
public override string GetProcedureUri(MethodInfo method)
=> string.IsNullOrWhiteSpace(this._name)
? base.GetProcedureUri(method)
: string.Format(base.GetProcedureUri(method), this._name.Trim().ToLower());
/// <summary>
/// Creates an interceptor for registering a service
/// </summary>
/// <param name="name">The string that presents name of service (for marking URI)</param>
/// <returns></returns>
public static RegistrationInterceptor Create(string name = null, string invokePolicy = WampInvokePolicy.Roundrobin)
=> new RegistrationInterceptor(name, new RegisterOptions { Invoke = invokePolicy });
}
// --------------------------------------------------------------------------------------------
/// <summary>
/// Presents an interceptor for calling a service
/// </summary>
public class ProxyInterceptor : CalleeProxyInterceptor
{
readonly string _name;
/// <summary>
/// Initializes an interceptor for calling a service
/// </summary>
/// <param name="name">The string that presents name of the service (for registering with right URI)</param>
/// <param name="options">The options for calling</param>
public ProxyInterceptor(string name = null, CallOptions options = null)
: base(options ?? new CallOptions { DiscloseMe = false, ReceiveProgress = false })
=> this._name = name;
public override string GetProcedureUri(MethodInfo method)
=> string.IsNullOrWhiteSpace(this._name)
? base.GetProcedureUri(method)
: string.Format(base.GetProcedureUri(method), this._name.Trim().ToLower());
/// <summary>
/// Creates an interceptor for calling a service
/// </summary>
/// <param name="name">The string that presents name of service (for marking URI)</param>
/// <returns></returns>
public static CachedCalleeProxyInterceptor Create(string name = null)
=> new CachedCalleeProxyInterceptor(new ProxyInterceptor(name));
}
}