1 // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
2 
3 using System.Net.Http;
4 using System.Web.Http.Controllers;
5 
6 namespace System.Web.Http.Filters
7 {
8     public class HttpActionExecutedContext
9     {
10         private HttpActionContext _actionContext;
11 
HttpActionExecutedContext(HttpActionContext actionContext, Exception exception)12         public HttpActionExecutedContext(HttpActionContext actionContext, Exception exception)
13         {
14             if (actionContext == null)
15             {
16                 throw Error.ArgumentNull("actionContext");
17             }
18 
19             Exception = exception;
20             _actionContext = actionContext;
21         }
22 
23         /// <summary>
24         /// Initializes a new instance of the <see cref="HttpActionExecutedContext"/> class.
25         /// </summary>
26         /// <remarks>The default constructor is intended for use by unit testing only.</remarks>
HttpActionExecutedContext()27         public HttpActionExecutedContext()
28         {
29         }
30 
31         public HttpActionContext ActionContext
32         {
33             get { return _actionContext; }
34             set
35             {
36                 if (value == null)
37                 {
38                     throw Error.PropertyNull();
39                 }
40                 _actionContext = value;
41             }
42         }
43 
44         public Exception Exception { get; set; }
45 
46         public HttpResponseMessage Response
47         {
48             get
49             {
50                 return ActionContext != null ? ActionContext.Response : null;
51             }
52 
53             set
54             {
55                 ActionContext.Response = value;
56             }
57         }
58 
59         /// <summary>
60         /// Gets the current <see cref="HttpRequestMessage"/>.
61         /// </summary>
62         public HttpRequestMessage Request
63         {
64             get
65             {
66                 return (ActionContext != null && ActionContext.ControllerContext != null)
67                            ? ActionContext.ControllerContext.Request
68                            : null;
69             }
70         }
71     }
72 }
73