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.
85 lines
2.7 KiB
85 lines
2.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Application.Services;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace IoTNode.Controllers
|
|
{
|
|
public class CommandController : Controller
|
|
{
|
|
private readonly ILogger<CommandController> _logger;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
private readonly IRepository<Scene> _senceRepo;
|
|
private readonly INodeService _nodeService;
|
|
|
|
public CommandController(ILogger<CommandController> logger,
|
|
IHttpClientFactory httpClientFactory,
|
|
IRepository<Device> deviceRepo,
|
|
IRepository<Scene> senceRepo,
|
|
INodeService nodeService)
|
|
{
|
|
this._logger = logger;
|
|
this._httpClientFactory = httpClientFactory;
|
|
this._deviceRepo = deviceRepo;
|
|
this._senceRepo = senceRepo;
|
|
this._nodeService = nodeService;
|
|
}
|
|
|
|
public IActionResult Exec(string node, string cmd, Guid id)
|
|
{
|
|
try
|
|
{
|
|
var query = string.Empty;
|
|
foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id")))
|
|
{
|
|
query = query.SetParam(item.Key, item.Value);
|
|
}
|
|
return Json(this._nodeService.Exec(id, cmd, query));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Json(ApiResponse.Error(ex));
|
|
}
|
|
}
|
|
|
|
public IActionResult ExecAll(string node, string cmd, List<Guid> id)
|
|
{
|
|
try
|
|
{
|
|
var query = string.Empty;
|
|
foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id")))
|
|
{
|
|
query = query.SetParam(item.Key, item.Value);
|
|
}
|
|
return Json(this._nodeService.ExecAll(id, cmd, query));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Json(ApiResponse.Error(ex));
|
|
}
|
|
}
|
|
|
|
public IActionResult Sence(string node, Guid id)
|
|
{
|
|
try
|
|
{
|
|
return Json(this._nodeService.Sence(id));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Json(ApiResponse.Error(ex));
|
|
}
|
|
}
|
|
}
|
|
} |