private void DoPost(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            Dictionary <string, Stream> files = httpRequest.Files.AllKeys.ToDictionary(n => n, n => httpRequest.Files[n].InputStream);

            DirectRequest[] requests  = new DirectRequestsBuilder().Build(new StreamReader(httpRequest.InputStream, httpRequest.ContentEncoding), httpRequest.Form, files);
            var             responses = new DirectResponse[requests.Length];

            for (int i = 0; i < requests.Length; i++)
            {
                responses[i] = new DirectHandler(_metadata, _directHandlerInterceptor).Handle(requests[i]);
            }
            using (var textWriter = new StreamWriter(httpResponse.OutputStream, httpResponse.ContentEncoding))
            {
                if (requests[0].Upload)
                {
                    httpResponse.ContentType = "text/html";
                    textWriter.Write("<html><body><textarea>");
                    SerializeResponse(responses, textWriter);
                    textWriter.Write("</textarea></body></html>");
                }
                else
                {
                    httpResponse.ContentType = "application/json";
                    SerializeResponse(responses, textWriter);
                }
            }
        }
 private void DoPost(HttpRequest httpRequest, HttpResponse httpResponse)
 {
     Dictionary<string, Stream> files = httpRequest.Files.AllKeys.ToDictionary(n => n, n => httpRequest.Files[n].InputStream);
     DirectRequest[] requests = new DirectRequestsBuilder().Build(new StreamReader(httpRequest.InputStream, httpRequest.ContentEncoding), httpRequest.Form, files);
     var responses = new DirectResponse[requests.Length];
     for(int i = 0; i < requests.Length; i++)
     {
         responses[i] = new DirectHandler(_objectFactory, _metadata).Handle(requests[i]);
     }
     using(var textWriter = new StreamWriter(httpResponse.OutputStream, httpResponse.ContentEncoding))
     {
         if(requests[0].Upload)
         {
             httpResponse.ContentType = "text/html";
             textWriter.Write("<html><body><textarea>");
             SerializeResponse(responses, textWriter);
             textWriter.Write("</textarea></body></html>");
         }
         else
         {
             httpResponse.ContentType = "application/json";
             SerializeResponse(responses, textWriter);
         }
     }
 }
 private void DoPost(HttpRequest httpRequest, HttpResponse httpResponse)
 {
     var directRequestsBuilder = new DirectRequestsBuilder();
     DirectRequest[] requests = httpRequest.Form.Count > 0 ? directRequestsBuilder.BuildFromFormData(httpRequest.Form) : directRequestsBuilder.BuildFromRequestData(new StreamReader(httpRequest.InputStream, httpRequest.ContentEncoding));
     var responses = new DirectResponse[requests.Length];
     for(int i = 0; i < requests.Length; i++)
     {
         responses[i] = new DirectHandler(_objectFactory, _metadata).Handle(requests[i]);
     }
     httpResponse.ContentType = "application/json";
     using(var jsonWriter = new JsonTextWriter(new StreamWriter(httpResponse.OutputStream, httpResponse.ContentEncoding)))
     {
         new JsonSerializer().Serialize(jsonWriter, responses.Length == 1 ? (object)responses[0] : responses);
     }
 }