/// <summary> /// Returns the content to the client with a specified HttpStatusCode. /// </summary> /// <param name="content">Object to return to the client, can be null</param> /// <param name="code">Status code for the client</param> /// <returns></returns> protected object WithStatusCode(object content, HttpStatusCode code) { JsonServiceResult result = new JsonServiceResult(content); result.Code = code; return(result); }
/// <summary> /// Returns a resource to the client with the specified content type and HttpStatusCode. /// </summary> /// <param name="resource">Resource to return, as a stream</param> /// <param name="contentType">content type of the resource</param> /// <param name="code">Status code for the client</param> /// <returns></returns> protected object Resource(Stream resource, string contentType, HttpStatusCode code) { JsonServiceResult result = new JsonServiceResult(resource, contentType); result.Code = code; return(result); }
/// <summary> /// Returns json or resources to the client. /// </summary> /// <param name="content">The content to return to the client.</param> public void Respond(object content) { if (_service.IsRunning) { using (JsonServiceResult result = (content as JsonServiceResult) ?? new JsonServiceResult(content)) { var data = result.Content; _response.StatusCode = (int)result.Code; _response.StatusDescription = result.Code.ToString(); _response.ContentType = result.ContentType; _headers.ToList().ForEach(kvp => { _response.AddHeader(kvp.Key, kvp.Value); }); if (data.CanSeek) { data.Position = 0; _response.ContentLength64 = data.Length; } data.CopyTo(_response.OutputStream); _response.Close(); data.Close(); } } }
/// <summary> /// Returns the content to the client with a specified HttpStatusCode. /// </summary> /// <param name="content">Object to return to the client, can be null</param> /// <param name="code">Status code for the client</param> /// <returns></returns> protected object WithStatusCode(object content, HttpStatusCode code) { JsonServiceResult result = new JsonServiceResult(content); result.Code = code; return result; }
/// <summary> /// Returns a resource to the client with the specified content type and HttpStatusCode. /// </summary> /// <param name="resource">Resource to return, as a stream</param> /// <param name="contentType">content type of the resource</param> /// <param name="code">Status code for the client</param> /// <returns></returns> protected object Resource(Stream resource, string contentType, HttpStatusCode code) { JsonServiceResult result = new JsonServiceResult(resource, contentType); result.Code = code; return result; }