diff --git a/csharp/App/VrmGrabber/Controller.cs b/csharp/App/VrmGrabber/Controller.cs index 93e80dd8d..8ce112351 100644 --- a/csharp/App/VrmGrabber/Controller.cs +++ b/csharp/App/VrmGrabber/Controller.cs @@ -1,75 +1,133 @@ -using System.ComponentModel.Design; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; -using System.Text.Json.Nodes; -using Flurl.Util; -using InnovEnergy.App.Backend.Database; +using HandlebarsDotNet; +using InnovEnergy.App.VrmGrabber.Database; using InnovEnergy.Lib.Victron.VictronVRM; using Microsoft.AspNetCore.Mvc; +using FILE=System.IO.File; -namespace InnovEnergy.App.Backend.Controllers; +namespace InnovEnergy.App.VrmGrabber; -using Token = String; +public record Install( + String Name, + String Ip, + UInt64 Vrm, + String Identifier, + String Serial +); -[ApiController] -[Route("api/")] +[Controller] public class Controller : ControllerBase { - [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(); - } - - [HttpGet(nameof(GetInstallationList))] - public Object GetInstallationList() + [HttpGet] + [Route("/")] + [Produces("text/html")] + public ActionResult Index() { var instList = Db.InstallationsAndDetails.Keys.ToList(); - if (instList.Count == 0) return 0; - var returnJson = new Dictionary>(); - foreach (var installation in instList) + 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 => { - returnJson[installation.Name] = new Dictionary(); - returnJson[installation.Name].Add("ip", $" On-Device-Gui "); try { - returnJson[installation.Name].Add("idSite", - $" Dashboard "); - returnJson[installation.Name] - .Add("identifier", $"{installation.Json["identifier"]?.GetValue()}"); - returnJson[installation.Name].Add("machine serial number", $"{Serial(installation)}"); + return new Install(i.Name, Ip(i), i.IdSite, i.Identifier, Serial(i)); } catch (Exception) { - continue; + return new Install(i.Name, Ip(i), i.IdSite, "0", Serial(i)); } - } + }); + + + var data = new + { + inst = insts + }; - return returnJson; + var result = template(data); + + return new ContentResult + { + ContentType = "text/html", + Content = result + }; } - private static String? Ip(Installation installation) + private String Ip(Installation installation) { - return Db.InstallationsAndDetails[installation].RemoteSupportIp(); + return Db.InstallationsAndDetails[installation].RemoteSupportIp() ?? "Unknown"; } - private static String? Serial(Installation installation) + private String Serial(Installation installation) { - return Db.InstallationsAndDetails[installation].MachineSerial(); + 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...) diff --git a/csharp/App/VrmGrabber/DataTypes/Installation.cs b/csharp/App/VrmGrabber/DataTypes/Installation.cs index 215125a08..2d118add8 100644 --- a/csharp/App/VrmGrabber/DataTypes/Installation.cs +++ b/csharp/App/VrmGrabber/DataTypes/Installation.cs @@ -1,7 +1,6 @@ using InnovEnergy.Lib.Victron.VictronVRM; -using SQLite; -namespace InnovEnergy.App.Backend.DataTypes; +namespace InnovEnergy.App.VrmGrabber.DataTypes; public class Installation : TreeNode diff --git a/csharp/App/VrmGrabber/DataTypes/Methods/Installation.cs b/csharp/App/VrmGrabber/DataTypes/Methods/Installation.cs index 965d14203..7f89dd8d5 100644 --- a/csharp/App/VrmGrabber/DataTypes/Methods/Installation.cs +++ b/csharp/App/VrmGrabber/DataTypes/Methods/Installation.cs @@ -1,4 +1,4 @@ -namespace InnovEnergy.App.Backend.DataTypes.Methods; +namespace InnovEnergy.App.VrmGrabber.DataTypes.Methods; public static class InstallationMethods diff --git a/csharp/App/VrmGrabber/DataTypes/TreeNode.cs b/csharp/App/VrmGrabber/DataTypes/TreeNode.cs index 20b741853..e141688b7 100644 --- a/csharp/App/VrmGrabber/DataTypes/TreeNode.cs +++ b/csharp/App/VrmGrabber/DataTypes/TreeNode.cs @@ -1,6 +1,6 @@ using SQLite; -namespace InnovEnergy.App.Backend.DataTypes; +namespace InnovEnergy.App.VrmGrabber.DataTypes; public abstract partial class TreeNode { diff --git a/csharp/App/VrmGrabber/Database/Create.cs b/csharp/App/VrmGrabber/Database/Create.cs index 3af2c275b..b8d7dc25f 100644 --- a/csharp/App/VrmGrabber/Database/Create.cs +++ b/csharp/App/VrmGrabber/Database/Create.cs @@ -1,7 +1,6 @@ -using InnovEnergy.App.Backend.DataTypes; +using InnovEnergy.App.VrmGrabber.DataTypes; - -namespace InnovEnergy.App.Backend.Database; +namespace InnovEnergy.App.VrmGrabber.Database; public static partial class Db diff --git a/csharp/App/VrmGrabber/Database/Db.cs b/csharp/App/VrmGrabber/Database/Db.cs index 1cae5749e..41f91a55c 100644 --- a/csharp/App/VrmGrabber/Database/Db.cs +++ b/csharp/App/VrmGrabber/Database/Db.cs @@ -1,17 +1,15 @@ - using System.Diagnostics.CodeAnalysis; using System.Reactive.Concurrency; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; -using static System.Text.Json.JsonSerializer; using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Victron.VictronVRM; - using SQLite; -using Installation = InnovEnergy.App.Backend.DataTypes.Installation; +using static System.Text.Json.JsonSerializer; +using Installation = InnovEnergy.App.VrmGrabber.DataTypes.Installation; -namespace InnovEnergy.App.Backend.Database; +namespace InnovEnergy.App.VrmGrabber.Database; public static partial class Db diff --git a/csharp/App/VrmGrabber/Database/Delete.cs b/csharp/App/VrmGrabber/Database/Delete.cs index cfa4fcff6..e15fa4b31 100644 --- a/csharp/App/VrmGrabber/Database/Delete.cs +++ b/csharp/App/VrmGrabber/Database/Delete.cs @@ -1,8 +1,6 @@ -using InnovEnergy.App.Backend.DataTypes; +using InnovEnergy.App.VrmGrabber.DataTypes; - - -namespace InnovEnergy.App.Backend.Database; +namespace InnovEnergy.App.VrmGrabber.Database; public static partial class Db diff --git a/csharp/App/VrmGrabber/Database/Read.cs b/csharp/App/VrmGrabber/Database/Read.cs index 4d084355a..4ef6c174c 100644 --- a/csharp/App/VrmGrabber/Database/Read.cs +++ b/csharp/App/VrmGrabber/Database/Read.cs @@ -1,8 +1,6 @@ -using InnovEnergy.App.Backend.DataTypes; +using InnovEnergy.App.VrmGrabber.DataTypes; - - -namespace InnovEnergy.App.Backend.Database; +namespace InnovEnergy.App.VrmGrabber.Database; public static partial class Db diff --git a/csharp/App/VrmGrabber/Program.cs b/csharp/App/VrmGrabber/Program.cs index ce467e44a..02a2a9a6b 100644 --- a/csharp/App/VrmGrabber/Program.cs +++ b/csharp/App/VrmGrabber/Program.cs @@ -1,18 +1,13 @@ -using InnovEnergy.App.Backend.Database; +using InnovEnergy.App.VrmGrabber.Database; using Microsoft.OpenApi.Models; -namespace InnovEnergy.App.Backend; +namespace InnovEnergy.App.VrmGrabber; public static class Program { - - - public static void Main(String[] args) { - //Db.CreateFakeRelations(); - Db.Init(); - + var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); @@ -26,9 +21,9 @@ public static class Program var app = builder.Build(); app.UseSwagger(); app.UseSwaggerUI(); - app.UseHttpsRedirection(); app.MapControllers(); + // app.MapGet("/", () => Controller.Index()); app.Run(); } diff --git a/csharp/App/VrmGrabber/VrmGrabber.csproj b/csharp/App/VrmGrabber/VrmGrabber.csproj index e49b745c3..45e814a59 100644 --- a/csharp/App/VrmGrabber/VrmGrabber.csproj +++ b/csharp/App/VrmGrabber/VrmGrabber.csproj @@ -3,6 +3,7 @@ + @@ -41,4 +42,8 @@ + + <_ContentIncludedByDefault Remove="wwwroot\index.html" /> + + diff --git a/doc/Pv-Steuerung-Victron.docx b/doc/Pv-Steuerung-Victron.docx new file mode 100644 index 000000000..7265db337 Binary files /dev/null and b/doc/Pv-Steuerung-Victron.docx differ diff --git a/doc/Pv-Steuerung-Victron.pdf b/doc/Pv-Steuerung-Victron.pdf new file mode 100644 index 000000000..7377d2fc7 Binary files /dev/null and b/doc/Pv-Steuerung-Victron.pdf differ