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;
}
///
/// 定时发送信息
///
///
///
///
[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);
}
///
/// 第一次连接发送信息
///
///
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 = "开始接收日志....
" } });
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;
//}
}
}
}