Ready to test
This commit is contained in:
parent
35ba7dc93f
commit
3e9b6a8211
381
.editorconfig
Normal file
381
.editorconfig
Normal file
@ -0,0 +1,381 @@
|
||||
[*.md]
|
||||
end_of_line = crlf
|
||||
file_header_template = unset
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = false
|
||||
root = true
|
||||
tab_width = 2
|
||||
[*.csproj]
|
||||
end_of_line = crlf
|
||||
file_header_template = unset
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = false
|
||||
root = true
|
||||
tab_width = 2
|
||||
[*.cs]
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = true
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
csharp_new_line_before_catch = false
|
||||
csharp_new_line_before_else = false
|
||||
csharp_new_line_before_finally = false
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = none
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_prefer_braces = false
|
||||
csharp_prefer_qualified_reference = true:error
|
||||
csharp_prefer_simple_default_expression = true:warning
|
||||
csharp_prefer_simple_using_statement = true:warning
|
||||
csharp_prefer_static_local_function = true:warning
|
||||
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = false
|
||||
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_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
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_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_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true
|
||||
csharp_style_conditional_delegate_call = true
|
||||
csharp_style_deconstructed_variable_declaration = false
|
||||
csharp_style_expression_bodied_accessors = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_constructors = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_indexers = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_methods = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_operators = when_on_single_line:warning
|
||||
csharp_style_expression_bodied_properties = when_on_single_line:warning
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
|
||||
csharp_style_inlined_variable_declaration = false
|
||||
csharp_style_namespace_declarations = file_scoped:warning
|
||||
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:warning
|
||||
csharp_style_prefer_not_pattern = true:warning
|
||||
csharp_style_prefer_null_check_over_type_check = true
|
||||
csharp_style_prefer_pattern_matching = true:warning
|
||||
csharp_style_prefer_range_operator = true:warning
|
||||
csharp_style_prefer_switch_expression = true:warning
|
||||
csharp_style_throw_expression = true
|
||||
csharp_style_unused_value_assignment_preference = discard_variable:warning
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
|
||||
csharp_style_var_elsewhere = false:warning
|
||||
csharp_style_var_for_built_in_types = false:warning
|
||||
csharp_style_var_when_type_is_apparent = false:warning
|
||||
csharp_using_directive_placement = outside_namespace
|
||||
dotnet_analyzer_diagnostic.category-Design.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Documentation.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Globalization.severity = none
|
||||
dotnet_analyzer_diagnostic.category-Interoperability.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Maintainability.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Naming.severity = none
|
||||
dotnet_analyzer_diagnostic.category-Performance.severity = none
|
||||
dotnet_analyzer_diagnostic.category-Reliability.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Security.severity = error
|
||||
dotnet_analyzer_diagnostic.category-SingleFile.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Style.severity = error
|
||||
dotnet_analyzer_diagnostic.category-Usage.severity = error
|
||||
dotnet_code_quality_unused_parameters = all
|
||||
dotnet_code_quality_unused_parameters = non_public
|
||||
dotnet_code_quality.CAXXXX.api_surface = private, internal
|
||||
dotnet_diagnostic.CA1001.severity = error # CA1001: Types that own disposable fields should be disposable
|
||||
dotnet_diagnostic.CA1051.severity = error # CA1051: Do not declare visible instance fields
|
||||
dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance
|
||||
dotnet_diagnostic.CA1513.severity = warning # Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
|
||||
dotnet_diagnostic.CA1825.severity = warning # CA1825: Avoid zero-length array allocations
|
||||
dotnet_diagnostic.CA1829.severity = error # CA1829: Use Length/Count property instead of Count() when available
|
||||
dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
|
||||
dotnet_diagnostic.CA1860.severity = error # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance
|
||||
dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
|
||||
dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.
|
||||
dotnet_diagnostic.CA2201.severity = none # CA2201: Exception type System.NullReferenceException is reserved by the runtime
|
||||
dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])'
|
||||
dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name
|
||||
dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2");
|
||||
dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant.
|
||||
dotnet_diagnostic.IDE0005.severity = error # Using directive is unnecessary
|
||||
dotnet_diagnostic.IDE0010.severity = none # Add missing cases to switch statement (IDE0010)
|
||||
dotnet_diagnostic.IDE0028.severity = error # IDE0028: Collection initialization can be simplified
|
||||
dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031)
|
||||
dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed
|
||||
dotnet_diagnostic.IDE0048.severity = none # Parentheses preferences (IDE0047 and IDE0048)
|
||||
dotnet_diagnostic.IDE0049.severity = warning # Use language keywords instead of framework type names for type references (IDE0049)
|
||||
dotnet_diagnostic.IDE0051.severity = error # Private member '' is unused [, ]
|
||||
dotnet_diagnostic.IDE0058.severity = error # IDE0058: Expression value is never used
|
||||
dotnet_diagnostic.IDE0060.severity = error # IDE0060: Remove unused parameter
|
||||
dotnet_diagnostic.IDE0074.severity = warning # IDE0074: Use compound assignment
|
||||
dotnet_diagnostic.IDE0130.severity = none # Namespace does not match folder structure (IDE0130)
|
||||
dotnet_diagnostic.IDE0270.severity = warning # IDE0270: Null check can be simplified
|
||||
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]csharp(IDE0290)
|
||||
dotnet_diagnostic.IDE0300.severity = error # IDE0300: Collection initialization can be simplified
|
||||
dotnet_diagnostic.IDE0301.severity = error #IDE0301: Collection initialization can be simplified
|
||||
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified
|
||||
dotnet_diagnostic.IDE2000.severity = error # IDE2000: Allow multiple blank lines
|
||||
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method
|
||||
dotnet_naming_rule.class_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.class_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.class_should_be_pascal_case.symbols = class
|
||||
dotnet_naming_rule.delegate_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.delegate_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.delegate_should_be_pascal_case.symbols = delegate
|
||||
dotnet_naming_rule.enum_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.enum_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.enum_should_be_pascal_case.symbols = enum
|
||||
dotnet_naming_rule.event_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.event_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.event_should_be_pascal_case.symbols = event
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||
dotnet_naming_rule.method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.method_should_be_pascal_case.symbols = method
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||
dotnet_naming_rule.private_method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.private_method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.private_method_should_be_pascal_case.symbols = private_method
|
||||
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.severity = warning
|
||||
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.style = private_of_internal_field
|
||||
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.symbols = private_or_internal_field
|
||||
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.severity = warning
|
||||
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.style = private_of_internal_field
|
||||
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.symbols = private_or_internal_static_field
|
||||
dotnet_naming_rule.property_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.property_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.property_should_be_pascal_case.symbols = property
|
||||
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.severity = warning
|
||||
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.style = private_of_internal_field
|
||||
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.symbols = public_or_protected_field
|
||||
dotnet_naming_rule.static_field_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.static_field_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.static_field_should_be_pascal_case.symbols = static_field
|
||||
dotnet_naming_rule.static_method_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.static_method_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.static_method_should_be_pascal_case.symbols = static_method
|
||||
dotnet_naming_rule.struct_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.struct_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.struct_should_be_pascal_case.symbols = struct
|
||||
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
|
||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.private_of_internal_field.capitalization = pascal_case
|
||||
dotnet_naming_style.private_of_internal_field.required_prefix = _
|
||||
dotnet_naming_style.private_of_internal_field.required_suffix =
|
||||
dotnet_naming_style.private_of_internal_field.word_separator =
|
||||
dotnet_naming_symbols.abstract_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.abstract_method.applicable_kinds = method
|
||||
dotnet_naming_symbols.abstract_method.required_modifiers = abstract
|
||||
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.class.applicable_kinds = class
|
||||
dotnet_naming_symbols.class.required_modifiers =
|
||||
dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.delegate.applicable_kinds = delegate
|
||||
dotnet_naming_symbols.delegate.required_modifiers =
|
||||
dotnet_naming_symbols.enum.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.enum.applicable_kinds = enum
|
||||
dotnet_naming_symbols.enum.required_modifiers =
|
||||
dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.event.applicable_kinds = event
|
||||
dotnet_naming_symbols.event.required_modifiers =
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
dotnet_naming_symbols.method.applicable_accessibilities = public
|
||||
dotnet_naming_symbols.method.applicable_kinds = method
|
||||
dotnet_naming_symbols.method.required_modifiers =
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
dotnet_naming_symbols.private_method.applicable_accessibilities = private
|
||||
dotnet_naming_symbols.private_method.applicable_kinds = method
|
||||
dotnet_naming_symbols.private_method.required_modifiers =
|
||||
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
|
||||
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
|
||||
dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
|
||||
dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static
|
||||
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.property.applicable_kinds = property
|
||||
dotnet_naming_symbols.property.required_modifiers =
|
||||
dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
|
||||
dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.public_or_protected_field.required_modifiers =
|
||||
dotnet_naming_symbols.static_field.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.static_field.applicable_kinds = field
|
||||
dotnet_naming_symbols.static_field.required_modifiers = static
|
||||
dotnet_naming_symbols.static_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.static_method.applicable_kinds = method
|
||||
dotnet_naming_symbols.static_method.required_modifiers = static
|
||||
dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.struct.applicable_kinds = struct
|
||||
dotnet_naming_symbols.struct.required_modifiers =
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
dotnet_remove_unnecessary_suppression_exclusions = 0
|
||||
dotnet_separate_import_directive_groups = true
|
||||
dotnet_sort_system_directives_first = true
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = true
|
||||
dotnet_style_coalesce_expression = true
|
||||
dotnet_style_collection_initializer = true:warning
|
||||
dotnet_style_explicit_tuple_names = true:warning
|
||||
dotnet_style_namespace_match_folder = true
|
||||
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
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||
dotnet_style_predefined_type_for_member_access = true:warning
|
||||
dotnet_style_prefer_auto_properties = true:warning
|
||||
dotnet_style_prefer_compound_assignment = true:warning
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = false
|
||||
dotnet_style_prefer_conditional_expression_over_return = false
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
|
||||
dotnet_style_prefer_inferred_tuple_names = true:warning
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:warning
|
||||
dotnet_style_prefer_simplified_interpolation = true
|
||||
dotnet_style_qualification_for_event = false:error
|
||||
dotnet_style_qualification_for_field = false
|
||||
dotnet_style_qualification_for_method = false:error
|
||||
dotnet_style_qualification_for_property = false:error
|
||||
dotnet_style_readonly_field = true:warning
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members
|
||||
end_of_line = crlf
|
||||
file_header_template = unset
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = false
|
||||
root = true
|
||||
tab_width = 4
|
||||
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1822
|
||||
# https://github.com/dotnet/aspnetcore/blob/main/.editorconfig
|
||||
# https://github.com/dotnet/project-system/blob/main/.editorconfig
|
||||
|
||||
# Question
|
||||
csharp_prefer_simple_using_statement = false # Question
|
||||
csharp_style_expression_bodied_constructors = when_on_single_line:none # Question
|
||||
csharp_style_expression_bodied_properties = true # Question
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning # Question
|
||||
csharp_style_pattern_matching_over_as_with_null_check = false # Question
|
||||
csharp_style_prefer_pattern_matching = false # Question
|
||||
csharp_style_prefer_range_operator = false # Question
|
||||
csharp_style_prefer_switch_expression = false # Question
|
||||
csharp_style_unused_value_assignment_preference = unused_local_variable # Question
|
||||
csharp_style_unused_value_expression_statement_preference = false # Question
|
||||
csharp_style_var_elsewhere = false:none # Question
|
||||
csharp_style_var_for_built_in_types = false:none # Question
|
||||
csharp_style_var_when_type_is_apparent = false:warning # Question
|
||||
dotnet_diagnostic.CA1001.severity = none # Question - Types that own disposable fields should be disposable
|
||||
dotnet_diagnostic.CA1051.severity = none # Question - Do not declare visible instance fields
|
||||
dotnet_diagnostic.CA1416.severity = none # Question - This call site is reachable on all platforms.
|
||||
dotnet_diagnostic.CA1510.severity = none # Question - Use
|
||||
dotnet_diagnostic.CA1834.severity = none # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
|
||||
dotnet_diagnostic.CA1860.severity = none # Question - Avoid using
|
||||
dotnet_diagnostic.CA1862.severity = none # Question - Prefer using
|
||||
dotnet_diagnostic.CA2208.severity = none # Question - Instantiate argument exceptions correctly
|
||||
dotnet_diagnostic.CA2211.severity = none # Question - Non-constant fields should not be visible
|
||||
dotnet_diagnostic.CA2249.severity = none # Question - Use
|
||||
dotnet_diagnostic.CA2253.severity = none # Question - Named placeholders should not be numeric values
|
||||
dotnet_diagnostic.CS0103.severity = none # Question - The name
|
||||
dotnet_diagnostic.CS0168.severity = none # Question - The variable
|
||||
dotnet_diagnostic.CS0219.severity = none # Question - The variable
|
||||
dotnet_diagnostic.CS0612.severity = none # Question - is obsolete
|
||||
dotnet_diagnostic.CS0618.severity = none # Question - Compiler Warning (level 2)
|
||||
dotnet_diagnostic.CS0659.severity = none # Question - Compiler Warning (level 3)
|
||||
dotnet_diagnostic.CS8019.severity = warning # Question - Unnecessary using directive.
|
||||
dotnet_diagnostic.CS8600.severity = none # Question - Converting null literal or possible null value to non-nullable type
|
||||
dotnet_diagnostic.CS8602.severity = none # Question - Dereference of a possibly null reference.
|
||||
dotnet_diagnostic.CS8603.severity = none # Question - Possible null reference return
|
||||
dotnet_diagnostic.CS8604.severity = none # Question - Possible null reference argument for parameter.
|
||||
dotnet_diagnostic.CS8618.severity = none # Question - Non-nullable variable must contain a non-null value when exiting constructor
|
||||
dotnet_diagnostic.CS8625.severity = none # Question - Cannot convert null literal to non-nullable reference type.
|
||||
dotnet_diagnostic.CS8629.severity = none # Question - Nullable value type may be null
|
||||
dotnet_diagnostic.CS8765.severity = none # Question - Nullability of type of parameter
|
||||
dotnet_diagnostic.IDE0005.severity = none # Question - Remove unnecessary using directives
|
||||
dotnet_diagnostic.IDE0008.severity = warning # Question - Use explicit type instead of
|
||||
dotnet_diagnostic.IDE0017.severity = none # Question - Object initialization can be simplified
|
||||
dotnet_diagnostic.IDE0019.severity = none # Question - Use pattern matching
|
||||
dotnet_diagnostic.IDE0021.severity = none # Question - Use expression body for constructor
|
||||
dotnet_diagnostic.IDE0022.severity = none # Question - Use expression body for method
|
||||
dotnet_diagnostic.IDE0025.severity = none # Question - Use expression body for property
|
||||
dotnet_diagnostic.IDE0027.severity = none # Question - Use expression body for accessor
|
||||
dotnet_diagnostic.IDE0028.severity = none # Question - Use collection initializers or expressions
|
||||
dotnet_diagnostic.IDE0031.severity = none # Question - Null check can be simplified
|
||||
dotnet_diagnostic.IDE0032.severity = none # Question - Use auto property
|
||||
dotnet_diagnostic.IDE0037.severity = none # Question - Member name can be simplified
|
||||
dotnet_diagnostic.IDE0041.severity = none # Question - Null check can be simplified
|
||||
dotnet_diagnostic.IDE0047.severity = none # Question - Parentheses preferences
|
||||
dotnet_diagnostic.IDE0049.severity = warning # Question - Name can be simplified
|
||||
dotnet_diagnostic.IDE0051.severity = none # Question - Remove unused private member
|
||||
dotnet_diagnostic.IDE0053.severity = none # Question - Use expression body for lambdas
|
||||
dotnet_diagnostic.IDE0054.severity = none # Question - Use compound assignment
|
||||
dotnet_diagnostic.IDE0055.severity = none # Question - Formatting rule
|
||||
dotnet_diagnostic.IDE0057.severity = none # Question - Substring can be simplified
|
||||
dotnet_diagnostic.IDE0058.severity = none # Question - Remove unnecessary expression value
|
||||
dotnet_diagnostic.IDE0059.severity = none # Question - Unnecessary assignment of a value to
|
||||
dotnet_diagnostic.IDE0060.severity = none # Question - Remove unused parameter
|
||||
dotnet_diagnostic.IDE0063.severity = none # Question - Use simple
|
||||
dotnet_diagnostic.IDE0065.severity = none # Question -
|
||||
dotnet_diagnostic.IDE0066.severity = none # Question - Use
|
||||
dotnet_diagnostic.IDE0078.severity = none # Question - Use pattern matching (may change code meaning)
|
||||
dotnet_diagnostic.IDE0090.severity = warning # Question - Simplify new expression
|
||||
dotnet_diagnostic.IDE0100.severity = error # Question - Remove redundant equality
|
||||
dotnet_diagnostic.IDE0160.severity = warning # Question - Use block-scoped namespace
|
||||
dotnet_diagnostic.IDE0161.severity = warning # Question - Namespace declaration preferences
|
||||
dotnet_diagnostic.IDE0270.severity = none # Question - Null check can be simplified
|
||||
dotnet_diagnostic.IDE0300.severity = none # Question - Collection initialization can be simplified
|
||||
dotnet_diagnostic.IDE1006.severity = none # Question - Use collection expression for builder dotnet_style_prefer_collection_expression
|
||||
dotnet_style_null_propagation = false # Question
|
||||
dotnet_style_object_initializer = false # Question
|
||||
dotnet_style_prefer_auto_properties = false # Question
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = true # Question
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = false:warning # Question
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = false # Question
|
1
.vscode/format-report.json
vendored
Normal file
1
.vscode/format-report.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[]
|
32
.vscode/launch.json
vendored
Normal file
32
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/Gatus-to-MonA.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "node Launch Current Opened File",
|
||||
"program": "${file}"
|
||||
}
|
||||
]
|
||||
}
|
5
.vscode/mklink.md
vendored
Normal file
5
.vscode/mklink.md
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# mklink
|
||||
|
||||
```bash Wed Jul 24 2024 08:28:01 GMT-0700 (Mountain Standard Time)
|
||||
mklink /J "L:\DevOps\Mesa_FI\gatus-to-mona\.vscode\.UserSecrets" "C:\Users\phares\AppData\Roaming\Microsoft\UserSecrets\97abd809-d0ab-4a62-93b3-6f9640770e96"
|
||||
```
|
15
.vscode/settings.json
vendored
Normal file
15
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"[markdown]": {
|
||||
"editor.wordWrap": "off"
|
||||
},
|
||||
"files.exclude": {
|
||||
"**/.git": false,
|
||||
"**/node_modules": true
|
||||
},
|
||||
"files.watcherExclude": {
|
||||
"**/node_modules": true
|
||||
},
|
||||
"cSpell.words": [
|
||||
"Gatus"
|
||||
]
|
||||
}
|
132
.vscode/tasks.json
vendored
Normal file
132
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "User Secrets Init",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"user-secrets",
|
||||
"-p",
|
||||
"${workspaceFolder}/Gatus-to-MonA.csproj",
|
||||
"init"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "User Secrets Set",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"user-secrets",
|
||||
"-p",
|
||||
"${workspaceFolder}/Gatus-to-MonA.csproj",
|
||||
"set",
|
||||
"_UserSecretsId",
|
||||
"97abd809-d0ab-4a62-93b3-6f9640770e96"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "Format",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"format",
|
||||
"--report",
|
||||
".vscode",
|
||||
"--verbosity",
|
||||
"detailed",
|
||||
"--severity",
|
||||
"warn"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"-r",
|
||||
"win-x64",
|
||||
"${workspaceFolder}/Gatus-to-MonA.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "build Linux",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"-r",
|
||||
"linux-x64",
|
||||
"${workspaceFolder}/Gatus-to-MonA.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "Format-Whitespaces",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"format",
|
||||
"whitespace"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "Publish AOT",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"-r",
|
||||
"win-x64",
|
||||
"-c",
|
||||
"Release",
|
||||
"-p:PublishAot=true",
|
||||
"${workspaceFolder}/Gatus-to-MonA.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "Publish AOT Linux",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"-r",
|
||||
"linux-x64",
|
||||
"-c",
|
||||
"Release",
|
||||
"-p:PublishAot=true",
|
||||
"${workspaceFolder}/Gatus-to-MonA.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "File-Folder-Helper AOT s X Day-Helper-2025-03-20",
|
||||
"type": "shell",
|
||||
"command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe",
|
||||
"args": [
|
||||
"s",
|
||||
"X",
|
||||
"L:/DevOps/Mesa_FI/gatus-to-mona",
|
||||
"Day-Helper-2025-03-20",
|
||||
"false",
|
||||
"4"
|
||||
],
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
22
Gatus-to-MonA.csproj
Normal file
22
Gatus-to-MonA.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
<UserSecretsId>97abd809-d0ab-4a62-93b3-6f9640770e96</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.1" />
|
||||
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.14" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
0
Gatus-to-MonA.yaml
Normal file
0
Gatus-to-MonA.yaml
Normal file
97
Helpers/HelperGatusToMona.cs
Normal file
97
Helpers/HelperGatusToMona.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using Gatus.To.MonA.Infineon.Monitoring.MonA;
|
||||
using Gatus.To.MonA.Models;
|
||||
|
||||
namespace Gatus.To.MonA.Helpers;
|
||||
|
||||
internal static partial class HelperGatusToMona {
|
||||
|
||||
private static IMonIn? _MonIn;
|
||||
|
||||
private static string GetFile(AppSettings appSettings) =>
|
||||
Path.Combine(appSettings.GatusToMonaConfiguration.Directory, appSettings.GatusConfiguration.FileName);
|
||||
|
||||
internal static bool UpdateCount(AppSettings appSettings, ILogger<Worker> logger, CancellationToken cancellationToken) {
|
||||
ReadOnlyCollection<string> successMatches = GetSuccessMatches(appSettings, logger, cancellationToken);
|
||||
SendPerformanceMessage(appSettings, logger, successMatches, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetSuccessMatches(AppSettings appSettings, ILogger<Worker> logger, CancellationToken cancellationToken) {
|
||||
List<string> results = [];
|
||||
string value;
|
||||
string[] segments;
|
||||
string file = GetFile(appSettings);
|
||||
ReadOnlyCollection<string> lines = GetLines(appSettings, file, cancellationToken);
|
||||
foreach (string line in lines) {
|
||||
if (!line.StartsWith(appSettings.GatusConfiguration.Metric))
|
||||
continue;
|
||||
segments = line.Split('{');
|
||||
if (segments.Length != 2)
|
||||
continue;
|
||||
value = segments[1];
|
||||
if (value.Length < 2)
|
||||
continue;
|
||||
if (value[^1] is not '0' and not '1')
|
||||
continue;
|
||||
logger.LogDebug(value);
|
||||
if (line.EndsWith('1'))
|
||||
results.Add(string.Concat('{', value));
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetLines(AppSettings appSettings, string file, CancellationToken cancellationToken) {
|
||||
string[] results;
|
||||
FileStream fileStream = new(file, FileMode.Truncate);
|
||||
HttpClient httpClient = new();
|
||||
Task<Stream> streamTask = httpClient.GetStreamAsync(appSettings.GatusConfiguration.URL, cancellationToken);
|
||||
streamTask.Wait(cancellationToken);
|
||||
Task task = streamTask.Result.CopyToAsync(fileStream, cancellationToken);
|
||||
task.Wait(cancellationToken);
|
||||
fileStream.Dispose();
|
||||
streamTask.Dispose();
|
||||
httpClient.Dispose();
|
||||
results = File.ReadAllLines(file);
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void SendPerformanceMessage(AppSettings appSettings, ILogger<Worker> logger, ReadOnlyCollection<string> successMatches, CancellationToken cancellationToken) {
|
||||
string performanceName = string.Concat(appSettings.MonAConfiguration.Resource, appSettings.MonAConfiguration.Suffix);
|
||||
Task<HttpResponseMessage> httpResponseMessage = _MonIn.SendPerformanceMessage(appSettings.MonAConfiguration.Site,
|
||||
appSettings.MonAConfiguration.Resource,
|
||||
performanceName,
|
||||
value: successMatches.Count,
|
||||
description: string.Empty);
|
||||
httpResponseMessage.Wait(cancellationToken);
|
||||
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
|
||||
Task<string> body = httpResponseMessage.Result.Content.ReadAsStringAsync(cancellationToken);
|
||||
body.Wait(cancellationToken);
|
||||
logger.LogDebug(body.Result);
|
||||
}
|
||||
|
||||
internal static void Heartbeat(AppSettings appSettings, IHttpClientFactory httpClientFactory, ILogger<Worker> logger, State state, CancellationToken cancellationToken) {
|
||||
_MonIn ??= MonIn.GetInstance(httpClientFactory);
|
||||
CreateEmptyFile(appSettings);
|
||||
Task<HttpResponseMessage> httpResponseMessage = _MonIn.SendStatus(appSettings.MonAConfiguration.Site,
|
||||
appSettings.MonAConfiguration.Resource,
|
||||
appSettings.MonAConfiguration.StateName,
|
||||
state);
|
||||
httpResponseMessage.Wait(cancellationToken);
|
||||
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
|
||||
Task<string> body = httpResponseMessage.Result.Content.ReadAsStringAsync(cancellationToken);
|
||||
body.Wait(cancellationToken);
|
||||
logger.LogDebug(body.Result);
|
||||
}
|
||||
|
||||
private static void CreateEmptyFile(AppSettings appSettings) {
|
||||
if (!Directory.Exists(appSettings.GatusToMonaConfiguration.Directory))
|
||||
_ = Directory.CreateDirectory(appSettings.GatusToMonaConfiguration.Directory);
|
||||
string file = GetFile(appSettings);
|
||||
File.WriteAllText(file, string.Empty);
|
||||
}
|
||||
|
||||
}
|
144
Infineon/Monitoring/MonA/IMonIn.cs
Normal file
144
Infineon/Monitoring/MonA/IMonIn.cs
Normal file
@ -0,0 +1,144 @@
|
||||
namespace Gatus.To.MonA.Infineon.Monitoring.MonA;
|
||||
|
||||
public interface IMonIn {
|
||||
Task<HttpResponseMessage> SendStatus(string site, string resource, string stateName, State state);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime timeStamp,
|
||||
string resource,
|
||||
string stateName,
|
||||
State state);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
string resource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime timeStamp,
|
||||
string resource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
int? interval);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
DateTime? timeStamp,
|
||||
string performanceName,
|
||||
double value,
|
||||
string unit);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string unit,
|
||||
int? interval);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
int? interval);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string unit);
|
||||
|
||||
Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description,
|
||||
string unit,
|
||||
int? interval);
|
||||
}
|
250
Infineon/Monitoring/MonA/MonIn.cs
Normal file
250
Infineon/Monitoring/MonA/MonIn.cs
Normal file
@ -0,0 +1,250 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Gatus.To.MonA.Infineon.Monitoring.MonA;
|
||||
|
||||
public class MonIn : IMonIn {
|
||||
private readonly string _MonInUrl;
|
||||
private readonly HttpClient _HttpClient;
|
||||
private static CultureInfo? _CultureInfo;
|
||||
private static readonly Dictionary<string, MonIn> _Instances = [];
|
||||
public const string MonInUrl = "http://moninhttp.{0}.infineon.com/input/text";
|
||||
private static readonly DateTime _Utc1970DateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site, string resource, string stateName, State state) =>
|
||||
SendStatus(site, new DateTime?(), resource, string.Empty, stateName, state, string.Empty);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime timeStamp,
|
||||
string resource,
|
||||
string stateName,
|
||||
State state) =>
|
||||
SendStatus(site, new DateTime?(timeStamp), resource, string.Empty, stateName, state, string.Empty);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site,
|
||||
string resource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description) =>
|
||||
SendStatus(site, new DateTime?(), resource, string.Empty, stateName, state, description);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime timeStamp,
|
||||
string resource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description) =>
|
||||
SendStatus(site, new DateTime?(timeStamp), resource, string.Empty, stateName, state, description);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state) =>
|
||||
SendStatus(site, new DateTime?(), resource, subResource, stateName, state, string.Empty);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site,
|
||||
DateTime timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state) =>
|
||||
SendStatus(site, new DateTime?(timeStamp), resource, subResource, stateName, state, string.Empty);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description) =>
|
||||
SendStatus(site, new DateTime?(), resource, subResource, stateName, state, description);
|
||||
|
||||
public Task<HttpResponseMessage> SendStatus(
|
||||
string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
State state,
|
||||
string description) {
|
||||
string statusMessage = CreateStatusMessage(site, timeStamp, resource, subResource, stateName, state.ToString(), description);
|
||||
StringContent stringContent = new(statusMessage, Encoding.UTF8, "application/text");
|
||||
lock (_HttpClient)
|
||||
return _HttpClient.PostAsync(string.Format(_MonInUrl, site), stringContent);
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value) =>
|
||||
SendPerformanceMessage(site, new DateTime?(), resource, string.Empty, performanceName, value, string.Empty, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description) =>
|
||||
SendPerformanceMessage(site, new DateTime?(), resource, string.Empty, performanceName, value, description, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, description, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
int? interval) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, string.Empty, interval);
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
DateTime? timeStamp,
|
||||
string performanceName,
|
||||
double value,
|
||||
string unit) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, unit, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string unit,
|
||||
int? interval) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, unit, interval);
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value) =>
|
||||
SendPerformanceMessage(site, new DateTime?(), resource, subResource, performanceName, value, string.Empty, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, subResource, performanceName, value, string.Empty, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description) =>
|
||||
SendPerformanceMessage(site, new DateTime?(), resource, subResource, performanceName, value, description, string.Empty, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
int? interval) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, subResource, performanceName, value, string.Empty, string.Empty, interval);
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string unit) =>
|
||||
SendPerformanceMessage(site, timeStamp, resource, subResource, performanceName, value, string.Empty, unit, new int?());
|
||||
|
||||
public Task<HttpResponseMessage> SendPerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description,
|
||||
string unit,
|
||||
int? interval) {
|
||||
string performanceMessage = CreatePerformanceMessage(site, timeStamp, resource, subResource, performanceName, value, description, unit, interval);
|
||||
StringContent stringContent = new(performanceMessage, Encoding.UTF8, "application/text");
|
||||
lock (_HttpClient)
|
||||
return _HttpClient.PostAsync(string.Format(_MonInUrl, site), stringContent);
|
||||
}
|
||||
|
||||
private static string CreateStatusMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string stateName,
|
||||
string state,
|
||||
string description) {
|
||||
StringBuilder stringBuilder = new();
|
||||
if (string.IsNullOrEmpty(subResource))
|
||||
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" {4} \n{5}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), stateName.Trim(), state.Trim(), description.Trim());
|
||||
else
|
||||
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" \"{4}\" {5} \n{6}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), subResource.Trim(), stateName.Trim(), state.Trim(), description.Trim());
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static string CreatePerformanceMessage(string site,
|
||||
DateTime? timeStamp,
|
||||
string resource,
|
||||
string subResource,
|
||||
string performanceName,
|
||||
double value,
|
||||
string description,
|
||||
string unit,
|
||||
int? interval) {
|
||||
StringBuilder stringBuilder = new();
|
||||
if (string.IsNullOrEmpty(subResource)) {
|
||||
if (unit.Equals(string.Empty) && !interval.HasValue)
|
||||
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" {4} \n{5}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), performanceName.Trim(), value, description.Trim());
|
||||
else
|
||||
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" {4} {5} {{interval={6}, unit={7}}}\n", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), performanceName.Trim(), value, description.Trim(), interval.HasValue ? interval.Value.ToString() : (object)string.Empty, unit.Trim());
|
||||
} else if (unit.Equals(string.Empty) && !interval.HasValue)
|
||||
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" \"{4}\" {5} \n{6}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), subResource.Trim(), performanceName.Trim(), value, description.Trim());
|
||||
else
|
||||
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" \"{4}\" {5} {6} {{interval={7}, unit={8}}}\n", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), subResource.Trim(), performanceName.Trim(), value, description.Trim(), interval.HasValue ? interval.Value.ToString() : (object)string.Empty, unit.Trim());
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public static MonIn GetInstance(IHttpClientFactory httpClientFactory, string url = MonInUrl) {
|
||||
MonIn instance;
|
||||
if (_Instances.ContainsKey(url)) {
|
||||
instance = _Instances[url];
|
||||
} else {
|
||||
lock (_Instances) {
|
||||
if (!_Instances.ContainsKey(url)) {
|
||||
instance = new MonIn(httpClientFactory, url);
|
||||
_Instances.Add(url, instance);
|
||||
} else
|
||||
instance = _Instances[url];
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private MonIn(IHttpClientFactory httpClientFactory, string url) {
|
||||
_MonInUrl = url;
|
||||
_CultureInfo = new CultureInfo("en-US");
|
||||
_HttpClient = httpClientFactory.CreateClient();
|
||||
}
|
||||
|
||||
private static string GetDateTimeNowAsPosix(DateTime timeStamp) {
|
||||
if (timeStamp > DateTime.Now)
|
||||
timeStamp = DateTime.Now;
|
||||
return ((int)timeStamp.ToUniversalTime().Subtract(_Utc1970DateTime).TotalSeconds).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
}
|
10
Infineon/Monitoring/MonA/State.cs
Normal file
10
Infineon/Monitoring/MonA/State.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Gatus.To.MonA.Infineon.Monitoring.MonA;
|
||||
|
||||
public enum State {
|
||||
Up,
|
||||
Ok,
|
||||
Warning,
|
||||
Critical,
|
||||
Down,
|
||||
Unknown,
|
||||
}
|
58
Models/AppSettings.cs
Normal file
58
Models/AppSettings.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Gatus.To.MonA.Models;
|
||||
|
||||
public record AppSettings(GatusConfiguration GatusConfiguration,
|
||||
GatusToMonaConfiguration GatusToMonaConfiguration,
|
||||
MonAConfiguration MonAConfiguration) {
|
||||
|
||||
public static AppSettings Get(IConfigurationRoot configurationRoot) {
|
||||
AppSettings result;
|
||||
#pragma warning disable IL3050, IL2026
|
||||
GatusConfiguration? gatusConfiguration = configurationRoot.GetSection(nameof(GatusConfiguration)).Get<GatusConfiguration>();
|
||||
GatusToMonaConfiguration? gatusToMonaConfiguration = configurationRoot.GetSection(nameof(GatusToMonaConfiguration)).Get<GatusToMonaConfiguration>();
|
||||
MonAConfiguration? monAConfiguration = configurationRoot.GetSection(nameof(MonAConfiguration)).Get<MonAConfiguration>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
if (gatusConfiguration is null
|
||||
|| gatusToMonaConfiguration is null
|
||||
|| monAConfiguration is null
|
||||
|| gatusToMonaConfiguration?.Company is null) {
|
||||
List<string> paths = [];
|
||||
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) {
|
||||
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
||||
continue;
|
||||
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
||||
continue;
|
||||
paths.Add(physicalFileProvider.Root);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
}
|
||||
result = new(gatusConfiguration,
|
||||
gatusToMonaConfiguration,
|
||||
monAConfiguration);
|
||||
Verify(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Verify(AppSettings appSettings) {
|
||||
if (string.IsNullOrEmpty(appSettings.GatusToMonaConfiguration.Company))
|
||||
throw new Exception("Company name must have a value!");
|
||||
if (appSettings.MonAConfiguration.Minutes < 1)
|
||||
throw new Exception("MonA Minutes must have a value more than one!");
|
||||
TimeSpan timeSpan = new(DateTime.MinValue.AddMinutes(appSettings.MonAConfiguration.Minutes).Ticks - DateTime.MinValue.Ticks);
|
||||
if (appSettings.GatusToMonaConfiguration.MillisecondsDelay < timeSpan.TotalMilliseconds)
|
||||
throw new Exception($"MonA doesn't support more than once per five minutes ({timeSpan.TotalMilliseconds})!");
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
string result = JsonSerializer.Serialize(this, AppSettingsSourceGenerationContext.Default.AppSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(AppSettings))]
|
||||
internal partial class AppSettingsSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
20
Models/GatusConfiguration.cs
Normal file
20
Models/GatusConfiguration.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Gatus.To.MonA.Models;
|
||||
|
||||
public record GatusConfiguration(string FileName,
|
||||
string Metric,
|
||||
string URL) {
|
||||
|
||||
public override string ToString() {
|
||||
string result = JsonSerializer.Serialize(this, GatusConfigurationSourceGenerationContext.Default.GatusConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(GatusConfiguration))]
|
||||
internal partial class GatusConfigurationSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
21
Models/GatusToMonaConfiguration.cs
Normal file
21
Models/GatusToMonaConfiguration.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Gatus.To.MonA.Models;
|
||||
|
||||
public record GatusToMonaConfiguration(string Company,
|
||||
string Directory,
|
||||
string Helper,
|
||||
int MillisecondsDelay) {
|
||||
|
||||
public override string ToString() {
|
||||
string result = JsonSerializer.Serialize(this, GatusToMonaConfigurationSourceGenerationContext.Default.GatusToMonaConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(GatusToMonaConfiguration))]
|
||||
internal partial class GatusToMonaConfigurationSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
22
Models/MonAConfiguration.cs
Normal file
22
Models/MonAConfiguration.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Gatus.To.MonA.Models;
|
||||
|
||||
public record MonAConfiguration(int Minutes,
|
||||
string Resource,
|
||||
string Site,
|
||||
string StateName,
|
||||
string Suffix) {
|
||||
|
||||
public override string ToString() {
|
||||
string result = JsonSerializer.Serialize(this, MonAConfigurationSourceGenerationContext.Default.MonAConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(MonAConfiguration))]
|
||||
internal partial class MonAConfigurationSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
54
Program.cs
Normal file
54
Program.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using Gatus.To.MonA.Models;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
|
||||
namespace Gatus.To.MonA;
|
||||
|
||||
public class Program {
|
||||
|
||||
internal static async Task Main(string[] args) {
|
||||
ILogger<Program>? logger = null;
|
||||
#pragma warning disable IL3050
|
||||
WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args);
|
||||
#pragma warning restore IL3050
|
||||
_ = webApplicationBuilder.Configuration.AddUserSecrets<Program>();
|
||||
AppSettings appSettings = AppSettings.Get(webApplicationBuilder.Configuration);
|
||||
try {
|
||||
#pragma warning disable IL2026
|
||||
List<string> collection =
|
||||
[
|
||||
$"BuildNumber:{webApplicationBuilder.Configuration.GetValue<string>("BuildNumber")};",
|
||||
$"GitCommit:{webApplicationBuilder.Configuration.GetValue<string>("GitCommit")};"
|
||||
];
|
||||
#pragma warning restore IL2026
|
||||
_ = webApplicationBuilder.Services.AddHttpClient();
|
||||
_ = webApplicationBuilder.Services.AddHostedService<Worker>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton(collection);
|
||||
_ = webApplicationBuilder.Services.AddSingleton(appSettings);
|
||||
if (WindowsServiceHelpers.IsWindowsService()) {
|
||||
collection.Add(nameof(WindowsServiceLifetime));
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IHostLifetime, WindowsServiceLifetime>();
|
||||
_ = webApplicationBuilder.Logging.AddEventLog(settings => {
|
||||
#pragma warning disable CA1416
|
||||
if (string.IsNullOrEmpty(settings.SourceName))
|
||||
settings.SourceName = webApplicationBuilder.Environment.ApplicationName;
|
||||
#pragma warning restore
|
||||
});
|
||||
}
|
||||
using WebApplication webApplication = webApplicationBuilder.Build();
|
||||
logger = webApplication.Services.GetRequiredService<ILogger<Program>>();
|
||||
if (string.IsNullOrEmpty(appSettings.GatusToMonaConfiguration.Company)) {
|
||||
Environment.ExitCode = -1;
|
||||
_ = webApplication.StopAsync();
|
||||
}
|
||||
logger.LogInformation("Starting Web Application");
|
||||
logger.LogCritical("{Company}", appSettings.GatusToMonaConfiguration.Company);
|
||||
await webApplication.RunAsync();
|
||||
} catch (Exception ex) {
|
||||
try { logger?.LogCritical(ex, "WebApplication terminated unexpectedly"); } catch (Exception) { }
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
20
README.md
Normal file
20
README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Introduction
|
||||
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
|
||||
|
||||
# Getting Started
|
||||
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
|
||||
1. Installation process
|
||||
2. Software dependencies
|
||||
3. Latest releases
|
||||
4. API references
|
||||
|
||||
# Build and Test
|
||||
TODO: Describe and show how to build your code and run the tests.
|
||||
|
||||
# Contribute
|
||||
TODO: Explain how other users and developers can contribute to make your code better.
|
||||
|
||||
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
|
||||
- [ASP.NET Core](https://github.com/aspnet/Home)
|
||||
- [Visual Studio Code](https://github.com/Microsoft/vscode)
|
||||
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
|
71
Worker.cs
Normal file
71
Worker.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System.Data;
|
||||
|
||||
using Gatus.To.MonA.Models;
|
||||
|
||||
using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
|
||||
namespace Gatus.To.MonA;
|
||||
|
||||
public partial class Worker : BackgroundService {
|
||||
|
||||
private bool? _First;
|
||||
private readonly bool _IsWindowsService;
|
||||
private readonly ILogger<Worker> _Logger;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IHttpClientFactory _HttpClientFactory;
|
||||
|
||||
public Worker(IHttpClientFactory httpClientFactory, ILogger<Worker> logger, IServiceProvider serviceProvider, AppSettings appSettings, List<string> collection) {
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
_HttpClientFactory = httpClientFactory;
|
||||
logger.LogInformation(string.Join(Environment.NewLine, collection));
|
||||
try { logger.LogInformation("<{folder}>", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); } catch (Exception) { }
|
||||
_First = null;
|
||||
_IsWindowsService = collection.Contains(nameof(WindowsServiceLifetime));
|
||||
}
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken) {
|
||||
if (_AppSettings.GatusToMonaConfiguration.Helper == nameof(Helpers.HelperGatusToMona))
|
||||
Helpers.HelperGatusToMona.Heartbeat(_AppSettings, _HttpClientFactory, _Logger, Infineon.Monitoring.MonA.State.Down, cancellationToken);
|
||||
return base.StopAsync(cancellationToken);
|
||||
}
|
||||
|
||||
private async Task Body(CancellationToken cancellationToken) {
|
||||
if (!_IsWindowsService) {
|
||||
_Logger.LogInformation("Set break point and skip to run {_AppSettings.GatusToMonaConfiguration.Helper}!", _AppSettings.GatusToMonaConfiguration.Helper);
|
||||
throw new EvaluateException($"Set break point and skip to run {_AppSettings.GatusToMonaConfiguration.Helper}!");
|
||||
}
|
||||
if (!_IsWindowsService) {
|
||||
for (int i = 0; i < int.MaxValue; i++) {
|
||||
BodyInner(cancellationToken);
|
||||
Thread.Sleep(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay);
|
||||
}
|
||||
}
|
||||
while (_IsWindowsService && !cancellationToken.IsCancellationRequested) {
|
||||
BodyInner(cancellationToken);
|
||||
await Task.Delay(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void BodyInner(CancellationToken cancellationToken) {
|
||||
_Logger.LogInformation("A) Next execute will be at {date}", DateTime.Now.AddMilliseconds(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay).ToString("yyyy-MM-dd hh:mm:ss.fff tt"));
|
||||
if (_First is null || _First.Value) {
|
||||
_First = false;
|
||||
if (_AppSettings.GatusToMonaConfiguration.Helper == nameof(Helpers.HelperGatusToMona))
|
||||
Helpers.HelperGatusToMona.Heartbeat(_AppSettings, _HttpClientFactory, _Logger, Infineon.Monitoring.MonA.State.Up, cancellationToken);
|
||||
}
|
||||
if (!Directory.Exists(_AppSettings.GatusToMonaConfiguration.Directory))
|
||||
_ = Directory.CreateDirectory(_AppSettings.GatusToMonaConfiguration.Directory);
|
||||
else {
|
||||
_ = _AppSettings.GatusToMonaConfiguration.Helper switch {
|
||||
nameof(Helpers.HelperGatusToMona) => Helpers.HelperGatusToMona.UpdateCount(_AppSettings, _Logger, cancellationToken),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
}
|
||||
_Logger.LogInformation("B) Next execute will be at {date}", DateTime.Now.AddMilliseconds(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay).ToString("yyyy-MM-dd hh:mm:ss.fff tt"));
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken) =>
|
||||
await Body(cancellationToken);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user