132 lines
3.8 KiB
C#
132 lines
3.8 KiB
C#
using System.Web;
|
|
using HandlebarsDotNet;
|
|
using InnovEnergy.App.RemoteSupportConsole;
|
|
using InnovEnergy.App.VrmGrabber.Database;
|
|
using InnovEnergy.Lib.Victron.VictronVRM;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using FILE=System.IO.File;
|
|
|
|
namespace InnovEnergy.App.VrmGrabber;
|
|
|
|
public record Install(
|
|
String Name,
|
|
String Ip,
|
|
UInt64 Vrm,
|
|
String Identifier,
|
|
String Serial,
|
|
String EscapedName
|
|
);
|
|
|
|
[Controller]
|
|
public class Controller : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
[Route("/")]
|
|
[Produces("text/html")]
|
|
public ActionResult Index()
|
|
{
|
|
var instList = Db.InstallationsAndDetails.Keys.ToList();
|
|
if (instList.Count == 0) return new ContentResult
|
|
{
|
|
ContentType = "text/html",
|
|
Content = "<p>Please wait page is still loading</p>"
|
|
};
|
|
|
|
String source = @"<head>
|
|
<style>
|
|
tbody {
|
|
background-color: #e4f0f5;
|
|
}
|
|
|
|
table {
|
|
border-collapse: collapse;
|
|
border: 2px solid rgb(200, 200, 200);
|
|
letter-spacing: 1px;
|
|
font-family: sans-serif;
|
|
font-size: 0.8rem;
|
|
position: absolute; top: 0; bottom: 0; left: 0; right: 0;
|
|
}
|
|
|
|
td,
|
|
th {
|
|
border: 1px solid rgb(190, 190, 190);
|
|
padding: 5px 10px;
|
|
}
|
|
|
|
td {
|
|
text-align: left;
|
|
}</style></head>
|
|
|
|
<table>
|
|
<tbody>
|
|
{{#inst}}
|
|
{{> installations}}
|
|
{{/inst}}
|
|
</tbody>
|
|
</table>";
|
|
|
|
String partialSource =
|
|
@"<tr><td>{{Name}}</td>
|
|
<td><a target='_blank' href=http://{{Ip}}>{{Ip}}</a></td>
|
|
<td><a target='_blank' href=https://vrm.victronenergy.com/installation/{{Vrm}}/dashboard>VRM</a></td>
|
|
<td>{{Identifier}}</td>
|
|
<td>{{Serial}}</td>
|
|
<td><a target='_blank' href='https://salidomo.innovenergy.ch/d/ENkNRQXmk/installation?refresh=5s&orgId=1&var-Installation={{EscapedName}}&kiosk=tv'>Grafana</a></td></tr>";
|
|
|
|
Handlebars.RegisterTemplate("installations", partialSource);
|
|
var template = Handlebars.Compile(source);
|
|
var insts = instList.Select(i =>
|
|
{
|
|
return new Install(i.Name, Ip(i), i.IdSite, i.Identifier, Serial(i), HttpUtility.UrlEncode(i.Name));
|
|
});
|
|
|
|
|
|
var data = new
|
|
{
|
|
inst = insts
|
|
};
|
|
|
|
var result = template(data);
|
|
|
|
return new ContentResult
|
|
{
|
|
ContentType = "text/html",
|
|
Content = result
|
|
};
|
|
}
|
|
|
|
private String Ip(Installation installation)
|
|
{
|
|
|
|
return VpnInfo.LookUpIp(installation.Identifier, Serial(installation)).Result ?? "Unknown";
|
|
}
|
|
|
|
private String Serial(Installation installation)
|
|
{
|
|
return Db.InstallationsAndDetails[installation].MachineSerial() ?? "Unknown";
|
|
}
|
|
|
|
// [HttpGet(nameof(GetInstallation))]
|
|
// [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
|
// public Object GetInstallation(UInt64 serialNumber)
|
|
// {
|
|
// var instList = Db.InstallationsAndDetails.Values.ToList();
|
|
// foreach (var detailList in instList.Select((value, index) => new { Value = value, Index = index}))
|
|
// {
|
|
// if (detailList.Value.All(detail => detail.Json["idSite"]?.GetValue<UInt64>() != serialNumber)) continue;
|
|
// var retour = Db.InstallationsAndDetails.Keys.ToList()[detailList.Index].Json;
|
|
// retour["details"] = JsonSerializer.Deserialize<JsonArray>(JsonSerializer.Serialize(detailList.Value.Select(d => d.Json).ToArray()));
|
|
// return retour;
|
|
// }
|
|
//
|
|
// return new NotFoundResult();
|
|
// }
|
|
}
|
|
|
|
|
|
|
|
|
|
// installation Name, ip (link uf gui), idSite (vrm link), identifier , machineserial (HQ...)
|
|
|
|
|