Esempio n. 1
0
        public void Configure(
            IApplicationBuilder application,
            IHostingEnvironment environment,
            MqttServerService mqttServerService,
            PythonScriptHostService pythonScriptHostService,
            DataSharingService dataSharingService,
            MqttSettingsModel mqttSettings)
        {
            if (environment.IsDevelopment())
            {
                application.UseDeveloperExceptionPage();
            }
            else
            {
                application.UseHsts();
            }

            application.UseCors(x => x
                                .AllowAnyOrigin()
                                .AllowAnyMethod()
                                .AllowAnyHeader()
                                .AllowCredentials());

            application.UseAuthentication();

            application.UseStaticFiles();

            application.UseHttpsRedirection();
            application.UseMvc();

            ConfigureWebSocketEndpoint(application, mqttServerService, mqttSettings);

            dataSharingService.Configure();
            pythonScriptHostService.Configure();

            mqttServerService.Configure();

            application.UseSwagger(o => o.RouteTemplate = "/api/{documentName}/swagger.json");

            application.UseSwaggerUI(o =>
            {
                o.RoutePrefix   = "api";
                o.DocumentTitle = "MQTTnet.Server API";
                o.SwaggerEndpoint("/api/v1/swagger.json", "MQTTnet.Server API v1");
                o.DisplayRequestDuration();
                o.DocExpansion(DocExpansion.List);
                o.DefaultModelRendering(ModelRendering.Model);
            });
        }
Esempio n. 2
0
        public void Configure(
            IApplicationBuilder application,
            MqttServerService mqttServerService,
            PythonScriptHostService pythonScriptHostService,
            DataSharingService dataSharingService,
            MqttSettingsModel mqttSettings)
        {
            application.UseDefaultFiles();
            application.UseStaticFiles();

            application.UseHsts();
            application.UseRouting();
            application.UseCors(x => x
                                .AllowAnyOrigin()
                                .AllowAnyMethod()
                                .AllowAnyHeader());

            application.UseAuthentication();
            application.UseAuthorization();

            application.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            ConfigureWebSocketEndpoint(application, mqttServerService, mqttSettings);

            dataSharingService.Configure();
            pythonScriptHostService.Configure();

            mqttServerService.Configure();

            application.UseSwagger(o => o.RouteTemplate = "/api/{documentName}/swagger.json");

            application.UseSwaggerUI(o =>
            {
                o.RoutePrefix   = "api";
                o.DocumentTitle = "MQTTnet.Server API";
                o.SwaggerEndpoint("/api/v1/swagger.json", "MQTTnet.Server API v1");
                o.DisplayRequestDuration();
                o.DocExpansion(DocExpansion.List);
                o.DefaultModelRendering(ModelRendering.Model);
            });
        }
Esempio n. 3
0
        public MqttServerService(
            MqttSettingsModel mqttSettings,
            CustomMqttFactory mqttFactory,
            MqttClientConnectedHandler mqttClientConnectedHandler,
            MqttClientDisconnectedHandler mqttClientDisconnectedHandler,
            MqttClientSubscribedTopicHandler mqttClientSubscribedTopicHandler,
            MqttClientUnsubscribedTopicHandler mqttClientUnsubscribedTopicHandler,
            MqttServerConnectionValidator mqttConnectionValidator,
            MqttSubscriptionInterceptor mqttSubscriptionInterceptor,
            MqttUnsubscriptionInterceptor mqttUnsubscriptionInterceptor,
            MqttApplicationMessageInterceptor mqttApplicationMessageInterceptor,
            MqttServerStorage mqttServerStorage,
            PythonScriptHostService pythonScriptHostService,
            ILogger <MqttServerService> logger)
        {
            _settings = mqttSettings ?? throw new ArgumentNullException(nameof(mqttSettings));
            _mqttClientConnectedHandler         = mqttClientConnectedHandler ?? throw new ArgumentNullException(nameof(mqttClientConnectedHandler));
            _mqttClientDisconnectedHandler      = mqttClientDisconnectedHandler ?? throw new ArgumentNullException(nameof(mqttClientDisconnectedHandler));
            _mqttClientSubscribedTopicHandler   = mqttClientSubscribedTopicHandler ?? throw new ArgumentNullException(nameof(mqttClientSubscribedTopicHandler));
            _mqttClientUnsubscribedTopicHandler = mqttClientUnsubscribedTopicHandler ?? throw new ArgumentNullException(nameof(mqttClientUnsubscribedTopicHandler));
            _mqttConnectionValidator            = mqttConnectionValidator ?? throw new ArgumentNullException(nameof(mqttConnectionValidator));
            _mqttSubscriptionInterceptor        = mqttSubscriptionInterceptor ?? throw new ArgumentNullException(nameof(mqttSubscriptionInterceptor));
            _mqttUnsubscriptionInterceptor      = mqttUnsubscriptionInterceptor ?? throw new ArgumentNullException(nameof(mqttUnsubscriptionInterceptor));
            _mqttApplicationMessageInterceptor  = mqttApplicationMessageInterceptor ?? throw new ArgumentNullException(nameof(mqttApplicationMessageInterceptor));
            _mqttServerStorage       = mqttServerStorage ?? throw new ArgumentNullException(nameof(mqttServerStorage));
            _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            _webSocketServerAdapter = new MqttWebSocketServerAdapter(mqttFactory.Logger);

            var adapters = new List <IMqttServerAdapter>
            {
                new MqttTcpServerAdapter(mqttFactory.Logger)
                {
                    TreatSocketOpeningErrorAsWarning = true // Opening other ports than for HTTP is not allows in Azure App Services.
                },
                _webSocketServerAdapter
            };

            _mqttServer = mqttFactory.CreateMqttServer(adapters);
        }
Esempio n. 4
0
        public MqttServerService(
            SettingsModel settings,
            CustomMqttFactory mqttFactory,
            MqttClientConnectedHandler mqttClientConnectedHandler,
            MqttClientDisconnectedHandler mqttClientDisconnectedHandler,
            MqttClientSubscribedTopicHandler mqttClientSubscribedTopicHandler,
            MqttClientUnsubscribedTopicHandler mqttClientUnsubscribedTopicHandler,
            MqttConnectionValidator mqttConnectionValidator,
            MqttSubscriptionInterceptor mqttSubscriptionInterceptor,
            MqttApplicationMessageInterceptor mqttApplicationMessageInterceptor,
            MqttServerStorage mqttServerStorage,
            PythonScriptHostService pythonScriptHostService,
            ILogger <MqttServerService> logger)
        {
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));
            _mqttClientConnectedHandler         = mqttClientConnectedHandler ?? throw new ArgumentNullException(nameof(mqttClientConnectedHandler));
            _mqttClientDisconnectedHandler      = mqttClientDisconnectedHandler ?? throw new ArgumentNullException(nameof(mqttClientDisconnectedHandler));
            _mqttClientSubscribedTopicHandler   = mqttClientSubscribedTopicHandler ?? throw new ArgumentNullException(nameof(mqttClientSubscribedTopicHandler));
            _mqttClientUnsubscribedTopicHandler = mqttClientUnsubscribedTopicHandler ?? throw new ArgumentNullException(nameof(mqttClientUnsubscribedTopicHandler));
            _mqttConnectionValidator            = mqttConnectionValidator ?? throw new ArgumentNullException(nameof(mqttConnectionValidator));
            _mqttSubscriptionInterceptor        = mqttSubscriptionInterceptor ?? throw new ArgumentNullException(nameof(mqttSubscriptionInterceptor));
            _mqttApplicationMessageInterceptor  = mqttApplicationMessageInterceptor ?? throw new ArgumentNullException(nameof(mqttApplicationMessageInterceptor));
            _mqttServerStorage       = mqttServerStorage ?? throw new ArgumentNullException(nameof(mqttServerStorage));
            _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            _webSocketServerAdapter = new MqttWebSocketServerAdapter(mqttFactory.Logger.CreateChildLogger());

            var adapters = new List <IMqttServerAdapter>
            {
                new MqttTcpServerAdapter(mqttFactory.Logger.CreateChildLogger()),
                _webSocketServerAdapter
            };

            _mqttServer = mqttFactory.CreateMqttServer(adapters);
        }
Esempio n. 5
0
 public MqttServerConnectionValidator(PythonScriptHostService pythonScriptHostService, ILogger <MqttServerConnectionValidator> logger)
 {
     _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public MqttSubscriptionInterceptor(PythonScriptHostService pythonScriptHostService, ILogger <MqttSubscriptionInterceptor> logger)
 {
     _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 7
0
 public DataSharingService(PythonScriptHostService pythonScriptHostService, ILogger <DataSharingService> logger)
 {
     _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public MqttClientUnsubscribedTopicHandler(PythonScriptHostService pythonScriptHostService, ILogger <MqttClientUnsubscribedTopicHandler> logger)
 {
     _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 9
0
 public ScriptsController(PythonScriptHostService pythonScriptHostService)
 {
     _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
 }
Esempio n. 10
0
 public MqttClientDisconnectedHandler(PythonScriptHostService pythonScriptHostService, ILogger <MqttClientDisconnectedHandler> logger)
 {
     _pythonScriptHostService = pythonScriptHostService ?? throw new ArgumentNullException(nameof(pythonScriptHostService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }