From d5cae2931772c1e0643a25bd85ddc50a0b639700 Mon Sep 17 00:00:00 2001 From: Fernando Cerqueira Date: Tue, 20 Feb 2024 09:08:18 -0300 Subject: [PATCH] v.2.0.0-beta2 --- README.md | 2 +- README.txt | 2 +- docs/apis/apis.md | 2 + .../healthcheckplus.healthreportextensions.md | 126 ++++++++++++++++++ .../healthcheckplus.istatehealthchecksplus.md | 8 +- docs/index.md | 2 +- src/HealthCheckPlus.csproj | 4 +- src/HealthReportExtensions.cs | 94 +++++++++++++ src/IDataHealthPlus.cs | 7 +- src/IStateHealthChecksPlus.cs | 4 +- src/Internal/CacheHealthCheckPlus.cs | 6 +- 11 files changed, 242 insertions(+), 15 deletions(-) create mode 100644 docs/apis/healthcheckplus.healthreportextensions.md create mode 100644 src/HealthReportExtensions.cs diff --git a/README.md b/README.md index 1f1dd7b..ad4f424 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ public class MyBussines { //do something } - if (healthCheckApp.StatusDep(MyEnum.HcTeste2).Status == HealthStatus.Unhealthy) + if (healthCheckApp.StatusResult(MyEnum.HcTeste2).Status == HealthStatus.Unhealthy) { //do something. This dependency 'HcTeste2' is not available } diff --git a/README.txt b/README.txt index 4672565..ec8c6f8 100644 --- a/README.txt +++ b/README.txt @@ -188,7 +188,7 @@ public class MyBussines { //do something } - if (healthCheckApp.StatusDep(MyEnum.HcTeste2).Status == HealthStatus.Unhealthy) + if (healthCheckApp.StatusResult(MyEnum.HcTeste2).Status == HealthStatus.Unhealthy) { //do something. This dependency 'HcTeste2' is not available } diff --git a/docs/apis/apis.md b/docs/apis/apis.md index 31b59b7..c8785ad 100644 --- a/docs/apis/apis.md +++ b/docs/apis/apis.md @@ -13,6 +13,8 @@ - [HealthCheckTrigger](./healthcheckplus.healthchecktrigger.md) +- [HealthReportExtensions](./healthcheckplus.healthreportextensions.md) + - [IDataHealthPlus](./healthcheckplus.idatahealthplus.md) - [IStateHealthChecksPlus](./healthcheckplus.istatehealthchecksplus.md) diff --git a/docs/apis/healthcheckplus.healthreportextensions.md b/docs/apis/healthcheckplus.healthreportextensions.md new file mode 100644 index 0000000..9a2ccd6 --- /dev/null +++ b/docs/apis/healthcheckplus.healthreportextensions.md @@ -0,0 +1,126 @@ +# HealthCheckPlus API:HealthReportExtensions + +[![Build](https://github.com/FRACerqueira/HealthCheckPlus/workflows/Build/badge.svg)](https://github.com/FRACerqueira/HealthCheckPlus/actions/workflows/build.yml) +[![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/FRACerqueira/HealthCheckPlus/blob/master/LICENSE) +[![NuGet](https://img.shields.io/nuget/v/HealthCheckPlus)](https://www.nuget.org/packages/HealthCheckPlus/) +[![Downloads](https://img.shields.io/nuget/dt/HealthCheckPlus)](https://www.nuget.org/packages/HealthCheckPlus/) + +[**Back to List Api**](./apis.md) + +# HealthReportExtensions + +Namespace: HealthCheckPlus + +The Extensions for HealthReport + +```csharp +public static class HealthReportExtensions +``` + +Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [HealthReportExtensions](./healthcheckplus.healthreportextensions.md) + +## Methods + +### **StatusResult(HealthReport, Enum)** + +The last data for HealthCheck. + +```csharp +public static HealthStatus StatusResult(HealthReport report, Enum keydep) +``` + +#### Parameters + +`report` HealthReport
+The . + +`keydep` [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum)
+The Enum value dependence. + +#### Returns + +HealthStatus + +###
**TryGetDegraded(HealthReport, ref Dictionary`2)** + +Try get all degraded status. + +```csharp +public static bool TryGetDegraded(HealthReport report, ref Dictionary`2 result) +``` + +#### Parameters + +`report` HealthReport
+The . + +`result` [Dictionary`2&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2&)
+the Dictionary with all HealthCheck Result with degraded status + +#### Returns + +True if found, oyherwise false. + +###
**TryGetHealthy(HealthReport, ref Dictionary`2)** + +Try get all healthy status. + +```csharp +public static bool TryGetHealthy(HealthReport report, ref Dictionary`2 result) +``` + +#### Parameters + +`report` HealthReport
+The . + +`result` [Dictionary`2&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2&)
+the Dictionary with all HealthCheck Result with healthy status + +#### Returns + +True if found, oyherwise false. + +###
**TryGetNotHealthy(HealthReport, ref Dictionary`2)** + +Try get all not healthy status. + +```csharp +public static bool TryGetNotHealthy(HealthReport report, ref Dictionary`2 result) +``` + +#### Parameters + +`report` HealthReport
+The . + +`result` [Dictionary`2&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2&)
+the Dictionary with all HealthCheck Result with not healthy status + +#### Returns + +True if found, oyherwise false. + +###
**TryGetUnhealthy(HealthReport, ref Dictionary`2)** + +Try get all unhealthy status. + +```csharp +public static bool TryGetUnhealthy(HealthReport report, ref Dictionary`2 result) +``` + +#### Parameters + +`report` HealthReport
+The . + +`result` [Dictionary`2&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2&)
+the Dictionary with all HealthCheck Result with unhealthy status + +#### Returns + +True if found, oyherwise false. + + +- - - +[**Back to List Api**](./apis.md) diff --git a/docs/apis/healthcheckplus.istatehealthchecksplus.md b/docs/apis/healthcheckplus.istatehealthchecksplus.md index a402171..4053639 100644 --- a/docs/apis/healthcheckplus.istatehealthchecksplus.md +++ b/docs/apis/healthcheckplus.istatehealthchecksplus.md @@ -53,12 +53,12 @@ name of url request([HealthCheckPlusOptions.HealthCheckName](./healthcheckplus.o HealthStatus -###
**StatusDep(Enum)** +### **StatusResult(Enum)** The last data for HealthCheck. ```csharp -HealthCheckResult StatusDep(Enum keydep) +HealthCheckResult StatusResult(Enum keydep) ``` #### Parameters @@ -70,12 +70,12 @@ The Enum value dependence. HealthCheckResult -### **StatusDep(String)** +### **StatusResult(String)** The last data for HealthCheck. ```csharp -HealthCheckResult StatusDep(string keydep) +HealthCheckResult StatusResult(string keydep) ``` #### Parameters diff --git a/docs/index.md b/docs/index.md index 979c101..f423f23 100644 --- a/docs/index.md +++ b/docs/index.md @@ -206,7 +206,7 @@ public class MyBussines { //do something } - if (healthCheckApp.StatusDep(MyEnum.HcTeste2).Status == HealthStatus.Unhealthy) + if (healthCheckApp.StatusResult(MyEnum.HcTeste2).Status == HealthStatus.Unhealthy) { //do something. This dependency 'HcTeste2' is not available } diff --git a/src/HealthCheckPlus.csproj b/src/HealthCheckPlus.csproj index 323a594..ed16309 100644 --- a/src/HealthCheckPlus.csproj +++ b/src/HealthCheckPlus.csproj @@ -21,7 +21,7 @@ HealthCheckPlus NugetREADME.md https://fracerqueira.github.io/HealthCheckPlus - 2.0.0-beta1 + 2.0.0-beta2 icon.png © 2023 - Fernando Cerqueira false @@ -66,7 +66,7 @@ - + diff --git a/src/HealthReportExtensions.cs b/src/HealthReportExtensions.cs new file mode 100644 index 0000000..ecdca2f --- /dev/null +++ b/src/HealthReportExtensions.cs @@ -0,0 +1,94 @@ +// ******************************************************************************************** +// MIT LICENCE +// The maintenance and evolution is maintained by the HealthCheckPlus project under MIT license +// ******************************************************************************************** + +using System.Runtime.CompilerServices; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace HealthCheckPlus +{ + /// + /// The Extensions for HealthReport + /// + public static class HealthReportExtensions + { + /// + /// The last data for HealthCheck. + /// + /// The . + /// + /// The Enum value dependence. + /// + public static HealthStatus StatusResult(this HealthReport report, Enum keydep) + { + var aux = report.Entries + .Where(x => x.Key == keydep.ToString()); + if (!aux.Any()) + { + throw new ArgumentException($"The {nameof(keydep)} must not found.", nameof(keydep)); + } + return aux + .Select(X => X.Value.Status) + .FirstOrDefault(); + } + + /// + /// Try get all not healthy status. + /// + /// The . + /// the Dictionary with all HealthCheck Result with not healthy status + /// True if found, oyherwise false. + public static bool TryGetNotHealthy(this HealthReport report, out Dictionary result) + { + result = GetEntriesStatus(report, x => x.Status != HealthStatus.Healthy); + return result.Count != 0; + } + + /// + /// Try get all healthy status. + /// + /// The . + /// the Dictionary with all HealthCheck Result with healthy status + /// True if found, oyherwise false. + public static bool TryGetHealthy(this HealthReport report, out Dictionary result) + { + result = GetEntriesStatus(report, x => x.Status == HealthStatus.Healthy); + return result.Count != 0; + } + + /// + /// Try get all degraded status. + /// + /// The . + /// the Dictionary with all HealthCheck Result with degraded status + /// True if found, oyherwise false. + public static bool TryGetDegraded(this HealthReport report, out Dictionary result) + { + result = GetEntriesStatus(report, x => x.Status == HealthStatus.Degraded); + return result.Count != 0; + } + + /// + /// Try get all unhealthy status. + /// + /// The . + /// the Dictionary with all HealthCheck Result with unhealthy status + /// True if found, oyherwise false. + public static bool TryGetUnhealthy(this HealthReport report, out Dictionary result) + { + result = GetEntriesStatus(report,x => x.Status == HealthStatus.Unhealthy); + return result.Count != 0; + } + + private static Dictionary GetEntriesStatus(HealthReport report, Predicate predicate) + { + Dictionary result = []; + foreach (var item in report.Entries.Where(x => predicate(x.Value))) + { + result.Add(item.Key, new HealthCheckResult(item.Value.Status, item.Value.Description, item.Value.Exception, item.Value.Data)); + } + return result; + } + } +} diff --git a/src/IDataHealthPlus.cs b/src/IDataHealthPlus.cs index bbe242c..b68c3af 100644 --- a/src/IDataHealthPlus.cs +++ b/src/IDataHealthPlus.cs @@ -1,4 +1,9 @@ -using Microsoft.Extensions.Diagnostics.HealthChecks; +// ******************************************************************************************** +// MIT LICENCE +// The maintenance and evolution is maintained by the HealthCheckPlus project under MIT license +// ******************************************************************************************** + +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace HealthCheckPlus { diff --git a/src/IStateHealthChecksPlus.cs b/src/IStateHealthChecksPlus.cs index bdfa471..7489459 100644 --- a/src/IStateHealthChecksPlus.cs +++ b/src/IStateHealthChecksPlus.cs @@ -19,7 +19,7 @@ public interface IStateHealthChecksPlus /// /// The Enum value dependence. /// - HealthCheckResult StatusDep(Enum keydep); + HealthCheckResult StatusResult(Enum keydep); /// /// The last data for HealthCheck. @@ -27,7 +27,7 @@ public interface IStateHealthChecksPlus /// /// The name dependence. /// - HealthCheckResult StatusDep(string keydep); + HealthCheckResult StatusResult(string keydep); /// /// Gets a representing the aggregate status of all the health checks. diff --git a/src/Internal/CacheHealthCheckPlus.cs b/src/Internal/CacheHealthCheckPlus.cs index da9c506..9e29590 100644 --- a/src/Internal/CacheHealthCheckPlus.cs +++ b/src/Internal/CacheHealthCheckPlus.cs @@ -150,12 +150,12 @@ public ItemCacheHealth FullStatus(string keydep) #region IStateHealthChecksPlus - public HealthCheckResult StatusDep(Enum keydep) + public HealthCheckResult StatusResult(Enum keydep) { - return StatusDep(keydep.ToString()); + return StatusResult(keydep.ToString()); } - public HealthCheckResult StatusDep(string keydep) + public HealthCheckResult StatusResult(string keydep) { return _statusDeps[keydep].Lastresult; }