You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Reflection;
|
|
using WcfControlMonitorLib;
|
|
using WcfControlMonitorWebLib.Hubs;
|
|
|
|
namespace WcfControlMonitorWebLib
|
|
{
|
|
/// <summary>
|
|
/// 启动项
|
|
/// </summary>
|
|
public class Startup
|
|
{
|
|
/// <summary>
|
|
/// 服务配置
|
|
/// </summary>
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(policy =>
|
|
{
|
|
policy
|
|
.SetIsOriginAllowed(_ => true)
|
|
.AllowAnyHeader()
|
|
.AllowCredentials()
|
|
.AllowAnyMethod();
|
|
});
|
|
});
|
|
services.AddMvc(options => options.Filters.Add<ActionFilter>());
|
|
services.AddSignalR();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用配置
|
|
/// </summary>
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseCors();
|
|
app.UseMvc();
|
|
app.UseSignalR(builder => builder.MapHub<MonitorHub>("/signalr/monitor"));
|
|
|
|
//订阅某个事件实现数据推送
|
|
//SControlMonitor.MonitorHub += (sender, e) => app.ApplicationServices.GetService<IHubContext<MonitorHub>>().Clients.All.SendAsync("broadcast", sender);
|
|
|
|
Model.CGetInfo.DeviceChange += (Device) =>
|
|
{
|
|
var hub = app.ApplicationServices.GetService<IHubContext<MonitorHub>>();
|
|
hub.Clients.All.SendAsync("broadcast", Device);
|
|
};
|
|
}
|
|
}
|
|
}
|