/// <summary> /// Adds a WebSocket service with the specified behavior, <paramref name="path"/>, /// and <paramref name="initializer"/>. /// </summary> /// <remarks> /// <para> /// This method converts <paramref name="path"/> to URL-decoded string, /// 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> /// <param name="path"> /// A <see cref="string"/> that represents the absolute path to the service to add. /// </param> /// <param name="initializer"> /// A <c>Func<T></c> delegate that references the method used to initialize /// a new specified typed <see cref="WebSocketBehavior"/> instance (a new /// <see cref="IWebSocketSession"/> instance). /// </param> /// <typeparam name="TBehavior"> /// The type of the behavior of the service to add. The TBehavior must inherit /// the <see cref="WebSocketBehavior"/> class. /// </typeparam> public void AddWebSocketService <TBehavior> (string path, Func <TBehavior> initializer) where TBehavior : WebSocketBehavior { var msg = path.CheckIfValidServicePath() ?? (initializer == null ? "'initializer' is null." : null); if (msg != null) { _logger.Error(msg); return; } _services.Add <TBehavior> (path, initializer); }
/// <summary> /// Adds the specified typed WebSocket service with the specified <paramref name="path"/> /// and <paramref name="constructor"/>. /// </summary> /// <remarks> /// <para> /// This method converts <paramref name="path"/> to URL-decoded string and removes <c>'/'</c> /// from tail end of <paramref name="path"/>. /// </para> /// <para> /// <paramref name="constructor"/> returns a initialized specified typed /// <see cref="WebSocketService"/> instance. /// </para> /// </remarks> /// <param name="path"> /// A <see cref="string"/> that represents the absolute path to the WebSocket service to add. /// </param> /// <param name="constructor"> /// A Func<T> delegate that references the method used to initialize a new specified /// typed <see cref="WebSocketService"/> instance (a new <see cref="IWebSocketSession"/> /// instance). /// </param> /// <typeparam name="T"> /// The type of the WebSocket service. The T must inherit the <see cref="WebSocketService"/> /// class. /// </typeparam> public void AddWebSocketService <T> (string path, Func <T> constructor) where T : WebSocketService { var msg = path.CheckIfValidServicePath() ?? (constructor == null ? "'constructor' must not be null." : null); if (msg != null) { _logger.Error(String.Format("{0}\nservice path: {1}", msg, path)); return; } var host = new WebSocketServiceHost <T> (path, constructor, _logger); if (!KeepClean) { host.KeepClean = false; } _services.Add(host.Path, host); }
/// <summary> /// Adds a WebSocket service with the specified behavior, <paramref name="path"/>, /// and <paramref name="initializer"/>. /// </summary> /// <remarks> /// <para> /// This method converts <paramref name="path"/> to URL-decoded string, /// 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> /// <param name="path"> /// A <see cref="string"/> that represents the absolute path to the service to add. /// </param> /// <param name="initializer"> /// A Func<T> delegate that references the method used to initialize a new specified /// typed <see cref="WebSocketBehavior"/> instance (a new <see cref="IWebSocketSession"/> /// instance). /// </param> /// <typeparam name="TBehavior"> /// The type of the behavior of the service to add. The TBehavior must inherit /// the <see cref="WebSocketBehavior"/> class. /// </typeparam> public void AddWebSocketService <TBehavior> (string path, Func <TBehavior> initializer) where TBehavior : WebSocketBehavior { var msg = path.CheckIfValidServicePath() ?? (initializer == null ? "'initializer' is null." : null); if (msg != null) { _logger.Error(String.Format("{0}\nservice path: {1}", msg, path)); return; } var host = new WebSocketServiceHost <TBehavior> (path, initializer, _logger); if (!KeepClean) { host.KeepClean = false; } _services.Add(host.Path, host); }
private void onOpen(object sender, EventArgs e) { ID = _sessions.Add(this); OnOpen(); }