[Modify] Replace it

This commit is contained in:
sta 2017-06-07 15:02:21 +09:00
parent c4f13a5c50
commit 8b5f19e2fc

View File

@ -1084,43 +1084,96 @@ namespace WebSocketSharp.Server
#region Public Methods #region Public Methods
/// <summary> /// <summary>
/// Adds the WebSocket service with the specified behavior, <paramref name="path"/>, /// Adds a WebSocket service with the specified behavior,
/// and <paramref name="initializer"/>. /// <paramref name="path"/>, and <paramref name="creator"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <paramref name="path"/> is converted to a URL-decoded string and
/// This method converts <paramref name="path"/> to URL-decoded string, /// '/' is trimmed from the end of the converted string if any.
/// and removes <c>'/'</c> from tail end of <paramref name="path"/>.
/// </para>
/// <para>
/// <paramref name="initializer"/> returns an initialized specified typed
/// <see cref="WebSocketBehavior"/> instance.
/// </para>
/// </remarks> /// </remarks>
/// <param name="path"> /// <param name="path">
/// A <see cref="string"/> that represents the absolute path to the service to add. /// A <see cref="string"/> that represents an absolute path to
/// the service to add.
/// </param> /// </param>
/// <param name="initializer"> /// <param name="creator">
/// A <c>Func&lt;T&gt;</c> delegate that references the method used to initialize /// <para>
/// a new specified typed <see cref="WebSocketBehavior"/> instance (a new /// A <c>Func&lt;TBehavior&gt;</c> delegate.
/// <see cref="IWebSocketSession"/> instance). /// </para>
/// <para>
/// It invokes the method called for creating
/// a new session instance for the service.
/// </para>
/// <para>
/// The method must create a new instance of
/// the specified behavior class and return it.
/// </para>
/// </param> /// </param>
/// <typeparam name="TBehavior"> /// <typeparam name="TBehavior">
/// The type of the behavior of the service to add. The TBehavior must inherit /// <para>
/// the <see cref="WebSocketBehavior"/> class. /// The type of the behavior for the service.
/// </para>
/// <para>
/// It must inherit the <see cref="WebSocketBehavior"/> class.
/// </para>
/// </typeparam> /// </typeparam>
public void AddWebSocketService<TBehavior> (string path, Func<TBehavior> initializer) /// <exception cref="ArgumentNullException">
/// <para>
/// <paramref name="path"/> is <see langword="null"/>.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="creator"/> is <see langword="null"/>.
/// </para>
/// </exception>
/// <exception cref="ArgumentException">
/// <para>
/// <paramref name="path"/> is an empty string.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="path"/> is not an absolute path.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="path"/> includes either or both
/// query and fragment components.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="path"/> is already in use.
/// </para>
/// </exception>
public void AddWebSocketService<TBehavior> (
string path, Func<TBehavior> creator
)
where TBehavior : WebSocketBehavior where TBehavior : WebSocketBehavior
{ {
var msg = path.CheckIfValidServicePath () ?? if (path == null)
(initializer == null ? "'initializer' is null." : null); throw new ArgumentNullException ("path");
if (msg != null) { if (creator == null)
_log.Error (msg); throw new ArgumentNullException ("creator");
return;
if (path.Length == 0)
throw new ArgumentException ("An empty string.", "path");
if (path[0] != '/')
throw new ArgumentException ("Not an absolute path.", "path");
if (path.IndexOfAny (new[] { '?', '#' }) > -1) {
var msg = "It includes either or both query and fragment components.";
throw new ArgumentException (msg, "path");
} }
_services.Add<TBehavior> (path, initializer); _services.Add<TBehavior> (path, creator);
} }
/// <summary> /// <summary>