Skip to content

Commit 6bd1b8a

Browse files
feat: add an example how to the client with Blazor framework (#338)
1 parent 28f440f commit 6bd1b8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3782
-10
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ jobs:
135135
sed -i '/<TargetFrameworks>netcoreapp3.1;netcoreapp5.0;netcoreapp6.0<\/TargetFrameworks>/c\<TargetFramework>'netcoreapp5.0'<\/TargetFramework>' Client.Legacy.Test/Client.Legacy.Test.csproj
136136
sed -i '/<TargetFrameworks>netcoreapp3.1;netcoreapp5.0;netcoreapp6.0<\/TargetFrameworks>/c\<TargetFramework>'netcoreapp5.0'<\/TargetFramework>' Client.Linq.Test/Client.Linq.Test.csproj
137137
sed -i '/<TargetFrameworks>netcoreapp3.1;netcoreapp5.0;netcoreapp6.0<\/TargetFrameworks>/c\<TargetFramework>'netcoreapp5.0'<\/TargetFramework>' Examples/Examples.csproj
138+
- run: dotnet sln remove Examples/ExampleBlazor/ExampleBlazor.csproj
138139
- run: dotnet nuget locals --clear all
139140
- run: dotnet restore --no-cache --force -s https://api.nuget.org/v3/index.json
140141
- run: dotnet build

.editorconfig

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[*]
32
charset = utf-8
43
end_of_line = lf
@@ -13,9 +12,9 @@ csharp_preferred_modifier_order = public, private, protected, internal, new, sta
1312
csharp_style_var_elsewhere = true
1413
csharp_style_var_for_built_in_types = true
1514
csharp_style_var_when_type_is_apparent = true
16-
csharp_for_built_in_types=use_var
17-
csharp_for_simple_types=use_var
18-
csharp_for_other_types=use_var
15+
csharp_for_built_in_types = use_var
16+
csharp_for_simple_types = use_var
17+
csharp_for_other_types = use_var
1918
dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined
2019
dotnet_naming_rule.constants_rule.resharper_style = AaBb, Default + AaBb
2120
dotnet_naming_rule.constants_rule.severity = warning
@@ -29,11 +28,11 @@ dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style
2928
dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols
3029
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
3130
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
32-
dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected
31+
dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public, internal, protected, protected_internal, private_protected
3332
dotnet_naming_symbols.constants_symbols.applicable_kinds = field
3433
dotnet_naming_symbols.constants_symbols.required_modifiers = const
3534
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
36-
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
35+
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
3736
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
3837
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
3938
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
@@ -66,10 +65,10 @@ resharper_suggest_var_or_type_simple_types_highlighting = hint
6665
resharper_web_config_module_not_resolved_highlighting = warning
6766
resharper_web_config_type_not_resolved_highlighting = warning
6867
resharper_web_config_wrong_module_highlighting = warning
69-
csharp_use_roslyn_logic_for_evident_types=true
70-
csharp_prefer_explicit_discard_declaration=true
71-
csharp_max_line_length=120
72-
csharp_braces_for_ifelse=required
68+
csharp_use_roslyn_logic_for_evident_types = true
69+
csharp_prefer_explicit_discard_declaration = true
70+
csharp_max_line_length = 120
71+
csharp_braces_for_ifelse = required
7372

7473
[*.{appxmanifest,asax,ascx,aspx,axaml,build,cg,cginc,compute,cs,cshtml,dtd,fs,fsi,fsscript,fsx,hlsl,hlsli,hlslinc,master,ml,mli,nuspec,paml,razor,resw,resx,shader,skin,usf,ush,vb,xaml,xamlx,xoml,xsd}]
7574
indent_style = space

Examples/ExampleBlazor/App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace ExampleBlazor.Data;
2+
3+
public class ChartData
4+
{
5+
public readonly string Name;
6+
public readonly string Sup;
7+
public double Min;
8+
public double Max;
9+
public double Step;
10+
public double MinorStep;
11+
private readonly Action _stateHasChanged;
12+
private double _value = 0;
13+
14+
public double Value
15+
{
16+
get => _value;
17+
set
18+
{
19+
_value = value;
20+
_stateHasChanged.Invoke();
21+
}
22+
}
23+
24+
public ChartData(string name, string sup, double min, double max, Action stateHasChanged)
25+
{
26+
Name = name;
27+
Sup = sup;
28+
Min = min;
29+
Max = max;
30+
Step = (max - min) / 4;
31+
MinorStep = Step / 10;
32+
_stateHasChanged = stateHasChanged;
33+
}
34+
35+
36+
public async Task FetchDataMean(string? selectedBucket, string? selectedDevice)
37+
{
38+
if (selectedBucket != null && !string.IsNullOrEmpty(selectedDevice))
39+
{
40+
var table = await InfluxModel.FetchDataMean(selectedBucket, selectedDevice, "7d", "environment", Name);
41+
if (table != null)
42+
{
43+
var value = table.Records.FirstOrDefault()!.Values.First(rec => rec.Key == "_value").Value;
44+
Value = Math.Round(Convert.ToDouble(value), 2);
45+
}
46+
else
47+
{
48+
Value = 0;
49+
}
50+
}
51+
else
52+
{
53+
Value = 0;
54+
}
55+
}
56+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using InfluxDB.Client;
2+
3+
namespace ExampleBlazor.Data;
4+
5+
public class Client
6+
{
7+
public string? Url;
8+
public string? Token;
9+
public string? Org;
10+
11+
public Client()
12+
{
13+
}
14+
15+
public Client(string? url, string? token, string? org)
16+
{
17+
Url = url;
18+
Token = token;
19+
Org = org;
20+
}
21+
22+
public InfluxDBClient GetClient(double timespanSeconds = 10)
23+
{
24+
var options = new InfluxDBClientOptions.Builder()
25+
.Url(Url)
26+
.AuthenticateToken(Token)
27+
.TimeOut(TimeSpan.FromSeconds(timespanSeconds))
28+
.Build();
29+
30+
return InfluxDBClientFactory.Create(options);
31+
}
32+
}

0 commit comments

Comments
 (0)