Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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();
        }
Exemplo n.º 4
0
 /// <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");
 }
Exemplo n.º 5
0
 /// <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)
 {
 }
Exemplo n.º 6
0
 /// <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)
 {
 }
Exemplo n.º 7
0
 /// <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())
 {
 }
Exemplo n.º 8
0
 /// <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)
 {
 }
Exemplo n.º 9
0
 /// <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)
 {
 }
Exemplo n.º 10
0
 /// <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)
 {
 }
Exemplo n.º 11
0
 /// <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)
 {
 }