增加功能:增加页面WebSocket连接

This commit is contained in:
Argo-MacBookPro 2018-06-12 13:46:06 +08:00
parent 3d574edfa8
commit ee7f36fa53
4 changed files with 25 additions and 26 deletions

View File

@ -1,7 +1,10 @@
using Bootstrap.Admin.Models; using Bootstrap.Admin.Models;
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Longbow.Web.WebSockets;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
namespace Bootstrap.Admin.Controllers namespace Bootstrap.Admin.Controllers
{ {

View File

@ -51,33 +51,25 @@
$.extend({ $.extend({
pullNotification: function () { pullNotification: function () {
if ($('.notify-row').length == 0) return; if ($('.notify-row').length == 0) return;
return;
setTimeout(function () { var uri = "ws://" + window.location.host + "/WS";
NProgress.status = true; var socket = new WebSocket(uri);
NProgress.configure({ trickle: false }); socket.onmessage = function (e) {
$.bc({ var result = JSON.parse(e.data);
url: 'api/WS', for (index in result) {
method: 'GET', var cate = result[index].Category;
swal: false, var msg = result[index].Message;
callback: function (result) { switch (cate) {
NProgress.status = false; case "Notification":
for (index in result) { toastr.error(msg, "应用程序出现错误");
var cate = result[index].Category; break;
var msg = result[index].Message; case "Users":
switch (cate) { toastr.info(msg, "新用户注册");
case "Notification": break;
toastr.error(msg, "应用程序出现错误");
break;
case "Users":
toastr.info(msg, "新用户注册");
break;
}
};
if (result.length > 0) $.reloadWidget();
$.pullNotification();
} }
}); };
}, 5000); if (result.length > 0) $.reloadWidget();
};
}, },
reloadWidget: function () { reloadWidget: function () {
if ($('.notify-row').length == 0) return; if ($('.notify-row').length == 0) return;

View File

@ -12,6 +12,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security" Version="1.0.3" /> <PackageReference Include="Bootstrap.Security" Version="1.0.3" />
<PackageReference Include="Longbow.Web" Version="1.0.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,6 +1,7 @@
using Longbow.Cache; using Longbow.Cache;
using Longbow.Data; using Longbow.Data;
using Longbow.Logging; using Longbow.Logging;
using Longbow.Web.WebSockets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; 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("@Message", ex.Message));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace))); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace)));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
CacheManager.Clear(RetrieveExceptionsDataKey);
WebSocketPushManager.SendAsync(new List<object> { new { Category = "Notification", ex.Message } });
} }
} }
catch (Exception e) catch (Exception e)