2 // System.Web.Compilation.SessionStateItemCollection
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Marek Habersack (grendello@gmail.com)
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)
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:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
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.
34 using System.Collections;
35 using System.Collections.Generic;
36 using System.Collections.Specialized;
37 using System.Globalization;
39 using System.Threading;
40 using System.Web.Util;
42 namespace System.Web.SessionState
44 public class HttpSessionStateContainer : IHttpSessionState
47 HttpStaticObjectsCollection staticObjects;
51 SessionStateMode mode;
53 internal bool abandoned;
54 ISessionStateItemCollection sessionItems;
55 HttpCookieMode cookieMode;
57 public HttpSessionStateContainer (string id,
58 ISessionStateItemCollection sessionItems,
59 HttpStaticObjectsCollection staticObjects,
62 HttpCookieMode cookieMode,
63 SessionStateMode mode,
67 throw new ArgumentNullException ("id");
69 this.sessionItems = sessionItems;
71 this.staticObjects = staticObjects;
72 this.timeout = timeout;
73 this.newSession = newSession;
74 this.cookieMode = cookieMode;
76 this.isReadOnly = isReadonly;
77 this.isCookieless = cookieMode == HttpCookieMode.UseUri;
82 HttpContext current = HttpContext.Current;
84 return Encoding.Default.CodePage;
86 return current.Response.ContentEncoding.CodePage;
90 HttpContext current = HttpContext.Current;
92 current.Response.ContentEncoding = Encoding.GetEncoding (value);
96 public HttpCookieMode CookieMode {
97 get { return cookieMode; }
102 if (sessionItems != null)
103 return sessionItems.Count;
108 public bool IsAbandoned {
109 get { return abandoned; }
112 public bool IsCookieless {
113 get { return isCookieless; }
116 public bool IsNewSession {
117 get { return newSession; }
120 public bool IsReadOnly {
121 get { return isReadOnly; }
124 public bool IsSynchronized {
125 get { return false; }
128 object IHttpSessionState.this [int index] {
130 if (sessionItems == null || sessionItems.Count == 0)
132 return sessionItems [index];
136 if (sessionItems != null)
137 sessionItems [index] = value;
141 object IHttpSessionState.this [string name] {
143 if (sessionItems == null || sessionItems.Count == 0)
145 return sessionItems [name];
149 if (sessionItems != null)
150 sessionItems [name] = value;
154 NameObjectCollectionBase.KeysCollection IHttpSessionState.Keys {
156 if (sessionItems != null)
157 return sessionItems.Keys;
163 get { return Thread.CurrentThread.CurrentCulture.LCID; }
164 set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
167 public SessionStateMode Mode {
171 public string SessionID {
175 public HttpStaticObjectsCollection StaticObjects {
176 get { return staticObjects; }
179 public Object SyncRoot {
184 get { return timeout; }
187 throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
192 internal void SetNewSession (bool value)
197 public void Abandon ()
202 public void Add (string name, Object value)
204 if (sessionItems == null)
206 sessionItems [name] = value;
211 if (sessionItems == null)
213 sessionItems.Clear ();
216 public void CopyTo (Array array, int index)
218 if (sessionItems == null)
220 NameObjectCollectionBase.KeysCollection all = sessionItems.Keys;
221 for (int i = 0; i < all.Count; i++)
222 array.SetValue (all.Get(i), i + index);
225 public IEnumerator GetEnumerator ()
227 if (sessionItems == null)
229 return sessionItems.GetEnumerator ();
232 public void Remove (string name)
234 if (sessionItems == null)
236 sessionItems.Remove (name);
239 public void RemoveAll ()
241 if (sessionItems == null)
243 sessionItems.Clear ();
246 public void RemoveAt (int index)
248 if (sessionItems == null)
250 sessionItems.RemoveAt (index);