/// <summary> /// Initializes a new instance of the <see cref="SocketService"/> class. /// </summary> /// <param name="loggerFactory">The factory used to create loggers.</param> /// <param name="middleware">The <see cref="IMiddleware"/> to include first in the application pipeline.</param> /// <param name="configure">The configuration options of <see cref="SocketService"/> specific features.</param> public SocketService(ILoggerFactory loggerFactory, IMiddleware middleware, ServerOptionsDelegate configure) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } _logger = loggerFactory.CreateLogger("Bytewizer.TinyCLR.Sockets"); var options = new ServerOptions(); if (middleware != null) { options.Pipeline(app => { app.Use(middleware); }); } configure(options); Application = options.Application; _listener = new SocketListener(options.Listener); _listener.Connected += ClientConnected; _listener.Disconnected += ClientDisconnected; Options = options; }
/// <summary> /// Adds and configures a socket server application. /// </summary> public static IHostBuilder ConfigureHost(this IHostBuilder builder, ServerOptionsDelegate options) { var server = new SocketServer(options); builder.ConfigureServices((context, services) => services.AddSingleton(typeof(IServer), server)); builder.ConfigureServices((context, services) => services.AddHostedService(typeof(SocketHostService))); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="SocketService"/> class. /// </summary> /// <param name="configure">The configuration options of <see cref="SocketService"/> specific features.</param> /// <param name="filter"> /// The request <see cref="Middleware"/> to add to the pipeline. /// Filters are executed in the order they are added. /// </param> public SocketService(ServerOptionsDelegate configure, IMiddleware filter) { var options = new ServerOptions(); if (filter != null) { options.Register(filter); } configure(options); Options = options; _listener = new SocketListener(Options.Listener); _listener.Connected += ClientConnected; Pipeline = ((ApplicationBuilder)Options.Pipeline).Build(); }
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="loggerFactory">The factory used to create loggers.</param> /// <param name="middleware">The <see cref="IMiddleware"/> to include in the application pipeline.</param> /// <param name="configure">The configuration options of <see cref="HttpServer"/> specific features.</param> public HttpServer(ILoggerFactory loggerFactory, IMiddleware middleware, ServerOptionsDelegate configure) : base(loggerFactory, middleware, configure) { _logger = loggerFactory.CreateLogger("Bytewizer.TinyCLR.Http"); }
/// <summary> /// Initializes a new instance of the <see cref="SocketServer"/> class. /// </summary> /// <param name="loggerFactory">The factory used to create loggers.</param> /// <param name="configure">The configuration options of <see cref="SocketServer"/> specific features.</param> public HttpServer(ILoggerFactory loggerFactory, ServerOptionsDelegate configure) : this(loggerFactory, new HttpMiddleware(), configure) { }
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="configure">The configuration options of <see cref="HttpServer"/> specific features.</param> public HttpServer(ServerOptionsDelegate configure) : this(NullLoggerFactory.Instance, new HttpMiddleware(), configure) { }
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="configure">The configuration options of <see cref="HttpServer"/> specific features.</param> public HttpServer(ServerOptionsDelegate configure) : base(configure, new HttpMiddleware()) { }
/// <summary> /// Initializes a new instance of the <see cref="SocketServer"/> class. /// </summary> /// <param name="configure">The configuration options of <see cref="SocketServer"/> specific features.</param> public SocketServer(ServerOptionsDelegate configure) : base(configure) { }
/// <summary> /// Initializes a new instance of the <see cref="SocketService"/> class. /// </summary> /// <param name="configure">The configuration options of <see cref="SocketService"/> specific features.</param> public SocketService(ServerOptionsDelegate configure) : this(configure, null) { }
/// <summary> /// Initializes a new instance of the <see cref="SocketServer"/> class. /// </summary> /// <param name="loggerFactory">The factory used to create loggers.</param> /// <param name="configure">The configuration options of <see cref="SocketServer"/> specific features.</param> public SocketServer(ILoggerFactory loggerFactory, ServerOptionsDelegate configure) : this(loggerFactory, null, configure) { }
/// <summary> /// Initializes a new instance of the <see cref="SocketServer"/> class. /// </summary> /// <param name="configure">The configuration options of <see cref="SocketServer"/> specific features.</param> public SocketServer(ServerOptionsDelegate configure) : this(NullLoggerFactory.Instance, null, configure) { }