From 8e89d67e0c50a4661ac4826e279791d09c68e4c9 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Mon, 11 Jun 2018 18:37:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0WebSocket=E4=B8=AD=E9=97=B4=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=87=86=E5=A4=87=E6=9B=BF=E6=8D=A2=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=E5=AF=B9=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 1 - .../Controllers/Api/WSController.cs | 25 --------- Bootstrap.Admin/Startup.cs | 3 ++ Bootstrap.Admin/Views/Account/Register.cshtml | 7 ++- Bootstrap.Admin/WebSocketHandlerMiddleware.cs | 54 ------------------- Bootstrap.Admin/wwwroot/html/Test.html | 2 +- Bootstrap.DataAccess/NotificationHelper.cs | 2 +- 7 files changed, 11 insertions(+), 83 deletions(-) delete mode 100644 Bootstrap.Admin/Controllers/Api/WSController.cs delete mode 100644 Bootstrap.Admin/WebSocketHandlerMiddleware.cs diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 62b32f2a..b81e479b 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -9,7 +9,6 @@ - diff --git a/Bootstrap.Admin/Controllers/Api/WSController.cs b/Bootstrap.Admin/Controllers/Api/WSController.cs deleted file mode 100644 index 486d70ff..00000000 --- a/Bootstrap.Admin/Controllers/Api/WSController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Bootstrap.DataAccess; -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Linq; - -namespace Bootstrap.Admin.Controllers.Api -{ - /// - /// - /// - [Route("api/[controller]")] - public class WSController : Controller - { - /// - /// - /// - /// - /// - [HttpGet] - public List Get() - { - return NotificationHelper.MessagePool.ToList(); - } - } -} \ No newline at end of file diff --git a/Bootstrap.Admin/Startup.cs b/Bootstrap.Admin/Startup.cs index a8e45d78..5bf8620e 100644 --- a/Bootstrap.Admin/Startup.cs +++ b/Bootstrap.Admin/Startup.cs @@ -5,12 +5,14 @@ using Longbow.Cache.Middleware; using Longbow.Configuration; using Longbow.Data; using Longbow.Logging; +using Longbow.Web.WebSockets; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System; using System.IO; @@ -46,6 +48,7 @@ namespace Bootstrap.Admin { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; + JsonConvert.DefaultSettings = () => options.SerializerSettings; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); } diff --git a/Bootstrap.Admin/Views/Account/Register.cshtml b/Bootstrap.Admin/Views/Account/Register.cshtml index 10463130..5ce9ca1b 100644 --- a/Bootstrap.Admin/Views/Account/Register.cshtml +++ b/Bootstrap.Admin/Views/Account/Register.cshtml @@ -1,11 +1,16 @@ @{ ViewBag.Title = "注册新用户"; - Layout = "~/Views/Shared/_Layout.cshtml"; + Layout = "~/Views/Shared/_Root.cshtml"; } @section css { + + + } @section javascript { + + diff --git a/Bootstrap.Admin/WebSocketHandlerMiddleware.cs b/Bootstrap.Admin/WebSocketHandlerMiddleware.cs deleted file mode 100644 index 22f749c7..00000000 --- a/Bootstrap.Admin/WebSocketHandlerMiddleware.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Longbow.Configuration.Middleware; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using System; -using System.Net.WebSockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Bootstrap.Admin -{ - public class WebSocketHandlerMiddleware : LgbMiddleware - { - /// - /// - /// - /// - public WebSocketHandlerMiddleware(RequestDelegate next) : base(next) - { - - } - /// - /// - /// - /// - /// - public override async Task Invoke(HttpContext context) - { - if (!context.WebSockets.IsWebSocketRequest || !context.User.Identity.IsAuthenticated) return; - using (var socket = await context.WebSockets.AcceptWebSocketAsync()) - { - while (socket.State == WebSocketState.Open) - { - await Task.Delay(60000); - var data = new ArraySegment(Encoding.UTF8.GetBytes(DateTimeOffset.Now.ToString())); - await socket.SendAsync(data, WebSocketMessageType.Text, true, CancellationToken.None); - } - } - } - } - - public static class WebSocketExtensions - { - /// - /// - /// - /// - public static void UseWebSocketHandler(this IApplicationBuilder app) - { - app.UseWebSockets(); - app.Map("/Foo", builder => builder.UseMiddleware()); - } - } -} \ No newline at end of file diff --git a/Bootstrap.Admin/wwwroot/html/Test.html b/Bootstrap.Admin/wwwroot/html/Test.html index f4464450..6d888578 100644 --- a/Bootstrap.Admin/wwwroot/html/Test.html +++ b/Bootstrap.Admin/wwwroot/html/Test.html @@ -6,7 +6,7 @@