JSONRPC4NET no time for comments
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 4 Mar 2014 21:23:49 +0000 (22:23 +0100)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 4 Mar 2014 21:23:49 +0000 (22:23 +0100)
Mono/RemoteAgents/GTKLinux.sln
jsonrpc4net/jsonrpc4net/ExceptionResolver.cs
jsonrpc4net/jsonrpc4net/JsonRpcHttpAsyncClient.cs

index 4a9f35d..33a3f8f 100644 (file)
@@ -174,6 +174,8 @@ Global
                $28.inheritsSet = Mono
                $28.inheritsScope = text/x-csharp
                $28.scope = text/x-csharp
+               $0.VersionControlPolicy = $29
+               $29.inheritsSet = Mono
                description = @Little program to connect with remote applications\nthrough JSON API.
        EndGlobalSection
 EndGlobal
index 4b302c5..c00e6cd 100644 (file)
@@ -48,7 +48,7 @@ namespace GumartinM.JsonRPC4NET
             return new JsonRpcClientException(
               errorToken.Value<int?>("code") ?? 0,
               errorToken.Value<string>("message"),
-              errorToken.SelectToken("data"));
+              errorToken["data"]);
         }
 
         /// <summary>
@@ -59,7 +59,8 @@ namespace GumartinM.JsonRPC4NET
         /// <param name="message">Message.</param>
         private Exception CreateException(string exceptionTypeName, string message)
         {
-            return new Exception("Remote exception: " + exceptionTypeName + "Message: " + message);
+            return new Exception("Remote exception: " + exceptionTypeName +
+                                 " Remote message: " + message);
         }
     }
 }
index 2eaf5f2..50ad4fb 100644 (file)
@@ -8,6 +8,7 @@ using System.Net;
 using System.Net.Http;
 using System.Threading;
 using System.Threading.Tasks;
+using System.IO;
 
 namespace GumartinM.JsonRPC4NET
 {
@@ -29,7 +30,7 @@ namespace GumartinM.JsonRPC4NET
         private readonly JsonSerializerSettings _jsonSettings =
           new JsonSerializerSettings
           {
-              Error = delegate(object sender, ErrorEventArgs args)
+            Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
               {
                   _logger.Error(args.ErrorContext.Error.Message);
                   args.ErrorContext.Handled = true;
@@ -84,9 +85,12 @@ namespace GumartinM.JsonRPC4NET
 
                 if (response.StatusCode == HttpStatusCode.OK)
                 {
-                    byte[] jsonBytes = await response.Content.ReadAsByteArrayAsync();
+                                       //byte[] jsonBytes = await response.Content.ReadAsByteArrayAsync();
+                    Stream stream = await response.Content.ReadAsStreamAsync();
+
+                    //return this.ReadResponse<TResult>(jsonBytes);
+                    return await this.ReadResponseAsync<TResult>(stream);
 
-                    return this.ReadResponse<TResult>(jsonBytes);
                 }
 
                 throw new Exception("Unexpected response code: " + response.StatusCode);
@@ -103,6 +107,29 @@ namespace GumartinM.JsonRPC4NET
         {
             string json = System.Text.Encoding.UTF8.GetString(jsonBytes, 0, jsonBytes.Length);
 
+            return this.ReadResponse<TResult>(json);
+        }
+
+        /// <summary>
+        /// Reads the response.
+        /// </summary>
+        /// <returns>The response.</returns>
+        /// <param name="stream">Stream.</param>
+        /// <typeparam name="TResult">The 1st type parameter.</typeparam>
+        async private Task<POSTResult<TResult>> ReadResponseAsync<TResult>(Stream stream)
+               {
+                       using (StreamReader streamReader = new StreamReader (stream, System.Text.Encoding.UTF8))
+                       {
+                // This line makes this method useless (IMHO it is the same as the one working with bytes)
+                // How could I work with JSON saving memory?
+                               string json = await streamReader.ReadToEndAsync();
+
+                return this.ReadResponse<TResult>(json);
+                       }
+               }
+
+        private POSTResult<TResult> ReadResponse<TResult>(string json)
+        {
             JObject jsonObjects = JObject.Parse(json);
             IDictionary<string, JToken> jsonTokens = jsonObjects;