Example #1
0
        /// <summary>
        /// Запрос на выполнение json-rpc метода
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="returnType"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        /// <exception cref="JsonException">ошибочный ответ при приравнивание к типу</exception>
        public static object Invoke(Stream stream, Type returnType, IJsonRequest request)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException("returnType");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var streamer = new Streamer(stream);

            // send request
            streamer.WriteLine(request.ToString());

            // get response
            var response = streamer.ReadLine(TimeSpan.MaxValue);

            while (response == "")
            {
                response = streamer.ReadLine(TimeSpan.MaxValue);
            }

            return((new ResponseParser(response, returnType)).Result());
        }
Example #2
0
        private string InternalProcess(IJsonRequest request)
        {
            JsonRpcDispatcher dispatcher;

            mInternalRpcMethods.TryGetValue(request.Method, out dispatcher);

            try
            {
                if (dispatcher != null)
                {
                    return(dispatcher.Process(request.ToString()));
                }
            }
            catch (BadRequestException e)
            {
                return(OnError(request, e.ToString()));
            }

            return(OnError(request, null));
        }