1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Adapters
18 using System
.Collections
;
19 using System
.Web
.SessionState
;
22 /// Adapts the ASP.Net session as a simple dictionary for MonoRail
24 public class SessionAdapter
: MarshalByRefObject
, IDictionary
26 private HttpSessionState _session
;
29 /// Initializes a new instance of the <see cref="SessionAdapter"/> class.
31 /// <param name="session">The session.</param>
32 public SessionAdapter( HttpSessionState session
)
38 /// Returns an <see cref="T:System.Collections.IDictionaryEnumerator"></see> object for the <see cref="T:System.Collections.IDictionary"></see> object.
41 /// An <see cref="T:System.Collections.IDictionaryEnumerator"></see> object for the <see cref="T:System.Collections.IDictionary"></see> object.
43 IDictionaryEnumerator IDictionary
.GetEnumerator()
45 throw new NotImplementedException();
49 /// Gets an <see cref="T:System.Collections.ICollection"></see> object containing the keys of the <see cref="T:System.Collections.IDictionary"></see> object.
52 /// <returns>An <see cref="T:System.Collections.ICollection"></see> object containing the keys of the <see cref="T:System.Collections.IDictionary"></see> object.</returns>
53 public ICollection Keys
55 get { return _session.Keys; }
59 /// Copies the elements of the <see cref="T:System.Collections.ICollection"></see> to an <see cref="T:System.Array"></see>, starting at a particular <see cref="T:System.Array"></see> index.
61 /// <param name="array">The one-dimensional <see cref="T:System.Array"></see> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"></see>. The <see cref="T:System.Array"></see> must have zero-based indexing.</param>
62 /// <param name="index">The zero-based index in array at which copying begins.</param>
63 /// <exception cref="T:System.ArgumentNullException">array is null. </exception>
64 /// <exception cref="T:System.ArgumentOutOfRangeException">index is less than zero. </exception>
65 /// <exception cref="T:System.ArgumentException">array is multidimensional.-or- index is equal to or greater than the length of array.-or- The number of elements in the source <see cref="T:System.Collections.ICollection"></see> is greater than the available space from index to the end of the destination array. </exception>
66 /// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.ICollection"></see> cannot be cast automatically to the type of the destination array. </exception>
67 public void CopyTo(Array array
, int index
)
69 throw new NotImplementedException();
73 /// Gets the number of elements contained in the <see cref="T:System.Collections.ICollection"></see>.
76 /// <returns>The number of elements contained in the <see cref="T:System.Collections.ICollection"></see>.</returns>
79 get { return _session.Count; }
83 /// Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.
86 /// <returns>An object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.</returns>
87 public object SyncRoot
89 get { return _session.SyncRoot; }
93 /// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe).
96 /// <returns>true if access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe); otherwise, false.</returns>
97 public bool IsSynchronized
99 get { return _session.IsSynchronized; }
103 /// Returns an enumerator that iterates through a collection.
106 /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
108 public IEnumerator
GetEnumerator()
110 return _session
.GetEnumerator();
114 /// Determines whether the <see cref="T:System.Collections.IDictionary"></see> object contains an element with the specified key.
116 /// <param name="key">The key to locate in the <see cref="T:System.Collections.IDictionary"></see> object.</param>
118 /// true if the <see cref="T:System.Collections.IDictionary"></see> contains an element with the key; otherwise, false.
120 /// <exception cref="T:System.ArgumentNullException">key is null. </exception>
121 public bool Contains( object key
)
123 return _session
[ (String
)key
] != null;
127 /// Adds an element with the provided key and value to the <see cref="T:System.Collections.IDictionary"></see> object.
129 /// <param name="key">The <see cref="T:System.Object"></see> to use as the key of the element to add.</param>
130 /// <param name="value">The <see cref="T:System.Object"></see> to use as the value of the element to add.</param>
131 /// <exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.IDictionary"></see> object. </exception>
132 /// <exception cref="T:System.ArgumentNullException">key is null. </exception>
133 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.IDictionary"></see> is read-only.-or- The <see cref="T:System.Collections.IDictionary"></see> has a fixed size. </exception>
134 public void Add( object key
, object value )
136 _session
.Add( (String
)key
, value );
140 /// Removes all elements from the <see cref="T:System.Collections.IDictionary"></see> object.
142 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.IDictionary"></see> object is read-only. </exception>
149 /// Removes the element with the specified key from the <see cref="T:System.Collections.IDictionary"></see> object.
151 /// <param name="key">The key of the element to remove.</param>
152 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.IDictionary"></see> object is read-only.-or- The <see cref="T:System.Collections.IDictionary"></see> has a fixed size. </exception>
153 /// <exception cref="T:System.ArgumentNullException">key is null. </exception>
154 public void Remove( object key
)
156 _session
.Remove( (String
)key
);
160 /// Gets an <see cref="T:System.Collections.ICollection"></see> object containing the values in the <see cref="T:System.Collections.IDictionary"></see> object.
163 /// <returns>An <see cref="T:System.Collections.ICollection"></see> object containing the values in the <see cref="T:System.Collections.IDictionary"></see> object.</returns>
164 public ICollection Values
166 get { throw new NotImplementedException(); }
170 /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"></see> object is read-only.
173 /// <returns>true if the <see cref="T:System.Collections.IDictionary"></see> object is read-only; otherwise, false.</returns>
174 public bool IsReadOnly
176 get { return _session.IsReadOnly; }
180 /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"></see> object has a fixed size.
183 /// <returns>true if the <see cref="T:System.Collections.IDictionary"></see> object has a fixed size; otherwise, false.</returns>
184 public bool IsFixedSize
186 get { return false; }
190 /// Gets or sets the <see cref="System.Object"/> with the specified key.
193 public object this[ object key
]
195 get { return _session[ (String)key ]; }
198 _session
[ (String
)key
] = value;