Exemplo n.º 1
0
        public void Parse(HttpListenerContext httpContext)
        {
            var httpRequest = httpContext.Request;

            var rpcResultHandler = new AsyncCallback(
                callback =>
                {
                    var asyncData = ((JsonRpcStateAsync) callback);
                    var result = asyncData.Result;
                    var response = Encoding.UTF8.GetBytes(result);

                    var context = (HttpServiceContext)asyncData.AsyncState;

                    context.Request.Response.ContentType = "application/json";
                    context.Request.Response.ContentEncoding = Encoding.UTF8;
                    context.Request.Response.ContentLength64 = response.Length;
                    context.Request.Response.OutputStream.Write(response, 0, response.Length);

                    _logger.Verbose("tx: {0}", result.PrettifyJson());
                });

            using (var reader = new StreamReader(httpRequest.InputStream, Encoding.UTF8))
            {
                var line = reader.ReadToEnd();
                _logger.Verbose("rx: {0}", line.PrettifyJson());

                var rpcRequest = new HttpServiceRequest(line, httpContext);
                var rpcContext = new HttpServiceContext(this, rpcRequest);

                var async = new JsonRpcStateAsync(rpcResultHandler, rpcContext) { JsonRpc = line };
                JsonRpcProcessor.Process(Pool.Config.Coin.Name, async, rpcContext);
            }
        }
Exemplo n.º 2
0
 public HttpServiceContext(IMiner miner, HttpServiceRequest request)
 {
     Miner = miner;
     Request = request;
 }