mirror of
https://github.com/Stefan-5422/-T5-Elektrifikatsiya.git
synced 2026-09-04 00:45:58 +02:00
Fix formatting and other stuff
whoopsie
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
using Blazorise;
|
||||
|
||||
using Elektrifikatsiya.Components.TodoApp;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elektrifikatsiya.Components.TodoApp;
|
||||
public abstract class BaseTodoItems : ComponentBase
|
||||
{
|
||||
protected Validations validations;
|
||||
|
||||
protected string description;
|
||||
|
||||
protected Filter filter = Filter.All;
|
||||
|
||||
protected List<Todo> todos = new()
|
||||
{
|
||||
new() { Description = "Buy milk" },
|
||||
new() { Description = "Call John regarding the meeting" },
|
||||
new() { Description = "Walk a dog" },
|
||||
};
|
||||
|
||||
protected IEnumerable<Todo> Todos
|
||||
{
|
||||
get
|
||||
{
|
||||
var query = from t in todos select t;
|
||||
|
||||
if (filter == Filter.Active)
|
||||
query = from q in query where !q.Completed select q;
|
||||
|
||||
if (filter == Filter.Completed)
|
||||
query = from q in query where q.Completed select q;
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
protected void SetFilter(Filter filter)
|
||||
{
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
protected void OnCheckAll(bool isChecked)
|
||||
{
|
||||
todos.ForEach(x => x.Completed = isChecked);
|
||||
}
|
||||
|
||||
protected async Task OnAddTodo()
|
||||
{
|
||||
if (await validations.ValidateAll())
|
||||
{
|
||||
todos.Add(new() { Description = description });
|
||||
description = null;
|
||||
|
||||
await validations.ClearAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnClearCompleted()
|
||||
{
|
||||
todos.RemoveAll(x => x.Completed);
|
||||
filter = Filter.All;
|
||||
}
|
||||
|
||||
protected Task OnTodoStatusChanged(bool isChecked)
|
||||
{
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Elektrifikatsiya.Components.TodoApp;
|
||||
|
||||
public enum Filter
|
||||
{
|
||||
All,
|
||||
Active,
|
||||
Completed,
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Elektrifikatsiya.Components.TodoApp;
|
||||
|
||||
public class Todo
|
||||
{
|
||||
public bool Completed { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<ListGroupItem>
|
||||
<Field Horizontal Padding="Padding.IsAuto.OnAll">
|
||||
<FieldBody ColumnSize="ColumnSize.Is1">
|
||||
<Check TValue="bool" Checked="@Todo.Completed" CheckedChanged="@OnCheckedChanged"></Check>
|
||||
</FieldBody>
|
||||
<FieldBody ColumnSize="ColumnSize.Is11">
|
||||
@Todo.Description
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</ListGroupItem>
|
||||
@code{
|
||||
Task OnCheckedChanged( bool isChecked )
|
||||
{
|
||||
Todo.Completed = isChecked;
|
||||
|
||||
return StatusChanged?.Invoke( isChecked );
|
||||
}
|
||||
|
||||
[Parameter] public Todo Todo { get; set; }
|
||||
|
||||
[Parameter] public Func<bool, Task> StatusChanged { get; set; }
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
@inherits BaseTodoItems
|
||||
<Container Fluid>
|
||||
<Row>
|
||||
<Column>
|
||||
<Card>
|
||||
<CardHeader Padding="Padding.Is1.FromBottom">
|
||||
<CardTitle Size="4">Todo List</CardTitle>
|
||||
</CardHeader>
|
||||
<CardBody Padding="Padding.Is0.FromBottom">
|
||||
<Fields>
|
||||
<Column ColumnSize="ColumnSize.Is1">
|
||||
<Check TValue="bool" Checked="@Todos.All(x=>x.Completed)" CheckedChanged="@OnCheckAll">All</Check>
|
||||
</Column>
|
||||
<Column ColumnSize="ColumnSize.Is11">
|
||||
<Addons>
|
||||
<Addon AddonType="AddonType.Body">
|
||||
<Validations @ref="validations" Mode="ValidationMode.Manual">
|
||||
<Validation Validator="@ValidationRule.IsNotEmpty">
|
||||
<TextEdit @bind-Text="@description" Placeholder="What needs to be done?"></TextEdit>
|
||||
</Validation>
|
||||
</Validations>
|
||||
</Addon>
|
||||
<Addon AddonType="AddonType.End">
|
||||
<Button Color="Color.Primary" Clicked="@OnAddTodo">
|
||||
<Icon Name="IconName.Add" />Add
|
||||
</Button>
|
||||
</Addon>
|
||||
</Addons>
|
||||
</Column>
|
||||
</Fields>
|
||||
</CardBody>
|
||||
<CardBody Padding="Padding.Is0.OnY">
|
||||
<ListGroup Flush>
|
||||
@foreach ( var todo in Todos )
|
||||
{
|
||||
<TodoItem Todo="@todo" StatusChanged="@OnTodoStatusChanged" />
|
||||
}
|
||||
</ListGroup>
|
||||
</CardBody>
|
||||
<CardFooter Padding="Padding.Is3.FromBottom">
|
||||
<Field Horizontal>
|
||||
<FieldBody ColumnSize="ColumnSize.Is10">
|
||||
<Buttons Role="ButtonsRole.Addons">
|
||||
<Button Color="Color.Info" Clicked="@(() => SetFilter( Filter.All ))" Active="@(filter == Filter.All)">All</Button>
|
||||
<Button Color="Color.Info" Clicked="@(() => SetFilter( Filter.Active ))" Active="@(filter == Filter.Active)">Active</Button>
|
||||
<Button Color="Color.Info" Clicked="@(() => SetFilter( Filter.Completed ))" Active="@(filter == Filter.Completed)">Completed</Button>
|
||||
</Buttons>
|
||||
</FieldBody>
|
||||
<FieldBody ColumnSize="ColumnSize.Is2">
|
||||
<Button Color="Color.Warning" Float="Float.End" Clicked="@OnClearCompleted" Display="@(todos.Any(x=>x.Completed) ? Display.Always : Display.None)">Clear Completed</Button>
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</Column>
|
||||
</Row>
|
||||
</Container>
|
||||
@@ -1,17 +1,42 @@
|
||||
@using System.Diagnostics;
|
||||
@using FluentResults;
|
||||
|
||||
@inject Elektrifikatsiya.Services.IAuthenticationService AuthenticationService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
<Image Source="logo.png" Width="Width.Is50" Height="Height.Is50"> </Image>
|
||||
<Card Width="Width.Is50" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Padding="Padding.Is5">
|
||||
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.Is3.WithOffset">
|
||||
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle">
|
||||
<TextEdit Placeholder="Username" />
|
||||
<TextEdit @bind-Text="username" Placeholder="Username" />
|
||||
</Field>
|
||||
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle">
|
||||
<TextEdit Role="TextRole.Password" Placeholder="Password" />
|
||||
<TextEdit @bind-Text="password" Role="TextRole.Password" Placeholder="Password" />
|
||||
</Field>
|
||||
<Button Color="Color.Primary" Position="Position.Relative.Bottom.Is50.Start.Is50.Translate.MiddleX">Login</Button>
|
||||
</Column>
|
||||
<Button Width="Width.Is25" Disabled="disabled" Color="color" Clicked="Clicked" Position="Position.Relative.Bottom.Is50.Start.Is50.Translate.MiddleX">Login</Button>
|
||||
</Column>
|
||||
</Card>
|
||||
@code {
|
||||
private string username = string.Empty;
|
||||
private string password = string.Empty;
|
||||
private Color color = Color.Primary;
|
||||
private bool disabled;
|
||||
private async Task Clicked()
|
||||
{
|
||||
color = Color.Primary;
|
||||
disabled = true;
|
||||
|
||||
Result loginResult = await AuthenticationService.LoginUserAsync(username, password);
|
||||
|
||||
if (loginResult.IsSuccess)
|
||||
{
|
||||
NavigationManager.NavigateTo("/", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = Color.Danger;
|
||||
disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc.Diagnostics;
|
||||
|
||||
namespace Elektrifikatsiya.Models;
|
||||
|
||||
@@ -50,48 +50,47 @@ public class PrometheusDataWrapper
|
||||
|
||||
public FluentResults.Result<List<(double, double)>> MatrixTypeToTimestampFloatTuple()
|
||||
{
|
||||
if (ResultType != ResultType.Matrix)
|
||||
{
|
||||
return FluentResults.Result.Fail("The response did not have the Matrix Type");
|
||||
}
|
||||
if (ResultType != ResultType.Matrix)
|
||||
{
|
||||
return FluentResults.Result.Fail("The response did not have the Matrix Type");
|
||||
}
|
||||
|
||||
List<(double, double)> result = new List<(double, double)>();
|
||||
|
||||
if (Result.Count == 0 || Result[0]?.Values is null || Result[0]?.Values?[0] is null)
|
||||
{
|
||||
return FluentResults.Result.Fail("There was no result in the Response Body");
|
||||
return FluentResults.Result.Fail("There was no result in the Response Body");
|
||||
}
|
||||
|
||||
foreach (object value in Result[0]!.Values!)
|
||||
{
|
||||
{
|
||||
|
||||
string[] segment = value.ToString()!.Split(",");
|
||||
string[] segment = value.ToString()!.Split(",");
|
||||
|
||||
result.Add((Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2])));
|
||||
}
|
||||
result.Add((Convert.ToDouble(segment[0][2..^1], CultureInfo.InvariantCulture), Convert.ToDouble(segment[1][1..^2], CultureInfo.InvariantCulture)));
|
||||
}
|
||||
Debug.WriteLine(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public FluentResults.Result<(double, double)> VectorTypeToTimestampFloatTuple()
|
||||
{
|
||||
if (ResultType != ResultType.Vector)
|
||||
{
|
||||
return FluentResults.Result.Fail("The response did not have the Vector Type");
|
||||
}
|
||||
if (ResultType != ResultType.Vector)
|
||||
{
|
||||
return FluentResults.Result.Fail("The response did not have the Vector Type");
|
||||
}
|
||||
|
||||
string[]? segment = Result.FirstOrDefault()?.Value.ToString()?.Split(",") ?? null;
|
||||
string[]? segment = Result.FirstOrDefault()?.Value?.ToString()?.Split(",");
|
||||
|
||||
if (segment is null)
|
||||
{
|
||||
return FluentResults.Result.Fail("There was no result in the Response Body");
|
||||
}
|
||||
if (segment is null)
|
||||
{
|
||||
return FluentResults.Result.Fail("There was no result in the Response Body");
|
||||
}
|
||||
|
||||
return((Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2])));
|
||||
return (Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2], CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PrometheusDataMetric
|
||||
{
|
||||
[JsonPropertyName("__name__")] public string Name { get; set; }
|
||||
|
||||
@@ -14,144 +14,155 @@
|
||||
|
||||
|
||||
<Row Style="height:50%; width:100%" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
||||
<Row Style="height:90%; width:100%">
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
||||
<Bar Breakpoint="Breakpoint.Desktop"
|
||||
Background="Background.White"
|
||||
ThemeContrast="ThemeContrast.None"
|
||||
Shadow="Shadow.Remove"
|
||||
Border="Border.Is1.RoundedTop">
|
||||
<BarBrand>
|
||||
<Column ColumnSize="ColumnSize.Is9">
|
||||
Add a plug via wifi
|
||||
</Column>
|
||||
<Column ColumnSize="ColumnSize.Is3.Is6.WithOffset">
|
||||
<LoadingIndicator @bind-Visible="@visible"/>
|
||||
<Row Style="height:90%; width:100%">
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
||||
<Bar Breakpoint="Breakpoint.Desktop"
|
||||
Background="Background.White"
|
||||
ThemeContrast="ThemeContrast.None"
|
||||
Shadow="Shadow.Remove"
|
||||
Border="Border.Is1.RoundedTop">
|
||||
<BarBrand>
|
||||
<Column ColumnSize="ColumnSize.Is9">
|
||||
Add a plug via wifi
|
||||
</Column>
|
||||
<Column ColumnSize="ColumnSize.Is3.Is6.WithOffset">
|
||||
<LoadingIndicator @bind-Visible="@visible" />
|
||||
|
||||
</Column>
|
||||
</BarBrand>
|
||||
</Bar>
|
||||
<ListView Class="w-100"
|
||||
TItem="IPAddress"
|
||||
Data="@ipAddresses"
|
||||
TextField="@((_)=>(""))"
|
||||
ValueField="@((_)=>(""))"
|
||||
Mode="ListGroupMode.Static"
|
||||
Style="border-radius: 0px 0px">
|
||||
<ItemTemplate>
|
||||
<ListGroupItem>
|
||||
<Row>
|
||||
<Column ColumnSize="ColumnSize.Is8">
|
||||
<Row>
|
||||
</Row>
|
||||
<Row Width="Width.Is100">
|
||||
<Column>
|
||||
<Small>IP: @context.Item</Small>
|
||||
</Column>
|
||||
</Row>
|
||||
</Column>
|
||||
<Column ColumnSize="ColumnSize.Is4">
|
||||
<Button Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Clicked="@(async () => await DeviceManagmentService.RegisterDevice(context.Item,(await AuthenticationService.GetUserAsync()).ValueOrDefault))" Outline>
|
||||
<BarIcon IconName="IconName.Add" />
|
||||
</Button>
|
||||
</Column>
|
||||
</Row>
|
||||
</ListGroupItem>
|
||||
</ItemTemplate>
|
||||
</ListView>
|
||||
</Column>
|
||||
</Row>
|
||||
</Column>
|
||||
</BarBrand>
|
||||
</Bar>
|
||||
<ListView Class="w-100"
|
||||
TItem="IPAddress"
|
||||
Data="@ipAddresses"
|
||||
TextField="@((_)=>(""))"
|
||||
ValueField="@((_)=>(""))"
|
||||
Mode="ListGroupMode.Static"
|
||||
Style="border-radius: 0px 0px">
|
||||
<ItemTemplate>
|
||||
<ListGroupItem>
|
||||
<Row>
|
||||
<Column ColumnSize="ColumnSize.Is8">
|
||||
<Row>
|
||||
</Row>
|
||||
<Row Width="Width.Is100">
|
||||
<Column>
|
||||
<Small>IP: @context.Item</Small>
|
||||
</Column>
|
||||
</Row>
|
||||
</Column>
|
||||
<Column ColumnSize="ColumnSize.Is4">
|
||||
<Button Disabled="disabled" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Clicked="@(async () => await RegisterDevice(context.Item))" Outline>
|
||||
<BarIcon IconName="IconName.Add" />
|
||||
</Button>
|
||||
</Column>
|
||||
</Row>
|
||||
</ListGroupItem>
|
||||
</ItemTemplate>
|
||||
</ListView>
|
||||
</Column>
|
||||
</Row>
|
||||
</Row>
|
||||
<Row Style="height:50%; width:100%; border-top-style:solid; border-top-color:#1a237e" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
||||
<Row Style="height:15%; width:100%"></Row>
|
||||
<Row Style="height:10%; width:100%">
|
||||
<Bar Breakpoint="Breakpoint.Desktop"
|
||||
Background="Background.White"
|
||||
ThemeContrast="ThemeContrast.None"
|
||||
Shadow="Shadow.Remove"
|
||||
Border="Border.Is1.RoundedTop"
|
||||
Style="width:100%">
|
||||
<BarBrand>
|
||||
Add a plug via IP
|
||||
</BarBrand>
|
||||
</Bar>
|
||||
<ListGroup Style="width:100%; border-radius: 0px 0px">
|
||||
<ListGroupItem Color="Color.Default">
|
||||
<Form>
|
||||
<Field Horizontal>
|
||||
<FieldBody ColumnSize="ColumnSize.Is12">
|
||||
<TextEdit Placeholder="Enter the Device IP here" />
|
||||
<br>
|
||||
<Button style="background-color:#1a237e; color:white" Type="ButtonType.Submit" PreventDefaultOnSubmit>CONNECT</Button>
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</Form>
|
||||
</ListGroupItem>
|
||||
</ListGroup>
|
||||
</Row>
|
||||
<Row Style="height:75%; width:100%"></Row>
|
||||
</Column>
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
||||
<Row Style="height:15%; width:100%"></Row>
|
||||
<Row Style="height:10%; width:100%">
|
||||
<Bar Breakpoint="Breakpoint.Desktop"
|
||||
Background="Background.White"
|
||||
ThemeContrast="ThemeContrast.None"
|
||||
Shadow="Shadow.Remove"
|
||||
Border="Border.Is1.RoundedTop"
|
||||
Style="width:100%">
|
||||
<BarBrand>
|
||||
Add a plug via IP
|
||||
</BarBrand>
|
||||
</Bar>
|
||||
<ListGroup Style="width:100%; border-radius: 0px 0px">
|
||||
<ListGroupItem Color="Color.Default">
|
||||
<Form>
|
||||
<Validation @ref="ipValidation" Validator="ValidateIPv4">
|
||||
<Field Horizontal>
|
||||
<FieldBody ColumnSize="ColumnSize.Is12">
|
||||
<TextEdit @bind-Text="ipText" Placeholder="Enter the Device IP here">
|
||||
<Feedback>
|
||||
<ValidationNone>Please enter a ip address.</ValidationNone>
|
||||
<ValidationSuccess>Ip address is valid.</ValidationSuccess>
|
||||
<ValidationError>Ip address is not valid!</ValidationError>
|
||||
</Feedback>
|
||||
</TextEdit>
|
||||
<br>
|
||||
<Button style="background-color:#1a237e; color:white" Type="ButtonType.Submit" Disabled="ipValidation?.Status != ValidationStatus.Success || disabled" Clicked="@(async (_)=> await RegisterDevice(IPAddress.Parse(ipText!)))" PreventDefaultOnSubmit>CONNECT</Button>
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</Validation>
|
||||
</Form>
|
||||
</ListGroupItem>
|
||||
</ListGroup>
|
||||
</Row>
|
||||
<Row Style="height:75%; width:100%"></Row>
|
||||
</Column>
|
||||
</Row>
|
||||
|
||||
@code {
|
||||
List<IPAddress> ipAddresses = new List<IPAddress>();
|
||||
List<IPAddress> ipAddresses = new List<IPAddress>();
|
||||
|
||||
Validation? ipValidation;
|
||||
Validation? ipValidation;
|
||||
|
||||
bool visible = true;
|
||||
bool visible = true;
|
||||
bool disabled = false;
|
||||
|
||||
string ipText = null!;
|
||||
string ipText = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
MdnsDiscovery.OnDeviceFound += async ipAddress =>
|
||||
{
|
||||
visible = false;
|
||||
if (!ipAddresses.Contains(ipAddress))
|
||||
{
|
||||
ipAddresses.Add(ipAddress);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
};
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
MdnsDiscovery.OnDeviceFound += async ipAddress =>
|
||||
{
|
||||
visible = false;
|
||||
if (!ipAddresses.Contains(ipAddress))
|
||||
{
|
||||
ipAddresses.Add(ipAddress);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
};
|
||||
|
||||
MdnsDiscovery.FetchChachedDevices();
|
||||
}
|
||||
MdnsDiscovery.FetchChachedDevices();
|
||||
}
|
||||
|
||||
private async Task RegisterDevice(IPAddress ipAddress)
|
||||
{
|
||||
Result<Device> result = await DeviceManagmentService.RegisterDevice(ipAddress, (await AuthenticationService.GetUserAsync()).ValueOrDefault);
|
||||
private async Task RegisterDevice(IPAddress ipAddress)
|
||||
{
|
||||
disabled = true;
|
||||
Result<Device> result = await DeviceManagmentService.RegisterDevice(ipAddress, (await AuthenticationService.GetUserAsync()).ValueOrDefault);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
await MessageService.Success("Device added!");
|
||||
}
|
||||
else
|
||||
{
|
||||
await MessageService.Error(string.Join(',', result.Errors.Select(e => e.Message)), "Adding device failed!");
|
||||
}
|
||||
}
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
await MessageService.Success("Device added!");
|
||||
}
|
||||
else
|
||||
{
|
||||
await MessageService.Error(string.Join(',', result.Errors.Select(e => e.Message)), "Adding device failed!");
|
||||
}
|
||||
disabled = false;
|
||||
}
|
||||
|
||||
public void ValidateIPv4(ValidatorEventArgs e)
|
||||
{
|
||||
string? input = Convert.ToString(e.Value);
|
||||
public void ValidateIPv4(ValidatorEventArgs e)
|
||||
{
|
||||
string? input = Convert.ToString(e.Value);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
e.Status = ValidationStatus.None;
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
e.Status = ValidationStatus.None;
|
||||
return;
|
||||
}
|
||||
|
||||
string[] splitValues = input.Split('.');
|
||||
if (splitValues.Length != 4)
|
||||
{
|
||||
e.Status = ValidationStatus.Error;
|
||||
return;
|
||||
}
|
||||
string[] splitValues = input.Split('.');
|
||||
if (splitValues.Length != 4)
|
||||
{
|
||||
e.Status = ValidationStatus.Error;
|
||||
return;
|
||||
}
|
||||
|
||||
e.Status = splitValues.All(r => byte.TryParse(r, out _)) ? ValidationStatus.Success : ValidationStatus.Error;
|
||||
}
|
||||
e.Status = splitValues.All(r => byte.TryParse(r, out _)) ? ValidationStatus.Success : ValidationStatus.Error;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -152,6 +152,12 @@
|
||||
{
|
||||
plugnames += $"shellyplug-s-{device.MacAddress}/relay/0|";
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(plugnames))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
plugnames = plugnames[0..^1];
|
||||
|
||||
Debug.WriteLine($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]""");
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
@using Elektrifikatsiya.Components.TodoApp
|
||||
@page "/apps/todo"
|
||||
<TodoItems />
|
||||
@@ -60,7 +60,7 @@ IAuthenticationService authenticationService = serviceScope.ServiceProvider.GetR
|
||||
|
||||
if (!mainDatabase.Users.Any())
|
||||
{
|
||||
authenticationService.RegisterUserAsync("admin", "admin", Role.Admin);
|
||||
_ = authenticationService.RegisterUserAsync("admin", "admin", Role.Admin);
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -33,12 +33,12 @@ public class UpdateService : IHostedService, IDisposable
|
||||
_ = deviceStatusService.TrackDevice(device);
|
||||
}
|
||||
|
||||
timer = new Timer((_) => Update(), null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
|
||||
timer = new Timer(async (_) => await Update(), null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
|
||||
|
||||
logger.LogInformation("Update service started.");
|
||||
}
|
||||
|
||||
private async void Update()
|
||||
private async Task Update()
|
||||
{
|
||||
Result<List<Device>> getDeviceStatusResult = deviceStatusService.GetDevices();
|
||||
|
||||
|
||||
Binary file not shown.
@@ -10,18 +10,15 @@ namespace Elektrifikatsiya.Utilities;
|
||||
|
||||
public class PrometheusQuery
|
||||
{
|
||||
private string connectionString;
|
||||
private readonly HttpClient client = new();
|
||||
|
||||
public PrometheusQuery(string connectionString)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
client.BaseAddress = new Uri(connectionString);
|
||||
}
|
||||
|
||||
public Task<PrometheusQueryResult?> Query(string query)
|
||||
{
|
||||
var res = client.GetStringAsync($"/api/v1/query?query={UrlEncoder.Create().Encode(query)}").Result;
|
||||
return client.GetFromJsonAsync<PrometheusQueryResult>($"/api/v1/query?query={UrlEncoder.Create().Encode(query)}", new JsonSerializerOptions()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
|
||||
Reference in New Issue
Block a user