</Reference>
<Reference Include="Mono.Posix" />
<Reference Include="jsonrpc4net">
- <HintPath>..\..\jsonrpc4net\jsonrpc4net\bin\Debug\jsonrpc4net.dll</HintPath>
- </Reference>
- <Reference Include="log4net">
- <HintPath>..\..\..\..\..\..\..\usr\mymono\custom\log4net-1.2.13\cli\1.0\log4net.dll</HintPath>
+ <HintPath>..\..\..\jsonrpc4net\jsonrpc4net\bin\Debug\jsonrpc4net.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http">
- <HintPath>..\..\..\..\..\..\..\usr\mymono\lib\mono\4.5\System.Net.Http.dll</HintPath>
+ <HintPath>..\..\..\..\..\..\..\..\usr\mymono\lib\mono\4.5\System.Net.Http.dll</HintPath>
+ </Reference>
+ <Reference Include="NLog">
+ <HintPath>..\..\..\ThirdParty\Libs\NLog\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=c7439020c8fedf87">
<Package>monodevelop</Package>
<Folder Include="ViewModel\" />
<Folder Include="View\" />
</ItemGroup>
- <ItemGroup>
- <None Include="Log4Net.config">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<log4net debug="true">
- <!-- EasyConsoleAppender is set to be a ConsoleAppender -->
- <appender name="EasyConsoleAppender" type="log4net.Appender.ConsoleAppender">
- <layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="%-4timestamp [%thread] %-5level %logger %type %ndc - %message%newline" />
- </layout>
- </appender>
-
- <root>
- <level value="INFO" />
- <appender-ref ref="EasyConsoleAppender" />
- </root>
-</log4net>
using Gtk;
using System.Threading.Tasks;
using Example.RemoteAgents.GTKLinux.View;
-using log4net;
+using NLog;
namespace Example.RemoteAgents.GTKLinux
{
public partial class MainWindow: Gtk.Window
{
private readonly ViewImpl _view;
- private static readonly ILog logger = LogManager.GetLogger(
- System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
async private void ButtonGetDateClicked(object sender, EventArgs a)
{
try {
- string currentDate = await _view.GetCurrentDateAsync();
- if (currentDate != null)
- {
- this.RemoteDate.Buffer.Text = currentDate;
- }
+ this.RemoteDate.Buffer.Text = await _view.GetCurrentDateAsync();
}
catch (Exception e)
{
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
-//[assembly: AssemblyKeyFile("")]
-[assembly: log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config", Watch=true)]
+//[assembly: AssemblyKeyFile("")]
\ No newline at end of file
using System;
using System.Threading.Tasks;
-using GumartinM.JsonRPC4Mono;
+using GumartinM.JsonRPC4NET;
using System.ComponentModel;
namespace Example.RemoteAgents.GTKLinux.ViewModel
+++ /dev/null
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jsonrpc4net", "jsonrpc4net\jsonrpc4net.csproj", "{0C624E8F-9C80-457F-A7D1-39FA29E23F79}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = jsonrpc4net\jsonrpc4net.csproj
- description = jsonrpc4net library implementation (just for fun)
- EndGlobalSection
-EndGlobal
+++ /dev/null
-using System;
-using Newtonsoft.Json.Linq;
-using System.Collections.Generic;
-
-namespace GumartinM.JsonRPC4Mono
-{
- public class ExceptionResolver
- {
- /// <summary>
- /// Resolves the exception.
- /// </summary>
- /// <returns>The exception.</returns>
- /// <param name="errorToken">Error token.</param>
- public Exception ResolveException(JToken errorToken)
- {
- JObject errorData = (JObject) errorToken;
- IDictionary<string, JToken> errorTokens = errorData;
-
- if (!errorTokens.ContainsKey("data"))
- {
- return CreateJsonRpcClientException(errorToken);
- }
-
- JToken dataToken = errorToken["data"];
- JObject data = (JObject) dataToken;
- errorTokens = data;
-
- if (!errorTokens.ContainsKey("exceptionTypeName"))
- {
- return CreateJsonRpcClientException(errorToken);
- }
-
- string exceptionTypeName = data["exceptionTypeName"].Value<string>();
- string message = data.Value<string>("message");
-
- Exception endException = CreateException(exceptionTypeName, message);
-
- return endException;
- }
-
- /// <summary>
- /// Creates the json rpc client exception.
- /// </summary>
- /// <returns>The json rpc client exception.</returns>
- /// <param name="errorToken">Error token.</param>
- private JsonRpcClientException CreateJsonRpcClientException(JToken errorToken)
- {
- return new JsonRpcClientException(
- errorToken.Value<int?>("code") ?? 0,
- errorToken.Value<string>("message"),
- errorToken.SelectToken("data"));
- }
-
- /// <summary>
- /// Creates the exception.
- /// </summary>
- /// <returns>The exception.</returns>
- /// <param name="exceptionTypeName">Exception type name.</param>
- /// <param name="message">Message.</param>
- private Exception CreateException(string exceptionTypeName, string message)
- {
- return new Exception("Remote exception: " + exceptionTypeName + "Message: " + message);
- }
- }
-}
-
+++ /dev/null
-using System;
-using System.Runtime.Serialization;
-using Newtonsoft.Json.Linq;
-
-namespace GumartinM.JsonRPC4Mono
-{
- public class JsonRpcClientException : System.Exception, ISerializable
- {
- /// <summary>
- /// The _code.
- /// </summary>
- private readonly int _code;
-
- /// <summary>
- /// The _data.
- /// </summary>
- private readonly JToken _data;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Example.RemoteAgents.GTKLinux.Model.JsonRpcClientException"/> class.
- /// </summary>
- /// <param name="code">Code.</param>
- /// <param name="message">Message.</param>
- /// <param name="data">Data.</param>
- public JsonRpcClientException(int code, String message, JToken data) : base(message)
- {
- _code = code;
- _data = data;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Example.RemoteAgents.GTKLinux.Model.JsonRpcClientException"/> class.
- /// </summary>
- /// <param name="info">Info.</param>
- /// <param name="context">Context.</param>
- protected JsonRpcClientException(SerializationInfo info, StreamingContext context)
- {
- // TODO
- }
-
- /// <summary>
- /// Gets the code.
- /// </summary>
- /// <returns>The code.</returns>
- public int getCode() {
- return _code;
- }
-
- /// <summary>
- /// Gets the data.
- /// </summary>
- /// <returns>The data.</returns>
- public JToken getData() {
- return _data;
- }
- }
-}
-
+++ /dev/null
-using System;
-using System.Net.Http;
-using System.Threading.Tasks;
-using System.Threading;
-using log4net;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Serialization;
-using System.Net;
-using Newtonsoft.Json.Linq;
-using System.Collections.Generic;
-
-namespace GumartinM.JsonRPC4Mono
-{
- public class JsonRpcHttpAsyncClient
- {
- private long _nextId;
-
- /// <summary>
- /// The logger.
- /// </summary>
- private static readonly ILog logger = LogManager.GetLogger(
- System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
-
- /// <summary>
- /// The _json settings.
- /// </summary>
- private readonly JsonSerializerSettings _jsonSettings =
- new JsonSerializerSettings{
- Error = delegate(object sender, ErrorEventArgs args)
- {
- logger.Error(args.ErrorContext.Error.Message);
- args.ErrorContext.Handled = true;
- }
- };
-
- /// <summary>
- /// The _exception resolver.
- /// </summary>
- private readonly ExceptionResolver _exceptionResolver = new ExceptionResolver();
-
-
-
- /// <summary>
- /// Posts the remote service async.
- /// </summary>
- /// <returns>The remote service async.</returns>
- /// <param name="uri">URI.</param>
- /// <param name="method">Method.</param>
- /// <typeparam name="TResult">The 1st type parameter.</typeparam>
- async public Task<TResult> PostRemoteServiceAsync<TResult>(string uri, string method)
- {
- POSTResult<TResult> postResult = await this.PostAsync<TResult>(uri, method, CancellationToken.None);
-
- return postResult.result;
- }
-
- /// <summary>
- /// Posts the async.
- /// </summary>
- /// <returns>The async.</returns>
- /// <param name="uri">URI.</param>
- /// <param name="method">Method.</param>
- /// <param name="cancellation">Cancellation.</param>
- /// <typeparam name="TResult">The 1st type parameter.</typeparam>
- async private Task<POSTResult<TResult>> PostAsync<TResult>(string uri, string method, CancellationToken cancellation)
- {
- var postData = new POST();
- postData.id = Interlocked.Increment(ref _nextId).ToString();
- postData.jsonrpc = "2.0";
- postData.method = method;
-
- string data = JsonConvert.SerializeObject(postData, _jsonSettings);
-
- // see: http://stackoverflow.com/questions/1329739/nested-using-statements-in-c-sharp
- // see: http://stackoverflow.com/questions/5895879/when-do-we-need-to-call-dispose-in-dot-net-c
- //TODO: Am I really sure I have to call the Dispose method of HttpContent content? In this case, shouldn't it be stupid?
- // For HttpResponseMessage response I am sure I have to do it but I am not for HttpContent content.
- using (HttpContent content = new StringContent(data, System.Text.Encoding.UTF8, "application/json-rpc"))
- using (HttpResponseMessage response = await this.PostAsync(uri, content, cancellation))
- {
-
- if (response.StatusCode == HttpStatusCode.OK) {
- byte[] jsonBytes = await response.Content.ReadAsByteArrayAsync();
-
- return this.ReadResponse<TResult>(jsonBytes);
- }
-
- throw new Exception("Unexpected response code: " + response.StatusCode);
- }
- }
-
- /// <summary>
- /// Reads the response.
- /// </summary>
- /// <returns>The response.</returns>
- /// <param name="jsonBytes">Json bytes.</param>
- /// <typeparam name="TResult">The 1st type parameter.</typeparam>
- private POSTResult<TResult> ReadResponse<TResult>(byte[] jsonBytes)
- {
- string json = System.Text.Encoding.UTF8.GetString(jsonBytes);
-
- JObject jsonObjects = JObject.Parse(json);
- IDictionary<string, JToken> jsonTokens = jsonObjects;
-
-
- if (jsonTokens.ContainsKey("error"))
- {
- throw _exceptionResolver.ResolveException(jsonObjects["error"]);
- }
-
- if (jsonTokens.ContainsKey("result"))
- {
- return JsonConvert.DeserializeObject<POSTResult<TResult>>(json, _jsonSettings);
- }
-
- throw new JsonRpcClientException(0, "There is not neither error nor result in JSON response data.", jsonObjects);
- }
-
- /// <summary>
- /// Send a POST request to the specified Uri as an asynchronous operation.
- /// </summary>
- /// <param name="uri">The Uri the request is sent to.</param>
- /// <param name="content">The HTTP request content sent to the server.</param>
- /// <param name="System.Threading.CancellationToken">Cancellation token.</param>
- /// <exception cref="System.InvalidOperationException">When some error.</exception>
- /// <returns>System.Threading.Tasks.Task<![CDATA[<TResult>]]>.The task object representing the asynchronous operation.</returns>
- async private Task<HttpResponseMessage> PostAsync(string uri, HttpContent content, CancellationToken cancellation)
- {
- using (HttpClient client = new HttpClient{ Timeout = TimeSpan.FromSeconds(5)})
- {
- // TODO: cancellation
- return await client.PostAsync(uri, content, cancellation);
- }
- }
-
- private class POST
- {
- public string id { get; set; }
- public string jsonrpc { get; set; }
- public string method { get; set; }
- }
-
-
- private class POSTResult<TResult>
- {
- public string id { get; set; }
- public string jsonrpc { get; set; }
- public TResult result { get; set; }
- }
- }
-}
-
+++ /dev/null
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-// Information about this assembly is defined by the following attributes.
-// Change them to the values specific to your project.
-[assembly: AssemblyTitle("jsonrpc4net")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("gustavo")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
-// The form "{Major}.{Minor}.*" will automatically update the build and revision,
-// and "{Major}.{Minor}.{Build}.*" will update just the revision.
-[assembly: AssemblyVersion("1.0.*")]
-// The following attributes are used to specify the signing key for the assembly,
-// if desired. See the Mono documentation for more information about signing.
-//[assembly: AssemblyDelaySign(false)]
-//[assembly: AssemblyKeyFile("")]
-
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>12.0.0</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{0C624E8F-9C80-457F-A7D1-39FA29E23F79}</ProjectGuid>
- <OutputType>Library</OutputType>
- <RootNamespace>GumartinM.JsonRPC4Mono</RootNamespace>
- <AssemblyName>jsonrpc4net</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <Description>Dirty implementation of JSON RPC. Just trying to learn how
-to use C#.</Description>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug</OutputPath>
- <DefineConstants>DEBUG;</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <ConsolePause>false</ConsolePause>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>full</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release</OutputPath>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <ConsolePause>false</ConsolePause>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Net.Http">
- <HintPath>..\..\..\..\..\..\..\usr\mymono\lib\mono\4.5\System.Net.Http.dll</HintPath>
- </Reference>
- <Reference Include="log4net">
- <HintPath>..\..\..\..\..\..\..\usr\mymono\custom\log4net-1.2.13\cli\1.0\log4net.dll</HintPath>
- </Reference>
- <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=c7439020c8fedf87">
- <Package>monodevelop</Package>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="JsonRpcHttpAsyncClient.cs" />
- <Compile Include="ExceptionResolver.cs" />
- <Compile Include="JsonRpcClientException.cs" />
- </ItemGroup>
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
\ No newline at end of file
+++ /dev/null
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30110.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jsonrpc4net", "jsonrpc4net\jsonrpc4net.csproj", "{9FC57CC3-23D0-486B-A3E4-92C547561949}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|ARM = Debug|ARM
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
- Release|ARM = Release|ARM
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|ARM.ActiveCfg = Debug|ARM
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|ARM.Build.0 = Debug|ARM
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|x86.ActiveCfg = Debug|x86
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|x86.Build.0 = Debug|x86
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|Any CPU.Build.0 = Release|Any CPU
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|ARM.ActiveCfg = Release|ARM
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|ARM.Build.0 = Release|ARM
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|x86.ActiveCfg = Release|x86
- {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|x86.Build.0 = Release|x86
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
+++ /dev/null
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Generic;
-
-namespace GumartinM.JsonRPC4Mono
-{
- public class ExceptionResolver
- {
- /// <summary>
- /// Resolves the exception.
- /// </summary>
- /// <returns>The exception.</returns>
- /// <param name="errorToken">Error token.</param>
- public Exception ResolveException(JToken errorToken)
- {
- JObject errorData = (JObject)errorToken;
- IDictionary<string, JToken> errorTokens = errorData;
-
- if (!errorTokens.ContainsKey("data"))
- {
- return CreateJsonRpcClientException(errorToken);
- }
-
- JToken dataToken = errorToken["data"];
- JObject data = (JObject)dataToken;
- errorTokens = data;
-
- if (!errorTokens.ContainsKey("exceptionTypeName"))
- {
- return CreateJsonRpcClientException(errorToken);
- }
-
- string exceptionTypeName = data["exceptionTypeName"].Value<string>();
- string message = data.Value<string>("message");
-
- Exception endException = CreateException(exceptionTypeName, message);
-
- return endException;
- }
-
- /// <summary>
- /// Creates the json rpc client exception.
- /// </summary>
- /// <returns>The json rpc client exception.</returns>
- /// <param name="errorToken">Error token.</param>
- private JsonRpcClientException CreateJsonRpcClientException(JToken errorToken)
- {
- return new JsonRpcClientException(
- errorToken.Value<int?>("code") ?? 0,
- errorToken.Value<string>("message"),
- errorToken.SelectToken("data"));
- }
-
- /// <summary>
- /// Creates the exception.
- /// </summary>
- /// <returns>The exception.</returns>
- /// <param name="exceptionTypeName">Exception type name.</param>
- /// <param name="message">Message.</param>
- private Exception CreateException(string exceptionTypeName, string message)
- {
- return new Exception("Remote exception: " + exceptionTypeName + "Message: " + message);
- }
- }
-}
+++ /dev/null
-using Newtonsoft.Json.Linq;
-using System;
-
-namespace GumartinM.JsonRPC4Mono
-{
- public class JsonRpcClientException : System.Exception
- {
- /// <summary>
- /// The _code.
- /// </summary>
- private readonly int _code;
-
- /// <summary>
- /// The _data.
- /// </summary>
- private readonly JToken _data;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Example.RemoteAgents.GTKLinux.Model.JsonRpcClientException"/> class.
- /// </summary>
- /// <param name="code">Code.</param>
- /// <param name="message">Message.</param>
- /// <param name="data">Data.</param>
- public JsonRpcClientException(int code, String message, JToken data)
- : base(message)
- {
- _code = code;
- _data = data;
- }
-
- /// <summary>
- /// Gets the code.
- /// </summary>
- /// <returns>The code.</returns>
- public int getCode()
- {
- return _code;
- }
-
- /// <summary>
- /// Gets the data.
- /// </summary>
- /// <returns>The data.</returns>
- public JToken getData()
- {
- return _data;
- }
- }
-}
+++ /dev/null
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
-using NLog;
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Net.Http;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace GumartinM.JsonRPC4Mono
-{
- public class JsonRpcHttpAsyncClient
- {
- /// <summary>
- /// RPC call id.
- /// </summary>
- private long _nextId;
-
- /// <summary>
- /// The logger.
- /// </summary>
- private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
-
- /// <summary>
- /// The _json settings.
- /// </summary>
- private readonly JsonSerializerSettings _jsonSettings =
- new JsonSerializerSettings
- {
- Error = delegate(object sender, ErrorEventArgs args)
- {
- _logger.Error(args.ErrorContext.Error.Message);
- args.ErrorContext.Handled = true;
- }
- };
-
- /// <summary>
- /// The _exception resolver.
- /// </summary>
- private readonly ExceptionResolver _exceptionResolver = new ExceptionResolver();
-
-
-
- /// <summary>
- /// Posts the remote service async.
- /// </summary>
- /// <returns>The remote service async.</returns>
- /// <param name="uri">URI.</param>
- /// <param name="method">Method.</param>
- /// <typeparam name="TResult">The 1st type parameter.</typeparam>
- async public Task<TResult> PostRemoteServiceAsync<TResult>(string uri, string method)
- {
- POSTResult<TResult> postResult = await this.PostAsync<TResult>(uri, method, CancellationToken.None);
-
- return postResult.result;
- }
-
- /// <summary>
- /// Posts the async.
- /// </summary>
- /// <returns>The async.</returns>
- /// <param name="uri">URI.</param>
- /// <param name="method">Method.</param>
- /// <param name="cancellation">Cancellation.</param>
- /// <typeparam name="TResult">The 1st type parameter.</typeparam>
- async private Task<POSTResult<TResult>> PostAsync<TResult>(string uri, string method, CancellationToken cancellation)
- {
- var postData = new POST();
- postData.id = Interlocked.Increment(ref _nextId).ToString();
- postData.jsonrpc = "2.0";
- postData.method = method;
-
- string data = JsonConvert.SerializeObject(postData, _jsonSettings);
-
- // see: http://stackoverflow.com/questions/1329739/nested-using-statements-in-c-sharp
- // see: http://stackoverflow.com/questions/5895879/when-do-we-need-to-call-dispose-in-dot-net-c
- //TODO: Am I really sure I have to call the Dispose method of HttpContent content? In this case, shouldn't it be stupid?
- // For HttpResponseMessage response I am sure I have to do it but I am not for HttpContent content.
- using (HttpContent content = new StringContent(data, System.Text.Encoding.UTF8, "application/json-rpc"))
- using (HttpResponseMessage response = await this.PostAsync(uri, content, cancellation))
- {
-
- if (response.StatusCode == HttpStatusCode.OK)
- {
- byte[] jsonBytes = await response.Content.ReadAsByteArrayAsync();
-
- return this.ReadResponse<TResult>(jsonBytes);
- }
-
- throw new Exception("Unexpected response code: " + response.StatusCode);
- }
- }
-
- /// <summary>
- /// Reads the response.
- /// </summary>
- /// <returns>The response.</returns>
- /// <param name="jsonBytes">Json bytes.</param>
- /// <typeparam name="TResult">The 1st type parameter.</typeparam>
- private POSTResult<TResult> ReadResponse<TResult>(byte[] jsonBytes)
- {
- string json = System.Text.Encoding.UTF8.GetString(jsonBytes, 0, jsonBytes.Length);
-
- JObject jsonObjects = JObject.Parse(json);
- IDictionary<string, JToken> jsonTokens = jsonObjects;
-
-
- if (jsonTokens.ContainsKey("error"))
- {
- throw _exceptionResolver.ResolveException(jsonObjects["error"]);
- }
-
- if (jsonTokens.ContainsKey("result"))
- {
- return JsonConvert.DeserializeObject<POSTResult<TResult>>(json, _jsonSettings);
- }
-
- throw new JsonRpcClientException(0, "There is not neither error nor result in JSON response data.", jsonObjects);
- }
-
- /// <summary>
- /// Send a POST request to the specified Uri as an asynchronous operation.
- /// </summary>
- /// <param name="uri">The Uri the request is sent to.</param>
- /// <param name="content">The HTTP request content sent to the server.</param>
- /// <param name="System.Threading.CancellationToken">Cancellation token.</param>
- /// <exception cref="System.InvalidOperationException">When some error.</exception>
- /// <returns>System.Threading.Tasks.Task<![CDATA[<TResult>]]>.The task object representing the asynchronous operation.</returns>
- async private Task<HttpResponseMessage> PostAsync(string uri, HttpContent content, CancellationToken cancellation)
- {
- using (HttpClient client = new HttpClient { Timeout = TimeSpan.FromSeconds(5) })
- {
- // TODO: cancellation
- return await client.PostAsync(uri, content, cancellation);
- }
- }
-
- private class POST
- {
- public string id { get; set; }
- public string jsonrpc { get; set; }
- public string method { get; set; }
- }
-
-
- private class POSTResult<TResult>
- {
- public string id { get; set; }
- public string jsonrpc { get; set; }
- public TResult result { get; set; }
- }
- }
-}
+++ /dev/null
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Resources;
-
-// La información general de un ensamblado se controla mediante el siguiente
-// conjunto de atributos. Cambie los valores de estos atributos para modificar la información
-// asociada a un ensamblado.
-[assembly: AssemblyTitle("jsonrpc4net")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("jsonrpc4net")]
-[assembly: AssemblyCopyright("Copyright © 2014")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Si ComVisible se establece en False, los componentes COM no verán los
-// tipos de este ensamblado. Si necesita obtener acceso a un tipo de este ensamblado desde
-// COM, establezca el atributo ComVisible en True en este tipo.
-[assembly: ComVisible(false)]
-
-// El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM
-[assembly: Guid("9fc57cc3-23d0-486b-a3e4-92c547561949")]
-
-// La información de versión de un ensamblado consta de los cuatro valores siguientes:
-//
-// Versión principal
-// Versión secundaria
-// Número de compilación
-// Revisión
-//
-// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y revisión
-// mediante el carácter '*', como se muestra a continuación:
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: NeutralResourcesLanguageAttribute("es-ES")]
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>10.0.20506</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{9FC57CC3-23D0-486B-A3E4-92C547561949}</ProjectGuid>
- <ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>GumartinM.JsonRPC4Mono</RootNamespace>
- <AssemblyName>jsonrpc4net</AssemblyName>
- <TargetFrameworkIdentifier>WindowsPhone</TargetFrameworkIdentifier>
- <TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
- <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
- <SilverlightApplication>false</SilverlightApplication>
- <ValidateXaml>true</ValidateXaml>
- <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
- <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
- <SupportedCultures>en-US</SupportedCultures>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>Bin\Debug</OutputPath>
- <DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
- <NoStdLib>true</NoStdLib>
- <NoConfig>true</NoConfig>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <DocumentationFile>
- </DocumentationFile>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>Bin\Release</OutputPath>
- <DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
- <NoStdLib>true</NoStdLib>
- <NoConfig>true</NoConfig>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>Bin\x86\Debug</OutputPath>
- <DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
- <NoStdLib>true</NoStdLib>
- <NoConfig>true</NoConfig>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>Bin\x86\Release</OutputPath>
- <DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
- <NoStdLib>true</NoStdLib>
- <NoConfig>true</NoConfig>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|ARM' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>Bin\ARM\Debug</OutputPath>
- <DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
- <NoStdLib>true</NoStdLib>
- <NoConfig>true</NoConfig>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|ARM' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>Bin\ARM\Release</OutputPath>
- <DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
- <NoStdLib>true</NoStdLib>
- <NoConfig>true</NoConfig>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="ExceptionResolver.cs" />
- <Compile Include="JsonRpcClientException.cs" />
- <Compile Include="JsonRpcHttpAsyncClient.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <ItemGroup>
- <Reference Include="Newtonsoft.Json">
- <HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\portable-net45+wp80+win8\Newtonsoft.Json.dll</HintPath>
- </Reference>
- <Reference Include="NLog">
- <HintPath>..\packages\NLog.2.1.0\lib\sl4-windowsphone71\NLog.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http.Extensions">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http.Primitives">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.Primitives.dll</HintPath>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
- <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
- <ProjectExtensions />
- <Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
- <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
- <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
- <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
- </Target>
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="Microsoft.Bcl" version="1.1.3" targetFramework="wp80" />
- <package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="wp80" />
- <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="wp80" />
- <package id="Newtonsoft.Json" version="6.0.1" targetFramework="wp80" />
- <package id="NLog" version="2.1.0" targetFramework="wp80" />
-</packages>
\ No newline at end of file
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jsonrpc4net", "jsonrpc4net\jsonrpc4net.Monodevelop.csproj", "{0C624E8F-9C80-457F-A7D1-39FA29E23F79}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0C624E8F-9C80-457F-A7D1-39FA29E23F79}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = jsonrpc4net\jsonrpc4net.csproj
+ description = jsonrpc4net library implementation (just for fun)
+ EndGlobalSection
+EndGlobal
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.30110.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jsonrpc4net", "jsonrpc4net\jsonrpc4net.WindowsPhone8.csproj", "{9FC57CC3-23D0-486B-A3E4-92C547561949}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|ARM = Debug|ARM
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|ARM = Release|ARM
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|ARM.ActiveCfg = Debug|ARM
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|ARM.Build.0 = Debug|ARM
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|x86.ActiveCfg = Debug|x86
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Debug|x86.Build.0 = Debug|x86
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|ARM.ActiveCfg = Release|ARM
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|ARM.Build.0 = Release|ARM
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|x86.ActiveCfg = Release|x86
+ {9FC57CC3-23D0-486B-A3E4-92C547561949}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
--- /dev/null
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+
+namespace GumartinM.JsonRPC4NET
+{
+ public class ExceptionResolver
+ {
+ /// <summary>
+ /// Resolves the exception.
+ /// </summary>
+ /// <returns>The exception.</returns>
+ /// <param name="errorToken">Error token.</param>
+ public Exception ResolveException(JToken errorToken)
+ {
+ JObject errorData = (JObject)errorToken;
+ IDictionary<string, JToken> errorTokens = errorData;
+
+ if (!errorTokens.ContainsKey("data"))
+ {
+ return CreateJsonRpcClientException(errorToken);
+ }
+
+ JToken dataToken = errorToken["data"];
+ JObject data = (JObject)dataToken;
+ errorTokens = data;
+
+ if (!errorTokens.ContainsKey("exceptionTypeName"))
+ {
+ return CreateJsonRpcClientException(errorToken);
+ }
+
+ string exceptionTypeName = data["exceptionTypeName"].Value<string>();
+ string message = data.Value<string>("message");
+
+ Exception endException = CreateException(exceptionTypeName, message);
+
+ return endException;
+ }
+
+ /// <summary>
+ /// Creates the json rpc client exception.
+ /// </summary>
+ /// <returns>The json rpc client exception.</returns>
+ /// <param name="errorToken">Error token.</param>
+ private JsonRpcClientException CreateJsonRpcClientException(JToken errorToken)
+ {
+ return new JsonRpcClientException(
+ errorToken.Value<int?>("code") ?? 0,
+ errorToken.Value<string>("message"),
+ errorToken.SelectToken("data"));
+ }
+
+ /// <summary>
+ /// Creates the exception.
+ /// </summary>
+ /// <returns>The exception.</returns>
+ /// <param name="exceptionTypeName">Exception type name.</param>
+ /// <param name="message">Message.</param>
+ private Exception CreateException(string exceptionTypeName, string message)
+ {
+ return new Exception("Remote exception: " + exceptionTypeName + "Message: " + message);
+ }
+ }
+}
--- /dev/null
+using Newtonsoft.Json.Linq;
+using System;
+
+namespace GumartinM.JsonRPC4NET
+{
+ public class JsonRpcClientException : System.Exception
+ {
+ /// <summary>
+ /// The _code.
+ /// </summary>
+ private readonly int _code;
+
+ /// <summary>
+ /// The _data.
+ /// </summary>
+ private readonly JToken _data;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Example.RemoteAgents.GTKLinux.Model.JsonRpcClientException"/> class.
+ /// </summary>
+ /// <param name="code">Code.</param>
+ /// <param name="message">Message.</param>
+ /// <param name="data">Data.</param>
+ public JsonRpcClientException(int code, String message, JToken data)
+ : base(message)
+ {
+ _code = code;
+ _data = data;
+ }
+
+ /// <summary>
+ /// Gets the code.
+ /// </summary>
+ /// <returns>The code.</returns>
+ public int getCode()
+ {
+ return _code;
+ }
+
+ /// <summary>
+ /// Gets the data.
+ /// </summary>
+ /// <returns>The data.</returns>
+ public JToken getData()
+ {
+ return _data;
+ }
+ }
+}
--- /dev/null
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Serialization;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Net.Http;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace GumartinM.JsonRPC4NET
+{
+ public class JsonRpcHttpAsyncClient
+ {
+ /// <summary>
+ /// RPC call id.
+ /// </summary>
+ private long _nextId;
+
+ /// <summary>
+ /// The logger.
+ /// </summary>
+ private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
+
+ /// <summary>
+ /// The _json settings.
+ /// </summary>
+ private readonly JsonSerializerSettings _jsonSettings =
+ new JsonSerializerSettings
+ {
+ Error = delegate(object sender, ErrorEventArgs args)
+ {
+ _logger.Error(args.ErrorContext.Error.Message);
+ args.ErrorContext.Handled = true;
+ }
+ };
+
+ /// <summary>
+ /// The _exception resolver.
+ /// </summary>
+ private readonly ExceptionResolver _exceptionResolver = new ExceptionResolver();
+
+
+
+ /// <summary>
+ /// Posts the remote service async.
+ /// </summary>
+ /// <returns>The remote service async.</returns>
+ /// <param name="uri">URI.</param>
+ /// <param name="method">Method.</param>
+ /// <typeparam name="TResult">The 1st type parameter.</typeparam>
+ async public Task<TResult> PostRemoteServiceAsync<TResult>(string uri, string method)
+ {
+ POSTResult<TResult> postResult = await this.PostAsync<TResult>(uri, method, CancellationToken.None);
+
+ return postResult.result;
+ }
+
+ /// <summary>
+ /// Posts the async.
+ /// </summary>
+ /// <returns>The async.</returns>
+ /// <param name="uri">URI.</param>
+ /// <param name="method">Method.</param>
+ /// <param name="cancellation">Cancellation.</param>
+ /// <typeparam name="TResult">The 1st type parameter.</typeparam>
+ async private Task<POSTResult<TResult>> PostAsync<TResult>(string uri, string method, CancellationToken cancellation)
+ {
+ var postData = new POST();
+ postData.id = Interlocked.Increment(ref _nextId).ToString();
+ postData.jsonrpc = "2.0";
+ postData.method = method;
+
+ string data = JsonConvert.SerializeObject(postData, _jsonSettings);
+
+ // see: http://stackoverflow.com/questions/1329739/nested-using-statements-in-c-sharp
+ // see: http://stackoverflow.com/questions/5895879/when-do-we-need-to-call-dispose-in-dot-net-c
+ //TODO: Am I really sure I have to call the Dispose method of HttpContent content? In this case, shouldn't it be stupid?
+ // For HttpResponseMessage response I am sure I have to do it but I am not for HttpContent content.
+ using (HttpContent content = new StringContent(data, System.Text.Encoding.UTF8, "application/json-rpc"))
+ using (HttpResponseMessage response = await this.PostAsync(uri, content, cancellation))
+ {
+
+ if (response.StatusCode == HttpStatusCode.OK)
+ {
+ byte[] jsonBytes = await response.Content.ReadAsByteArrayAsync();
+
+ return this.ReadResponse<TResult>(jsonBytes);
+ }
+
+ throw new Exception("Unexpected response code: " + response.StatusCode);
+ }
+ }
+
+ /// <summary>
+ /// Reads the response.
+ /// </summary>
+ /// <returns>The response.</returns>
+ /// <param name="jsonBytes">Json bytes.</param>
+ /// <typeparam name="TResult">The 1st type parameter.</typeparam>
+ private POSTResult<TResult> ReadResponse<TResult>(byte[] jsonBytes)
+ {
+ string json = System.Text.Encoding.UTF8.GetString(jsonBytes, 0, jsonBytes.Length);
+
+ JObject jsonObjects = JObject.Parse(json);
+ IDictionary<string, JToken> jsonTokens = jsonObjects;
+
+
+ if (jsonTokens.ContainsKey("error"))
+ {
+ throw _exceptionResolver.ResolveException(jsonObjects["error"]);
+ }
+
+ if (jsonTokens.ContainsKey("result"))
+ {
+ return JsonConvert.DeserializeObject<POSTResult<TResult>>(json, _jsonSettings);
+ }
+
+ throw new JsonRpcClientException(0, "There is not error nor result in JSON response data.", jsonObjects);
+ }
+
+ /// <summary>
+ /// Send a POST request to the specified Uri as an asynchronous operation.
+ /// </summary>
+ /// <param name="uri">The Uri the request is sent to.</param>
+ /// <param name="content">The HTTP request content sent to the server.</param>
+ /// <param name="System.Threading.CancellationToken">Cancellation token.</param>
+ /// <exception cref="System.InvalidOperationException">When some error.</exception>
+ /// <returns>System.Threading.Tasks.Task<![CDATA[<TResult>]]>.The task object representing the asynchronous operation.</returns>
+ async private Task<HttpResponseMessage> PostAsync(string uri, HttpContent content, CancellationToken cancellation)
+ {
+ using (HttpClient client = new HttpClient { Timeout = TimeSpan.FromSeconds(5) })
+ {
+ // TODO: cancellation
+ return await client.PostAsync(uri, content, cancellation);
+ }
+ }
+
+ private class POST
+ {
+ public string id { get; set; }
+ public string jsonrpc { get; set; }
+ public string method { get; set; }
+ }
+
+
+ private class POSTResult<TResult>
+ {
+ public string id { get; set; }
+ public string jsonrpc { get; set; }
+ public TResult result { get; set; }
+ }
+ }
+}
--- /dev/null
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Resources;
+
+// La información general de un ensamblado se controla mediante el siguiente
+// conjunto de atributos. Cambie los valores de estos atributos para modificar la información
+// asociada a un ensamblado.
+[assembly: AssemblyTitle("jsonrpc4net")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("jsonrpc4net")]
+[assembly: AssemblyCopyright("Copyright © 2014")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Si ComVisible se establece en False, los componentes COM no verán los
+// tipos de este ensamblado. Si necesita obtener acceso a un tipo de este ensamblado desde
+// COM, establezca el atributo ComVisible en True en este tipo.
+[assembly: ComVisible(false)]
+
+// El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM
+[assembly: Guid("9fc57cc3-23d0-486b-a3e4-92c547561949")]
+
+// La información de versión de un ensamblado consta de los cuatro valores siguientes:
+//
+// Versión principal
+// Versión secundaria
+// Número de compilación
+// Revisión
+//
+// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y revisión
+// mediante el carácter '*', como se muestra a continuación:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: NeutralResourcesLanguageAttribute("es-ES")]
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>12.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0C624E8F-9C80-457F-A7D1-39FA29E23F79}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>GumartinM.JsonRPC4NET</RootNamespace>
+ <AssemblyName>jsonrpc4net</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <Description>Dirty implementation of JSON RPC. Just trying to learn how
+to use C#.</Description>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>full</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Net.Http">
+ <HintPath>..\..\..\..\..\..\..\usr\mymono\lib\mono\4.5\System.Net.Http.dll</HintPath>
+ </Reference>
+ <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=c7439020c8fedf87">
+ <Package>monodevelop</Package>
+ </Reference>
+ <Reference Include="NLog">
+ <HintPath>..\..\ThirdParty\Libs\NLog\net45\NLog.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="JsonRpcHttpAsyncClient.cs" />
+ <Compile Include="ExceptionResolver.cs" />
+ <Compile Include="JsonRpcClientException.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.20506</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{9FC57CC3-23D0-486B-A3E4-92C547561949}</ProjectGuid>
+ <ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>GumartinM.JsonRPC4Mono</RootNamespace>
+ <AssemblyName>jsonrpc4net</AssemblyName>
+ <TargetFrameworkIdentifier>WindowsPhone</TargetFrameworkIdentifier>
+ <TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
+ <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>true</ValidateXaml>
+ <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
+ <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
+ <SupportedCultures>en-US</SupportedCultures>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>Bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <DocumentationFile>
+ </DocumentationFile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>Bin\Release</OutputPath>
+ <DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>Bin\x86\Debug</OutputPath>
+ <DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>Bin\x86\Release</OutputPath>
+ <DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|ARM' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>Bin\ARM\Debug</OutputPath>
+ <DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|ARM' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>Bin\ARM\Release</OutputPath>
+ <DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="ExceptionResolver.cs" />
+ <Compile Include="JsonRpcClientException.cs" />
+ <Compile Include="JsonRpcHttpAsyncClient.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\portable-net45+wp80+win8\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="NLog">
+ <HintPath>..\packages\NLog.2.1.0\lib\sl4-windowsphone71\NLog.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http.Extensions">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.Extensions.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http.Primitives">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\sl4-windowsphone71\System.Net.Http.Primitives.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
+ <ProjectExtensions />
+ <Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
+ <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
+ <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
+ <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
+ </Target>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.Bcl" version="1.1.3" targetFramework="wp80" />
+ <package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="wp80" />
+ <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="wp80" />
+ <package id="Newtonsoft.Json" version="6.0.1" targetFramework="wp80" />
+ <package id="NLog" version="2.1.0" targetFramework="wp80" />
+</packages>
\ No newline at end of file