From 99f7c9616ef807332e95d70ee286d8a4e48cc65c Mon Sep 17 00:00:00 2001 From: sta Date: Sat, 12 Apr 2014 17:59:40 +0900 Subject: [PATCH] Refactored HttpListenerPrefixCollection.cs --- .../Net/HttpListenerPrefixCollection.cs | 518 +++++++++--------- 1 file changed, 267 insertions(+), 251 deletions(-) diff --git a/websocket-sharp/Net/HttpListenerPrefixCollection.cs b/websocket-sharp/Net/HttpListenerPrefixCollection.cs index b83a254f..170ac3c8 100644 --- a/websocket-sharp/Net/HttpListenerPrefixCollection.cs +++ b/websocket-sharp/Net/HttpListenerPrefixCollection.cs @@ -1,32 +1,41 @@ -// -// HttpListenerPrefixCollection.cs -// Copied from System.Net.HttpListenerPrefixCollection.cs -// -// Author: -// Gonzalo Paniagua Javier (gonzalo@novell.com) -// -// Copyright (c) 2005 Novell, Inc. (http://www.novell.com) -// Copyright (c) 2012-2013 sta.blockhead -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// +#region License +/* + * HttpListenerPrefixCollection.cs + * + * This code is derived from System.Net.HttpListenerPrefixCollection.cs of Mono + * (http://www.mono-project.com). + * + * The MIT License + * + * Copyright (c) 2005 Novell, Inc. (http://www.novell.com) + * Copyright (c) 2012-2014 sta.blockhead + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#endregion + +#region Authors +/* + * Authors: + * - Gonzalo Paniagua Javier + */ +#endregion using System; using System.Collections; @@ -34,255 +43,262 @@ using System.Collections.Generic; namespace WebSocketSharp.Net { - /// - /// Provides the collection used to store the URI prefixes for the . - /// - public class HttpListenerPrefixCollection : ICollection, IEnumerable, IEnumerable - { - #region Private Fields + /// + /// Provides the collection used to store the URI prefixes for the . + /// + /// + /// The responds to the request which has a requested URI that + /// the prefixes most closely match. + /// + public class HttpListenerPrefixCollection + : ICollection, IEnumerable, IEnumerable + { + #region Private Fields - private HttpListener _listener; - private List _prefixes; + private HttpListener _listener; + private List _prefixes; - #endregion + #endregion - #region Private Constructors + #region Private Constructors - private HttpListenerPrefixCollection () - { - _prefixes = new List (); - } + private HttpListenerPrefixCollection () + { + _prefixes = new List (); + } - #endregion + #endregion - #region Internal Constructors + #region Internal Constructors - internal HttpListenerPrefixCollection (HttpListener listener) - : this () - { - _listener = listener; - } + internal HttpListenerPrefixCollection (HttpListener listener) + : this () + { + _listener = listener; + } - #endregion + #endregion - #region Public Properties + #region Public Properties - /// - /// Gets the number of prefixes contained in the . - /// - /// - /// A that contains the number of prefixes. - /// - public int Count { - get { - return _prefixes.Count; - } - } + /// + /// Gets the number of prefixes contained in the . + /// + /// + /// An that represents the number of prefixes. + /// + public int Count { + get { + return _prefixes.Count; + } + } - /// - /// Gets a value indicating whether access to the - /// is read-only. - /// - /// - /// Always returns false. - /// - public bool IsReadOnly { - get { - return false; - } - } + /// + /// Gets a value indicating whether the access to the + /// is read-only. + /// + /// + /// Always returns false. + /// + public bool IsReadOnly { + get { + return false; + } + } - /// - /// Gets a value indicating whether access to the - /// is synchronized. - /// - /// - /// Always returns false. - /// - public bool IsSynchronized { - get { - return false; - } - } + /// + /// Gets a value indicating whether the access to the + /// is synchronized. + /// + /// + /// Always returns false. + /// + public bool IsSynchronized { + get { + return false; + } + } - #endregion + #endregion - #region Public Methods + #region Public Methods - /// - /// Adds the specified to the . - /// - /// - /// A that contains a URI prefix to add. - /// - /// - /// is . - /// - /// - /// is invalid. - /// - /// - /// The associated with this - /// is closed. - /// - public void Add (string uriPrefix) - { - _listener.CheckDisposed (); - ListenerPrefix.CheckUriPrefix (uriPrefix); - if (_prefixes.Contains (uriPrefix)) - return; + /// + /// Adds the specified to + /// the . + /// + /// + /// A that represents the URI prefix to add. The prefix must be + /// a well-formed URI prefix with http or https scheme, and must be terminated with + /// a "/". + /// + /// + /// is . + /// + /// + /// is invalid. + /// + /// + /// The associated with + /// this is closed. + /// + public void Add (string uriPrefix) + { + _listener.CheckDisposed (); + ListenerPrefix.CheckUriPrefix (uriPrefix); + if (_prefixes.Contains (uriPrefix)) + return; - _prefixes.Add (uriPrefix); - if (_listener.IsListening) - EndPointManager.AddPrefix (uriPrefix, _listener); - } + _prefixes.Add (uriPrefix); + if (_listener.IsListening) + EndPointManager.AddPrefix (uriPrefix, _listener); + } - /// - /// Removes all URI prefixes from the . - /// - /// - /// The associated with this - /// is closed. - /// - public void Clear () - { - _listener.CheckDisposed (); - _prefixes.Clear (); - if (_listener.IsListening) - EndPointManager.RemoveListener (_listener); - } + /// + /// Removes all URI prefixes from the . + /// + /// + /// The associated with + /// this is closed. + /// + public void Clear () + { + _listener.CheckDisposed (); + _prefixes.Clear (); + if (_listener.IsListening) + EndPointManager.RemoveListener (_listener); + } - /// - /// Returns a value indicating whether the contains - /// the specified . - /// - /// - /// true if the contains ; - /// otherwise, false. - /// - /// - /// A that contains a URI prefix to test. - /// - /// - /// is . - /// - /// - /// The associated with this - /// is closed. - /// - public bool Contains (string uriPrefix) - { - _listener.CheckDisposed (); - if (uriPrefix == null) - throw new ArgumentNullException ("uriPrefix"); + /// + /// Returns a value indicating whether the contains + /// the specified . + /// + /// + /// true if the contains + /// ; otherwise, false. + /// + /// + /// A that represents the URI prefix to test. + /// + /// + /// is . + /// + /// + /// The associated with + /// this is closed. + /// + public bool Contains (string uriPrefix) + { + _listener.CheckDisposed (); + if (uriPrefix == null) + throw new ArgumentNullException ("uriPrefix"); - return _prefixes.Contains (uriPrefix); - } + return _prefixes.Contains (uriPrefix); + } - /// - /// Copies the contents of the to - /// the specified . - /// - /// - /// An that receives the URI prefix strings - /// in the . - /// - /// - /// An that contains the zero-based index in - /// at which copying begins. - /// - /// - /// The associated with this - /// is closed. - /// - public void CopyTo (Array array, int offset) - { - _listener.CheckDisposed (); - ((ICollection) _prefixes).CopyTo (array, offset); - } + /// + /// Copies the contents of the to + /// the specified . + /// + /// + /// An that receives the URI prefix strings in + /// the . + /// + /// + /// An that represents the zero-based index in + /// at which copying begins. + /// + /// + /// The associated with + /// this is closed. + /// + public void CopyTo (Array array, int offset) + { + _listener.CheckDisposed (); + ((ICollection) _prefixes).CopyTo (array, offset); + } - /// - /// Copies the contents of the to - /// the specified array of . - /// - /// - /// An array of that receives the URI prefix strings - /// in the . - /// - /// - /// An that contains the zero-based index in - /// at which copying begins. - /// - /// - /// The associated with this - /// is closed. - /// - public void CopyTo (string [] array, int offset) - { - _listener.CheckDisposed (); - _prefixes.CopyTo (array, offset); - } + /// + /// Copies the contents of the to + /// the specified array of . + /// + /// + /// An array of that receives the URI prefix strings in + /// the . + /// + /// + /// An that represents the zero-based index in + /// at which copying begins. + /// + /// + /// The associated with + /// this is closed. + /// + public void CopyTo (string [] array, int offset) + { + _listener.CheckDisposed (); + _prefixes.CopyTo (array, offset); + } - /// - /// Gets an object that can be used to iterate through the . - /// - /// - /// An object that implements the IEnumerator<string> interface and provides access to - /// the URI prefix strings in the . - /// - public IEnumerator GetEnumerator () - { - return _prefixes.GetEnumerator (); - } + /// + /// Gets the enumerator used to iterate through the . + /// + /// + /// An instance used to iterate + /// through the . + /// + public IEnumerator GetEnumerator () + { + return _prefixes.GetEnumerator (); + } - /// - /// Removes the specified from the list of prefixes - /// in the . - /// - /// - /// true if is successfully found and removed; - /// otherwise, false. - /// - /// - /// A that contains a URI prefix to remove. - /// - /// - /// is . - /// - /// - /// The associated with this - /// is closed. - /// - public bool Remove (string uriPrefix) - { - _listener.CheckDisposed (); - if (uriPrefix == null) - throw new ArgumentNullException ("uriPrefix"); + /// + /// Removes the specified from the list of prefixes in + /// the . + /// + /// + /// true if is successfully found and removed; + /// otherwise, false. + /// + /// + /// A that represents the URI prefix to remove. + /// + /// + /// is . + /// + /// + /// The associated with + /// this is closed. + /// + public bool Remove (string uriPrefix) + { + _listener.CheckDisposed (); + if (uriPrefix == null) + throw new ArgumentNullException ("uriPrefix"); - var result = _prefixes.Remove (uriPrefix); - if (result && _listener.IsListening) - EndPointManager.RemovePrefix (uriPrefix, _listener); + var result = _prefixes.Remove (uriPrefix); + if (result && _listener.IsListening) + EndPointManager.RemovePrefix (uriPrefix, _listener); - return result; - } + return result; + } - #endregion + #endregion - #region Explicit Interface Implementation + #region Explicit Interface Implementation - /// - /// Gets an object that can be used to iterate through the . - /// - /// - /// An object that implements the interface and provides access to - /// the URI prefix strings in the . - /// - IEnumerator IEnumerable.GetEnumerator () - { - return _prefixes.GetEnumerator (); - } + /// + /// Gets the enumerator used to iterate through the . + /// + /// + /// An instance used to iterate through + /// the . + /// + IEnumerator IEnumerable.GetEnumerator () + { + return _prefixes.GetEnumerator (); + } - #endregion - - } + #endregion + } }