Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / AsyncTimeoutAttribute.cs
1 namespace System.Web.Mvc {
2     using System;
3     using System.Diagnostics.CodeAnalysis;
4     using System.Web.Mvc.Async;
5
6     [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "Unsealed so that subclassed types can set properties in the default constructor.")]
7     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
8     public class AsyncTimeoutAttribute : ActionFilterAttribute {
9
10         // duration is specified in milliseconds
11         public AsyncTimeoutAttribute(int duration) {
12             if (duration < -1) {
13                 throw Error.AsyncCommon_InvalidTimeout("duration");
14             }
15
16             Duration = duration;
17         }
18
19         public int Duration {
20             get;
21             private set;
22         }
23
24         public override void OnActionExecuting(ActionExecutingContext filterContext) {
25             if (filterContext == null) {
26                 throw new ArgumentNullException("filterContext");
27             }
28
29             IAsyncManagerContainer container = filterContext.Controller as IAsyncManagerContainer;
30             if (container == null) {
31                 throw Error.AsyncCommon_ControllerMustImplementIAsyncManagerContainer(filterContext.Controller.GetType());
32             }
33
34             container.AsyncManager.Timeout = Duration;
35
36             base.OnActionExecuting(filterContext);
37         }
38
39     }
40 }