main
1using System.Collections.Generic;
2using System.Runtime.Remoting.Messaging;
3using System.Runtime.Remoting.Proxies;
4using gorilla.commons.utility;
5
6namespace Gorilla.Commons.Infrastructure.Proxies
7{
8 public class RemotingProxyFactory<T> : RealProxy
9 {
10 readonly T target;
11 readonly IEnumerable<Interceptor> interceptors;
12
13 public RemotingProxyFactory(T target, IEnumerable<Interceptor> interceptors) : base(typeof (T))
14 {
15 this.target = target;
16 this.interceptors = interceptors;
17 }
18
19 public override IMessage Invoke(IMessage message)
20 {
21 if (message.is_an_implementation_of<IMethodCallMessage>())
22 {
23 var call = message.downcast_to<IMethodCallMessage>();
24 var invocation = new MethodCallInvocation<T>(interceptors, call, target);
25 invocation.proceed();
26 return return_value(invocation.return_value, invocation.arguments, call);
27 }
28 return null;
29 }
30
31 IMessage return_value(object return_value, object[] out_parameters, IMethodCallMessage call)
32 {
33 return new ReturnMessage(return_value,
34 out_parameters,
35 out_parameters == null ? 0 : out_parameters.Length,
36 call.LogicalCallContext, call);
37 }
38
39 public T create_proxy()
40 {
41 return GetTransparentProxy().downcast_to<T>();
42 }
43 }
44}