From: gu.martinm@gmail.com Date: Fri, 7 Mar 2014 23:26:18 +0000 (+0100) Subject: No time for comments. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=dd0dea6538912288d499fc9c06f3f2b0ad7db415;p=CSharpForFun%2F.git No time for comments. --- diff --git a/Mono/RemoteAgents/GTKLinux/ViewModel/ViewModel.cs b/Mono/RemoteAgents/GTKLinux/ViewModel/ViewModel.cs index 8178d35..497c086 100644 --- a/Mono/RemoteAgents/GTKLinux/ViewModel/ViewModel.cs +++ b/Mono/RemoteAgents/GTKLinux/ViewModel/ViewModel.cs @@ -18,7 +18,7 @@ namespace Example.RemoteAgents.GTKLinux.ViewModel async public Task SetWriteTextAsync(params object[] parameters) { - await _remoteClient.PostWithParametersRemoteServiceAsync(uriSetWriteText, "setWriteText", parameters); + await _remoteClient.PostRemoteServiceAsync(uriSetWriteText, "setWriteText", parameters); } } } diff --git a/jsonrpc4net/jsonrpc4net/JsonRpcHttpAsyncClient.cs b/jsonrpc4net/jsonrpc4net/JsonRpcHttpAsyncClient.cs index 856115d..9802343 100644 --- a/jsonrpc4net/jsonrpc4net/JsonRpcHttpAsyncClient.cs +++ b/jsonrpc4net/jsonrpc4net/JsonRpcHttpAsyncClient.cs @@ -42,40 +42,12 @@ namespace GumartinM.JsonRPC4NET /// private readonly ExceptionResolver _exceptionResolver = new ExceptionResolver(); - - /// - /// Posts the remote service async. + /// The JSON RPC version. /// - /// The remote service async. - /// URI. - /// Method. - /// The 1st type parameter. - async public Task PostRemoteServiceAsync(string uri, string method) - { - var postData = new POST(); - postData.id = Interlocked.Increment(ref _nextId).ToString(); - postData.jsonrpc = "2.0"; - postData.method = method; + private readonly string _JSON_RPC_VERSION = "2.0"; - string jsonData = JsonConvert.SerializeObject(postData, _jsonSettings); - - POSTResult postResult = await this.PostAsync(uri, method, jsonData, CancellationToken.None); - return postResult.result; - } - - /// - /// Posts the remote service async. - /// - /// The remote service async. - /// URI. - /// Method. - /// The 1st type parameter. - async public Task PostRemoteServiceAsync(string uri, string method) - { - await this.PostRemoteServiceAsync(uri, method); - } /// /// Posts the with parameters remote service async. @@ -83,18 +55,29 @@ namespace GumartinM.JsonRPC4NET /// The with parameters remote service async. /// URI. /// Method. - /// Parameters. + /// Arguments. /// The 1st type parameter. - async public Task PostWithParametersRemoteServiceAsync(string uri, string method, params object[] parameters) + async public Task PostRemoteServiceAsync(string uri, string method, params object[] arguments) { - var inputParameters = new List(parameters); - var postData = new POSTParameters(); - postData.id = Interlocked.Increment(ref _nextId).ToString(); - postData.jsonrpc = "2.0"; - postData.method = method; - postData.@params = inputParameters; + string jsonData; - string jsonData = JsonConvert.SerializeObject(postData, _jsonSettings); + if (arguments != null) + { + var inputParameters = new List(arguments); + var postData = new POSTWithParameters(); + postData.id = Interlocked.Increment(ref _nextId).ToString(); + postData.jsonrpc = _JSON_RPC_VERSION; + postData.method = method; + postData.@params = inputParameters; + jsonData = JsonConvert.SerializeObject(postData, _jsonSettings); + } else + { + var postData = new POST(); + postData.id = Interlocked.Increment(ref _nextId).ToString(); + postData.jsonrpc = _JSON_RPC_VERSION; + postData.method = method; + jsonData = JsonConvert.SerializeObject(postData, _jsonSettings); + } POSTResult postResult = await this.PostAsync(uri, method, jsonData, CancellationToken.None); @@ -108,9 +91,9 @@ namespace GumartinM.JsonRPC4NET /// URI. /// Method. /// Parameters. - async public Task PostWithParametersRemoteServiceAsync(string uri, string method, params object[] parameters) + async public Task PostRemoteServiceAsync(string uri, string method, params object[] parameters) { - await this.PostWithParametersRemoteServiceAsync(uri, method, parameters); + await this.PostRemoteServiceAsync(uri, method, parameters); } /// @@ -219,20 +202,19 @@ namespace GumartinM.JsonRPC4NET public string method { get; set; } } - - private class POSTResult + private class POSTWithParameters { public string id { get; set; } public string jsonrpc { get; set; } - public TResult result { get; set; } + public string method { get; set; } + public List @params { get; set; } } - private class POSTParameters + private class POSTResult { public string id { get; set; } public string jsonrpc { get; set; } - public string method { get; set; } - public List @params { get; set; } + public TResult result { get; set; } } } }