コード例 #1
0
        public void Execute()
        {
            NetworkStream responseStream = currentClient.GetStream();

            EnsureResponseStream(responseStream);

            string payload = string.Empty;

            if (serializerOptions != null)
            {
                payload = JsonSerializer.Serialize(dataTransferObject, dataTransferObject.GetType(), serializerOptions);
            }
            else
            {
                payload = JsonSerializer.Serialize(dataTransferObject, dataTransferObject.GetType());
            }

            HttpResponseHeader responseHeader = new HttpResponseHeader(HttpStatusCode.OK, payload?.Length ?? 0, "Json");

            responseHeader.AddRange(tempHeaderEntries);

            byte[] responseHeaderBytes = Encoding.UTF8.GetBytes(responseHeader.ToString());
            responseStream.Write(responseHeaderBytes);

            byte[] responseMessageBytes = Encoding.UTF8.GetBytes(payload);
            responseStream.Write(responseMessageBytes);
        }
コード例 #2
0
        public static HttpStatusCodeResult StatusMessage(HttpStatusCode status, TcpClient client, string message)
        {
            HttpResponseHeader responseHeader = new HttpResponseHeader(status, message?.Length ?? 0, "text, plain");

            return(new HttpStatusCodeResult(client, responseHeader, message));
        }
コード例 #3
0
 public HttpStatusCodeResult(TcpClient currentClient, HttpResponseHeader responseHeader, string message)
     : base(currentClient, responseHeader)
 {
     this.message = message;
 }
コード例 #4
0
 public HttpStatusCodeResult(TcpClient currentClient, HttpResponseHeader responseHeader)
     : this(currentClient, responseHeader, null)
 {
 }
コード例 #5
0
 public HttpActionResult(TcpClient currentClient, HttpResponseHeader responseHeader)
 {
     this.currentClient  = currentClient ?? throw new ArgumentNullException($"{nameof(currentClient)} cannot be null.");
     this.responseHeader = responseHeader ?? throw new ArgumentNullException($"{nameof(responseHeader)} cannot be null.");
 }