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;
81 HttpContext current = HttpContext.Current;
83 return Encoding.Default.CodePage;
85 return current.Response.ContentEncoding.CodePage;
89 HttpContext current = HttpContext.Current;
91 current.Response.ContentEncoding = Encoding.GetEncoding (value);
95 public HttpCookieMode CookieMode {
96 get { return cookieMode; }
101 if (sessionItems != null)
102 return sessionItems.Count;
107 public bool IsAbandoned {
108 get { return abandoned; }
111 public bool IsCookieless {
112 get { return isCookieless; }
115 public bool IsNewSession {
116 get { return newSession; }
119 public bool IsReadOnly {
120 get { return isReadOnly; }
123 public bool IsSynchronized {
124 get { return false; }
127 object IHttpSessionState.this [int index] {
129 if (sessionItems == null || sessionItems.Count == 0)
131 return sessionItems [index];
135 if (sessionItems != null)
136 sessionItems [index] = value;
140 object IHttpSessionState.this [string name] {
142 if (sessionItems == null || sessionItems.Count == 0)
144 return sessionItems [name];
148 if (sessionItems != null)
149 sessionItems [name] = value;
153 NameObjectCollectionBase.KeysCollection IHttpSessionState.Keys {
155 if (sessionItems != null)
156 return sessionItems.Keys;
162 get { return Thread.CurrentThread.CurrentCulture.LCID; }
163 set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
166 public SessionStateMode Mode {
170 public string SessionID {
174 public HttpStaticObjectsCollection StaticObjects {
175 get { return staticObjects; }
178 public Object SyncRoot {
183 get { return timeout; }
186 throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
191 internal void SetNewSession (bool value)
196 public void Abandon ()
201 public void Add (string name, Object value)
203 if (sessionItems == null)
205 sessionItems [name] = value;
210 if (sessionItems == null)
212 sessionItems.Clear ();
215 public void CopyTo (Array array, int index)
217 if (sessionItems == null)
219 NameObjectCollectionBase.KeysCollection all = sessionItems.Keys;
220 for (int i = 0; i < all.Count; i++)
221 array.SetValue (all.Get(i), i + index);
224 public IEnumerator GetEnumerator ()
226 if (sessionItems == null)
228 return sessionItems.GetEnumerator ();
231 public void Remove (string name)
233 if (sessionItems == null)
235 sessionItems.Remove (name);
238 public void RemoveAll ()
240 if (sessionItems == null)
242 sessionItems.Clear ();
245 public void RemoveAt (int index)
247 if (sessionItems == null)
249 sessionItems.RemoveAt (index);