Former-commit-id: 98c966bb172859a4bdc3f9684015c4ea58e91b52
TangShanKaiPing
wanggang 6 years ago
parent 61a609003a
commit 483048dbe8

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -241,10 +242,15 @@ namespace Infrastructure.Web
}
public virtual void UseSignalR(IApplicationBuilder app)
{
this.UseSignalR<BasePageHub>(app);
}
protected void UseSignalR<T>(IApplicationBuilder app) where T : Hub
{
app.UseSignalR(routes =>
{
routes.MapHub<PageHub>("/hub", o =>
routes.MapHub<T>("/hub", o =>
{
o.ApplicationMaxBufferSize = long.MaxValue;
o.TransportMaxBufferSize = long.MaxValue;

@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Infrastructure.Web.SignalR
{
public class PageHub : Hub
public class BasePageHub : Hub
{
public override Task OnConnectedAsync()
{
@ -25,10 +25,13 @@ namespace Infrastructure.Web.SignalR
return base.OnDisconnectedAsync(exception);
}
public Task Send(string group, string method, string message)
public virtual void ServerToClient(string group, string method, string message)
{
Clients.Group(group).SendAsync(method, message);
}
public virtual void ClientToServer(string message)
{
Console.WriteLine($"PageHub>Send {message} To {group}.{message}");
return Clients.Group(group).SendAsync(method, message);
}
}
}

@ -38,7 +38,8 @@ namespace FBeeService
{
try
{
this.Connection.SendAsync("Notify", device.ToJson());
Console.WriteLine("notify to server");
this.Connection.SendAsync("ClientToServer", device.ToJson());
}
catch (Exception ex)
{
@ -49,7 +50,7 @@ namespace FBeeService
public override void ConnectionOn()
{
this.Connection.On("Request", (string path, string queryString) =>
this.Connection.On("ServerToClient", (string path, string queryString) =>
{
using (var scope = this.applicationServices.CreateScope())
{

@ -26,7 +26,7 @@ namespace FBeeService
new EFConfigurationValue { Id = "email:password", Value= "aA123456"},
new EFConfigurationValue { Id = "server.ip", Value= "" },
new EFConfigurationValue { Id = "server.urls", Value= "http://*:8008" },
new EFConfigurationValue { Id = "notify:enabled", Value= "true"},
new EFConfigurationValue { Id = "notify:enabled", Value= "false"},
new EFConfigurationValue { Id = "notify:host", Value= $"{host}:8001"},
new EFConfigurationValue { Id = "timer.seconds", Value="600"},
new EFConfigurationValue { Id = "connectId", Value= Guid.NewGuid().ToBase62() },

@ -0,0 +1,13 @@
using Infrastructure.Web.SignalR;
using System;
namespace IoTCenter.Services
{
public class PageHub : BasePageHub
{
public override void ClientToServer(string message)
{
Console.WriteLine(message);
}
}
}

@ -2,6 +2,8 @@ using Application.Services;
using Infrastructure.Email;
using Infrastructure.Sms;
using IoT.UI.Shard;
using IoTCenter.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@ -23,9 +25,9 @@ namespace IoTCenter
base.ConfigureServices(services);
}
public override void OnModelCreating(ModelBuilder modelBuilder)
public override void UseSignalR(IApplicationBuilder app)
{
base.OnModelCreating(modelBuilder);
this.UseSignalR<PageHub>(app);
}
}
}
Loading…
Cancel
Save