增加功能:增加页面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.DataAccess;
using Longbow.Web.WebSockets;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
namespace Bootstrap.Admin.Controllers
{

View File

@ -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;

View File

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

View File

@ -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<object> { new { Category = "Notification", ex.Message } });
}
}
catch (Exception e)