using System.Data.Common; using System.IdentityModel.Tokens.Jwt; using System.Web; using HandlebarsDotNet; using InnovEnergy.App.RemoteSupportConsole; using InnovEnergy.App.VrmGrabber.Database; using Microsoft.AspNetCore.Mvc; using FILE=System.IO.File; using VrmInstallation = InnovEnergy.Lib.Victron.VictronVRM.Installation; namespace InnovEnergy.App.VrmGrabber; public record Install( String Name, String Ip, Int64 Vrm, String Identifier, String Serial, String EscapedName, String Online, String LastSeen, Int64 NumBatteries, String BatteryVersion ); [Controller] public class Controller : ControllerBase { [HttpGet] [Route("/")] [Produces("text/html")] public ActionResult Index() { String source = @"
{{#inst}} {{> installations}} {{/inst}}
Name Gui VRM Grafana Identifier Last Seen Serial #Batteries Firmware-Version
"; String partialSource = @"{{Name}} {{online}} {{Ip}} VRM Grafana {{Identifier}} {{LastSeen}} {{Serial}} {{NumBatteries}} {{BatteryVersion}} "; var instList = Db.Installations.ToList(); if (instList.Count == 0) return new ContentResult { ContentType = "text/html", Content = "

Please wait page is still loading

" }; Handlebars.RegisterTemplate("installations", partialSource); var template = Handlebars.Compile(source); var insts = instList.Select(i => new Install( i.Name, i.Ip, i.Vrm, i.Identifier, i.Serial, i.EscapedName, i.Online, DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(i.LastSeen)).ToString(), i.NumberOfBatteries, i.BatteryFirmwareVersion)); var data = new { inst = insts }; var result = template(data); return new ContentResult { ContentType = "text/html", Content = result }; } // [HttpGet(nameof(GetInstallation))] // [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "")] // 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() != serialNumber)) continue; // var retour = Db.InstallationsAndDetails.Keys.ToList()[detailList.Index].Json; // retour["details"] = JsonSerializer.Deserialize(JsonSerializer.Serialize(detailList.Value.Select(d => d.Json).ToArray())); // return retour; // } // // return new NotFoundResult(); // } }