Moved chain building and validation from Mono.Security to System
[mono.git] / mcs / class / System.Web / System.Web.UI / ControlCachePolicy.cs
1 //
2 // System.Web.UI.ControlCachePolicy
3 //
4 // Authors:
5 //      Dick Porter  <dick@ximian.com>
6 //      Marek Habersack <mhabersack@novell.com>
7 //
8 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System.Web.Caching;
31
32 namespace System.Web.UI
33 {
34         public sealed class ControlCachePolicy
35         {
36                 BasePartialCachingControl bpcc;
37                 bool cached;
38                 
39                 internal ControlCachePolicy () : this (null)
40                 {
41                 }
42
43                 internal ControlCachePolicy (BasePartialCachingControl bpcc)
44                 {
45                         this.bpcc = bpcc;
46                 }
47                 
48                 public bool Cached 
49                 {
50                         get {
51                                 AssertBasePartialCachingControl ();
52                                 return cached;
53                         }
54                         
55                         set {
56                                 AssertBasePartialCachingControl ();
57                                 cached = value;
58                         }
59                 }
60
61                 public CacheDependency Dependency 
62                 {
63                         get {
64                                 AssertBasePartialCachingControl ();
65                                 return bpcc.Dependency;
66                         }
67                         set {
68                                 AssertBasePartialCachingControl ();
69                                 bpcc.Dependency = value;
70                         }
71                 }
72
73                 public TimeSpan Duration 
74                 {
75                         get {
76                                 AssertBasePartialCachingControl ();
77                                 return TimeSpan.FromMinutes (bpcc.Duration);
78                         }
79                         set {
80                                 AssertBasePartialCachingControl ();
81                                 bpcc.Duration = value.Minutes;
82                         }
83                 }
84
85                 public bool SupportsCaching 
86                 {
87                         get {
88                                 return bpcc != null;
89                         }
90                 }
91
92                 public string VaryByControl 
93                 {
94                         get {
95                                 AssertBasePartialCachingControl ();
96                                 return bpcc.VaryByControls;
97                         }
98                         set {
99                                 AssertBasePartialCachingControl ();
100                                 bpcc.VaryByControls = value;
101                         }
102                 }
103
104                 public HttpCacheVaryByParams VaryByParams {
105                         get {
106                                 AssertBasePartialCachingControl ();
107                                 throw new NotImplementedException ();
108                         }
109                 }
110
111                 public void SetExpires (DateTime expirationTime)
112                 {
113                         AssertBasePartialCachingControl ();
114                         bpcc.ExpirationTime = expirationTime;
115                 }
116
117                 public void SetSlidingExpiration (bool useSlidingExpiration)
118                 {
119                         AssertBasePartialCachingControl ();
120                         bpcc.SlidingExpiration = useSlidingExpiration;
121                 }
122
123                 public void SetVaryByCustom (string varyByCustom)
124                 {
125                         AssertBasePartialCachingControl ();
126                         bpcc.VaryByCustom = varyByCustom;
127                 }
128
129                 void AssertBasePartialCachingControl ()
130                 {
131                         if (bpcc == null)
132                                 throw new HttpException ("The user control is not associated with a 'BasePartialCachingControl' and is not cacheable.");
133                 }
134                 
135         }
136 }