diff --git a/Bootstrap.Admin/Controllers/HomeController.cs b/Bootstrap.Admin/Controllers/HomeController.cs index 97ec68fd..1962ec77 100644 --- a/Bootstrap.Admin/Controllers/HomeController.cs +++ b/Bootstrap.Admin/Controllers/HomeController.cs @@ -1,7 +1,10 @@ using Bootstrap.Admin.Models; using Bootstrap.DataAccess; +using Longbow.Web.WebSockets; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; namespace Bootstrap.Admin.Controllers { diff --git a/Bootstrap.Admin/wwwroot/js/common-scripts.js b/Bootstrap.Admin/wwwroot/js/common-scripts.js index b3554599..79ee5616 100644 --- a/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -51,33 +51,25 @@ $.extend({ pullNotification: function () { if ($('.notify-row').length == 0) return; - return; - setTimeout(function () { - NProgress.status = true; - NProgress.configure({ trickle: false }); - $.bc({ - url: 'api/WS', - method: 'GET', - swal: false, - callback: function (result) { - NProgress.status = false; - for (index in result) { - var cate = result[index].Category; - var msg = result[index].Message; - switch (cate) { - case "Notification": - toastr.error(msg, "应用程序出现错误"); - break; - case "Users": - toastr.info(msg, "新用户注册"); - break; - } - }; - if (result.length > 0) $.reloadWidget(); - $.pullNotification(); + + var uri = "ws://" + window.location.host + "/WS"; + var socket = new WebSocket(uri); + socket.onmessage = function (e) { + var result = JSON.parse(e.data); + for (index in result) { + var cate = result[index].Category; + var msg = result[index].Message; + switch (cate) { + case "Notification": + toastr.error(msg, "应用程序出现错误"); + break; + case "Users": + toastr.info(msg, "新用户注册"); + break; } - }); - }, 5000); + }; + if (result.length > 0) $.reloadWidget(); + }; }, reloadWidget: function () { if ($('.notify-row').length == 0) return; diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index e05f312c..8414232e 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -12,6 +12,7 @@ + diff --git a/Bootstrap.DataAccess/ExceptionHelper.cs b/Bootstrap.DataAccess/ExceptionHelper.cs index 986aa77d..501e884b 100644 --- a/Bootstrap.DataAccess/ExceptionHelper.cs +++ b/Bootstrap.DataAccess/ExceptionHelper.cs @@ -1,6 +1,7 @@ using Longbow.Cache; using Longbow.Data; using Longbow.Logging; +using Longbow.Web.WebSockets; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -39,6 +40,8 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Message", ex.Message)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace))); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); + CacheManager.Clear(RetrieveExceptionsDataKey); + WebSocketPushManager.SendAsync(new List { new { Category = "Notification", ex.Message } }); } } catch (Exception e)