Skip to content

Commit

Permalink
style: use file scoped namespaces, enable implicit usings and use spa…
Browse files Browse the repository at this point in the history
…ces instead of tabs
  • Loading branch information
skwasjer committed Jul 10, 2022
1 parent 31eaaa8 commit ceb83a4
Show file tree
Hide file tree
Showing 63 changed files with 3,502 additions and 3,624 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ insert_final_newline = true
[*.{cs,csproj,tt}]
charset = utf-8-bom
end_of_line = crlf
indent_style = tab
indent_style = space

[*.{csproj,props,targets}]
indent_size = 2
Expand Down
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project>

<PropertyGroup>
<LangVersion>latest</LangVersion>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -13,6 +15,6 @@
<!-- System.Diagnostics.DiagnosticSource -->
<PackageVersion_DiagnosticSource>6.0.0</PackageVersion_DiagnosticSource>
<PackageVersion_DiagnosticSource Condition="'$(TargetFramework)'!='net6.0'">4.7.0</PackageVersion_DiagnosticSource>

</PropertyGroup>

</Project>
21 changes: 10 additions & 11 deletions src/Correlate.Abstractions/CorrelationContext.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace Correlate
namespace Correlate;

/// <summary>
/// Represents the correlation context.
/// </summary>
public class CorrelationContext
{
/// <summary>
/// Represents the correlation context.
/// </summary>
public class CorrelationContext
{
/// <summary>
/// Gets or sets the correlation id.
/// </summary>
public string? CorrelationId { get; set; }
}
/// <summary>
/// Gets or sets the correlation id.
/// </summary>
public string? CorrelationId { get; set; }
}
105 changes: 50 additions & 55 deletions src/Correlate.Abstractions/ExceptionContext.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Correlate
namespace Correlate;

/// <summary>
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled.
/// </summary>
public class ExceptionContext
{
/// <summary>
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled.
/// </summary>
public class ExceptionContext
{
internal ExceptionContext(CorrelationContext correlationContext, Exception exception)
{
CorrelationContext = correlationContext;
Exception = exception;
}
internal ExceptionContext(CorrelationContext correlationContext, Exception exception)
{
CorrelationContext = correlationContext;
Exception = exception;
}

/// <summary>
/// Gets the correlation context
/// </summary>
public CorrelationContext CorrelationContext { get; }
/// <summary>
/// Gets the correlation context
/// </summary>
public CorrelationContext CorrelationContext { get; }

/// <summary>
/// Gets the exception that occurred.
/// </summary>
public Exception Exception { get; }
/// <summary>
/// Gets the exception that occurred.
/// </summary>
public Exception Exception { get; }

/// <summary>
/// Gets or sets whether the exception is considered handled.
/// </summary>
public bool IsExceptionHandled { get; set; }
}
/// <summary>
/// Gets or sets whether the exception is considered handled.
/// </summary>
public bool IsExceptionHandled { get; set; }
}

/// <summary>
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled and provide a return value.
/// </summary>
public class ExceptionContext<T> : ExceptionContext
{
// ReSharper disable once RedundantDefaultMemberInitializer
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private T _result = default!;
/// <summary>
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled and provide a return value.
/// </summary>
public class ExceptionContext<T> : ExceptionContext
{
// ReSharper disable once RedundantDefaultMemberInitializer
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private T _result = default!;

internal ExceptionContext(CorrelationContext correlationContext, Exception exception)
: base(correlationContext, exception)
{
}
internal ExceptionContext(CorrelationContext correlationContext, Exception exception)
: base(correlationContext, exception)
{
}

/// <summary>
/// Gets or sets the result value to return.
/// </summary>
[AllowNull]
public T Result
{
get
{
return _result;
}
set
{
IsExceptionHandled = true;
_result = value!;
}
}
}
/// <summary>
/// Gets or sets the result value to return.
/// </summary>
[AllowNull]
public T Result
{
get => _result;
set
{
IsExceptionHandled = true;
_result = value!;
}
}
}
33 changes: 16 additions & 17 deletions src/Correlate.Abstractions/IActivity.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
namespace Correlate
namespace Correlate;

/// <summary>
/// Describes an activity that can be started and stopped as desired to signal start/stop of a correlation context.
/// </summary>
public interface IActivity
{
/// <summary>
/// Describes an activity that can be started and stopped as desired to signal start/stop of a correlation context.
/// </summary>
public interface IActivity
{
/// <summary>
/// Signals the start of an the activity
/// </summary>
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param>
/// <returns>The created correlation context (also accessible via <see cref="ICorrelationContextAccessor"/>), or null if diagnostics and logging is disabled.</returns>
CorrelationContext Start(string correlationId);
/// <summary>
/// Signals the start of an the activity
/// </summary>
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param>
/// <returns>The created correlation context (also accessible via <see cref="ICorrelationContextAccessor" />), or null if diagnostics and logging is disabled.</returns>
CorrelationContext Start(string correlationId);

/// <summary>
/// Signals the activity is complete.
/// </summary>
void Stop();
}
/// <summary>
/// Signals the activity is complete.
/// </summary>
void Stop();
}
25 changes: 12 additions & 13 deletions src/Correlate.Abstractions/IActivityFactory.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Correlate
namespace Correlate;

/// <summary>
/// Represents a factory that creates new activities, used to start a new correlation context.
/// </summary>
public interface IActivityFactory
{
/// <summary>
/// Represents a factory that creates new activities, used to start a new correlation context.
/// </summary>
public interface IActivityFactory
{
/// <summary>
/// Creates a new activity that can be started and stopped manually.
/// </summary>
/// <returns>The correlated activity.</returns>
IActivity CreateActivity();
}
}
/// <summary>
/// Creates a new activity that can be started and stopped manually.
/// </summary>
/// <returns>The correlated activity.</returns>
IActivity CreateActivity();
}
60 changes: 28 additions & 32 deletions src/Correlate.Abstractions/IAsyncCorrelationManager.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
using System;
using System.Threading.Tasks;
namespace Correlate;

namespace Correlate
/// <summary>
/// Describes methods for starting a correlation context asynchronously.
/// </summary>
public interface IAsyncCorrelationManager
{
/// <summary>
/// Describes methods for starting a correlation context asynchronously.
/// </summary>
public interface IAsyncCorrelationManager
{
/// <summary>
/// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>.
/// </summary>
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param>
/// <param name="correlatedTask">The task to execute.</param>
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param>
/// <returns>An awaitable that completes once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns>
/// <remarks>
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would.
/// </remarks>
Task CorrelateAsync(string? correlationId, Func<Task> correlatedTask, OnException? onException);
/// <summary>
/// Executes the <paramref name="correlatedTask" /> with its own <see cref="CorrelationContext" />.
/// </summary>
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param>
/// <param name="correlatedTask">The task to execute.</param>
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param>
/// <returns>An awaitable that completes once the <paramref name="correlatedTask" /> has executed and the correlation context has disposed.</returns>
/// <remarks>
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would.
/// </remarks>
Task CorrelateAsync(string? correlationId, Func<Task> correlatedTask, OnException? onException);

/// <summary>
/// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>.
/// </summary>
/// <typeparam name="T">The return type of the awaitable task.</typeparam>
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param>
/// <param name="correlatedTask">The task to execute.</param>
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param>
/// <returns>An awaitable that completes with a result <typeparamref name="T"/> once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns>
/// <remarks>
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would.
/// </remarks>
Task<T> CorrelateAsync<T>(string? correlationId, Func<Task<T>> correlatedTask, OnException<T>? onException);
}
/// <summary>
/// Executes the <paramref name="correlatedTask" /> with its own <see cref="CorrelationContext" />.
/// </summary>
/// <typeparam name="T">The return type of the awaitable task.</typeparam>
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param>
/// <param name="correlatedTask">The task to execute.</param>
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param>
/// <returns>An awaitable that completes with a result <typeparamref name="T" /> once the <paramref name="correlatedTask" /> has executed and the correlation context has disposed.</returns>
/// <remarks>
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would.
/// </remarks>
Task<T> CorrelateAsync<T>(string? correlationId, Func<Task<T>> correlatedTask, OnException<T>? onException);
}
21 changes: 10 additions & 11 deletions src/Correlate.Abstractions/ICorrelationContextAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace Correlate
namespace Correlate;

/// <summary>
/// Provides access to the <see cref="CorrelationContext" />.
/// </summary>
public interface ICorrelationContextAccessor
{
/// <summary>
/// Provides access to the <see cref="CorrelationContext"/>.
/// </summary>
public interface ICorrelationContextAccessor
{
/// <summary>
/// Gets or sets <see cref="CorrelationContext"/>.
/// </summary>
CorrelationContext? CorrelationContext { get; set; }
}
/// <summary>
/// Gets or sets <see cref="CorrelationContext" />.
/// </summary>
CorrelationContext? CorrelationContext { get; set; }
}
33 changes: 16 additions & 17 deletions src/Correlate.Abstractions/ICorrelationContextFactory.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
namespace Correlate
namespace Correlate;

/// <summary>
/// Describes how to create/clean up a <see cref="CorrelationContext" />.
/// </summary>
public interface ICorrelationContextFactory
{
/// <summary>
/// Describes how to create/clean up a <see cref="CorrelationContext"/>.
/// </summary>
public interface ICorrelationContextFactory
{
/// <summary>
/// Creates a new <see cref="CorrelationContext"/>.
/// </summary>
/// <param name="correlationId">The correlation id to associate to the context.</param>
/// <returns>The <see cref="CorrelationContext"/> containing the correlation id.</returns>
CorrelationContext Create(string correlationId);
/// <summary>
/// Creates a new <see cref="CorrelationContext" />.
/// </summary>
/// <param name="correlationId">The correlation id to associate to the context.</param>
/// <returns>The <see cref="CorrelationContext" /> containing the correlation id.</returns>
CorrelationContext Create(string correlationId);

/// <summary>
/// Disposes the <see cref="CorrelationContext"/>.
/// </summary>
void Dispose();
}
/// <summary>
/// Disposes the <see cref="CorrelationContext" />.
/// </summary>
void Dispose();
}
23 changes: 11 additions & 12 deletions src/Correlate.Abstractions/ICorrelationIdFactory.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Correlate
namespace Correlate;

/// <summary>
/// Describes a way of generating new correlation ids.
/// </summary>
public interface ICorrelationIdFactory
{
/// <summary>
/// Describes a way of generating new correlation ids.
/// </summary>
public interface ICorrelationIdFactory
{
/// <summary>
/// Creates a new correlation id.
/// </summary>
/// <returns>The new correlation id.</returns>
string Create();
}
/// <summary>
/// Creates a new correlation id.
/// </summary>
/// <returns>The new correlation id.</returns>
string Create();
}
Loading

0 comments on commit ceb83a4

Please sign in to comment.