HttpSessionState.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // System.Web.SessionState.HttpSessionState
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Specialized;
  12. using System.Globalization;
  13. using System.Threading;
  14. namespace System.Web.SessionState {
  15. public sealed class HttpSessionState : ICollection, IEnumerable
  16. {
  17. private string _id;
  18. private SessionDictionary _dict;
  19. private HttpStaticObjectsCollection _staticObjects;
  20. private int _timeout;
  21. private bool _newSession;
  22. private bool _isCookieless;
  23. private SessionStateMode _mode;
  24. private bool _isReadonly;
  25. private bool _abandoned;
  26. internal HttpSessionState (string id,
  27. SessionDictionary dict,
  28. HttpStaticObjectsCollection staticObjects,
  29. int timeout,
  30. bool newSession,
  31. bool isCookieless,
  32. SessionStateMode mode,
  33. bool isReadonly)
  34. {
  35. _id = id;
  36. _dict = dict;
  37. _staticObjects = staticObjects;
  38. _timeout = timeout;
  39. _newSession = newSession;
  40. _isCookieless = isCookieless;
  41. _mode = mode;
  42. _isReadonly = isReadonly;
  43. }
  44. // Compatibility with ASP
  45. public int CodePage
  46. {
  47. get { return 0; }
  48. set { }
  49. }
  50. public HttpSessionState Contents
  51. {
  52. get { return this; }
  53. }
  54. public int Count
  55. {
  56. get { return _dict.Count; }
  57. }
  58. internal bool IsAbandoned
  59. {
  60. get { return _abandoned; }
  61. }
  62. public bool IsCookieless
  63. {
  64. get { return _isCookieless; }
  65. }
  66. public bool IsNewSession
  67. {
  68. get { return _newSession; }
  69. }
  70. public bool IsReadOnly
  71. {
  72. get { return _isReadonly; }
  73. }
  74. public bool IsSynchronized
  75. {
  76. get { return false; }
  77. }
  78. public object this [string key]
  79. {
  80. get { return _dict [key]; }
  81. set { _dict [key] = value; }
  82. }
  83. public object this [int index]
  84. {
  85. get { return _dict [index]; }
  86. set {
  87. string key = _dict.Keys [index];
  88. _dict [key] = value;
  89. }
  90. }
  91. public NameObjectCollectionBase.KeysCollection Keys
  92. {
  93. get { return _dict.Keys; }
  94. }
  95. public int LCID
  96. {
  97. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  98. set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
  99. }
  100. public SessionStateMode Mode
  101. {
  102. get { return _mode; }
  103. }
  104. public string SessionID
  105. {
  106. get { return _id; }
  107. }
  108. public HttpStaticObjectsCollection StaticObjects
  109. {
  110. get { return _staticObjects; }
  111. }
  112. public object SyncRoot
  113. {
  114. get { return this; }
  115. }
  116. public int Timeout
  117. {
  118. get { return _timeout; }
  119. set { _timeout = value; }
  120. }
  121. public void Abandon ()
  122. {
  123. _abandoned = true;
  124. }
  125. public void Add (string name, object value)
  126. {
  127. _dict [name] = value;
  128. }
  129. public void Clear ()
  130. {
  131. if (_dict != null)
  132. _dict.Clear ();
  133. }
  134. public void CopyTo (Array array, int index)
  135. {
  136. NameObjectCollectionBase.KeysCollection all = Keys;
  137. for (int i = 0; i < all.Count; i++)
  138. array.SetValue (_dict [all [i]], i + index);
  139. }
  140. public IEnumerator GetEnumerator ()
  141. {
  142. return _dict.GetEnumerator ();
  143. }
  144. public void Remove (string name)
  145. {
  146. _dict.Remove (name);
  147. }
  148. public void RemoveAll ()
  149. {
  150. _dict.Clear ();
  151. }
  152. public void RemoveAt (int index)
  153. {
  154. _dict.RemoveAt (index);
  155. }
  156. }
  157. }