From 1f745951d408c9a184c9e551d9353fd11f2e87ec Mon Sep 17 00:00:00 2001 From: Stefan <32109571+Stefan-5422@users.noreply.github.com> Date: Wed, 1 Mar 2023 12:46:19 +0100 Subject: [PATCH 1/6] Fix: Broken stuff --- .../Elektrifikatsiya/Models/Device.cs | 2 + .../Elektrifikatsiya/Pages/AddPlug.razor | 5 +- .../Elektrifikatsiya/Pages/Dashboard.razor | 4 +- .../Elektrifikatsiya/Program.cs | 2 + .../Implementations/DeviceManagmentService.cs | 173 +++++++++--------- .../Services/Implementations/UpdateService.cs | 11 +- 6 files changed, 106 insertions(+), 91 deletions(-) diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs index 0bcca1a..4d15c15 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs @@ -34,4 +34,6 @@ public class Device User = user; Room = room; } + + private Device(){} } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor index 91ba629..efabc58 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor @@ -1,6 +1,7 @@ @page "/addplug" @using Blazorise.Components; @using Elektrifikatsiya.Models; +@using System.Net @inject IVersionProvider VersionProvider @@ -22,7 +23,7 @@ - IP: @context.Item.Address + IP: @context.Item.IpAddress @@ -39,5 +40,5 @@ @code { - List plugs = new List() { new Device("Placeholder", "Plug", System.Net.IPAddress.Broadcast, 60, "Oldin", "4AHINF"), new Device("Placeholder", "Plug", System.Net.IPAddress.Broadcast, 60, "Oldin", "4AHINF"), new Device("Placeholder", "Plug", System.Net.IPAddress.Broadcast, 60, "Oldin", "4AHINF") }; + List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; } diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor index de1ed5c..b905ed3 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor @@ -1,6 +1,7 @@ @page "/" @using Blazorise.Components; @using Elektrifikatsiya.Models; +@using System.Net @inject IVersionProvider VersionProvider @@ -69,8 +70,7 @@ //TODO: insert new event here if plug produces one List events = new List() { new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now) }; //TODO: insert new Device here if user adds one - List plugs = new List() { new Device("Placeholder", "Plug", System.Net.IPAddress.Broadcast, 60, "Oldin", "4AHINF"), new Device("Placeholder", "Plug", System.Net.IPAddress.Broadcast, 60, "Oldin", "4AHINF"), new Device("Placeholder", "Plug", System.Net.IPAddress.Broadcast, 60, "Oldin", "4AHINF") }; - + List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; //code for graph LineChart lineChart; diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs index dfa27db..4f9d13e 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs @@ -4,6 +4,7 @@ using Blazorise.Icons.Material; using Blazorise.Material; using Elektrifikatsiya.Database; +using Elektrifikatsiya.Models; using Elektrifikatsiya.Services; using Elektrifikatsiya.Services.Implementations; @@ -20,6 +21,7 @@ builder.Services.AddTransient() builder.Services.AddDbContext(options => options.UseSqlite("Data Source=./UserDatabase.sqlite")); builder.Services.AddDbContext((options) => options.UseSqlite("Data Source=./DeviceManagement.sqlite")); builder.Services.AddBootstrapProviders(); +builder.Services.AddHttpClient(); builder.Services.AddBlazorise(options => { options.Immediate = true; diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs index b659cf1..7cb9954 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs @@ -10,116 +10,123 @@ namespace Elektrifikatsiya.Services.Implementations; public class DeviceManagmentService : IDeviceManagmentService { - private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; - private readonly IDeviceStatusService deviceStatusService; - private readonly HttpClient httpClient; + private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; + private readonly IDeviceStatusService deviceStatusService; + private readonly IServiceScopeFactory serviceScopeFactory; + private readonly HttpClient httpClient; - public DeviceManagmentService(DeviceManagmentDatabaseContext deviceManagmentDatabaseContext, IDeviceStatusService deviceStatusService, HttpClient httpClient) - { - this.deviceManagmentDatabaseContext = deviceManagmentDatabaseContext; - this.deviceStatusService = deviceStatusService; - this.httpClient = httpClient; - } + public DeviceManagmentService(IServiceScopeFactory serviceScopeFactory, IDeviceStatusService deviceStatusService, HttpClient httpClient) + { + this.deviceManagmentDatabaseContext = deviceManagmentDatabaseContext; + this.deviceStatusService = deviceStatusService; + this.httpClient = httpClient; + } - public Result GetDevice(string macAdress) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result GetDevice(string macAdress) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - Device? device = getDevicesResult.Value.FirstOrDefault(d => d.MacAddress == macAdress); + Device? device = getDevicesResult.Value.FirstOrDefault(d => d.MacAddress == macAdress); - if (device is null) - { - return Result.Fail("Device does not exist!"); - } + if (device is null) + { + return Result.Fail("Device does not exist!"); + } - return device; - } + return device; + } - public Result> GetDevices() - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result> GetDevices() + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - return getDevicesResult.Value.ToList(); - } + return getDevicesResult.Value.ToList(); + } - public Result> GetDevicesInRoom(string room) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result> GetDevicesInRoom(string room) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - return getDevicesResult.Value.Where(d => d.Room == room).ToList(); - } + return getDevicesResult.Value.Where(d => d.Room == room).ToList(); + } - public Result> GetDevicesOfUser(int userId) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result> GetDevicesOfUser(int userId) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - return getDevicesResult.Value.Where(d => d.User.Id == userId).ToList(); - } + return getDevicesResult.Value.Where(d => d.User.Id == userId).ToList(); + } - public async Task> Register(IPAddress ip, User user, string? name = null, string room = "default") - { - ShellyResponse? shellyResponse = await httpClient.GetFromJsonAsync($"{ip}/shelly"); + public async Task> Register(IPAddress ip, User user, string? name = null, string room = "default") + { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); - if(shellyResponse is null || shellyResponse.Type != "SHPLG-S") - { - return Result.Fail("Device is not a \"SHPLG-S\" or not reachable!"); - } + ShellyResponse? shellyResponse = await httpClient.GetFromJsonAsync($"{ip}/shelly"); - string mac = shellyResponse.Mac; + if (shellyResponse is null || shellyResponse.Type != "SHPLG-S") + { + return Result.Fail("Device is not a \"SHPLG-S\" or not reachable!"); + } - if(PhysicalAddress.TryParse(mac, out _)) - { - return Result.Fail("Invalid mac address!"); - } + string mac = shellyResponse.Mac; - Device device = new Device(mac, name ?? mac, ip, user, room); + if (PhysicalAddress.TryParse(mac, out _)) + { + return Result.Fail("Invalid mac address!"); + } - deviceManagmentDatabaseContext.Add(device); - Result saveDatabaseChangesResult = await Result.Try(async Task () => await deviceManagmentDatabaseContext.SaveChangesAsync()); + Device device = new Device(mac, name ?? mac, ip, user, room); - Result trackDeviceResult = deviceStatusService.TrackDevice(device); + deviceManagmentDatabaseContext.Add(device); + Result saveDatabaseChangesResult = await Result.Try(async Task () => await deviceManagmentDatabaseContext.SaveChangesAsync()); - return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); - } + Result trackDeviceResult = deviceStatusService.TrackDevice(device); - public async Task Unregister(string macAdress) - { - Result getDeviceResult = GetDevice(macAdress); + return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); + } - if (getDeviceResult.IsFailed) - { - return getDeviceResult.ToResult(); - } + public async Task Unregister(string macAdress) + { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); - Result untrackDeviceResult = deviceStatusService.UntrackDevice(macAdress); + Result getDeviceResult = GetDevice(macAdress); - if (untrackDeviceResult.IsFailed) - { - return untrackDeviceResult; - } + if (getDeviceResult.IsFailed) + { + return getDeviceResult.ToResult(); + } - deviceManagmentDatabaseContext.Remove(getDeviceResult.Value); + Result untrackDeviceResult = deviceStatusService.UntrackDevice(macAdress); - return await Result.Try(async Task () => await deviceManagmentDatabaseContext.SaveChangesAsync()); - } + if (untrackDeviceResult.IsFailed) + { + return untrackDeviceResult; + } + + deviceManagmentDatabaseContext.Remove(getDeviceResult.Value); + + return await Result.Try(async Task () => await deviceManagmentDatabaseContext.SaveChangesAsync()); + } } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/UpdateService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/UpdateService.cs index 980826d..da74f9f 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/UpdateService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/UpdateService.cs @@ -10,19 +10,22 @@ public class UpdateService : IHostedService, IDisposable { private readonly ILogger logger; private readonly IDeviceStatusService deviceStatusService; - private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; + private readonly IServiceScopeFactory serviceScopeFactory; private Timer? timer = null; - public UpdateService(ILogger logger, IDeviceStatusService deviceStatusService, DeviceManagmentDatabaseContext deviceManagmentDatabaseContext) + public UpdateService(ILogger logger, IDeviceStatusService deviceStatusService, IServiceScopeFactory serviceScopeFactory) { this.logger = logger; this.deviceStatusService = deviceStatusService; - this.deviceManagmentDatabaseContext = deviceManagmentDatabaseContext; + this.serviceScopeFactory = serviceScopeFactory; } public async Task StartAsync(CancellationToken cancellationToken) { - logger.LogInformation("Starting update service..."); + IServiceScope serviceScope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = serviceScope.ServiceProvider.GetRequiredService(); + + logger.LogInformation("Starting update service..."); foreach (Device device in await deviceManagmentDatabaseContext.Devices.AsNoTracking().ToListAsync(cancellationToken)) { From 894a23855f75476237e3f84b1b860136e2237a45 Mon Sep 17 00:00:00 2001 From: Stefan <32109571+Stefan-5422@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:48:37 +0100 Subject: [PATCH 2/6] =?UTF-8?q?Device=20discovery=20and=20maybe=20adding?= =?UTF-8?q?=20devices=20=E2=95=AE(=E2=95=AF=E2=96=BD=E2=95=B0)=E2=95=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Elektrifikatsiya/Pages/AddPlug.razor | 26 ++- .../Elektrifikatsiya/Program.cs | 21 +- .../Properties/launchSettings.json | 2 +- .../Services/IDeviceManagmentService.cs | 6 +- .../Implementations/DeviceManagmentService.cs | 189 ++++++++++-------- .../Implementations/DeviceStatusService.cs | 11 +- .../Utilities/MdnsDiscovery.cs | 20 ++ 7 files changed, 168 insertions(+), 107 deletions(-) create mode 100644 src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor index efabc58..c6e1f26 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor @@ -2,13 +2,18 @@ @using Blazorise.Components; @using Elektrifikatsiya.Models; @using System.Net +@using Elektrifikatsiya.Services +@using Elektrifikatsiya.Services.Implementations +@using Elektrifikatsiya.Utilities @inject IVersionProvider VersionProvider +@inject IDeviceManagmentService DeviceManagmentService +@inject IAuthenticationService AuthenticationService @@ -18,17 +23,17 @@ - @context.Item.Name + @context.Item - IP: @context.Item.IpAddress + IP: @context.Item - + @@ -40,5 +45,14 @@ @code { - List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; + List ipAddresses = new List(); + + protected override async Task OnInitializedAsync() + { + MdnsDiscovery.OnDeviceFound += address => + { + ipAddresses.Add(address); + InvokeAsync(StateHasChanged); + }; + } } diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs index 4f9d13e..3c21487 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs @@ -15,16 +15,20 @@ WebApplicationBuilder builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); +builder.Services.AddHttpContextAccessor(); builder.Services.AddHostedService(); builder.Services.AddSingleton(); builder.Services.AddTransient(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddDbContext(options => options.UseSqlite("Data Source=./UserDatabase.sqlite")); builder.Services.AddDbContext((options) => options.UseSqlite("Data Source=./DeviceManagement.sqlite")); builder.Services.AddBootstrapProviders(); builder.Services.AddHttpClient(); builder.Services.AddBlazorise(options => { - options.Immediate = true; + options.Immediate = true; }); AddBlazorise(builder.Services); @@ -34,9 +38,9 @@ WebApplication app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - _ = app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - _ = app.UseHsts(); + _ = app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + _ = app.UseHsts(); } app.UseHttpsRedirection(); @@ -46,12 +50,11 @@ app.UseStaticFiles(); app.UseRouting(); app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); +app.MapControllers(); IServiceScope serviceScope = app.Services.GetRequiredService().CreateScope(); serviceScope.ServiceProvider.GetRequiredService().Database.EnsureCreated(); -app.MapControllers(); - AsyncServiceScope scope = app.Services.CreateAsyncScope(); scope.ServiceProvider.GetRequiredService().Database.EnsureCreated(); @@ -59,7 +62,7 @@ app.Run(); void AddBlazorise(IServiceCollection services) { - _ = services.AddBlazorise(); - _ = services.AddMaterialProviders(); - _ = services.AddMaterialIcons(); + _ = services.AddBlazorise(); + _ = services.AddMaterialProviders(); + _ = services.AddMaterialIcons(); } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Properties/launchSettings.json b/src/Elektrifikatsiya/Elektrifikatsiya/Properties/launchSettings.json index 71c02c5..fe359ad 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Properties/launchSettings.json +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Properties/launchSettings.json @@ -7,7 +7,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "https://localhost:7297;http://localhost:5255" + "applicationUrl": "https://localhost:56656;http://localhost:5255" }, "IIS Express": { "commandName": "IISExpress", diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/IDeviceManagmentService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/IDeviceManagmentService.cs index bda0e67..764ee22 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/IDeviceManagmentService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/IDeviceManagmentService.cs @@ -8,9 +8,9 @@ namespace Elektrifikatsiya.Services; public interface IDeviceManagmentService { - public Task> Register(IPAddress ip, User user, string? name = null, string room = "default"); + public Task> RegisterDevice(IPAddress ip, User user, string? name = null, string room = "default"); - public Task Unregister(string macAdress); + public Task UnregisterDevice(string macAdress); public Result GetDevice(string macAdress); @@ -19,4 +19,6 @@ public interface IDeviceManagmentService public Result> GetDevicesInRoom(string room); public Result> GetDevicesOfUser(int userId); + + public Task UpdateDevice(Device device); } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs index 7cb9954..11937e6 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs @@ -10,123 +10,138 @@ namespace Elektrifikatsiya.Services.Implementations; public class DeviceManagmentService : IDeviceManagmentService { - private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; - private readonly IDeviceStatusService deviceStatusService; - private readonly IServiceScopeFactory serviceScopeFactory; - private readonly HttpClient httpClient; + private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; + private readonly IServiceScopeFactory serviceScopeFactory; + private readonly IDeviceStatusService deviceStatusService; + private readonly HttpClient httpClient; - public DeviceManagmentService(IServiceScopeFactory serviceScopeFactory, IDeviceStatusService deviceStatusService, HttpClient httpClient) - { - this.deviceManagmentDatabaseContext = deviceManagmentDatabaseContext; - this.deviceStatusService = deviceStatusService; - this.httpClient = httpClient; - } + public DeviceManagmentService(IServiceScopeFactory serviceScopeFactory, IDeviceStatusService deviceStatusService, HttpClient httpClient) + { + this.serviceScopeFactory = serviceScopeFactory; + this.deviceStatusService = deviceStatusService; + this.httpClient = httpClient; - public Result GetDevice(string macAdress) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + } - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + public Result GetDevice(string macAdress) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - Device? device = getDevicesResult.Value.FirstOrDefault(d => d.MacAddress == macAdress); + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - if (device is null) - { - return Result.Fail("Device does not exist!"); - } + Device? device = getDevicesResult.Value.FirstOrDefault(d => d.MacAddress == macAdress); - return device; - } + if (device is null) + { + return Result.Fail("Device does not exist!"); + } - public Result> GetDevices() - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + return device; + } - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + public Result> GetDevices() + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - return getDevicesResult.Value.ToList(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - public Result> GetDevicesInRoom(string room) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + return getDevicesResult.Value.ToList(); + } - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + public Result> GetDevicesInRoom(string room) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - return getDevicesResult.Value.Where(d => d.Room == room).ToList(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - public Result> GetDevicesOfUser(int userId) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + return getDevicesResult.Value.Where(d => d.Room == room).ToList(); + } - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + public Result> GetDevicesOfUser(int userId) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - return getDevicesResult.Value.Where(d => d.User.Id == userId).ToList(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - public async Task> Register(IPAddress ip, User user, string? name = null, string room = "default") - { - using IServiceScope scope = serviceScopeFactory.CreateScope(); - DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); + return getDevicesResult.Value.Where(d => d.User.Id == userId).ToList(); + } - ShellyResponse? shellyResponse = await httpClient.GetFromJsonAsync($"{ip}/shelly"); + public async Task> RegisterDevice(IPAddress ip, User user, string? name = null, string room = "default") + { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); - if (shellyResponse is null || shellyResponse.Type != "SHPLG-S") - { - return Result.Fail("Device is not a \"SHPLG-S\" or not reachable!"); - } + ShellyResponse? shellyResponse = await httpClient.GetFromJsonAsync($"http://{ip}/shelly"); - string mac = shellyResponse.Mac; + if (shellyResponse is null || shellyResponse.Type != "SHPLG-S") + { + return Result.Fail("Device is not reachable or not a \"SHPLG-S\"!"); + } - if (PhysicalAddress.TryParse(mac, out _)) - { - return Result.Fail("Invalid mac address!"); - } + string mac = shellyResponse.Mac; - Device device = new Device(mac, name ?? mac, ip, user, room); + if (!PhysicalAddress.TryParse(mac, out _)) + { + return Result.Fail("Invalid mac address!"); + } - deviceManagmentDatabaseContext.Add(device); - Result saveDatabaseChangesResult = await Result.Try(async Task () => await deviceManagmentDatabaseContext.SaveChangesAsync()); + Device device = new Device(mac, name ?? mac, ip, user, room); - Result trackDeviceResult = deviceStatusService.TrackDevice(device); + deviceManagmentDatabaseContext.Add(device); + Result saveDatabaseChangesResult = await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); - return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); - } + Result trackDeviceResult = deviceStatusService.TrackDevice(device); - public async Task Unregister(string macAdress) - { - using IServiceScope scope = serviceScopeFactory.CreateScope(); - DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); + return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); + } + + public async Task UnregisterDevice(string macAdress) + { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); Result getDeviceResult = GetDevice(macAdress); - if (getDeviceResult.IsFailed) - { - return getDeviceResult.ToResult(); - } + if (getDeviceResult.IsFailed) + { + return getDeviceResult.ToResult(); + } - Result untrackDeviceResult = deviceStatusService.UntrackDevice(macAdress); + Result untrackDeviceResult = deviceStatusService.UntrackDevice(macAdress); - if (untrackDeviceResult.IsFailed) - { - return untrackDeviceResult; - } + if (untrackDeviceResult.IsFailed) + { + return untrackDeviceResult; + } - deviceManagmentDatabaseContext.Remove(getDeviceResult.Value); + deviceManagmentDatabaseContext.Remove(getDeviceResult.Value); - return await Result.Try(async Task () => await deviceManagmentDatabaseContext.SaveChangesAsync()); - } + return await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); + } + + public async Task UpdateDevice(Device device) + { + Result result = deviceStatusService.UpdateDeviceStatus(device); + + if (result.IsFailed) + { + return result; + } + + deviceManagmentDatabaseContext.Update(device); + + return await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); + } } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceStatusService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceStatusService.cs index 3574cec..2e6e904 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceStatusService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceStatusService.cs @@ -6,10 +6,15 @@ namespace Elektrifikatsiya.Services.Implementations; public class DeviceStatusService : IDeviceStatusService { - public event EventHandler? OnDeviceStatusChanged; + private readonly ILogger logger; + public event EventHandler? OnDeviceStatusChanged; private readonly Dictionary devices = new(); - + + public DeviceStatusService(ILogger logger) + { + this.logger = logger; + } public Result> GetDevices() { return devices.Values.ToList(); @@ -41,6 +46,8 @@ public class DeviceStatusService : IDeviceStatusService return Result.Fail("Device already tracked!"); } + logger.LogInformation("Tracking new Device {device}", device.IpAddress); + devices[device.MacAddress] = device; return Result.Ok(); diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs new file mode 100644 index 0000000..8b9c46a --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs @@ -0,0 +1,20 @@ +using System.Net; +using FluentResults; +using Tmds.MDns; + +namespace Elektrifikatsiya.Utilities; + +public static class MdnsDiscovery +{ + public static event Action OnDeviceFound; + + static ServiceBrowser serviceBrowser = new ServiceBrowser(); + + static MdnsDiscovery() + { + serviceBrowser.StartBrowse("_http._tcp"); + serviceBrowser.ServiceAdded += (_, eventArgs) => OnDeviceFound?.Invoke(eventArgs.Announcement.Addresses.First()); + serviceBrowser.ServiceChanged += (_, eventArgs) => OnDeviceFound?.Invoke(eventArgs.Announcement.Addresses.First()); + serviceBrowser.ServiceRemoved += (_, eventArgs) => OnDeviceFound?.Invoke(eventArgs.Announcement.Addresses.First()); + } +} \ No newline at end of file From 2f906063e9efe9750d4e5b1256354e52add04e17 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 7 Mar 2023 18:08:04 +0100 Subject: [PATCH 3/6] Improve MdnsDiscovery --- .../Elektrifikatsiya/Pages/AddPlug.razor | 3 +- .../Implementations/DeviceManagmentService.cs | 205 +++++++++--------- .../Utilities/MdnsDiscovery.cs | 17 +- 3 files changed, 121 insertions(+), 104 deletions(-) diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor index c6e1f26..8f84fef 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor @@ -47,8 +47,9 @@ @code { List ipAddresses = new List(); - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { + ipAddresses.AddRange(MdnsDiscovery.GetChachedDevices()); MdnsDiscovery.OnDeviceFound += address => { ipAddresses.Add(address); diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs index 11937e6..5bbf350 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs @@ -10,138 +10,149 @@ namespace Elektrifikatsiya.Services.Implementations; public class DeviceManagmentService : IDeviceManagmentService { - private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; - private readonly IServiceScopeFactory serviceScopeFactory; - private readonly IDeviceStatusService deviceStatusService; - private readonly HttpClient httpClient; + private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; + private readonly IServiceScopeFactory serviceScopeFactory; + private readonly IDeviceStatusService deviceStatusService; + private readonly ILogger logger; + private readonly HttpClient httpClient; - public DeviceManagmentService(IServiceScopeFactory serviceScopeFactory, IDeviceStatusService deviceStatusService, HttpClient httpClient) - { - this.serviceScopeFactory = serviceScopeFactory; - this.deviceStatusService = deviceStatusService; - this.httpClient = httpClient; + public DeviceManagmentService(IServiceScopeFactory serviceScopeFactory, IDeviceStatusService deviceStatusService, ILogger logger, HttpClient httpClient) + { + this.serviceScopeFactory = serviceScopeFactory; + this.deviceStatusService = deviceStatusService; + this.logger = logger; + this.httpClient = httpClient; - } + } - public Result GetDevice(string macAdress) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result GetDevice(string macAdress) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - Device? device = getDevicesResult.Value.FirstOrDefault(d => d.MacAddress == macAdress); + Device? device = getDevicesResult.Value.FirstOrDefault(d => d.MacAddress == macAdress); - if (device is null) - { - return Result.Fail("Device does not exist!"); - } + if (device is null) + { + return Result.Fail("Device does not exist!"); + } - return device; - } + return device; + } - public Result> GetDevices() - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result> GetDevices() + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - return getDevicesResult.Value.ToList(); - } + return getDevicesResult.Value.ToList(); + } - public Result> GetDevicesInRoom(string room) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result> GetDevicesInRoom(string room) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - return getDevicesResult.Value.Where(d => d.Room == room).ToList(); - } + return getDevicesResult.Value.Where(d => d.Room == room).ToList(); + } - public Result> GetDevicesOfUser(int userId) - { - Result> getDevicesResult = deviceStatusService.GetDevices(); + public Result> GetDevicesOfUser(int userId) + { + Result> getDevicesResult = deviceStatusService.GetDevices(); - if (getDevicesResult.IsFailed) - { - return getDevicesResult.ToResult(); - } + if (getDevicesResult.IsFailed) + { + return getDevicesResult.ToResult(); + } - return getDevicesResult.Value.Where(d => d.User.Id == userId).ToList(); - } + return getDevicesResult.Value.Where(d => d.User.Id == userId).ToList(); + } - public async Task> RegisterDevice(IPAddress ip, User user, string? name = null, string room = "default") - { - using IServiceScope scope = serviceScopeFactory.CreateScope(); - DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); + public async Task> RegisterDevice(IPAddress ip, User user, string? name = null, string room = "default") + { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); - ShellyResponse? shellyResponse = await httpClient.GetFromJsonAsync($"http://{ip}/shelly"); + ShellyResponse? shellyResponse = null; - if (shellyResponse is null || shellyResponse.Type != "SHPLG-S") - { - return Result.Fail("Device is not reachable or not a \"SHPLG-S\"!"); - } + try + { + shellyResponse = await httpClient.GetFromJsonAsync($"http://{ip}/shelly"); + } + catch (Exception ex) + { + logger.LogError("HTTP request failed! {message}", ex.Message); + } - string mac = shellyResponse.Mac; + if (shellyResponse is null || shellyResponse.Type != "SHPLG-S") + { + return Result.Fail("Device is not reachable or not a \"SHPLG-S\"!"); + } - if (!PhysicalAddress.TryParse(mac, out _)) - { - return Result.Fail("Invalid mac address!"); - } + string mac = shellyResponse.Mac; - Device device = new Device(mac, name ?? mac, ip, user, room); + if (!PhysicalAddress.TryParse(mac, out _)) + { + return Result.Fail("Invalid mac address!"); + } - deviceManagmentDatabaseContext.Add(device); - Result saveDatabaseChangesResult = await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); + Device device = new Device(mac, name ?? mac, ip, user, room); - Result trackDeviceResult = deviceStatusService.TrackDevice(device); + _ = deviceManagmentDatabaseContext.Add(device); + Result saveDatabaseChangesResult = await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); - return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); - } + Result trackDeviceResult = deviceStatusService.TrackDevice(device); - public async Task UnregisterDevice(string macAdress) - { - using IServiceScope scope = serviceScopeFactory.CreateScope(); - DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); + return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); + } + + public async Task UnregisterDevice(string macAdress) + { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); Result getDeviceResult = GetDevice(macAdress); - if (getDeviceResult.IsFailed) - { - return getDeviceResult.ToResult(); - } + if (getDeviceResult.IsFailed) + { + return getDeviceResult.ToResult(); + } - Result untrackDeviceResult = deviceStatusService.UntrackDevice(macAdress); + Result untrackDeviceResult = deviceStatusService.UntrackDevice(macAdress); - if (untrackDeviceResult.IsFailed) - { - return untrackDeviceResult; - } + if (untrackDeviceResult.IsFailed) + { + return untrackDeviceResult; + } - deviceManagmentDatabaseContext.Remove(getDeviceResult.Value); + _ = deviceManagmentDatabaseContext.Remove(getDeviceResult.Value); - return await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); - } + return await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); + } - public async Task UpdateDevice(Device device) - { - Result result = deviceStatusService.UpdateDeviceStatus(device); + public async Task UpdateDevice(Device device) + { + Result result = deviceStatusService.UpdateDeviceStatus(device); - if (result.IsFailed) - { - return result; - } + if (result.IsFailed) + { + return result; + } - deviceManagmentDatabaseContext.Update(device); + _ = deviceManagmentDatabaseContext.Update(device); - return await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); - } + return await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); + } } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs index 8b9c46a..55a8943 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Utilities/MdnsDiscovery.cs @@ -1,20 +1,25 @@ using System.Net; -using FluentResults; + using Tmds.MDns; namespace Elektrifikatsiya.Utilities; public static class MdnsDiscovery { - public static event Action OnDeviceFound; + public static event Action OnDeviceFound = null!; - static ServiceBrowser serviceBrowser = new ServiceBrowser(); + private static readonly ServiceBrowser serviceBrowser = new ServiceBrowser(); - static MdnsDiscovery() - { - serviceBrowser.StartBrowse("_http._tcp"); + static MdnsDiscovery() + { + serviceBrowser.StartBrowse("_http._tcp"); serviceBrowser.ServiceAdded += (_, eventArgs) => OnDeviceFound?.Invoke(eventArgs.Announcement.Addresses.First()); serviceBrowser.ServiceChanged += (_, eventArgs) => OnDeviceFound?.Invoke(eventArgs.Announcement.Addresses.First()); serviceBrowser.ServiceRemoved += (_, eventArgs) => OnDeviceFound?.Invoke(eventArgs.Announcement.Addresses.First()); } + + public static IEnumerable GetChachedDevices() + { + return serviceBrowser.Services.Select(s => s.Addresses.First()); + } } \ No newline at end of file From 814c0d9ca49dde81c2c3ed3ae77a52b2883ad563 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 7 Mar 2023 18:10:22 +0100 Subject: [PATCH 4/6] Improve error handling in DeviceManagmentService --- .../Implementations/DeviceManagmentService.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs index 5bbf350..34916e0 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/Implementations/DeviceManagmentService.cs @@ -10,7 +10,6 @@ namespace Elektrifikatsiya.Services.Implementations; public class DeviceManagmentService : IDeviceManagmentService { - private readonly DeviceManagmentDatabaseContext deviceManagmentDatabaseContext; private readonly IServiceScopeFactory serviceScopeFactory; private readonly IDeviceStatusService deviceStatusService; private readonly ILogger logger; @@ -22,7 +21,6 @@ public class DeviceManagmentService : IDeviceManagmentService this.deviceStatusService = deviceStatusService; this.logger = logger; this.httpClient = httpClient; - } public Result GetDevice(string macAdress) @@ -113,9 +111,12 @@ public class DeviceManagmentService : IDeviceManagmentService _ = deviceManagmentDatabaseContext.Add(device); Result saveDatabaseChangesResult = await Result.Try(Task () => deviceManagmentDatabaseContext.SaveChangesAsync()); - Result trackDeviceResult = deviceStatusService.TrackDevice(device); + if (saveDatabaseChangesResult.IsFailed) + { + return saveDatabaseChangesResult; + } - return Result.Merge(saveDatabaseChangesResult, trackDeviceResult).ToResult(device); + return deviceStatusService.TrackDevice(device); } public async Task UnregisterDevice(string macAdress) @@ -144,6 +145,9 @@ public class DeviceManagmentService : IDeviceManagmentService public async Task UpdateDevice(Device device) { + using IServiceScope scope = serviceScopeFactory.CreateScope(); + DeviceManagmentDatabaseContext deviceManagmentDatabaseContext = scope.ServiceProvider.GetRequiredService(); + Result result = deviceStatusService.UpdateDeviceStatus(device); if (result.IsFailed) From 9b5a9337104f2cba5e25bc8deea2c4ac0c400e3a Mon Sep 17 00:00:00 2001 From: Aldin296 <99395958+Aldin296@users.noreply.github.com> Date: Wed, 8 Mar 2023 10:17:08 +0100 Subject: [PATCH 5/6] Settings Page Frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit weiter eingabe felder für die Settings Page hinzugefügt --- .../Elektrifikatsiya/Pages/Dashboard.razor | 2 +- .../Elektrifikatsiya/Pages/Settings.razor | 78 ++++++++++++++++-- .../Elektrifikatsiya/UserDatabase.sqlite-shm | Bin 32768 -> 0 bytes .../Elektrifikatsiya/UserDatabase.sqlite-wal | 0 4 files changed, 74 insertions(+), 6 deletions(-) delete mode 100644 src/Elektrifikatsiya/Elektrifikatsiya/UserDatabase.sqlite-shm delete mode 100644 src/Elektrifikatsiya/Elektrifikatsiya/UserDatabase.sqlite-wal diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor index 049c64e..0991dfd 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor @@ -89,7 +89,7 @@ @code { //TODO: insert new event here if plug produces one - List events = new List() { new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now) }; + List events = new List() { new Event("Placeholder", "Event", DateTime.Now), new Event("Placeholder", "Event", DateTime.Now), new Event("Placeholder", "Event", DateTime.Now) }; //TODO: insert new Device here if user adds one List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Huso", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; //code for graph diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor index 415044c..00e3089 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor @@ -23,7 +23,7 @@ - + @context.Item.Name @@ -35,21 +35,89 @@ Room: @context.Item.Room - - @context.Item.PowerUsage W - - + + + + + + + + + + + Plug Name + + + Here you can change the Name of your Plug + + + + + + + + + + Change Max Output + + + Here you can limit how much Power your Plug uses + + + + + + + + + + Electricity Price + + + Here you enter your electricity price. This is gonna calculate the overall Price of your System + + + + + + + + + + Select Room + + + Here you select or change the Room where you use your Plug. + + + + + Rooms + + Room 1 + + Room 2 + + Room 3 + + + + + Save + + + diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/UserDatabase.sqlite-shm b/src/Elektrifikatsiya/Elektrifikatsiya/UserDatabase.sqlite-shm deleted file mode 100644 index fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIuAr62r3 Date: Wed, 8 Mar 2023 10:14:43 +0100 Subject: [PATCH 6/6] Dashboard fix Fix for responsive behaviour --- .../Elektrifikatsiya/Pages/Dashboard.razor | 162 +++++++++--------- 1 file changed, 82 insertions(+), 80 deletions(-) diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor index 0991dfd..3dc0ff8 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor @@ -4,88 +4,90 @@ @using System.Net @inject IVersionProvider VersionProvider - - - - - - Plugs - - - - - - - - - - @context.Item.Name - - - - - User: @context.Item.User - - Room: @context.Item.Room - - - @context.Item.PowerUsage W - - - - - - - - - - - - + + + + + + + Plugs + + + + + + + + + + @context.Item.Name + + + + + User: @context.Item.User + + Room: @context.Item.Room + + + @context.Item.PowerUsage W + + + + + + + + + + + + + + + + + Logs + + + + + + @context.Item.EventName + @context.Item.Date + + @context.Item.Description + + + + + + + + Aktualisieren + - - - - Plugs - - - + + - - - @context.Item.EventName - @context.Item.Date - - @context.Item.Description - - - - - - - - Aktualisieren - - - @code { //TODO: insert new event here if plug produces one