2 // System.Web.HttpApplicationState
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System
.Threading
;
31 using System
.Collections
.Specialized
;
36 public sealed class HttpApplicationState
: NameObjectCollectionBase
38 private HttpStaticObjectsCollection _AppObjects
;
39 private HttpStaticObjectsCollection _SessionObjects
;
41 private ReaderWriterLock _Lock
;
43 internal HttpApplicationState ()
45 _AppObjects
= new HttpStaticObjectsCollection ();
46 _SessionObjects
= new HttpStaticObjectsCollection ();
47 _Lock
= new ReaderWriterLock ();
50 internal HttpApplicationState (HttpStaticObjectsCollection AppObj
,
51 HttpStaticObjectsCollection SessionObj
)
59 _AppObjects
= new HttpStaticObjectsCollection ();
62 if (null != SessionObj
)
64 _SessionObjects
= SessionObj
;
68 _SessionObjects
= new HttpStaticObjectsCollection ();
70 _Lock
= new ReaderWriterLock ();
73 public void Add (string name
, object value)
75 _Lock
.AcquireWriterLock (-1);
78 BaseAdd (name
, value);
82 _Lock
.ReleaseWriterLock ();
88 _Lock
.AcquireWriterLock (-1);
95 _Lock
.ReleaseWriterLock ();
99 public object Get (string name
)
103 _Lock
.AcquireReaderLock (-1);
106 ret
= BaseGet (name
);
110 _Lock
.ReleaseReaderLock ();
116 public object Get (int index
)
120 _Lock
.AcquireReaderLock (-1);
123 ret
= BaseGet (index
);
127 _Lock
.ReleaseReaderLock ();
133 public string GetKey (int index
)
137 _Lock
.AcquireReaderLock (-1);
140 ret
= BaseGetKey (index
);
144 _Lock
.ReleaseReaderLock ();
152 _Lock
.AcquireWriterLock (-1);
155 public void Remove (string name
)
157 _Lock
.AcquireWriterLock (-1);
164 _Lock
.ReleaseWriterLock ();
168 public void RemoveAll ()
173 public void RemoveAt (int index
)
175 _Lock
.AcquireWriterLock (-1);
178 BaseRemoveAt (index
);
182 _Lock
.ReleaseWriterLock ();
186 public void Set (string name
, object value)
188 _Lock
.AcquireWriterLock (-1);
191 BaseSet (name
, value);
195 _Lock
.ReleaseWriterLock ();
199 public void UnLock ()
201 _Lock
.ReleaseWriterLock ();
204 public string [] AllKeys
208 string [] ret
= null;
210 _Lock
.AcquireReaderLock (-1);
213 ret
= BaseGetAllKeys ();
217 _Lock
.ReleaseReaderLock ();
224 public HttpApplicationState Contents
229 public override int Count
235 _Lock
.AcquireReaderLock (-1);
242 _Lock
.ReleaseReaderLock ();
249 public object this [string name
]
251 get { return Get (name); }
252 set { Set (name, value); }
255 public object this [int index
]
257 get { return Get (index); }
260 // ASP Session based objects
261 internal HttpStaticObjectsCollection SessionObjects
263 get { return _SessionObjects; }
266 // ASP App based objects
267 public HttpStaticObjectsCollection StaticObjects
269 get { return _AppObjects; }