/[dgee]/dgee/cslib/System/Web/HttpApplicationState.cs
ViewVC logotype

Diff of /dgee/cslib/System/Web/HttpApplicationState.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by npg, Mon Jul 7 16:23:52 2003 UTC revision 1.2 by csmith, Sun Sep 21 10:55:48 2003 UTC
# Line 0  Line 1 
1    /**
2     * System.Web.HttpApplicationState
3     *
4     * This program is free software; you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation; either version 2 of the License, or
7     * (at your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the Free Software
16     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17     *
18     * Author: Patrik Torstensson (Patrik.Torstensson@labs2.com)
19     * Modifications: Michael Moore (mtmoore@uga.edu)
20     */
21    
22    using System;
23    using System.Threading;
24    using System.Web;
25    using System.Collections.Specialized;
26    
27    namespace System.Web {
28    
29    
30       [Serializable]
31       public sealed class HttpApplicationState : NameObjectCollectionBase
32       {
33          private HttpStaticObjectsCollection _AppObjects;
34          private HttpStaticObjectsCollection _SessionObjects;
35    
36    
37          public string [] AllKeys
38          {
39             get
40             {
41                string [] ret = null;
42    
43                LockRead();
44                try {
45                   ret = BaseGetAllKeys();
46                }
47                finally {
48                   UnlockRead();
49                }    
50    
51                return ret;
52             }
53          }
54    
55          public HttpApplicationState Contents
56          {
57             get
58             {
59                return this;
60             }
61          }
62    
63          override public int Count
64          {
65             get
66             {
67                int ret = 0;
68    
69                LockRead();
70                try {
71                   ret = base.Count;
72                }
73                finally {
74                   UnlockRead();
75                }    
76    
77                return ret;
78             }
79          }  
80    
81          public object this[string name]
82          {
83             get
84             {
85                return Get(name);
86             }
87             set
88             {
89                Set(name, value);
90             }
91          }
92    
93          public object this[int index]
94          {
95             get
96             {
97                return Get(index);
98             }
99          }
100    
101          //  ASP Session based objects
102          internal HttpStaticObjectsCollection SessionObjects
103          {
104             get
105             {
106                return _SessionObjects;
107             }
108          }
109    
110          //  ASP App based objects
111          public HttpStaticObjectsCollection StaticObjects
112          {
113             get
114             {
115                return _AppObjects;
116             }
117          }
118    
119    
120          // TODO : Change to ReadWriteLock when ready
121          private Mutex _Lock;
122    
123          private void LockRead()
124          {
125             Monitor.Enter(this);
126          }
127    
128          private void LockWrite()
129          {
130             Monitor.Enter(this);
131          }
132    
133          private void UnlockRead()
134          {
135             Monitor.Exit(this);
136          }
137    
138          private void UnlockWrite()  
139          {
140             Monitor.Exit(this);
141          }
142                    /** internal */
143          
144          public HttpApplicationState()
145          {
146             _AppObjects = new HttpStaticObjectsCollection();
147             _SessionObjects = new HttpStaticObjectsCollection();
148             _Lock = new Mutex();
149          }
150    
151          internal HttpApplicationState(HttpStaticObjectsCollection AppObj, HttpStaticObjectsCollection SessionObj)
152          {
153             if (null != AppObj)
154             {
155                _AppObjects = AppObj;
156             }
157             else
158             {
159                _AppObjects = new HttpStaticObjectsCollection();
160             }
161    
162             if (null != SessionObj)
163             {
164                _SessionObjects = SessionObj;
165             }
166             else
167             {
168                _SessionObjects = new HttpStaticObjectsCollection();
169             }
170             _Lock = new Mutex();
171          }
172    
173          public void Add(string name, object value)
174          {
175    
176             LockWrite();
177             try {
178                BaseAdd(name, value);
179             }
180             finally {
181                UnlockWrite();
182             }
183          }
184    
185          public void Clear()
186          {
187    
188             LockWrite();
189             try {
190                BaseClear();
191             }
192             finally {
193                UnlockWrite();
194             }
195          }
196    
197          public object Get(string name)
198          {
199             object ret = null;
200    
201             LockRead();
202             try {
203                ret = BaseGet(name);
204             }
205             finally {
206                UnlockRead();
207             }
208    
209             return ret;
210          }
211    
212          public object Get(int index)
213          {
214             object ret = null;
215            
216             LockRead();
217             try {
218                ret = BaseGet(index);
219             }
220             finally {
221                UnlockRead();
222             }
223    
224             return ret;
225          }  
226    
227          public string GetKey(int index)
228          {
229             string ret = null;
230    
231             LockRead();
232             try {
233                ret = BaseGetKey(index);
234             }
235             finally {
236                UnlockRead();
237             }
238    
239             return ret;
240          }      
241    
242          public void Lock()
243          {
244             LockWrite();
245          }
246    
247          public void Remove(string name)
248          {
249             LockWrite();
250             try {
251                BaseRemove(name);
252             }
253             finally {
254                UnlockWrite();
255             }      
256          }
257    
258          public void RemoveAll()
259          {
260             Clear();
261          }
262    
263          public void RemoveAt(int index)
264          {
265             LockWrite();
266             try {
267                BaseRemoveAt(index);
268             }
269             finally {
270                UnlockWrite();
271             }      
272          }
273    
274          public void Set(string name, object value)
275          {
276             LockWrite();
277             try {
278                BaseSet(name, value);
279             }
280             finally {
281                UnlockWrite();
282             }      
283          }  
284          
285          public void UnLock()
286          {
287             UnlockWrite();
288          }
289       }
290    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26