You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.3 KiB
70 lines
2.3 KiB
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using IoT.Shared.Services;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace IoTCenter.Services
|
|
{
|
|
public class IoTCenterJob
|
|
{
|
|
private readonly IRepository<IoTTimerCommand> _timerCommandRepo;
|
|
private readonly IRepository<IoTTiggerCommand> _tiggerCommandRepo;
|
|
private readonly IHubContext<IoTCenterHub> _hub;
|
|
|
|
public IoTCenterJob(IRepository<IoTTimerCommand> timerCommandRepo, IRepository<IoTTiggerCommand> tiggerCommandRepo, IHubContext<IoTCenterHub> hub)
|
|
{
|
|
this._timerCommandRepo = timerCommandRepo;
|
|
this._tiggerCommandRepo = tiggerCommandRepo;
|
|
this._hub = hub;
|
|
}
|
|
|
|
public void TimerHanle(Guid timerId)
|
|
{
|
|
var commands = this._timerCommandRepo.ReadOnlyTable()
|
|
.Include(o => o.Command)
|
|
.ThenInclude(o => o.Device)
|
|
.ThenInclude(o => o.Node)
|
|
.Where(o => o.IoTTimerId == timerId)
|
|
.Select(o => o.Command)
|
|
.ToList();
|
|
foreach (var command in commands)
|
|
{
|
|
try
|
|
{
|
|
this._hub.ServerToClient(Methods.ExecCommand, command.Id, command.Device.Node.Number, null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void TiggerHandle(Guid tiggerId)
|
|
{
|
|
var commands = this._tiggerCommandRepo.ReadOnlyTable()
|
|
.Include(o => o.Command)
|
|
.ThenInclude(o => o.Device)
|
|
.ThenInclude(o => o.Node)
|
|
.Where(o => o.IoTTiggerId == tiggerId)
|
|
.Select(o => o.Command)
|
|
.ToList();
|
|
foreach (var command in commands)
|
|
{
|
|
try
|
|
{
|
|
this._hub.ServerToClient(Methods.ExecCommand, command.Id, command.Device.Node.Number, null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |