New tests.
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / AsyncTimeoutAttribute.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Diagnostics.CodeAnalysis;\r
16     using System.Web.Mvc.Async;\r
17 \r
18     [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes",\r
19         Justification = "Unsealed so that subclassed types can set properties in the default constructor.")]\r
20     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]\r
21     public class AsyncTimeoutAttribute : ActionFilterAttribute {\r
22 \r
23         // duration is specified in milliseconds\r
24         public AsyncTimeoutAttribute(int duration) {\r
25             if (duration < -1) {\r
26                 throw Error.AsyncCommon_InvalidTimeout("duration");\r
27             }\r
28 \r
29             Duration = duration;\r
30         }\r
31 \r
32         public int Duration {\r
33             get;\r
34             private set;\r
35         }\r
36 \r
37         public override void OnActionExecuting(ActionExecutingContext filterContext) {\r
38             if (filterContext == null) {\r
39                 throw new ArgumentNullException("filterContext");\r
40             }\r
41 \r
42             IAsyncManagerContainer container = filterContext.Controller as IAsyncManagerContainer;\r
43             if (container == null) {\r
44                 throw Error.AsyncCommon_ControllerMustImplementIAsyncManagerContainer(filterContext.Controller.GetType());\r
45             }\r
46 \r
47             container.AsyncManager.Timeout = Duration;\r
48 \r
49             base.OnActionExecuting(filterContext);\r
50         }\r
51 \r
52     }\r
53 }\r