using HandlebarsDotNet; 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 ); [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 = "

Please wait page is still loading

" }; String source = @" {{#inst}} {{> installations}} {{/inst}}
"; String partialSource = @"{{Name}} {{Ip}} VRM {{Identifier}} {{Serial}}"; Handlebars.RegisterTemplate("installations", partialSource); var template = Handlebars.Compile(source); var insts = instList.Select(i => { try { return new Install(i.Name, Ip(i), i.IdSite, i.Identifier, Serial(i)); } catch (Exception) { return new Install(i.Name, Ip(i), i.IdSite, "0", Serial(i)); } }); var data = new { inst = insts }; var result = template(data); return new ContentResult { ContentType = "text/html", Content = result }; } private String Ip(Installation installation) { return Db.InstallationsAndDetails[installation].RemoteSupportIp() ?? "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 = "")] // 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(); // } } // installation Name, ip (link uf gui), idSite (vrm link), identifier , machineserial (HQ...)