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.
iot/projects/IoTDameon/Controllers/HomeController.cs

67 lines
1.9 KiB

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Reflection;
using System.Threading.Tasks;
namespace IoTDameon.Controllers
{
public class HomeController : Controller
{
private readonly IWebHostEnvironment _env;
private readonly UpdateIoTNodeService _service;
private readonly IHubContext<DefaultHub> _hub;
public HomeController(IWebHostEnvironment env, UpdateIoTNodeService service, IHubContext<DefaultHub> hub)
{
this._env = env;
this._service = service;
this._hub = hub;
}
public IActionResult Index()
{
return View();
}
public IActionResult Command(string command)
{
if (!string.IsNullOrEmpty(command))
{
try
{
this._hub.Clients.All.SendAsync("ServerToClient", command.Bash());
}
catch (Exception ex)
{
this._hub.Clients.All.SendAsync("ServerToClient", ex.ToString());
return Problem(ex.Message);
}
}
return Ok();
}
public IActionResult Update()
{
try
{
Task.Run(() =>
{
this._service.Update();
});
}
catch (Exception ex)
{
this._hub.Clients.All.SendAsync("ServerToClient", ex.ToString());
return Problem(ex.Message);
}
return Ok();
}
public IActionResult GetVersion()
{
return Content(Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
}
}
}