Fix for running against RabbitMQ 2.2
[mono.git] / mcs / class / System.Web / System.Web.SessionState_2.0 / HttpSessionStateContainer.cs
1 //
2 // System.Web.Compilation.SessionStateItemCollection
3 //
4 // Authors:
5 //   Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //   Marek Habersack (grendello@gmail.com)
7 //
8 // (C) 2006 Marek Habersack
9 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 //
12
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33 #if NET_2_0
34 using System.Collections;
35 using System.Collections.Generic;
36 using System.Collections.Specialized;
37 using System.Globalization;
38 using System.Text;
39 using System.Threading;
40 using System.Web.Util;
41
42 namespace System.Web.SessionState 
43 {
44         public class HttpSessionStateContainer : IHttpSessionState
45         {
46                 string id;
47                 HttpStaticObjectsCollection staticObjects;
48                 int timeout;
49                 bool newSession;
50                 bool isCookieless;
51                 SessionStateMode mode;
52                 bool isReadOnly;
53                 internal bool abandoned;
54                 ISessionStateItemCollection sessionItems;
55                 HttpCookieMode cookieMode;
56                 
57                 public HttpSessionStateContainer (string id,
58                                                   ISessionStateItemCollection sessionItems,
59                                                   HttpStaticObjectsCollection staticObjects,
60                                                   int timeout,
61                                                   bool newSession,
62                                                   HttpCookieMode cookieMode,
63                                                   SessionStateMode mode,
64                                                   bool isReadonly)
65                 {
66                         if (id == null)
67                                 throw new ArgumentNullException ("id");
68                         
69                         this.sessionItems = sessionItems;
70                         this.id = id;
71                         this.staticObjects = staticObjects;
72                         this.timeout = timeout;
73                         this.newSession = newSession;
74                         this.cookieMode = cookieMode;
75                         this.mode = mode;
76                         this.isReadOnly = isReadonly;
77                         this.isCookieless = cookieMode == HttpCookieMode.UseUri;
78                 }
79                 
80                 public int CodePage {
81                         get {
82                                 HttpContext current = HttpContext.Current;
83                                 if (current == null)
84                                         return Encoding.Default.CodePage;
85
86                                 return current.Response.ContentEncoding.CodePage;
87                         }
88                         
89                         set {
90                                 HttpContext current = HttpContext.Current;
91                                 if (current != null)
92                                         current.Response.ContentEncoding = Encoding.GetEncoding (value);
93                         }
94                 }
95                 
96                 public HttpCookieMode CookieMode {
97                         get { return cookieMode; }
98                 }
99                 
100                 public int Count {
101                         get {
102                                 if (sessionItems != null)
103                                         return sessionItems.Count;
104                                 return 0;
105                         }
106                 }
107                 
108                 public bool IsAbandoned {
109                         get { return abandoned; }
110                 }
111                 
112                 public bool IsCookieless {
113                         get { return isCookieless; }
114                 }
115                 
116                 public bool IsNewSession {
117                         get { return newSession; }
118                 }
119                 
120                 public bool IsReadOnly {
121                         get { return isReadOnly; }
122                 }
123                 
124                 public bool IsSynchronized {
125                         get { return false; }
126                 }
127                 
128                 object IHttpSessionState.this [int index] {
129                         get {
130                                 if (sessionItems == null || sessionItems.Count == 0)
131                                         return null;
132                                 return sessionItems [index];
133                         }
134                         
135                         set {
136                                 if (sessionItems != null)
137                                         sessionItems [index] = value;
138                         }
139                 }
140                 
141                 object IHttpSessionState.this [string name] {
142                         get {
143                                 if (sessionItems == null || sessionItems.Count == 0)
144                                         return null;
145                                 return sessionItems [name];
146                         }
147                         
148                         set {
149                                 if (sessionItems != null)
150                                         sessionItems [name] = value;
151                         }
152                 }
153                 
154                 NameObjectCollectionBase.KeysCollection IHttpSessionState.Keys {
155                         get {
156                                 if (sessionItems != null)
157                                         return sessionItems.Keys;
158                                 return null;
159                         }
160                 }
161                 
162                 public int LCID {
163                         get { return Thread.CurrentThread.CurrentCulture.LCID; }
164                         set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
165                 }
166                 
167                 public SessionStateMode Mode {
168                         get { return mode; }
169                 }
170                 
171                 public string SessionID {
172                         get { return id; }
173                 }
174                 
175                 public HttpStaticObjectsCollection StaticObjects {
176                         get { return staticObjects; }
177                 }
178                 
179                 public Object SyncRoot {
180                         get { return this; }
181                 }
182                 
183                 public int Timeout {
184                         get { return timeout; }
185                         set {
186                                 if (value < 1)
187                                         throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
188                                 timeout = value;
189                         }
190                 }
191
192                 internal void SetNewSession (bool value)
193                 {
194                         newSession = value;
195                 }
196                 
197                 public void Abandon ()
198                 {
199                         abandoned = true;
200                 }
201
202                 public void Add (string name, Object value)
203                 {
204                         if (sessionItems == null)
205                                 return;
206                         sessionItems [name] = value;
207                 }
208
209                 public void Clear ()
210                 {
211                         if (sessionItems == null)
212                                 return;
213                         sessionItems.Clear ();
214                 }
215
216                 public void CopyTo (Array array, int index)
217                 {
218                         if (sessionItems == null)
219                                 return;
220                         NameObjectCollectionBase.KeysCollection all = sessionItems.Keys;
221                         for (int i = 0; i < all.Count; i++)
222                                 array.SetValue (all.Get(i), i + index);
223                 }
224
225                 public IEnumerator GetEnumerator ()
226                 {
227                         if (sessionItems == null)
228                                 return null;
229                         return sessionItems.GetEnumerator ();
230                 }
231                 
232                 public void Remove (string name)
233                 {
234                         if (sessionItems == null)
235                                 return;
236                         sessionItems.Remove (name);
237                 }
238
239                 public void RemoveAll ()
240                 {
241                         if (sessionItems == null)
242                                 return;
243                         sessionItems.Clear ();
244                 }
245
246                 public void RemoveAt (int index)
247                 {
248                         if (sessionItems == null)
249                                 return;
250                         sessionItems.RemoveAt (index);
251                 }
252         }
253 }
254 #endif