forked from Astn/JSON-RPC.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
106 lines (98 loc) · 5.16 KB
/
Config.cs
File metadata and controls
106 lines (98 loc) · 5.16 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AustinHarris.JsonRpc
{
/// <summary>
/// The PreProcessHandler is called after the request has been parsed and prior to calling the associated method on the JsonRpcService.
/// If any non-null result is returned from the PreProcessHandler, the operation is aborted and the error is returned to the caller.
/// </summary>
/// <param name="request">The jsonRpc Request that is pending processing.</param>
/// <param name="context">The context associated with this request</param>
/// <returns>Any non-null result causes the operation to be aborted, and the JsonRpcException is returned to the caller.</returns>
public delegate JsonRpcException PreProcessHandler(JsonRequest request, object context);
/// <summary>
/// The PostProcessHandler is called after the response has been created and prior to returning the data to the caller.
/// If any non-null result is returned from the PostProcessHandler, the current return value is discared and the new return value used
/// in preference.
/// </summary>
/// <param name="request">The jsonRpc Request that has been processed.</param>
/// <param name="response">The jsonRpc Response that has been created.</param>
/// <param name="context">The context associated with this request/response pair</param>
/// <returns>Any non-null result causes the result to be discarded and the JsonRpcException is returned to the caller.</returns>
public delegate JsonRpcException PostProcessHandler(JsonRequest request, JsonResponse response, object context);
/// <summary>
/// Global configurations for JsonRpc
/// </summary>
public static class Config
{
/// <summary>
/// Sets the the PreProcessing Handler on the default session.
/// </summary>
/// <param name="handler"></param>
public static void SetPreProcessHandler(PreProcessHandler handler)
{
Handler.DefaultHandler.SetPreProcessHandler(handler);
}
/// <summary>
/// Sets the the PostProcessing Handler on the default session.
/// </summary>
/// <param name="handler"></param>
public static void SetPostProcessHandler(PostProcessHandler handler)
{
Handler.DefaultHandler.SetPostProcessHandler(handler);
}
/// <summary>
/// Sets the PreProcessing Handler on a specific session
/// </summary>
/// <param name="sessionId"></param>
/// <param name="handler"></param>
public static void SetBeforeProcessHandler(string sessionId, PreProcessHandler handler)
{
Handler.GetSessionHandler(sessionId).SetPreProcessHandler(handler);
}
/// <summary>
/// For exceptions thrown after the routed method has been called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
/// </summary>
/// <param name="handler"></param>
public static void SetErrorHandler(Func<JsonRequest, JsonRpcException, JsonRpcException> handler)
{
Handler.DefaultHandler.SetErrorHandler(handler);
}
/// <summary>
/// For exceptions thrown after the routed method has been called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
/// </summary>
/// <param name="sessionId"></param>
/// <param name="handler"></param>
public static void SetErrorHandler(string sessionId, Func<JsonRequest, JsonRpcException, JsonRpcException> handler)
{
Handler.GetSessionHandler(sessionId).SetErrorHandler(handler);
}
/// <summary>
/// For exceptions thrown during parsing and prior to a routed method being called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
/// </summary>
/// <param name="handler"></param>
public static void SetParseErrorHandler(Func<string,JsonRpcException,JsonRpcException> handler)
{
Handler.DefaultHandler.SetParseErrorHandler(handler);
}
/// <summary>
/// For exceptions thrown during parsing and prior to a routed method being called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
/// </summary>
/// <param name="sessionId"></param>
/// <param name="handler"></param>
public static void SetParseErrorHandler(string sessionId, Func<string, JsonRpcException, JsonRpcException> handler)
{
Handler.GetSessionHandler(sessionId).SetParseErrorHandler(handler);
}
}
}