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

48 lines
1.4 KiB

using CookComputing.XmlRpc;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http;
using System.Reflection;
namespace IoTDameon.Controllers
{
public class HomeController : Controller
{
private IHttpClientFactory _httpClientFactory;
public HomeController(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public IActionResult Index()
{
this.Process();
return Content("");
}
private void Process(bool stop = false)
{
try
{
var proxy = XmlRpcProxyGen.Create<ISupervisorService>();
proxy.Url = "http://192.168.1.3:9001/RPC2";
proxy.Credentials = new NetworkCredential("usr", "pwd");
var result = stop ? proxy.stopProcess("iotnode") : proxy.startProcess("iotnode");
}
catch (XmlRpcFaultException ex)
{
//start:60 stop:70
if (ex.FaultCode != 60 && ex.FaultCode != 70)
{
throw ex;
}
}
}
public IActionResult GetVersion()
{
return Content(Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
}
}
}