Skip to content

Commit ff90909

Browse files
author
Elad Zelingher
committed
A first draft for rpc settings
1 parent bbb2422 commit ff90909

10 files changed

+60
-22
lines changed

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/AsyncLocalRpcOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace WampSharp.V2.Rpc
1010
{
1111
public abstract class AsyncLocalRpcOperation: LocalRpcOperation
1212
{
13-
protected AsyncLocalRpcOperation(string procedure) : base(procedure)
13+
protected AsyncLocalRpcOperation(string procedure, ICalleeSettings settings = null) :
14+
base(procedure, settings)
1415
{
1516
}
1617

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/LocalRpcOperation.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ public abstract class LocalRpcOperation : IWampRpcOperation
1919
protected readonly static IWampFormatter<object> ObjectFormatter =
2020
WampObjectFormatter.Value;
2121

22-
protected LocalRpcOperation(string procedure)
22+
private readonly ICalleeSettings mSettings;
23+
24+
protected LocalRpcOperation(string procedure, ICalleeSettings settings = null)
2325
{
2426
mProcedure = procedure;
27+
mSettings = settings ?? new CalleeSettings();
2528
mLogger = LogProvider.GetLogger(typeof (LocalRpcOperation) + "." + procedure);
2629
}
2730

@@ -121,6 +124,11 @@ protected void ValidateInstanceType(object instance, MethodInfo method)
121124
}
122125
}
123126

127+
protected WampRpcRuntimeException ConvertExceptionToRuntimeException(Exception exception)
128+
{
129+
return mSettings.ConvertExceptionToRuntimeException(exception);
130+
}
131+
124132
protected class WampRpcErrorCallback : IWampErrorCallback
125133
{
126134
private readonly IWampRawRpcOperationRouterCallback mCallback;
@@ -145,11 +153,5 @@ public void Error(object details, string error, object[] arguments, object argum
145153
mCallback.Error(ObjectFormatter, details, error, arguments, argumentsKeywords);
146154
}
147155
}
148-
149-
protected static WampRpcRuntimeException ConvertExceptionToRuntimeException(Exception exception)
150-
{
151-
// TODO: Maybe try a different implementation.
152-
return new WampRpcRuntimeException(exception.Message);
153-
}
154156
}
155157
}

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/Reflection/AsyncMethodInfoRpcOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class AsyncMethodInfoRpcOperation : AsyncLocalRpcOperation
2121
private readonly CollectionResultTreatment mCollectionResultTreatment;
2222
private IWampResultExtractor mResultExtractor;
2323

24-
public AsyncMethodInfoRpcOperation(Func<object> instanceProvider, MethodInfo method, string procedureName) :
25-
base(procedureName)
24+
public AsyncMethodInfoRpcOperation(Func<object> instanceProvider, MethodInfo method, string procedureName, ICalleeSettings settings = null) :
25+
base(procedureName, settings)
2626
{
2727
mInstanceProvider = instanceProvider;
2828
mMethod = method;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace WampSharp.V2.Rpc
4+
{
5+
public interface ICalleeSettings
6+
{
7+
WampRpcRuntimeException ConvertExceptionToRuntimeException(Exception exception);
8+
}
9+
10+
public class CalleeSettings : ICalleeSettings
11+
{
12+
public bool IncludeExceptionStackTrace { get; set; }
13+
14+
public WampRpcRuntimeException ConvertExceptionToRuntimeException(Exception exception)
15+
{
16+
WampRpcRuntimeException result = new WampRpcRuntimeException(exception.Message);
17+
18+
if (IncludeExceptionStackTrace)
19+
{
20+
result.ArgumentsKeywords["stackTrace"] = exception.StackTrace;
21+
}
22+
23+
return result;
24+
}
25+
}
26+
}

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/Reflection/ICalleeRegistrationInterceptor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Reflection;
22
using WampSharp.V2.Core.Contracts;
3+
using WampSharp.V2.Rpc;
34

45
// ReSharper disable once CheckNamespace
56
namespace WampSharp.V2
@@ -23,5 +24,10 @@ public interface ICalleeRegistrationInterceptor
2324
/// Gets the procedure uri that will be used to register the given method.
2425
/// </summary>
2526
string GetProcedureUri(MethodInfo method);
27+
28+
/// <summary>
29+
/// Gets the settings to be used for the given method.
30+
/// </summary>
31+
ICalleeSettings GetSettings(MethodInfo method);
2632
}
2733
}

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/Reflection/OperationExtractor.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Reflection;
44
using System.Threading.Tasks;
5-
using WampSharp.Core.Utilities;
65
using WampSharp.V2.Core.Contracts;
76
using TaskExtensions = WampSharp.Core.Utilities.TaskExtensions;
87

@@ -58,27 +57,29 @@ protected IWampRpcOperation CreateRpcMethod(Func<object> instanceProvider, ICall
5857
string procedureUri =
5958
interceptor.GetProcedureUri(method);
6059

60+
ICalleeSettings settings = interceptor.GetSettings(method);
61+
6162
if (!typeof (Task).IsAssignableFrom(method.ReturnType))
6263
{
6364
MethodInfoValidation.ValidateTupleReturnType(method);
64-
return new SyncMethodInfoRpcOperation(instanceProvider, method, procedureUri);
65+
return new SyncMethodInfoRpcOperation(instanceProvider, method, procedureUri, settings);
6566
}
6667
else
6768
{
6869
if (method.IsDefined(typeof (WampProgressiveResultProcedureAttribute)))
6970
{
7071
MethodInfoValidation.ValidateProgressiveMethod(method);
71-
return CreateProgressiveOperation(instanceProvider, method, procedureUri);
72+
return CreateProgressiveOperation(instanceProvider, method, procedureUri, settings);
7273
}
7374
else
7475
{
7576
MethodInfoValidation.ValidateAsyncMethod(method);
76-
return new AsyncMethodInfoRpcOperation(instanceProvider, method, procedureUri);
77+
return new AsyncMethodInfoRpcOperation(instanceProvider, method, procedureUri, settings);
7778
}
7879
}
7980
}
8081

81-
private static IWampRpcOperation CreateProgressiveOperation(Func<object> instanceProvider, MethodInfo method, string procedureUri)
82+
private static IWampRpcOperation CreateProgressiveOperation(Func<object> instanceProvider, MethodInfo method, string procedureUri, ICalleeSettings settings)
8283
{
8384
//return new ProgressiveAsyncMethodInfoRpcOperation<returnType>
8485
// (instance, method, procedureUri);
@@ -94,7 +95,8 @@ private static IWampRpcOperation CreateProgressiveOperation(Func<object> instanc
9495
(IWampRpcOperation) Activator.CreateInstance(operationType,
9596
instanceProvider,
9697
method,
97-
procedureUri);
98+
procedureUri,
99+
settings);
98100

99101
return operation;
100102
}

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/Reflection/ProgressiveAsyncMethodInfoRpcOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class ProgressiveAsyncMethodInfoRpcOperation<T> : AsyncMethodInfoRpcOpera
1111
{
1212
private readonly RpcParameter[] mRpcParameters;
1313

14-
public ProgressiveAsyncMethodInfoRpcOperation(Func<object> instanceProvider, MethodInfo method, string procedureName) :
15-
base(instanceProvider, method, procedureName)
14+
public ProgressiveAsyncMethodInfoRpcOperation(Func<object> instanceProvider, MethodInfo method, string procedureName, ICalleeSettings settings = null) :
15+
base(instanceProvider, method, procedureName, settings)
1616
{
1717
RpcParameter[] baseParameters = base.Parameters;
1818

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/Reflection/SyncMethodInfoRpcOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class SyncMethodInfoRpcOperation : SyncLocalRpcOperation
2020
private readonly CollectionResultTreatment mCollectionResultTreatment;
2121
private IWampResultExtractor mResultExtractor;
2222

23-
public SyncMethodInfoRpcOperation(Func<object> instanceProvider, MethodInfo method, string procedureName) :
24-
base(procedureName)
23+
public SyncMethodInfoRpcOperation(Func<object> instanceProvider, MethodInfo method, string procedureName, ICalleeSettings settings = null) :
24+
base(procedureName, settings)
2525
{
2626
mInstanceProvider = instanceProvider;
2727
mMethod = method;

src/net45/WampSharp/WAMP2/V2/Rpc/Callee/SyncLocalRpcOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace WampSharp.V2.Rpc
99
{
1010
public abstract class SyncLocalRpcOperation: LocalRpcOperation
1111
{
12-
protected SyncLocalRpcOperation(string procedure)
13-
: base(procedure)
12+
protected SyncLocalRpcOperation(string procedure, ICalleeSettings settings = null)
13+
: base(procedure, settings)
1414
{
1515
}
1616

src/net45/WampSharp/WampSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
<Compile Include="WAMP2\V2\Rpc\Callee\Reflection\CalleeRegistrationInterceptor.cs" />
332332
<Compile Include="WAMP2\V2\Api\CalleeProxy\ProgressiveAsyncCalleeProxyInterceptor.cs" />
333333
<Compile Include="WAMP2\V2\Api\CalleeProxy\ICalleeProxyInterceptor.cs" />
334+
<Compile Include="WAMP2\V2\Rpc\Callee\Reflection\CalleeSettings.cs" />
334335
<Compile Include="WAMP2\V2\Rpc\Callee\Reflection\ICalleeRegistrationInterceptor.cs" />
335336
<Compile Include="WAMP2\V2\Rpc\Callee\Reflection\MethodInfoValidation.cs" />
336337
<Compile Include="Core\Utilities\MethodInvokeGenerator.cs" />

0 commit comments

Comments
 (0)