Skip to content

Commit

Permalink
feat: add an example how to the client with Blazor framework (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelahojna authored Sep 7, 2022
1 parent 28f440f commit 6bd1b8a
Show file tree
Hide file tree
Showing 58 changed files with 3,782 additions and 10 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ jobs:
sed -i '/<TargetFrameworks>netcoreapp3.1;netcoreapp5.0;netcoreapp6.0<\/TargetFrameworks>/c\<TargetFramework>'netcoreapp5.0'<\/TargetFramework>' Client.Legacy.Test/Client.Legacy.Test.csproj
sed -i '/<TargetFrameworks>netcoreapp3.1;netcoreapp5.0;netcoreapp6.0<\/TargetFrameworks>/c\<TargetFramework>'netcoreapp5.0'<\/TargetFramework>' Client.Linq.Test/Client.Linq.Test.csproj
sed -i '/<TargetFrameworks>netcoreapp3.1;netcoreapp5.0;netcoreapp6.0<\/TargetFrameworks>/c\<TargetFramework>'netcoreapp5.0'<\/TargetFramework>' Examples/Examples.csproj
- run: dotnet sln remove Examples/ExampleBlazor/ExampleBlazor.csproj
- run: dotnet nuget locals --clear all
- run: dotnet restore --no-cache --force -s https://api.nuget.org/v3/index.json
- run: dotnet build
Expand Down
19 changes: 9 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[*]
charset = utf-8
end_of_line = lf
Expand All @@ -13,9 +12,9 @@ csharp_preferred_modifier_order = public, private, protected, internal, new, sta
csharp_style_var_elsewhere = true
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true
csharp_for_built_in_types=use_var
csharp_for_simple_types=use_var
csharp_for_other_types=use_var
csharp_for_built_in_types = use_var
csharp_for_simple_types = use_var
csharp_for_other_types = use_var
dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined
dotnet_naming_rule.constants_rule.resharper_style = AaBb, Default + AaBb
dotnet_naming_rule.constants_rule.severity = warning
Expand All @@ -29,11 +28,11 @@ dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style
dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected
dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public, internal, protected, protected_internal, private_protected
dotnet_naming_symbols.constants_symbols.applicable_kinds = field
dotnet_naming_symbols.constants_symbols.required_modifiers = const
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
Expand Down Expand Up @@ -66,10 +65,10 @@ resharper_suggest_var_or_type_simple_types_highlighting = hint
resharper_web_config_module_not_resolved_highlighting = warning
resharper_web_config_type_not_resolved_highlighting = warning
resharper_web_config_wrong_module_highlighting = warning
csharp_use_roslyn_logic_for_evident_types=true
csharp_prefer_explicit_discard_declaration=true
csharp_max_line_length=120
csharp_braces_for_ifelse=required
csharp_use_roslyn_logic_for_evident_types = true
csharp_prefer_explicit_discard_declaration = true
csharp_max_line_length = 120
csharp_braces_for_ifelse = required

[*.{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}]
indent_style = space
Expand Down
12 changes: 12 additions & 0 deletions Examples/ExampleBlazor/App.razor
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>
56 changes: 56 additions & 0 deletions Examples/ExampleBlazor/Data/ChartData.cs
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;
}
}
}
32 changes: 32 additions & 0 deletions Examples/ExampleBlazor/Data/ClientSettings.cs
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);
}
}
Loading

0 comments on commit 6bd1b8a

Please sign in to comment.