4using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
21 private X509Certificate? certificate;
22 private readonly Uri endpoint;
31 : this(new Uri(Endpoint), null,
Sniffers)
43 this.endpoint = Endpoint;
53 : this(new Uri(Endpoint), Certificate,
Sniffers)
66 this.endpoint = Endpoint;
67 this.certificate = Certificate;
76 this.certificate = Certificate;
85 public Task<object?>
Request(
string Method, Dictionary<string, object> Parameters)
96 public Task<object?>
Request(
string Method)
107 public Task<object?>
Request(
string Method, IEnumerable Parameters)
121 Dictionary<string, object> Parameters)
145 IEnumerable Parameters)
159 string Method, Dictionary<string, object> Parameters)
186 string Method, IEnumerable Parameters)
209 Dictionary<string, object> Payload =
Request.BuildRequest(this.
id++);
210 ContentResponse Response = await this.SendNotification(HttpMethod, Payload);
213 if (!(Response.
Decoded is Dictionary<string, object> JsonResponse))
216 Response.
Decoded?.GetType().FullName);
222 throw new JsonRpcException(
"Unexpected response received: Result property missing.");
224 if (!Result.
Id.HasValue)
225 throw new JsonRpcException(
"Unexpected response received: Id property missing.");
227 if (Payload.TryGetValue(
"id", out
object PrevIdObj) &&
228 PrevIdObj is
long PrevId &&
229 PrevId != Result.
Id.Value)
242 public Task
Notify(
string Method, Dictionary<string, object> Parameters)
262 public Task
Notify(
string Method, IEnumerable Parameters)
275 Dictionary<string, object> Parameters)
297 IEnumerable Parameters)
310 string Method, Dictionary<string, object> Parameters)
360 private async Task<ContentResponse> SendNotification(
JsonRpcHttpMethod HttpMethod,
361 Dictionary<string, object> Payload)
370 StringBuilder sb =
new StringBuilder();
373 sb.Append(this.endpoint.OriginalString);
375 foreach (KeyValuePair<string, object> P
in Payload)
388 if (P.Value is
string s)
389 sb.Append(
System.
Net.WebUtility.UrlEncode(s));
395 new Uri(sb.ToString()),
this.certificate,
401 this.endpoint, Payload, this.certificate,
417 Response = this.CheckJsonRpcError(Response);
430 ex.
Content is Dictionary<string, object> Result &&
431 Result.TryGetValue(
"error", out
object ErrorObj) &&
432 ErrorObj is Dictionary<string, object>
Error &&
433 Error.TryGetValue(
"code", out
object Obj) && Obj is
int ErrorCode &&
434 Error.TryGetValue(
"message", out Obj) && Obj is
string ErrorMessage)
442 internal static JsonRpcError GetError(
int ErrorCode,
string ErrorMessage)
462 if (ErrorCode <= -32000 && ErrorCode >= -32099)
477 int i, c = Requests.Length;
478 Dictionary<string, object>[] Payloads =
new Dictionary<string, object>[c];
480 for (i = 0; i < c; i++)
483 Payloads[i] =
Request.BuildRequest(
Request.IsRequest ?
this.id++ : (
long?)
null);
490 this.endpoint, Payloads, this.certificate,
506 Response = this.CheckJsonRpcError(Response);
509 if (!(Response.
Decoded is Array A))
512 Response.
Decoded?.GetType().FullName);
518 for (i = 0; i < c; i++)
520 if (!(A.GetValue(i) is Dictionary<string, object> ItemResponse))
523 A.GetValue(i)?.GetType().FullName);
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
void AssertOk()
Asserts response is OK.
Exception class for web exceptions.
object Content
Decoded content.
Static class managing encoding and decoding of internet content.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > GetAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
const string JsonRpcContentType
application/json-rpc
Simple base class for classes implementing communication protocols.
void TransmitText(string Text)
Called when text has been transmitted.
void ReceiveText(string Text)
Called when text has been received.
ISniffer[] Sniffers
Registered sniffers.
bool HasSniffers
If there are sniffers registered on the object.
void Error(string Error)
Called to inform the viewer of an error state.
Base class for JSON-RPC error responses.
Base class for JSON-RPC exceptions.
JSON-RPC Internal error response.
JSON-RPC Invalid Parameters error response.
JSON-RPC Invalid Request error response.
JSON-RPC Method Not Found error response.
JSON-RPC Parse error response.
JSON-RPC Server error response.
async Task< JsonRpcResult[]> BatchProcess(params JsonRpcRequest[] Requests)
Processes a batch of requests.
Task Notify(JsonRpcHttpMethod HttpMethod, string Method, Dictionary< string, object > Parameters)
Sends a JSON-RPC notification.
Task Notify(JsonRpcHttpMethod HttpMethod, JsonRpcVersion Version, string Method)
Sends a JSON-RPC notification.
Task< object?> Request(JsonRpcHttpMethod HttpMethod, string Method)
Performs a JSON-RPC request.
Task< object?> Request(string Method)
Performs a JSON-RPC request.
Task Notify(JsonRpcHttpMethod HttpMethod, string Method, IEnumerable Parameters)
Sends a JSON-RPC notification.
Task Notify(JsonRpcHttpMethod HttpMethod, JsonRpcVersion Version, string Method, Dictionary< string, object > Parameters)
Sends a JSON-RPC notification.
Task< object?> Request(JsonRpcRequest Request)
Performs a JSON-RPC request.
JsonRpcClient(Uri Endpoint, params ISniffer[] Sniffers)
A JSON-RPC client
Task< object?> Request(JsonRpcHttpMethod HttpMethod, string Method, IEnumerable Parameters)
Performs a JSON-RPC request.
Task Notify(string Method, Dictionary< string, object > Parameters)
Sends a JSON-RPC notification.
Task< object?> Request(string Method, IEnumerable Parameters)
Performs a JSON-RPC request.
async Task Notify(JsonRpcHttpMethod HttpMethod, JsonRpcRequest Request)
Sends a JSON-RPC notification.
JsonRpcClient(string Endpoint, params ISniffer[] Sniffers)
A JSON-RPC client
Task< object?> Request(JsonRpcHttpMethod HttpMethod, JsonRpcVersion Version, string Method)
Performs a JSON-RPC request.
Task Notify(JsonRpcHttpMethod HttpMethod, JsonRpcVersion Version, string Method, IEnumerable Parameters)
Sends a JSON-RPC notification.
Task Notify(JsonRpcRequest Request)
Sends a JSON-RPC notification.
JsonRpcClient(Uri Endpoint, X509Certificate? Certificate, params ISniffer[] Sniffers)
A JSON-RPC client
async Task< object?> Request(JsonRpcHttpMethod HttpMethod, JsonRpcRequest Request)
Performs a JSON-RPC request.
Task< object?> Request(JsonRpcHttpMethod HttpMethod, string Method, Dictionary< string, object > Parameters)
Performs a JSON-RPC request.
Task Notify(string Method)
Sends a JSON-RPC notification.
Task< object?> Request(string Method, Dictionary< string, object > Parameters)
Performs a JSON-RPC request.
void UpdateCertificate(X509Certificate Certificate)
Updates the certificate used in mTLS negotiation.
Task< object?> Request(JsonRpcHttpMethod HttpMethod, JsonRpcVersion Version, string Method, IEnumerable Parameters)
Performs a JSON-RPC request.
Task< object?> Request(JsonRpcHttpMethod HttpMethod, JsonRpcVersion Version, string Method, Dictionary< string, object > Parameters)
Performs a JSON-RPC request.
Task Notify(JsonRpcHttpMethod HttpMethod, string Method)
Sends a JSON-RPC notification.
JsonRpcClient(string Endpoint, X509Certificate? Certificate, params ISniffer[] Sniffers)
A JSON-RPC client
Task Notify(string Method, IEnumerable Parameters)
Sends a JSON-RPC notification.
Information about a JSON-RPC request.
Information about a JSON-RPC result.
object? Result
Result of operation, if HasResult is true.
long? Id
ID matching the request, if any.
bool HasResult
If response has a result in Result, this property is true.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Interface for Mutual TLS (mTLS) Clients or TLS servers.
JsonRpcHttpMethod
HTTP method to use when making a JSON-RPC call.
JsonRpcVersion
JSON-RPC version