Skip to content

Commit

Permalink
Dothanhl/feature/dotnetformat (#715)
Browse files Browse the repository at this point in the history
Format
  • Loading branch information
Gnol-VN authored Feb 6, 2025
1 parent a2d5b36 commit 4b2565b
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/Abstractions/ExecutionContext/BaseExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BaseExecutionContext(IHostEnvironment? hostEnvironment = null)
BuildVersion = GetBuildVersion();

ClusterIpAddress = GetIpAddress(MachineName);

RegionName = GetVariable(RegionNameVariableName) ?? DefaultEmptyValue;
RegionShortName = GetVariable(RegionShortNameVariableName) ?? DefaultEmptyValue;
DeploymentSlice = GetVariable(SliceNameVariableName) ?? DefaultEmptyValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, Canc

private void ValidateCertificate(X509Certificate2? certificate, string certName, StringBuilder message, HealthCheckContext context, ref HealthStatus healthStatus)
{

string errorMessage = string.Empty;
DateTime localNow = DateTime.Now;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static IOmexHealthChecksBuilder AddOmexHealthChecks(this IServiceCollecti
/// <param name="predicate"></param>
public static bool TryRemoveServiceByPredicate(this IServiceCollection @this, Func<ServiceDescriptor, bool> predicate)
{
var descriptorToRemove = @this.SingleOrDefault(predicate);
ServiceDescriptor? descriptorToRemove = @this.SingleOrDefault(predicate);
if (descriptorToRemove != null)
{
return @this.Remove(descriptorToRemove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static IOmexHealthChecksBuilder AddCheck(
return (IOmexHealthChecksBuilder)HealthChecksBuilderDelegateExtensions.AddCheck(builder, name, check, tags, timeout);
}

var instance = new DelegateHealthCheck((ct) => new ValueTask<HealthCheckResult>(check()));
DelegateHealthCheck instance = new((ct) => new ValueTask<HealthCheckResult>(check()));
return builder.Add(new HealthCheckRegistration(name, instance, failureStatus: default, tags, timeout), parameters);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public static IOmexHealthChecksBuilder AddCheck(
return (IOmexHealthChecksBuilder)HealthChecksBuilderDelegateExtensions.AddCheck(builder, name, check, tags, timeout);
}

var instance = new DelegateHealthCheck((ct) => new ValueTask<HealthCheckResult>(check(ct)));
DelegateHealthCheck instance = new((ct) => new ValueTask<HealthCheckResult>(check(ct)));
return builder.Add(new HealthCheckRegistration(name, instance, failureStatus: default, tags, timeout), parameters);
}

Expand Down Expand Up @@ -144,7 +144,7 @@ public static IOmexHealthChecksBuilder AddAsyncCheck(
return (IOmexHealthChecksBuilder)HealthChecksBuilderDelegateExtensions.AddAsyncCheck(builder, name, check().AsTask, tags, timeout);
}

var instance = new DelegateHealthCheck((ct) => check());
DelegateHealthCheck instance = new((ct) => check());
return builder.Add(new HealthCheckRegistration(name, instance, failureStatus: default, tags, timeout), parameters);
}

Expand Down Expand Up @@ -185,10 +185,9 @@ public static IOmexHealthChecksBuilder AddAsyncCheck(
if (parameters == null)
{
return (IOmexHealthChecksBuilder)HealthChecksBuilderDelegateExtensions.AddAsyncCheck(builder, name, ct => check(ct).AsTask(), tags, timeout);
;
}

var instance = new DelegateHealthCheck((ct) => check(ct));
DelegateHealthCheck instance = new((ct) => check(ct));
return builder.Add(new HealthCheckRegistration(name, instance, failureStatus: default, tags, timeout), parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static HttpRequestMessage CloneRequestMessage(HttpRequestMessage message
clone.Headers.TryAddWithoutValidation(header.Key, header.Value);
}

clone.VersionPolicy = message.VersionPolicy;
clone.VersionPolicy = message.VersionPolicy;

foreach (KeyValuePair<string, object?> option in message.Options)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Diagnostics.HealthChecks/Internal/NonCapturingTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static Timer Create(TimerCallback callback, object? state, TimeSpan dueTi
}

// Don't capture the current ExecutionContext and its AsyncLocals onto the timer
var restoreFlow = false;
bool restoreFlow = false;
try
{
if (!ExecutionContext.IsFlowSuppressed())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

using System;
using System.Fabric;
using System.Fabric.Health;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.Omex.Extensions.Abstractions;
using System.Fabric.Health;

namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks
{
Expand Down
6 changes: 3 additions & 3 deletions src/Diagnostics.HealthChecks/Internal/ValueStopwatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public TimeSpan GetElapsedTime()
throw new InvalidOperationException("An uninitialized, or 'default', ValueStopwatch cannot be used to get elapsed time.");
}

var end = Stopwatch.GetTimestamp();
var timestampDelta = end - _startTimestamp;
var ticks = (long)(TimestampToTicks * timestampDelta);
long end = Stopwatch.GetTimestamp();
long timestampDelta = end - _startTimestamp;
long ticks = (long)(TimestampToTicks * timestampDelta);
return new TimeSpan(ticks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public OmexHealthCheckPublisherHostedService(
// actually tries to **run** health checks would be real baaaaad.
ValidateRegistrations(_healthCheckServiceOptions.Value.Registrations);

_defaultTimerOptions = (_healthCheckPublisherOptions.Value.Delay, _healthCheckPublisherOptions.Value.Period, _healthCheckPublisherOptions.Value.Timeout);
_defaultTimerOptions = (_healthCheckPublisherOptions.Value.Delay, _healthCheckPublisherOptions.Value.Period, _healthCheckPublisherOptions.Value.Timeout);

// Group healthcheck registrations by Delay, Period and Timeout, to build a Dictionary<(TimeSpan, TimeSpan, TimeSpan), List<HealthCheckRegistration>>
// For HCs with no Delay, Period or Timeout, we default to the publisher values
Expand All @@ -97,7 +97,7 @@ public OmexHealthCheckPublisherHostedService(

private (TimeSpan Delay, TimeSpan Period, TimeSpan Timeout) GetTimerOptionsOrDefault(string registrationName)
{
_healthCheckRegistrationOptions.Value.RegistrationParameters.TryGetValue(registrationName, out var registrationParameters);
_healthCheckRegistrationOptions.Value.RegistrationParameters.TryGetValue(registrationName, out HealthCheckRegistrationParameters? registrationParameters);

return (registrationParameters?.Delay ?? _healthCheckPublisherOptions.Value.Delay, registrationParameters?.Period ?? _healthCheckPublisherOptions.Value.Period, registrationParameters?.Timeout ?? _healthCheckPublisherOptions.Value.Timeout);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public Task StopAsync(CancellationToken cancellationToken = default)

if (_timersByOptions != null)
{
foreach (var timer in _timersByOptions.Values)
foreach (Timer timer in _timersByOptions.Values)
{
timer.Dispose();
}
Expand Down Expand Up @@ -180,13 +180,13 @@ internal async Task RunAsync((TimeSpan Delay, TimeSpan Period, TimeSpan Timeout)
{
timerOptions ??= _defaultTimerOptions;

var duration = ValueStopwatch.StartNew();
ValueStopwatch duration = ValueStopwatch.StartNew();
Logger.HealthCheckPublisherProcessingBegin(_logger);

CancellationTokenSource? cancellation = null;
try
{
var timeout = timerOptions.Value.Timeout;
TimeSpan timeout = timerOptions.Value.Timeout;

cancellation = CancellationTokenSource.CreateLinkedTokenSource(_stopping.Token);
_runTokenSource = cancellation;
Expand Down Expand Up @@ -218,18 +218,18 @@ private async Task RunAsyncCore((TimeSpan Delay, TimeSpan Period, TimeSpan Timeo
await Task.Yield();

// Concatenate predicates - we only run HCs at the set delay, period and timeout, and that are enabled
var withOptionsPredicate = (HealthCheckRegistration r) =>
Func<HealthCheckRegistration, bool> withOptionsPredicate = (HealthCheckRegistration r) =>
{
// Check whether the current timer options correspond to the ones of the HC registration
var rOptions = GetTimerOptionsOrDefault(r.Name);
var hasOptions = rOptions == timerOptions;
(TimeSpan Delay, TimeSpan Period, TimeSpan Timeout) rOptions = GetTimerOptionsOrDefault(r.Name);
bool hasOptions = rOptions == timerOptions;
if (!hasOptions)
{
return false;
}

// Check if HC is enabled
if (_healthCheckRegistrationOptions.Value.RegistrationParameters.TryGetValue(r.Name, out var hcrParams) && !hcrParams.IsEnabled)
if (_healthCheckRegistrationOptions.Value.RegistrationParameters.TryGetValue(r.Name, out HealthCheckRegistrationParameters? hcrParams) && !hcrParams.IsEnabled)
{
return false;
}
Expand All @@ -244,11 +244,11 @@ private async Task RunAsyncCore((TimeSpan Delay, TimeSpan Period, TimeSpan Timeo
};

// The health checks service does it's own logging, and doesn't throw exceptions.
var report = await _healthCheckService.CheckHealthAsync(withOptionsPredicate, cancellationToken).ConfigureAwait(false);
HealthReport report = await _healthCheckService.CheckHealthAsync(withOptionsPredicate, cancellationToken).ConfigureAwait(false);

var publishers = _publishers;
var tasks = new Task[publishers.Length];
for (var i = 0; i < publishers.Length; i++)
IHealthCheckPublisher[] publishers = _publishers;
Task[] tasks = new Task[publishers.Length];
for (int i = 0; i < publishers.Length; i++)
{
tasks[i] = RunPublisherAsync(publishers[i], report, cancellationToken);
}
Expand All @@ -258,7 +258,7 @@ private async Task RunAsyncCore((TimeSpan Delay, TimeSpan Period, TimeSpan Timeo

private async Task RunPublisherAsync(IHealthCheckPublisher publisher, HealthReport report, CancellationToken cancellationToken)
{
var duration = ValueStopwatch.StartNew();
ValueStopwatch duration = ValueStopwatch.StartNew();

try
{
Expand Down Expand Up @@ -289,9 +289,9 @@ private static void ValidateRegistrations(IEnumerable<HealthCheckRegistration> r
// Scan the list for duplicate names to provide a better error if there are duplicates.

StringBuilder? builder = null;
var distinctRegistrations = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
HashSet<string> distinctRegistrations = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

foreach (var registration in registrations)
foreach (HealthCheckRegistration registration in registrations)
{
if (!distinctRegistrations.Add(registration.Name))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Hosting.Services.Web/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static IApplicationBuilder UseObsoleteCorrelationHeadersMiddleware(this I
/// </summary>
public static IApplicationBuilder UseOmexExceptionHandler(this IApplicationBuilder builder, IHostEnvironment environment) =>
builder.UseOmexExceptionHandler(environment.IsDevelopment());

/// <summary>
/// Adds the default exception handling logic that will display a developer exception page in develop and a short message during deployment
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions tests/Abstractions.UnitTests/TagTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -29,7 +29,7 @@ public void Create_HasProperValues()
private static void AssertTagNames(string expectedTag, string? actualTag, string message)
{
#if DEBUG
StringAssert.EndsWith(actualTag?.Replace('\\','/'), expectedTag, message);
StringAssert.EndsWith(actualTag?.Replace('\\', '/'), expectedTag, message);
#else
Assert.AreEqual(expectedTag, actualTag, message);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void SendActivityMetric_WithSendParentName_ProducesMetricPointWithParentN
// 3. Assert
MeasurementResult result = listener.Results.First(m => environment.EnvironmentName.Equals(m.Tags[s_environmentTagName]));

if(expectParentNameToBeEmitted)
if (expectParentNameToBeEmitted)
{
AssertTag(result, "ParentName", nameof(parentName));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using Moq;
using Microsoft.Extensions.Options;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Microsoft.Omex.Extensions.Activities.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks.UnitTests.Extensions
{
Expand Down
Loading

0 comments on commit 4b2565b

Please sign in to comment.