1 #define EMBEDDED_IN_1_0
4 // System.Net.HttpListenerPrefixCollection.cs
7 // Gonzalo Paniagua Javier (gonzalo@novell.com)
9 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Generic;
34 using System; using System.Net; namespace MonoHttp {
36 internal class HttpListenerPrefixCollection : IEnumerable, ICollection {
40 internal class HttpListenerPrefixCollection : ICollection<string>, IEnumerable<string>, IEnumerable {
41 List<string> prefixes = new List<string> ();
43 HttpListener listener;
45 internal HttpListenerPrefixCollection (HttpListener listener)
47 this.listener = listener;
51 get { return prefixes.Count; }
54 public bool IsReadOnly {
58 public bool IsSynchronized {
62 public void Add (string uriPrefix)
64 listener.CheckDisposed ();
65 ListenerPrefix.CheckUri (uriPrefix);
66 if (prefixes.Contains (uriPrefix))
69 prefixes.Add (uriPrefix);
70 if (listener.IsListening)
71 EndPointManager.AddPrefix (uriPrefix, listener);
76 listener.CheckDisposed ();
78 if (listener.IsListening)
79 EndPointManager.RemoveListener (listener);
82 public bool Contains (string uriPrefix)
84 listener.CheckDisposed ();
85 return prefixes.Contains (uriPrefix);
88 public void CopyTo (string [] array, int offset)
90 listener.CheckDisposed ();
91 prefixes.CopyTo (array, offset);
94 public void CopyTo (Array array, int offset)
96 listener.CheckDisposed ();
97 ((ICollection) prefixes).CopyTo (array, offset);
101 public IEnumerator<string> GetEnumerator ()
103 return prefixes.GetEnumerator ();
106 object ICollection.SyncRoot { get { return this; } }
109 IEnumerator IEnumerable.GetEnumerator ()
111 return prefixes.GetEnumerator ();
114 public bool Remove (string uriPrefix)
116 listener.CheckDisposed ();
117 if (uriPrefix == null)
118 throw new ArgumentNullException ("uriPrefix");
120 bool result = prefixes.Contains (uriPrefix); if (result) prefixes.Remove (uriPrefix);;
121 if (result && listener.IsListening)
122 EndPointManager.RemovePrefix (uriPrefix, listener);