//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using DotNetOpenAuth.Messaging;
using Validation;
///
/// DotNetOpenAuth extensions for ASP.NET MVC.
///
public static class MvcExtensions {
///
/// Wraps a response message as an MVC so it can be conveniently returned from an MVC controller's action method.
///
/// The response message.
/// An instance.
public static ActionResult AsActionResult(this HttpResponseMessage response) {
Requires.NotNull(response, "response");
return new HttpResponseMessageActionResult(response);
}
///
/// An MVC that wraps an
///
private class HttpResponseMessageActionResult : ActionResult {
///
/// The wrapped response.
///
private readonly HttpResponseMessage response;
///
/// Initializes a new instance of the class.
///
/// The response.
internal HttpResponseMessageActionResult(HttpResponseMessage response) {
Requires.NotNull(response, "response");
this.response = response;
}
///
/// Enables processing of the result of an action method by a custom type that inherits from the class.
///
/// The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.
public override void ExecuteResult(ControllerContext context) {
// Sadly, MVC doesn't support writing to the response stream asynchronously.
this.response.SendAsync(context.HttpContext).GetAwaiter().GetResult();
}
}
}
}