-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
133 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Shiny.Mediator.AppSupport/AppSupportRequestContextExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Shiny.Mediator; | ||
|
||
|
||
public static class AppSupportRequestContextExtensions | ||
{ | ||
public static Exception? UserErrorNotificationException(this IRequestContext context) | ||
{ | ||
if (context.Values.TryGetValue(nameof(UserErrorNotificationException), out var exception)) | ||
return (Exception)exception; | ||
|
||
return null; | ||
} | ||
|
||
public static (string Title, string Message)? UserErrorNotificationAlert(this IRequestContext context) | ||
{ | ||
if (context.Values.TryGetValue(nameof(UserErrorNotificationAlert), out var exception)) | ||
return ((string Title, string Message))exception; | ||
|
||
return null; | ||
} | ||
|
||
internal static void SetUserErrorNotificationException(this IRequestContext context, Exception exception) | ||
=> context.Add(nameof(UserErrorNotificationException), exception); | ||
|
||
internal static void SetUserErrorNotificationAlert(this IRequestContext context, (string Title, string Message) alert) | ||
=> context.Add(nameof(UserErrorNotificationAlert), alert); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Shiny.Mediator; | ||
|
||
public interface IRequestContext | ||
{ | ||
Guid ExecutionId { get; } | ||
IReadOnlyDictionary<string, object> Values { get; } | ||
void Add(string key, object value); | ||
|
||
IRequestHandler RequestHandler { get; } | ||
} | ||
|
||
// TODO: RequestStreamContext OR reuse IRequestContext? | ||
// public class EventContext | ||
// { | ||
// // TODO: event types that were fired | ||
// // TODO: what about middleware that fired per event? | ||
// public Guid ExecutionId { get; } = Guid.NewGuid(); | ||
// public IReadOnlyDictionary<string, object> Store => this.store; | ||
// | ||
// readonly Dictionary<string, object> store = new(); | ||
// public void Add(string key, object value) | ||
// => this.store.Add(key, value); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using Shiny.Mediator; | ||
|
||
|
||
public delegate Task<TResult> RequestHandlerDelegate<TResult>(); | ||
public interface IRequestMiddleware<TRequest, TResult> | ||
{ | ||
Task<TResult> Process( | ||
TRequest request, | ||
RequestHandlerDelegate<TResult> next, | ||
IRequestHandler requestHandler, | ||
IRequestHandler requestHandler, | ||
IRequestContext context, | ||
CancellationToken cancellationToken | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Shiny.Mediator.Impl; | ||
|
||
public class RequestContext(IRequestHandler handler) : IRequestContext | ||
{ | ||
readonly Dictionary<string, object> store = new(); | ||
|
||
public Guid ExecutionId { get; }= Guid.NewGuid(); | ||
public IReadOnlyDictionary<string, object> Values => this.store.ToDictionary(); | ||
public void Add(string key, object value) => this.store.Add(key, value); | ||
|
||
public IRequestHandler RequestHandler => handler; | ||
// public object Request { get; } | ||
// public object? ReturnValue { get; set; } | ||
|
||
// public TResult? Result { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Shiny.Mediator; | ||
|
||
public static class RequestContextExtensions | ||
{ | ||
public static T? TryGetValue<T>(this IRequestContext context, string key) | ||
{ | ||
if (context.Values.TryGetValue(key, out var value) && value is T t) | ||
return t; | ||
|
||
return default; | ||
} | ||
|
||
|
||
public static TimeSpan? PerformanceLoggingThresholdBreached(this IRequestContext context) | ||
=> context.TryGetValue<TimeSpan>("PerformanceLogging.Breach"); | ||
|
||
internal static void SetPerformanceLoggingThresholdBreached(this IRequestContext context, TimeSpan elapsed) | ||
=> context.Add("PerformanceLogging.Breach", elapsed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters