|
@@ -24,7 +24,8 @@ namespace HTEX.Complex
|
|
|
{
|
|
|
public static void Main(string[] args)
|
|
|
{
|
|
|
- var builder = WebApplication.CreateBuilder(args); //builder.WebHost.ConfigureKestrel(options =>
|
|
|
+ var builder = WebApplication.CreateBuilder(args);
|
|
|
+ //builder.WebHost.ConfigureKestrel(options =>
|
|
|
//{
|
|
|
// //options.ListenAnyIP(4001, options => {
|
|
|
// // // options.UseHttps("Crt/iteden.pfx", "iteden");
|
|
@@ -75,9 +76,7 @@ namespace HTEX.Complex
|
|
|
};
|
|
|
});
|
|
|
builder.Services.AddControllers();
|
|
|
-#if DEBUG
|
|
|
- builder.WebHost.UseUrls(new[] { "https://*:7298" });
|
|
|
-#endif
|
|
|
+
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
//builder.Services.AddSwaggerGen();
|
|
@@ -109,36 +108,14 @@ namespace HTEX.Complex
|
|
|
.AllowAnyMethod();
|
|
|
});
|
|
|
});
|
|
|
-#if !DEBUG
|
|
|
- builder.Services.AddHangfire(config => {
|
|
|
- config.UseRedisStorage(builder.Configuration.GetValue<string>("Azure:Redis:ConnectionString"));
|
|
|
- });
|
|
|
- builder.Services.AddHangfireServer();
|
|
|
-#endif
|
|
|
-
|
|
|
builder.Services.AddControllersWithViews();
|
|
|
//MQTT 服务端API 发送消息到MQTT客户端 https://www.cnblogs.com/weskynet/p/16441219.html
|
|
|
- // builder.Services.AddHostedService<MqttHostService>();
|
|
|
-
|
|
|
-
|
|
|
#region MQTT配置
|
|
|
- //string hostIp = Configuration["MqttOption:HostIp"];//IP地址
|
|
|
- //int hostPort = int.Parse(Configuration["MqttOption:HostPort"]);//端口号
|
|
|
- //int timeout = int.Parse(Configuration["MqttOption:Timeout"]);//超时时间
|
|
|
- //string username = Configuration["MqttOption:UserName"];//用户名
|
|
|
- //string password = Configuration["MqttOption:Password"];//密码
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
builder.Services.AddSingleton<MQTTEvents>();
|
|
|
builder.Services.AddSingleton(new JsonSerializerOptions(JsonSerializerDefaults.Web));
|
|
|
-
|
|
|
- builder.Services.AddHostedMqttServerWithServices(x => {
|
|
|
+ builder.Services.AddHostedMqttServerWithServices(x =>
|
|
|
+ {
|
|
|
x.WithDefaultEndpoint()
|
|
|
- //.WithDefaultEndpointBoundIPAddress(System.Net.IPAddress.Parse("127.0.0.1"))
|
|
|
- //.WithDefaultEndpointPort(1883)
|
|
|
- //.WithEncryptedEndpointPort(1884)
|
|
|
.WithConnectionBacklog(1000)
|
|
|
.WithPersistentSessions(true).WithKeepAlive()
|
|
|
.WithDefaultCommunicationTimeout(TimeSpan.FromMilliseconds(30));
|
|
@@ -146,7 +123,7 @@ namespace HTEX.Complex
|
|
|
#endregion
|
|
|
|
|
|
var app = builder.Build();
|
|
|
- var events = app.Services.GetRequiredService<MQTTEvents>();
|
|
|
+
|
|
|
// Configure the HTTP request pipeline.
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
{
|
|
@@ -154,28 +131,14 @@ namespace HTEX.Complex
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
app.UseHsts();
|
|
|
}
|
|
|
-
|
|
|
- app.UseHttpsRedirection();
|
|
|
- app.UseStaticFiles();
|
|
|
-
|
|
|
app.UseRouting();
|
|
|
app.UseCors(); //使用跨域設定
|
|
|
- app.UseHttpsRedirection(); //開發中暫時關掉
|
|
|
app.UseAuthentication();
|
|
|
app.UseAuthorization();
|
|
|
- //app.MapControllerRoute(
|
|
|
- // name: "default",
|
|
|
- // pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
- //app.UseEndpoints(endpoints => {
|
|
|
- // endpoints.MapControllers();
|
|
|
- // endpoints.MapConnectionHandler<MqttConnectionHandler>("/mqtt", opts => opts.WebSockets.SubProtocolSelector = protocolList => protocolList.FirstOrDefault() ?? string.Empty);
|
|
|
- // endpoints.MapFallbackToFile("index.html");
|
|
|
- // endpoints.MapHub<SignalRScreenServerHub>("/signalr/screen").RequireCors("any");
|
|
|
- //});
|
|
|
app.MapControllers();
|
|
|
- app.MapConnectionHandler<MqttConnectionHandler>("/mqtt", opts => opts.WebSockets.SubProtocolSelector = protocolList => protocolList.FirstOrDefault() ?? string.Empty);
|
|
|
- app.MapFallbackToFile("index.html");
|
|
|
app.MapHub<SignalRScreenServerHub>("/signalr/screen").RequireCors("any");
|
|
|
+ app.MapConnectionHandler<MqttConnectionHandler>("/mqtt", opts => opts.WebSockets.SubProtocolSelector = protocolList => protocolList.FirstOrDefault() ?? string.Empty);
|
|
|
+ var events = app.Services.GetRequiredService<MQTTEvents>();
|
|
|
app.UseMqttServer(server =>
|
|
|
{
|
|
|
server.WithAttributeRouting(app.Services, allowUnmatchedRoutes: false);
|