HttpSessionState.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // System.Web.SessionState.HttpSessionState
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 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 NameValueCollection _state; //FIXME: it should be a ManagementNamedValueCollection
  18. private string _id;
  19. private SessionDictionary _dict;
  20. private HttpStaticObjectsCollection _staticObjects;
  21. private int _timeout;
  22. private bool _newSession;
  23. private bool _isCookieless;
  24. private SessionStateMode _mode;
  25. private bool _isReadonly;
  26. private bool _abandoned;
  27. internal HttpSessionState (string id,
  28. SessionDictionary dict,
  29. HttpStaticObjectsCollection staticObjects,
  30. int timeout,
  31. bool newSession,
  32. bool isCookieless,
  33. SessionStateMode mode,
  34. bool isReadonly)
  35. {
  36. _id = id;
  37. _dict = dict;
  38. _staticObjects = staticObjects;
  39. _timeout = timeout;
  40. _newSession = newSession;
  41. _isCookieless = isCookieless;
  42. _mode = mode;
  43. _isReadonly = isReadonly;
  44. }
  45. // Compatibility with ASP
  46. public int CodePage
  47. {
  48. get { return 0; }
  49. set { }
  50. }
  51. public HttpSessionState Contents
  52. {
  53. get { return this; }
  54. }
  55. public int Count
  56. {
  57. get { return _state.Count; }
  58. }
  59. internal bool IsAbandoned
  60. {
  61. get { return _abandoned; }
  62. }
  63. public bool IsCookieless
  64. {
  65. get { return _isCookieless; }
  66. }
  67. public bool IsNewSession
  68. {
  69. get { return _newSession; }
  70. }
  71. public bool IsReadOnly
  72. {
  73. get { return _isReadonly; }
  74. }
  75. public bool IsSynchronized
  76. {
  77. get { return false; }
  78. }
  79. public object this [string key]
  80. {
  81. get { return _state [key]; }
  82. set { _state [key] = (string) value; }
  83. }
  84. public object this [int index]
  85. {
  86. get { return _state [index]; }
  87. set {
  88. string key = _state.Keys [index];
  89. _state [key] = (string) value;
  90. }
  91. }
  92. public NameObjectCollectionBase.KeysCollection Keys
  93. {
  94. get { return _state.Keys; }
  95. }
  96. public int LCID
  97. {
  98. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  99. set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
  100. }
  101. public SessionStateMode Mode
  102. {
  103. get { return _mode; }
  104. }
  105. public string SessionID
  106. {
  107. get { return _id; }
  108. }
  109. public HttpStaticObjectsCollection StaticObjects
  110. {
  111. get { return _staticObjects; }
  112. }
  113. public object SyncRoot
  114. {
  115. get { return this; }
  116. }
  117. public int Timeout
  118. {
  119. get { return _timeout; }
  120. set { _timeout = value; }
  121. }
  122. public void Abandon ()
  123. {
  124. _abandoned = true;
  125. }
  126. public void Add (string name, object value)
  127. {
  128. if (_state == null)
  129. _state = new NameValueCollection ();
  130. _state.Add (name, (string) value);
  131. }
  132. public void Clear ()
  133. {
  134. if (_state != null)
  135. _state.Clear ();
  136. }
  137. public void CopyTo (Array array, int index)
  138. {
  139. if (_state == null)
  140. _state = new NameValueCollection ();
  141. _state.CopyTo (array, index);
  142. }
  143. public IEnumerator GetEnumerator ()
  144. {
  145. if (_state == null)
  146. _state = new NameValueCollection ();
  147. return _state.GetEnumerator ();
  148. }
  149. public void Remove (string name)
  150. {
  151. if (_state != null)
  152. _state.Remove (name);
  153. }
  154. public void RemoveAll ()
  155. {
  156. if (_state != null)
  157. foreach (string key in _state.AllKeys)
  158. _state.Remove (key);
  159. }
  160. [MonoTODO("Implement ManagementNameValueCollection")]
  161. public void RemoveAt (int index)
  162. {
  163. throw new NotImplementedException ();
  164. //if (_state != null)
  165. // _state.RemoveAt (index);
  166. }
  167. }
  168. }