Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/aspire/AStar.Dev.Web.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

// Uncomment the following to restrict the allowed schemes for service discovery.
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
// {

Check warning on line 39 in src/aspire/AStar.Dev.Web.ServiceDefaults/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
// options.AllowedSchemes = ["https"];
// });

Expand All @@ -53,24 +53,18 @@
});

_ = builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
_ = metrics.AddAspNetCoreInstrumentation()
.WithMetrics(metrics => _ = metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
_ = tracing.AddSource(builder.Environment.ApplicationName)
.AddRuntimeInstrumentation())
.WithTracing(tracing => _ = tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation(tracing =>
// Exclude health check requests from tracing
tracing.Filter = context => !context.Request.Path.StartsWithSegments(HealthEndpointPath)
&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
)
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});
.AddHttpClientInstrumentation());

_ = builder.AddOpenTelemetryExporters();

Expand All @@ -82,12 +76,12 @@
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (useOtlpExporter)
if(useOtlpExporter)
_ = builder.Services.AddOpenTelemetry().UseOtlpExporter();

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{

Check warning on line 84 in src/aspire/AStar.Dev.Web.ServiceDefaults/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}
Expand All @@ -110,7 +104,7 @@
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
if(app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
_ = app.MapHealthChecks(HealthEndpointPath);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/apis/AStar.Web.ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// Configure the HTTP request pipeline.
app.UseExceptionHandler();

if (app.Environment.IsDevelopment()) _ = app.MapOpenApi();
if(app.Environment.IsDevelopment()) _ = app.MapOpenApi();

string[] summaries =
["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace AStar.Dev.Functional.Extensions;

Expand All @@ -19,14 +15,14 @@ public static class CollectionAndStatusExtensions
public static async Task ApplyToCollectionAsync<T>(this Task<Result<IEnumerable<T>, Exception>> resultTask, ObservableCollection<T> target, Action<Exception>? onError = null)
{
Result<IEnumerable<T>, Exception> result = await resultTask.ConfigureAwait(false);
if (result is Result<IEnumerable<T>, Exception>.Ok ok)
if(result is Result<IEnumerable<T>, Exception>.Ok ok)
{
// Replace items while preserving collection instance
target.Clear();
foreach (T item in ok.Value ?? Enumerable.Empty<T>())
foreach(T item in ok.Value ?? Enumerable.Empty<T>())
target.Add(item);
}
else if (result is Result<IEnumerable<T>, Exception>.Error err)
else if(result is Result<IEnumerable<T>, Exception>.Error err)
{
onError?.Invoke(err.Reason);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Threading.Tasks;

namespace AStar.Dev.Functional.Extensions;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static Result<T, TError> ToResult<T, TError>(this Option<T> option, Func<
public static void Deconstruct<T>(this Option<T> option, out bool isSome, out T? value)
{
isSome = option is Option<T>.Some;
value = isSome ? ((Option<T>.Some)option).Value : default;
value = isSome ? ((Option<T>.Some)option).Value : default;
}

/// <summary>
Expand All @@ -119,8 +119,8 @@ public static async Task<Option<TResult>> MapAsync<T, TResult>(this Option<T> op
=> option switch
{
Option<T>.Some some => new Option<TResult>.Some(await mapAsync(some.Value)),
Option<T>.None => Option.None<TResult>(),
_ => throw new InvalidOperationException(UnreachableMessage)
Option<T>.None => Option.None<TResult>(),
_ => throw new InvalidOperationException(UnreachableMessage)
};

/// <summary>
Expand All @@ -146,8 +146,8 @@ public static async Task<Option<TResult>> BindAsync<T, TResult>(this Option<T> o
=> option switch
{
Option<T>.Some some => await bindAsync(some.Value),
Option<T>.None => Option.None<TResult>(),
_ => throw new InvalidOperationException(UnreachableMessage)
Option<T>.None => Option.None<TResult>(),
_ => throw new InvalidOperationException(UnreachableMessage)
};

/// <summary>
Expand Down Expand Up @@ -195,7 +195,8 @@ public static async Task<Result<T, TError>> ToResultAsync<T, TError>(this Task<O
/// </summary>
public static Option<T> Tap<T>(this Option<T> option, Action<T> action)
{
if(option is Option<T>.Some some) action(some.Value);
if(option is Option<T>.Some some)
action(some.Value);

return option;
}
Expand All @@ -205,7 +206,8 @@ public static Option<T> Tap<T>(this Option<T> option, Action<T> action)
/// </summary>
public static async Task<Option<T>> TapAsync<T>(this Option<T> option, Func<T, Task> actionAsync)
{
if(option is Option<T>.Some some) await actionAsync(some.Value);
if(option is Option<T>.Some some)
await actionAsync(some.Value);

return option;
}
Expand Down Expand Up @@ -239,8 +241,8 @@ public static async Task<TResult> MatchAsync<T, TResult>(this Option<T> option,
=> option switch
{
Option<T>.Some some => await onSomeAsync(some.Value),
Option<T>.None => onNone(),
_ => throw new InvalidOperationException(UnreachableMessage)
Option<T>.None => onNone(),
_ => throw new InvalidOperationException(UnreachableMessage)
};

/// <summary>
Expand All @@ -250,8 +252,8 @@ public static async Task<TResult> MatchAsync<T, TResult>(this Option<T> option,
=> option switch
{
Option<T>.Some some => onSome(some.Value),
Option<T>.None => await onNoneAsync(),
_ => throw new InvalidOperationException(UnreachableMessage)
Option<T>.None => await onNoneAsync(),
_ => throw new InvalidOperationException(UnreachableMessage)
};

/// <summary>
Expand All @@ -261,8 +263,8 @@ public static async Task<TResult> MatchAsync<T, TResult>(this Option<T> option,
=> option switch
{
Option<T>.Some some => await onSomeAsync(some.Value),
Option<T>.None => await onNoneAsync(),
_ => throw new InvalidOperationException(UnreachableMessage)
Option<T>.None => await onNoneAsync(),
_ => throw new InvalidOperationException(UnreachableMessage)
};

/// <summary>
Expand Down Expand Up @@ -320,7 +322,8 @@ public static IEnumerable<TResult> Choose<T, TResult>(this IEnumerable<T> source
{
Option<TResult> option = chooser(item);

if(option is Option<TResult>.Some some) yield return some.Value;
if(option is Option<TResult>.Some some)
yield return some.Value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// </summary>
/// <param name="value">The value to wrap. Null becomes <see cref="None" />.</param>
public static implicit operator Option<T>(T value)
=> value != null

Check warning on line 20 in src/nuget-packages/AStar.Dev.Functional.Extensions/Option{T}.cs

View workflow job for this annotation

GitHub Actions / build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)
? new Some(value)
: None.Instance;

Expand All @@ -28,7 +28,7 @@
/// <param name="onSome">Function to run when the value is present.</param>
/// <param name="onNone">Function to run when the value is absent.</param>
public TResult Match<TResult>(Func<T, TResult> onSome, Func<TResult> onNone)
=> this switch

Check warning on line 31 in src/nuget-packages/AStar.Dev.Functional.Extensions/Option{T}.cs

View workflow job for this annotation

GitHub Actions / build

Offload the code that's conditional on this type test to the appropriate subclass and remove the condition. (https://rules.sonarsource.com/csharp/RSPEC-3060)
{
Some some => onSome(some.Value),
None => onNone(),
Expand All @@ -43,7 +43,7 @@
/// <c>true</c> if the specified object is equal to the current instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object? obj)
=> obj is Option<T> other && this switch

Check warning on line 46 in src/nuget-packages/AStar.Dev.Functional.Extensions/Option{T}.cs

View workflow job for this annotation

GitHub Actions / build

Offload the code that's conditional on this type test to the appropriate subclass and remove the condition. (https://rules.sonarsource.com/csharp/RSPEC-3060)
{
Some some => other is Some otherSome && EqualityComparer<T>.Default.Equals(some.Value, otherSome.Value),
None => other is None,
Expand All @@ -59,7 +59,7 @@
/// An integer representing the hash code of the current instance.
/// </returns>
public override int GetHashCode()
=> this switch

Check warning on line 62 in src/nuget-packages/AStar.Dev.Functional.Extensions/Option{T}.cs

View workflow job for this annotation

GitHub Actions / build

Offload the code that's conditional on this type test to the appropriate subclass and remove the condition. (https://rules.sonarsource.com/csharp/RSPEC-3060)
{
Some some => HashCode.Combine(typeof(Some), some.Value),
None => typeof(None).GetHashCode(),
Expand All @@ -74,7 +74,7 @@
/// <returns>
/// True if the two <see cref="Option{T}" /> instances are considered equal; otherwise, false.
/// </returns>
public static bool operator ==(Option<T> left, Option<T> right) => left.Equals(right);

Check warning on line 77 in src/nuget-packages/AStar.Dev.Functional.Extensions/Option{T}.cs

View workflow job for this annotation

GitHub Actions / build

Remove this overload of 'operator =='. (https://rules.sonarsource.com/csharp/RSPEC-3875)

/// <summary>
/// Determines whether two <see cref="Option{T}" /> instances are not equal at a value level.
Expand All @@ -98,7 +98,8 @@
/// <exception cref="ArgumentNullException" />
public Some(T value)
{
if(value is null) throw new ArgumentNullException(nameof(value));
if(value is null)
throw new ArgumentNullException(nameof(value));

Value = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ public static async Task<Result<TNew, TError>> BindAsync<TSuccess, TError, TNew>
/// </returns>
public static Result<TSuccess, TError> Tap<TSuccess, TError>(this Result<TSuccess, TError> result, Action<TSuccess> action)
{
if(result is Result<TSuccess, TError>.Ok ok) action(ok.Value);
if(result is Result<TSuccess, TError>.Ok ok)
action(ok.Value);

return result;
}
Expand All @@ -282,7 +283,8 @@ public static Result<TSuccess, TError> Tap<TSuccess, TError>(this Result<TSucces
/// </returns>
public static Result<TSuccess, TError> TapError<TSuccess, TError>(this Result<TSuccess, TError> result, Action<TError> action)
{
if(result is Result<TSuccess, TError>.Error err) action(err.Reason);
if(result is Result<TSuccess, TError>.Error err)
action(err.Reason);

return result;
}
Expand All @@ -300,7 +302,8 @@ public static Result<TSuccess, TError> TapError<TSuccess, TError>(this Result<TS
/// </returns>
public static async Task<Result<TSuccess, TError>> TapAsync<TSuccess, TError>(this Result<TSuccess, TError> result, Func<TSuccess, Task> actionAsync)
{
if(result is Result<TSuccess, TError>.Ok ok) await actionAsync(ok.Value);
if(result is Result<TSuccess, TError>.Ok ok)
await actionAsync(ok.Value);

return result;
}
Expand Down Expand Up @@ -354,7 +357,8 @@ public static async Task<Result<TSuccess, TError>> TapAsync<TSuccess, TError>(th
/// </returns>
public static async Task<Result<TSuccess, TError>> TapErrorAsync<TSuccess, TError>(this Result<TSuccess, TError> result, Func<TError, Task> actionAsync)
{
if(result is Result<TSuccess, TError>.Error err) await actionAsync(err.Reason);
if(result is Result<TSuccess, TError>.Error err)
await actionAsync(err.Reason);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Threading.Tasks;

namespace AStar.Dev.Functional.Extensions;

/// <summary>
Expand All @@ -13,13 +10,13 @@ public static class ViewModelResultExtensions
/// </summary>
public static void Apply<T>(this Result<T, Exception> result, Action<T> onSuccess, Action<Exception>? onError = null)
{
if (result is Result<T, Exception>.Ok ok)
if(result is Result<T, Exception>.Ok ok)
{
onSuccess(ok.Value);
return;
}

if (result is Result<T, Exception>.Error err)
if(result is Result<T, Exception>.Error err)
{
onError?.Invoke(err.Reason);
}
Expand All @@ -40,13 +37,13 @@ public static async Task ApplyAsync<T>(this Task<Result<T, Exception>> resultTas
public static async Task ApplyAsync<T>(this Task<Result<T, Exception>> resultTask, Func<T, Task> onSuccessAsync, Func<Exception, Task>? onErrorAsync = null)
{
Result<T, Exception> result = await resultTask.ConfigureAwait(false);
if (result is Result<T, Exception>.Ok ok)
if(result is Result<T, Exception>.Ok ok)
{
await onSuccessAsync(ok.Value).ConfigureAwait(false);
return;
}

if (result is Result<T, Exception>.Error err && onErrorAsync is not null)
if(result is Result<T, Exception>.Error err && onErrorAsync is not null)
{
await onErrorAsync(err.Reason).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace AStar.Dev.OneDrive.Client.Services;
Expand Down
Loading