Skip to content

Commit

Permalink
Merge pull request hexagon-oss#23 from hexagon-oss/dotnet5_port
Browse files Browse the repository at this point in the history
Upgraded to .NET 5.0 and add REST API instead of unreliable WMI for external monitoring
  • Loading branch information
lukas-vonblon authored Jan 3, 2022
2 parents 558a14b + 70ef62c commit df52e64
Show file tree
Hide file tree
Showing 52 changed files with 1,592 additions and 1,320 deletions.
122 changes: 2 additions & 120 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,129 +4,11 @@ root = true
[*]
insert_final_newline = true
indent_style = space
indent_size = 2
tab_width = 2
indent_size = 4
tab_width = 4
trim_trailing_whitespace = true

[*.cs]
# Recommended max_line_length = 100

# New line preferences
csharp_new_line_before_open_brace = none
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_between_query_expression_clauses = false

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

# Use of this., avoid except for fields
dotnet_style_qualification_for_field = false:none
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Types: use keywords instead of BCL types, and permit var only when the type is clear
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = false:none
csharp_style_var_elsewhere = false:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Name all constant fields using PascalCase
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.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Code style defaults
csharp_using_directive_placement = outside_namespace:suggestion
dotnet_sort_system_directives_first = true
csharp_prefer_braces = when_multiline:suggestion
csharp_preserve_single_line_blocks = true:none
csharp_preserve_single_line_statements = false:none
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_simple_using_statement = false:none
csharp_style_prefer_switch_expression = true:suggestion

# Code quality
dotnet_style_readonly_field = true:suggestion
dotnet_code_quality_unused_parameters = non_public:suggestion

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring
dotnet_style_prefer_conditional_expression_over_return = true:refactoring
csharp_prefer_simple_default_expression = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = true:refactoring
csharp_style_expression_bodied_constructors = true:refactoring
csharp_style_expression_bodied_operators = true:refactoring
csharp_style_expression_bodied_properties = true:refactoring
csharp_style_expression_bodied_indexers = true:refactoring
csharp_style_expression_bodied_accessors = true:refactoring
csharp_style_expression_bodied_lambdas = true:refactoring
csharp_style_expression_bodied_local_functions = true:refactoring

# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Other features
csharp_style_prefer_index_operator = false:none
csharp_style_prefer_range_operator = false:none
csharp_style_pattern_local_over_anonymous_function = false:none

# Space preferences
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 = 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_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

# Analyzers
dotnet_code_quality.ca1802.api_surface = private, internal
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
bin
obj
launchSettings.json
/*.nupkg
5 changes: 0 additions & 5 deletions Directory.Build.props

This file was deleted.

35 changes: 35 additions & 0 deletions LibDemoConsole/HWVisitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using OpenHardwareMonitor.Hardware;

namespace LibDemoConsole {
internal class HWVisitor : IVisitor
{
int depth = 0;
public void VisitComputer(IComputer computer)
{
Serilog.Log.Information("{computer}", computer);
computer.Traverse(this);
}

public void VisitHardware(IHardware hardware)
{
Serilog.Log.Information(new string('\t', depth) + "{type} {name} {identifier}", hardware.HardwareType, hardware.Name, hardware.Identifier);
hardware.Update();
depth++;
hardware.Traverse(this);
depth--;
}

public void VisitParameter(IParameter parameter)
{
Serilog.Log.Information(new string('\t', depth) + "{type} {value} {name} {identifier}", parameter.Sensor.SensorType, parameter.Value , parameter.Name, parameter.Identifier);
}

public void VisitSensor(ISensor sensor)
{
Serilog.Log.Information(new string('\t', depth) + "{type} {value} {name} {identifier}", sensor.SensorType, sensor.Value, sensor.Name, sensor.Identifier);
depth++;
sensor.Traverse(this);
depth--;
}
}
}
16 changes: 16 additions & 0 deletions LibDemoConsole/LibDemoConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OpenHardwareMonitorLib\OpenHardwareMonitorLib.csproj" />
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions LibDemoConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using OpenHardwareMonitor.Hardware;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibDemoConsole
{
class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();

Computer c = new Computer()
{
CPUEnabled = true,
FanControllerEnabled = true,
GPUEnabled = true,
HDDEnabled = true,
MainboardEnabled = true,
RAMEnabled = true,
};
try
{
c.Open();
var visitor = new HWVisitor();
c.Accept(visitor);
}
finally
{
c.Close();
}
}
}
}
5 changes: 4 additions & 1 deletion OpenHardwareMonitor/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ class CommandLineOptions {
[Option("minimizetotray", HelpText = "Force minimize to tray")]
public bool MinimizeToTray { get; set; }

[Option('p', "port", HelpText = "Network port to use for remote web access (default: 8085)")]
[Option('p', "port", HelpText = "Network port to use for remote web access (default: 8086)")]
public int? WebServerPort { get; set; }

[Option('r', "run", HelpText = "Run webserver at startup")]
public bool RunWebServer { get; set; }

[Option("remote", HelpText = "Allow remote access to web server (if disabled, only localhost is allowed)", Default = false)]
public bool AllowRemoteAccess { get; set; }

[Option("ignoreconfiguration", HelpText = "Do not load configuration file at startup. If this is not specified, the other settings still supersede the " +
"settings from configuration, but default to the previous setting instead of the default")]
public bool DoNotLoadConfiguration { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion OpenHardwareMonitor/GUI/Gadget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public bool AlwaysOnTop {
}
}

public ContextMenu ContextMenu {
public ContextMenuStrip ContextMenu {
get {
return window.ContextMenu;
}
Expand Down
4 changes: 2 additions & 2 deletions OpenHardwareMonitor/GUI/GadgetWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GadgetWindow : NativeWindow, IDisposable {
private byte opacity = 255;
private Point location = new Point(100, 100);
private Size size = new Size(130, 84);
private ContextMenu contextMenu = null;
private ContextMenuStrip contextMenu = null;
private MethodInfo commandDispatch;
private IntPtr handleBitmapDC;
private Size bufferSize;
Expand Down Expand Up @@ -366,7 +366,7 @@ public Point Location {

public event EventHandler LocationChanged;

public ContextMenu ContextMenu {
public ContextMenuStrip ContextMenu {
get {
return contextMenu;
}
Expand Down
2 changes: 2 additions & 0 deletions OpenHardwareMonitor/GUI/HardwareNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public IHardware Hardware {
get { return hardware; }
}

public override string NodeId => Hardware.Identifier.ToString();

public override bool IsExpanded {
get {
return base.IsExpanded;
Expand Down
Loading

0 comments on commit df52e64

Please sign in to comment.