From aff8bb7b59c28939cfb5f0f280b5dbab0c79a501 Mon Sep 17 00:00:00 2001 From: DocBrown101 Date: Mon, 23 Dec 2024 19:43:40 +0100 Subject: [PATCH] small improvements & cleanup --- .gitignore | 48 ++-- arm64-build.sh => build/arm64-build.sh | 4 +- build-all.ps1 => build/build.ps1 | 13 +- x64-build.sh => build/x64-build.sh | 4 +- src/.editorconfig | 225 ++++++++---------- .../CollectorConfiguration.cs | 39 ++- .../ConsoleLogger.cs | 14 +- .../Metrics/MetricsCompositor.cs | 37 ++- .../Metrics/PayloadClient.cs | 8 +- src/Ve.Direct.InfluxDB.Collector/Program.cs | 4 +- 10 files changed, 184 insertions(+), 212 deletions(-) rename arm64-build.sh => build/arm64-build.sh (67%) rename build-all.ps1 => build/build.ps1 (72%) rename x64-build.sh => build/x64-build.sh (67%) diff --git a/.gitignore b/.gitignore index 32a1b10..0e628c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,3 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - # User-specific files *.rsuser *.suo @@ -10,12 +5,6 @@ *.userosscache *.sln.docstates -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - # Build results [Dd]ebug/ [Dd]ebugPublic/ @@ -23,14 +12,22 @@ mono_crash.* [Rr]eleases/ x64/ x86/ +[Ww][Ii][Nn]32/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ -build/ +bld/ +[Bb]uild/* [Bb]in/ [Oo]bj/ [Ll]og/ [Ll]ogs/ +# Build scripts +![Bb]uild/ +![Bb]uild/build.ps1 +![Bb]uild/arm64-build.sh +![Bb]uild/x64-build.sh + # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot @@ -61,6 +58,9 @@ project.lock.json project.fragment.lock.json artifacts/ +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + # StyleCop StyleCopReport.xml @@ -137,6 +137,11 @@ _TeamCity* .axoCover/* !.axoCover/settings.json +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + # Visual Studio code coverage results *.coverage *.coveragexml @@ -275,15 +280,6 @@ FakesAssemblies/ .ntvs_analysis.dat node_modules/ -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -316,12 +312,6 @@ __pycache__/ # Telerik's JustMock configuration file *.jmconfig -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - # OpenCover UI analysis results OpenCover/ @@ -348,3 +338,7 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + diff --git a/arm64-build.sh b/build/arm64-build.sh similarity index 67% rename from arm64-build.sh rename to build/arm64-build.sh index ae60f2e..57eedba 100644 --- a/arm64-build.sh +++ b/build/arm64-build.sh @@ -1,11 +1,11 @@ #! /bin/sh -dotnet publish ./src/Ve.Direct.InfluxDB.Collector/Ve.Direct.InfluxDB.Collector.csproj \ +dotnet publish ../src/Ve.Direct.InfluxDB.Collector/Ve.Direct.InfluxDB.Collector.csproj \ --runtime linux-arm64 \ --self-contained false \ -c Release \ -v minimal \ -f net8.0 \ - -o ./build \ + -o ./output/linux-arm64 \ -p:PublishReadyToRun=false \ -p:PublishSingleFile=true \ -p:CopyOutputSymbolsToPublishDirectory=false \ diff --git a/build-all.ps1 b/build/build.ps1 similarity index 72% rename from build-all.ps1 rename to build/build.ps1 index 0f1efa9..d8f6133 100644 --- a/build-all.ps1 +++ b/build/build.ps1 @@ -1,12 +1,11 @@ -$BuildPath = "$PSScriptRoot\build" -$BuildPathWinX64 = "$BuildPath\win-x64" -$BuildPathLinuxX64 = "$BuildPath\linux-x64" -$BuildPathLinuxARM64 = "$BuildPath\linux-arm64" +$BuildPathWinX64 = ".\output\win-x64" +$BuildPathLinuxX64 = ".\output\linux-x64" +$BuildPathLinuxARM64 = ".\output\linux-arm64" $Version = Get-Date -Format "yyyy-MM-dd" # 2020-11-1 $VersionDot = $Version -replace '-','.' # Dotnet restore and build -dotnet publish "$PSScriptRoot\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxDB.Collector.csproj" ` +dotnet publish "$PSScriptRoot\..\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxDB.Collector.csproj" ` --runtime win-x64 ` --self-contained false ` -c Release ` @@ -19,7 +18,7 @@ dotnet publish "$PSScriptRoot\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxD -p:Version=$VersionDot ` --nologo -dotnet publish "$PSScriptRoot\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxDB.Collector.csproj" ` +dotnet publish "$PSScriptRoot\..\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxDB.Collector.csproj" ` --runtime linux-x64 ` --self-contained false ` -c Release ` @@ -32,7 +31,7 @@ dotnet publish "$PSScriptRoot\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxD -p:Version=$VersionDot ` --nologo -dotnet publish "$PSScriptRoot\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxDB.Collector.csproj" ` +dotnet publish "$PSScriptRoot\..\src\Ve.Direct.InfluxDB.Collector\Ve.Direct.InfluxDB.Collector.csproj" ` --runtime linux-arm64 ` --self-contained false ` -c Release ` diff --git a/x64-build.sh b/build/x64-build.sh similarity index 67% rename from x64-build.sh rename to build/x64-build.sh index 2eabe52..5b3ad72 100644 --- a/x64-build.sh +++ b/build/x64-build.sh @@ -1,11 +1,11 @@ #! /bin/sh -dotnet publish ./src/Ve.Direct.InfluxDB.Collector/Ve.Direct.InfluxDB.Collector.csproj \ +dotnet publish ../src/Ve.Direct.InfluxDB.Collector/Ve.Direct.InfluxDB.Collector.csproj \ --runtime linux-x64 \ --self-contained false \ -c Release \ -v minimal \ -f net8.0 \ - -o ./build \ + -o ./output/linux-x64 \ -p:PublishReadyToRun=false \ -p:PublishSingleFile=true \ -p:CopyOutputSymbolsToPublishDirectory=false \ diff --git a/src/.editorconfig b/src/.editorconfig index 873ae96..2e6d0d3 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -1,139 +1,122 @@ # Informationen zu EDITORCONFIG-Dateien finden Sie unter https://aka.ms/editorconfigdocs -############################### -# Core EditorConfig Options # -############################### +############################### +# Core EditorConfig Options # +############################### root = true -# All files -[*] +# Code files +[*.{cs,csx,vb,vbx}] +end_of_line = crlf +indent_size = 4 indent_style = space -# Code files -[*.{cs,csx,vb,vbx}] -indent_size = 4 insert_final_newline = true -############################### -# .NET Coding Conventions # -############################### -[*.{cs,vb}] -# Organize usings +tab_width = 4 +############################### +# .NET Coding Conventions # +############################### +[*.{cs,vb}] +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_style.pascal_case_style.capitalization = pascal_case +dotnet_naming_symbols.constant_fields.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_prefer_inferred_anonymous_type_member_names = true:warning +dotnet_prefer_inferred_tuple_names = true:warning dotnet_sort_system_directives_first = true -# this. preferences -dotnet_style_qualification_for_field = true:warning -dotnet_style_qualification_for_property = true:warning -dotnet_style_qualification_for_method = true:warning -dotnet_style_qualification_for_event = true:warning -# Language keywords vs BCL types preferences -dotnet_style_predefined_type_for_locals_parameters_members = true:warning -dotnet_style_predefined_type_for_member_access = true:warning -# Parentheses preferences +dotnet_style_coalesce_expression = true:warning +dotnet_style_collection_initializer = true:warning +dotnet_style_explicit_tuple_names = true:warning +dotnet_style_namespace_match_folder = true:suggestion +dotnet_style_null_propagation = true:warning +dotnet_style_object_initializer = true:warning +dotnet_style_operator_placement_when_wrapping = beginning_of_line dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent -# Modifier preferences -dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_qualification_for_event = true:warning +dotnet_style_qualification_for_field = true:warning +dotnet_style_qualification_for_method = true:warning +dotnet_style_qualification_for_property = true:warning dotnet_style_readonly_field = true:warning -# Expression-level preferences -dotnet_style_object_initializer = true:warning -dotnet_style_collection_initializer = true:warning -dotnet_style_explicit_tuple_names = true:warning -dotnet_style_null_propagation = true:warning -dotnet_style_coalesce_expression = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion -dotnet_prefer_inferred_tuple_names = true:warning -dotnet_prefer_inferred_anonymous_type_member_names = true:warning -dotnet_style_prefer_auto_properties = true:suggestion -dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion -dotnet_style_prefer_conditional_expression_over_return = true:suggestion -############################### -# Naming Conventions # -############################### -# Style Definitions -dotnet_naming_style.pascal_case_style.capitalization = pascal_case -# Use PascalCase for constant fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.applicable_accessibilities = * -dotnet_naming_symbols.constant_fields.required_modifiers = const -############################### -# C# Coding Conventions # -############################### -[*.cs] -# var preferences -csharp_style_var_for_built_in_types = true:warning -csharp_style_var_when_type_is_apparent = true:warning -csharp_style_var_elsewhere = true:warning -# Expression-bodied members -csharp_style_expression_bodied_methods = when_on_single_line:silent -csharp_style_expression_bodied_constructors = false:warning -csharp_style_expression_bodied_operators = false:warning -csharp_style_expression_bodied_properties = true:warning -csharp_style_expression_bodied_indexers = true:warning -csharp_style_expression_bodied_accessors = true:warning -# Pattern matching preferences -csharp_style_pattern_matching_over_is_with_cast_check = true:warning -csharp_style_pattern_matching_over_as_with_null_check = true:warning -# Null-checking preferences -csharp_style_throw_expression = true:warning -csharp_style_conditional_delegate_call = true:warning -# Modifier preferences -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion -# Expression-level preferences -csharp_prefer_braces = true:suggestion -csharp_style_deconstructed_variable_declaration = true:warning -csharp_prefer_simple_default_expression = true:warning -csharp_style_pattern_local_over_anonymous_function = true:warning -csharp_style_inlined_variable_declaration = true:warning -############################### -# C# Formatting Rules # -############################### -# New line preferences -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true -# Indentation preferences -csharp_indent_case_contents = true -csharp_indent_switch_labels = true -csharp_indent_labels = flush_left +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +############################### +# C# Coding Conventions # +############################### +[*.cs] csharp_indent_block_contents = true csharp_indent_braces = false -# Space preferences -csharp_space_after_cast = false -csharp_space_after_keywords_in_control_flow_statements = true +csharp_indent_case_contents = true +csharp_indent_labels = flush_left +csharp_indent_switch_labels = true +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true +csharp_prefer_braces = true:suggestion +csharp_prefer_simple_default_expression = true:warning +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true csharp_space_after_comma = true csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true csharp_space_after_semicolon_in_for_statement = true -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_parentheses = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_square_brackets = false -csharp_space_before_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true csharp_space_before_comma = false csharp_space_before_dot = false csharp_space_before_open_square_brackets = false csharp_space_before_semicolon_in_for_statement = false -csharp_space_around_binary_operators = before_and_after -csharp_space_around_declaration_statements = do_not_ignore -# Wrapping preferences -csharp_preserve_single_line_statements = true -csharp_preserve_single_line_blocks = true - -# CA1031: Keine allgemeinen Ausnahmetypen abfangen -dotnet_diagnostic.CA1031.severity = silent - -# CA1030: Nach Möglichkeit Ereignisse verwenden -dotnet_diagnostic.CA1030.severity = silent - -# CA2007: Aufruf von "ConfigureAwait" für erwarteten Task erwägen -dotnet_diagnostic.CA2007.severity = suggestion +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false +csharp_style_conditional_delegate_call = true:warning +csharp_style_deconstructed_variable_declaration = true:warning +csharp_style_expression_bodied_accessors = true:warning +csharp_style_expression_bodied_constructors = false:warning +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:warning +csharp_style_expression_bodied_operators = false:warning +csharp_style_expression_bodied_properties = true:warning +csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion +csharp_style_inlined_variable_declaration = true:warning +csharp_style_namespace_declarations = file_scoped +csharp_style_pattern_local_over_anonymous_function = true:warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:warning +csharp_style_var_elsewhere = true:warning +csharp_style_var_for_built_in_types = true:warning +csharp_style_var_when_type_is_apparent = true:warning diff --git a/src/Ve.Direct.InfluxDB.Collector/CollectorConfiguration.cs b/src/Ve.Direct.InfluxDB.Collector/CollectorConfiguration.cs index 1b01755..264a945 100644 --- a/src/Ve.Direct.InfluxDB.Collector/CollectorConfiguration.cs +++ b/src/Ve.Direct.InfluxDB.Collector/CollectorConfiguration.cs @@ -4,48 +4,45 @@ public class CollectorConfiguration { - private readonly CommandOption outputDefinition; - private readonly CommandOption interval; - private readonly CommandOption serialPortName; - private readonly CommandOption influxDbUrl; - private readonly CommandOption influxDbBucket; - private readonly CommandOption influxDbOrg; - private readonly CommandOption influxMetricPrefix; - private readonly CommandOption useChecksums; - private readonly CommandOption debugOutput; - public OutputDefinition Output => this.outputDefinition.ParsedValue; - public int Interval => this.interval.ParsedValue; - public string SerialPortName => this.serialPortName.ParsedValue; - + public bool UseChecksums => this.useChecksums.ParsedValue; + public bool DebugOutput => this.debugOutput.ParsedValue; public string InfluxDbUrl => this.influxDbUrl.ParsedValue; public string InfluxDbBucket => this.influxDbBucket.ParsedValue; public string InfluxDbOrg => this.influxDbOrg.ParsedValue; public string InfluxMetricPrefix => this.influxMetricPrefix.ParsedValue; - public bool UseChecksums => this.useChecksums.ParsedValue; - - public bool DebugOutput => this.debugOutput.ParsedValue; - public enum OutputDefinition { Console, Influx } + private readonly CommandOption outputDefinition; + private readonly CommandOption interval; + private readonly CommandOption serialPortName; + private readonly CommandOption useChecksums; + private readonly CommandOption debugOutput; + private readonly CommandOption influxDbUrl; + private readonly CommandOption influxDbBucket; + private readonly CommandOption influxDbOrg; + private readonly CommandOption influxMetricPrefix; + + public CollectorConfiguration(CommandLineApplication app) { this.outputDefinition = app.Option("-o|--output", "Console or Influx", CommandOptionType.SingleValue); this.interval = app.Option("-i|--interval", "Interval in seconds", CommandOptionType.SingleValue).Accepts(v => v.Range(10, 3600)); this.serialPortName = app.Option("-p|--port", "The name of the port to use. USB VE.Direct cable would be /dev/ttyUSB0", CommandOptionType.SingleValue); + this.useChecksums = app.Option("-c", "Use checksums?", CommandOptionType.NoValue); + this.debugOutput = app.Option("--debugOutput", "Debug?", CommandOptionType.NoValue); + this.influxDbUrl = app.Option("--influxDbUrl", "The InfluxDb Url", CommandOptionType.SingleValue); this.influxDbBucket = app.Option("--influxDbBucket", "The InfluxDb Bucket name", CommandOptionType.SingleValue); this.influxDbOrg = app.Option("--influxDbOrg", "The InfluxDb Org name", CommandOptionType.SingleValue); this.influxMetricPrefix = app.Option("--influxMetricPrefix", "Used prefix for all metrics", CommandOptionType.SingleValue); - this.useChecksums = app.Option("-c", "Use checksums?", CommandOptionType.SingleOrNoValue); - this.debugOutput = app.Option("--debugOutput", "Debug?", CommandOptionType.SingleOrNoValue); this.SetDefaultValues(); } @@ -54,13 +51,13 @@ private void SetDefaultValues() { this.outputDefinition.DefaultValue = OutputDefinition.Console; this.interval.DefaultValue = 30; + this.useChecksums.DefaultValue = false; + this.debugOutput.DefaultValue = false; this.influxDbUrl.DefaultValue = "http://192.168.0.220:8086"; this.influxDbBucket.DefaultValue = "solar"; this.influxDbOrg.DefaultValue = "home"; this.influxMetricPrefix.DefaultValue = "ve_direct"; - this.useChecksums.DefaultValue = false; - this.debugOutput.DefaultValue = false; } } } diff --git a/src/Ve.Direct.InfluxDB.Collector/ConsoleLogger.cs b/src/Ve.Direct.InfluxDB.Collector/ConsoleLogger.cs index 8c7b927..bd4c2bd 100644 --- a/src/Ve.Direct.InfluxDB.Collector/ConsoleLogger.cs +++ b/src/Ve.Direct.InfluxDB.Collector/ConsoleLogger.cs @@ -34,23 +34,27 @@ public static void Debug(string message) Console.ForegroundColor = oldForeground; } - public static void Error(string message) + public static void Error(string message, string prefix = "ERROR") { var oldForeground = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"{DateTime.Now:o} ERROR {message}"); + Console.WriteLine($"{DateTime.Now:o} {prefix} {message}"); Console.ForegroundColor = oldForeground; } public static void Error(Exception exception) { - Error(exception.Message); + Error(exception.Message, "EXCEPTION"); - var innerException = exception.InnerException; + if (writeDebug) + { + Error(exception.StackTrace, "StackTrace"); + } + var innerException = exception.InnerException; while (innerException != null) { - Error(innerException.Message); + Error(innerException.Message, "INNEREXCEPTION"); innerException = innerException.InnerException; } } diff --git a/src/Ve.Direct.InfluxDB.Collector/Metrics/MetricsCompositor.cs b/src/Ve.Direct.InfluxDB.Collector/Metrics/MetricsCompositor.cs index ecf1f32..c3d1e81 100644 --- a/src/Ve.Direct.InfluxDB.Collector/Metrics/MetricsCompositor.cs +++ b/src/Ve.Direct.InfluxDB.Collector/Metrics/MetricsCompositor.cs @@ -41,24 +41,19 @@ namespace Ve.Direct.InfluxDB.Collector.Metrics /// '117': 'Invalid/incompatible firmware' /// '119': 'User settings invalid' /// - public class MetricsCompositor + public class MetricsCompositor(CollectorConfiguration configuration) { - private readonly PayloadClient payloadClient; - - public MetricsCompositor(CollectorConfiguration configuration) - { - this.payloadClient = new PayloadClient(configuration); - } + private readonly PayloadClient payloadClient = new(configuration); public void SendMetricsCallback(Dictionary rawData) { ConsoleLogger.Debug("Just received new raw data!"); - this.payloadClient.AddPayload(this.ConvertToMetricsTransmissionModel(rawData)); + this.payloadClient.AddPayload(ConvertToMetricsTransmissionModel(rawData)); _ = this.payloadClient.TrySendPayload(); } - private MetricsTransmissionModel ConvertToMetricsTransmissionModel(Dictionary data) + private static MetricsTransmissionModel ConvertToMetricsTransmissionModel(Dictionary data) { var transmissionMetrics = new MetricsTransmissionModel(); @@ -67,34 +62,34 @@ private MetricsTransmissionModel ConvertToMetricsTransmissionModel(Dictionary(); + this.pointDataList = []; var builder = new InfluxDBClientOptions.Builder(); builder.Url(configuration.InfluxDbUrl); @@ -78,16 +78,16 @@ public async Task TrySendPayload() try { var writeApi = this.influxDBClient.GetWriteApiAsync(); - await writeApi.WritePointsAsync(this.pointDataList); + await writeApi.WritePointsAsync(this.pointDataList).ConfigureAwait(false); ConsoleLogger.Debug("InfluxDb write operation completed successfully!"); ConsoleLogger.Debug($"{this.pointDataList.Count} data points were sent."); this.pointDataList.Clear(); } - catch (Exception ex) + catch (Exception e) { - ConsoleLogger.Error(ex.Message); + ConsoleLogger.Error(e); } } } diff --git a/src/Ve.Direct.InfluxDB.Collector/Program.cs b/src/Ve.Direct.InfluxDB.Collector/Program.cs index dcc267d..e532fd6 100644 --- a/src/Ve.Direct.InfluxDB.Collector/Program.cs +++ b/src/Ve.Direct.InfluxDB.Collector/Program.cs @@ -17,7 +17,7 @@ public static int Main(string[] args) app.HelpOption(); app.OnExecuteAsync(async cancellationToken => { - ConsoleLogger.Init(config.DebugOutput, "3.1.0"); + ConsoleLogger.Init(config.DebugOutput, "3.2.0"); ConsoleLogger.Debug($"Current output setting: {config.Output}"); try @@ -37,7 +37,7 @@ public static int Main(string[] args) throw new InvalidEnumArgumentException(nameof(config.Output)); } - await Task.CompletedTask; + await Task.CompletedTask.ConfigureAwait(false); } catch (Exception e) {