Skip to content

Commit

Permalink
💤 Putting to bed
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-uk committed Mar 23, 2024
1 parent d3ef5c9 commit 0c405a3
Show file tree
Hide file tree
Showing 18 changed files with 430 additions and 165 deletions.
35 changes: 35 additions & 0 deletions .vscode.disabled/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/bin/Debug/net6.0/dotnet-demoapp.dll",
"args": [],
"cwd": "${workspaceFolder}/src",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
15 changes: 15 additions & 0 deletions .vscode.disabled/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"[csharp]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"editor.defaultFormatter": "ms-dotnettools.csharp"
},

"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.useModernNet": true,
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.analyzeOpenDocumentsOnly": true,
"dotnet.defaultSolution": "dotnet-demoapp.sln"
}
42 changes: 42 additions & 0 deletions .vscode.disabled/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/dotnet-demoapp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/dotnet-demoapp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/src/dotnet-demoapp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
31 changes: 31 additions & 0 deletions dotnet-demoapp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.001.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-demoapp", "src\dotnet-demoapp.csproj", "{523F95F6-F77C-4110-9B1F-F7B789D93AEA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tests", "tests\tests.csproj", "{E86A9342-A225-40D9-A866-02C9D68E5CE6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{523F95F6-F77C-4110-9B1F-F7B789D93AEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{523F95F6-F77C-4110-9B1F-F7B789D93AEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{523F95F6-F77C-4110-9B1F-F7B789D93AEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{523F95F6-F77C-4110-9B1F-F7B789D93AEA}.Release|Any CPU.Build.0 = Release|Any CPU
{E86A9342-A225-40D9-A866-02C9D68E5CE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E86A9342-A225-40D9-A866-02C9D68E5CE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E86A9342-A225-40D9-A866-02C9D68E5CE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E86A9342-A225-40D9-A866-02C9D68E5CE6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6832A827-4833-4AFB-93CE-2A5B35FF2D7D}
EndGlobalSection
EndGlobal
6 changes: 4 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ help: ## 💬 This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

lint: ## 🔎 Lint & format, will not fix but sets exit code on error
@dotnet format --help > /dev/null 2> /dev/null || dotnet tool install --global dotnet-format
dotnet format --verbosity diag ./src
dotnet format --verbosity detailed --verify-no-changes ./src

lint-fix: ## 🌟 Lint & format, will try to fix code
dotnet format --verbosity detailed ./src

image: ## 🔨 Build container image from Dockerfile
docker build . --file build/Dockerfile \
Expand Down
131 changes: 131 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
root = true

# All files
[*]
indent_style = space

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# Indentation and spacing
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
tab_width = 4
insert_final_newline = true
charset = utf-8-bom

###############################
# .NET Coding Conventions #
###############################
# Organize usings
dotnet_sort_system_directives_first = true
# this. preferences
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
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_readonly_field = true: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_null_propagation = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent

###############################
# C# Coding Conventions #
###############################
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# 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:silent
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

###############################
# 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
# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

#####################################
# Enable analyzer rules sets #
#####################################
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 = error
dotnet_analyzer_diagnostic.category-Performance.severity = error
dotnet_analyzer_diagnostic.category-SingleFile.severity = error
dotnet_analyzer_diagnostic.category-Reliability.severity = error
dotnet_analyzer_diagnostic.category-Security.severity = error
dotnet_analyzer_diagnostic.category-Style.severity = error
dotnet_analyzer_diagnostic.category-Usage.severity = error
dotnet_analyzer_diagnostic.category-CodeQuality.severity = error

# This rule often clashes with CA1707 (no underscores)
dotnet_diagnostic.IDE0130.severity = none
15 changes: 4 additions & 11 deletions src/ApiHelper.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
using System.Diagnostics;
using System.Diagnostics;

namespace DotnetDemoapp
{
// Simple static methods to help with the API calls
// These could probably be made into full HTTP handlers
public class ApiHelper
{
public static async Task<(int, String)> GetOpenWeather(string apiKey, double posLat, double posLong)
public static async Task<(int, string)> GetOpenWeather(string apiKey, double posLat, double posLong)
{
// Call the OpenWeather API with provided lat & long
var request = new HttpRequestMessage(HttpMethod.Get, $"https://api.openweathermap.org/data/2.5/weather?lat={posLat}&lon={posLong}&appid={apiKey}&units=metric");
// This is not the best way to use HttpClient, but good enough
using var client = new HttpClient();
var response = await client.SendAsync(request);

if (response.IsSuccessStatusCode)
{
return (200, await response.Content.ReadAsStringAsync());
}
else
{
return (((int)response.StatusCode), null);
}
return response.IsSuccessStatusCode ? (200, await response.Content.ReadAsStringAsync()) : ((int)response.StatusCode, null);
}

public static async Task<double> GetCpuUsageForProcess()
Expand All @@ -41,4 +34,4 @@ public static async Task<double> GetCpuUsageForProcess()
return cpuUsageTotal * 100;
}
}
}
}
8 changes: 2 additions & 6 deletions src/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Diagnostics;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;

namespace DotnetDemoapp.Pages
{
Expand All @@ -12,11 +11,8 @@ public class ErrorModel : PageModel

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
public ErrorModel()
{
_logger = logger;
}

public void OnGet()
Expand Down
18 changes: 9 additions & 9 deletions src/Pages/Info.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<table class="table table-hover table-striped table">
<tr>
<td><i class="fa fa-fw fa-cube"></i> Containerized:</td>
@if (Model.isInContainer)
@if (Model.IsInContainer)
{
<td>Looks like we're running in a Docker container! &#x1F604;</td>
}
Expand All @@ -22,7 +22,7 @@
</tr>
<tr>
<td><i class="fa fa-fw fa-project-diagram"></i> Kubernetes:</td>
@if (Model.isInKubernetes)
@if (Model.IsInKubernetes)
{
<td>We're also running in a Kubernetes pod! &#x1f44d;</td>
}
Expand All @@ -33,7 +33,7 @@
</tr>
<tr>
<td><i class="fa fa-fw fa-microscope"></i> App Insights:</td>
@if (Model.isAppInsightsEnabled)
@if (Model.IsAppInsightsEnabled)
{
<td>Reporting telemetry to Azure Application Insights</td>
}
Expand All @@ -44,23 +44,23 @@
</tr>
<tr>
<td><i class="fa fa-fw fa-home"></i> Hostname:</td>
<td>@Model.hostname</td>
<td>@Model.Hostname</td>
</tr>
<tr>
<td><i class="fas fa-fw fa-cogs"></i> OS Details:</td>
<td>@Model.osDesc</td>
<td>@Model.OsDesc</td>
</tr>
<tr>
<td><i class="fa fa-fw fa-microchip"></i> Architecture:</td>
<td>@Model.osArch - @Model.processorCount cores</td>
<td>@Model.OsArch - @Model.ProcessorCount cores</td>
</tr>
<tr>
<td><i class="fab fa-fw fa-codepen"></i> Framework:</td>
<td>@Model.framework</td>
<td>@Model.Framework</td>
</tr>
<tr>
<td><i class="fas fa-fw fa-memory"></i> Memory:</td>
<td>@Model.workingSet MB / @String.Format("{0,12:n} MB", Model.physicalMem)</td>
<td>@Model.WorkingSet MB / @String.Format("{0,12:n} MB", Model.PhysicalMem)</td>
</tr>
</table>

Expand All @@ -70,7 +70,7 @@

<table class="table text-success bg-dark env-table">
<tbody>
@foreach (KeyValuePair<string, string> var in @Model.envVars)
@foreach (KeyValuePair<string, string> var in @Model.EnvVars)
{
@if (var.Key == "PATH") continue;
<tr>
Expand Down
Loading

0 comments on commit 0c405a3

Please sign in to comment.