-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an example how to the client with Blazor framework (#338)
- Loading branch information
1 parent
28f440f
commit 6bd1b8a
Showing
58 changed files
with
3,782 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1"/> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace ExampleBlazor.Data; | ||
|
||
public class ChartData | ||
{ | ||
public readonly string Name; | ||
public readonly string Sup; | ||
public double Min; | ||
public double Max; | ||
public double Step; | ||
public double MinorStep; | ||
private readonly Action _stateHasChanged; | ||
private double _value = 0; | ||
|
||
public double Value | ||
{ | ||
get => _value; | ||
set | ||
{ | ||
_value = value; | ||
_stateHasChanged.Invoke(); | ||
} | ||
} | ||
|
||
public ChartData(string name, string sup, double min, double max, Action stateHasChanged) | ||
{ | ||
Name = name; | ||
Sup = sup; | ||
Min = min; | ||
Max = max; | ||
Step = (max - min) / 4; | ||
MinorStep = Step / 10; | ||
_stateHasChanged = stateHasChanged; | ||
} | ||
|
||
|
||
public async Task FetchDataMean(string? selectedBucket, string? selectedDevice) | ||
{ | ||
if (selectedBucket != null && !string.IsNullOrEmpty(selectedDevice)) | ||
{ | ||
var table = await InfluxModel.FetchDataMean(selectedBucket, selectedDevice, "7d", "environment", Name); | ||
if (table != null) | ||
{ | ||
var value = table.Records.FirstOrDefault()!.Values.First(rec => rec.Key == "_value").Value; | ||
Value = Math.Round(Convert.ToDouble(value), 2); | ||
} | ||
else | ||
{ | ||
Value = 0; | ||
} | ||
} | ||
else | ||
{ | ||
Value = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using InfluxDB.Client; | ||
|
||
namespace ExampleBlazor.Data; | ||
|
||
public class Client | ||
{ | ||
public string? Url; | ||
public string? Token; | ||
public string? Org; | ||
|
||
public Client() | ||
{ | ||
} | ||
|
||
public Client(string? url, string? token, string? org) | ||
{ | ||
Url = url; | ||
Token = token; | ||
Org = org; | ||
} | ||
|
||
public InfluxDBClient GetClient(double timespanSeconds = 10) | ||
{ | ||
var options = new InfluxDBClientOptions.Builder() | ||
.Url(Url) | ||
.AuthenticateToken(Token) | ||
.TimeOut(TimeSpan.FromSeconds(timespanSeconds)) | ||
.Build(); | ||
|
||
return InfluxDBClientFactory.Create(options); | ||
} | ||
} |
Oops, something went wrong.