updated vrmgrabber
This commit is contained in:
parent
d1fb0a8ac2
commit
70a4a1bfb8
|
@ -1,74 +1,132 @@
|
|||
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 = "<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();
|
||||
}
|
||||
|
||||
[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<String, Dictionary<String, String>>();
|
||||
foreach (var installation in instList)
|
||||
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=https://{{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></tr>";
|
||||
|
||||
Handlebars.RegisterTemplate("installations", partialSource);
|
||||
var template = Handlebars.Compile(source);
|
||||
var insts = instList.Select(i =>
|
||||
{
|
||||
returnJson[installation.Name] = new Dictionary<String, String>();
|
||||
returnJson[installation.Name].Add("ip", $"<a target='_blank' href=https://{Ip(installation)}> On-Device-Gui </a>");
|
||||
try
|
||||
{
|
||||
returnJson[installation.Name].Add("idSite",
|
||||
$"<a target='_blank' href=https://vrm.victronenergy.com/installation/{installation.IdSite}/dashboard> Dashboard </a>");
|
||||
returnJson[installation.Name]
|
||||
.Add("identifier", $"{installation.Json["identifier"]?.GetValue<String>()}");
|
||||
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));
|
||||
}
|
||||
});
|
||||
|
||||
return returnJson;
|
||||
}
|
||||
|
||||
private static String? Ip(Installation installation)
|
||||
var data = new
|
||||
{
|
||||
return Db.InstallationsAndDetails[installation].RemoteSupportIp();
|
||||
inst = insts
|
||||
};
|
||||
|
||||
var result = template(data);
|
||||
|
||||
return new ContentResult
|
||||
{
|
||||
ContentType = "text/html",
|
||||
Content = result
|
||||
};
|
||||
}
|
||||
|
||||
private static String? Serial(Installation installation)
|
||||
private String Ip(Installation installation)
|
||||
{
|
||||
return Db.InstallationsAndDetails[installation].MachineSerial();
|
||||
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 = "<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...)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace InnovEnergy.App.Backend.DataTypes.Methods;
|
||||
namespace InnovEnergy.App.VrmGrabber.DataTypes.Methods;
|
||||
|
||||
|
||||
public static class InstallationMethods
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using SQLite;
|
||||
|
||||
namespace InnovEnergy.App.Backend.DataTypes;
|
||||
namespace InnovEnergy.App.VrmGrabber.DataTypes;
|
||||
|
||||
public abstract partial class TreeNode
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Flurl.Http" Version="3.2.4" />
|
||||
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
|
||||
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="6.5.1" />
|
||||
<PackageReference Include="MailKit" Version="3.6.0" />
|
||||
<PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.3" />
|
||||
|
@ -41,4 +42,8 @@
|
|||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\index.html" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue