123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using DllEapBll.Services;
- using DllEapDal;
- using DllEapEntity;
- using DllHsms;
- using log4net.Core;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.SignalR;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Logging;
- using RabbitMQ.Client;
- using RabbitMQ.Client.Events;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace DllEapBll.SignalR
- {
- public class LogHub : Hub
- {
- public LogHandler LogHandler { get; set; }
- public LogHub(LogHandler logHandler)
- {
- this.LogHandler = logHandler;
- }
- /// <summary>
- /// 定时发送信息
- /// </summary>
- /// <param name="filter"></param>
- /// <param name="recipe"></param>
- /// <returns></returns>
- [AllowAnonymous]
- public async Task GetLogStatus(string id)
- {
- var response = new EapResponse { Code = 1, Msg = string.Empty };
- string connectionId = Context.ConnectionId;
- string errorinfo = string.Empty;
- try
- {
- while (true)
- {
-
- }
- }
- catch (Exception e)
- {
- await Clients.Client(connectionId).SendAsync("Error", e.Message);
- }
- finally
- {
- await Clients.Client(connectionId).SendAsync("Finished");
- // Dispose();
- }
- }
- public EapResponse GetEap()
- {
- var res = new EapResponse { Code = 1, Msg = string.Empty };
- res.Data = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
- return res;
- }
- public async Task SendMessage(string message)
- {
- await Clients.All.SendAsync("ReceiveUpdate", message);
- }
- /// <summary>
- /// 第一次连接发送信息
- /// </summary>
- /// <returns></returns>
- public override async Task OnConnectedAsync()
- {
- var connectionId = Context.ConnectionId;
- var context = Context.GetHttpContext();
- var macCode = Context.GetHttpContext().Request.Query["macCode"].FirstOrDefault();
- var macId = Context.GetHttpContext().Request.Query["macId"].FirstOrDefault();
- await Clients.Client(connectionId).SendAsync("BeginConnection", new EapResponse { Code = 1, Data = new { MacCode = macCode, Log = "开始接收日志....<br><br>" } });
- string errorinfo = string.Empty;
- this.LogHandler.Startdll(Convert.ToInt32(macId), connectionId, errorinfo);
- }
- public override async Task OnDisconnectedAsync(Exception exception)
- {
- this.LogHandler.Dispose(Context.ConnectionId);
- await Clients.Client(Context.ConnectionId).SendAsync("Finished", "停止连接");
- }
- public EapResponse GetMachine(string filter)
- {
- var res = new EapResponse { Code = 1, Msg = string.Empty };
- string errorinfo = string.Empty;
- HsmsLog hsmsLog = new HsmsLog();
- hsmsLog.FType = 2;
- hsmsLog.MacID = 325;
- hsmsLog.Log = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-->asdgqwec2131231231234231dsfwaeqw123";
- hsmsLog.MacCode = "WB00012";
- res.Data = hsmsLog;
- return res;
- //using (IDatabase db = DbFactory.Base("eapslave"))
- //{
- // db.BeginTrans();
- // var dal = new MachineDal(db);
- // var entity = dal.Get(Convert.ToInt32(filter));
- // if (entity == null)
- // {
- // res.Code = -1;
- // res.Msg = errorinfo;
- // return res;
- // }
- // res.Data = entity;
- // return res;
- //}
- }
- }
- }
|