Beispiel #1
0
 /// <summary>
 ///     Outputs a JSON Response given an exception.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="ex">The ex.</param>
 /// <param name="statusCode">The status code.</param>
 /// <returns>A task for writing the output stream.</returns>
 public static Task <bool> JsonExceptionResponseAsync(this HttpListenerContext context, Exception ex, HttpStatusCode statusCode = HttpStatusCode.InternalServerError)
 {
     context.Response.StatusCode = (int)statusCode;
     return(context.JsonResponseAsync(ex));
 }
Beispiel #2
0
 /// <summary>
 ///     Outputs async a Json Response given a data object.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="data">The data.</param>
 /// <returns>A <c>true</c> value of type ref=JsonResponseAsync".</returns>
 public static Task <bool> JsonResponseAsync(this HttpListenerContext context, object data)
 {
     return(context.JsonResponseAsync(Json.Serialize(data)));
 }
Beispiel #3
0
 /// <summary>
 ///     Outputs a Json Response given a Json string.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="json">The JSON.</param>
 /// <returns> A <c>true</c> value of type ref=JsonResponseAsync".</returns>
 public static bool JsonResponse(this HttpListenerContext context, string json)
 {
     return(context.JsonResponseAsync(json).GetAwaiter().GetResult());
 }
Beispiel #4
0
 /// <summary>
 ///     Outputs a Json Response given a data object.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="data">The data.</param>
 /// <returns>A <c>true</c> value of type ref=JsonResponseAsync".</returns>
 public static bool JsonResponse(this HttpListenerContext context, object data)
 {
     return(context.JsonResponseAsync(data).GetAwaiter().GetResult());
 }