Exemplo n.º 1
0
        /// <summary>
        /// Get the JSON RPC response for the given HTTP request.
        /// </summary>
        /// <typeparam name="T">The type to deserialize the response result to.</typeparam>
        /// <param name="httpWebRequest">The web request.</param>
        /// <returns>A JSON RPC response with the result deserialized as the given type.</returns>
        private DaemonResponse <T> GetRpcResponse <T>(HttpWebRequest httpWebRequest)
        {
            try
            {
                string json = GetJsonResponse(httpWebRequest);

                // process response with converter. needed for all coin wallets which gives non-standard info.
                string jsonLC = PropertyConverter.DeserializeWithLowerCasePropertyNames(json).ToString();

                _logger.Verbose("rx: {0}", jsonLC.PrettifyJson());

                return(JsonConvert.DeserializeObject <DaemonResponse <T> >(jsonLC));
            }
            catch (RpcException rpcEx) {
                httpWebRequest = null;
                throw rpcEx;
            }
            catch (JsonException jsonEx)
            {
                httpWebRequest = null;
                throw new Exception("There was a problem deserializing the response from the coin wallet.", jsonEx);
            }
            catch (Exception exception)
            {
                httpWebRequest = null;
                throw _rpcExceptionFactory.GetRpcException("An unknown exception occured while reading json response.", exception);
            }
        }