-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process manager - add effect extensions (#36)
process manager - add effect extensions
- Loading branch information
Showing
29 changed files
with
334 additions
and
392 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
32 changes: 32 additions & 0 deletions
32
samples/Orchestration/ProcessManagerSample/Queries/GetClientQuery.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,32 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using NBB.Application.DataContracts; | ||
|
||
namespace ProcessManagerSample.Queries | ||
{ | ||
public class GetClientQuery : Query<Client> | ||
{ | ||
|
||
} | ||
|
||
public class GetClientQueryHandler : IRequestHandler<GetClientQuery, Client> | ||
{ | ||
public async Task<Client> Handle(GetClientQuery request, CancellationToken cancellationToken) | ||
{ | ||
return new Client("ion","vasile"); | ||
} | ||
} | ||
|
||
public class Client | ||
{ | ||
public Client(string clientName, string clientCode) | ||
{ | ||
ClientName = clientName; | ||
ClientCode = clientCode; | ||
} | ||
|
||
public string ClientName { get; set; } | ||
public string ClientCode { 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 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
22 changes: 0 additions & 22 deletions
22
src/Orchestration/NBB.ProcessManager.Definition/Effects/BoundedEffect.cs
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/Orchestration/NBB.ProcessManager.Definition/Effects/CancelTimeoutsEffect.cs
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/Orchestration/NBB.ProcessManager.Definition/Effects/Effect.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,18 @@ | ||
using MediatR; | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBB.ProcessManager.Definition.Effects | ||
{ | ||
public class Effect<TResult> : IEffect<TResult> | ||
{ | ||
public Func<IEffectRunner, Task<TResult>> Computation { get; } | ||
|
||
public Effect(Func<IEffectRunner, Task<TResult>> computation) | ||
{ | ||
Computation = computation; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Orchestration/NBB.ProcessManager.Definition/Effects/EffectExtensions.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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace NBB.ProcessManager.Definition.Effects | ||
{ | ||
public static class EffectExtensions | ||
{ | ||
public static IEffect<TEffectResult2> ContinueWith<TEffectResult1, TEffectResult2>(this IEffect<TEffectResult1> effect, | ||
Func<TEffectResult1, IEffect<TEffectResult2>> continuation) | ||
{ | ||
return new Effect<TEffectResult2>(async runner => | ||
{ | ||
var r1 = await effect.Computation(runner); | ||
return await continuation(r1).Computation(runner); | ||
}); | ||
} | ||
|
||
public static IEffect<TResult> Select<T, TResult>(this IEffect<T> effect, Func<T, TResult> selector) | ||
{ | ||
return new Effect<TResult>(async runner => | ||
{ | ||
var r1 = await effect.Computation(runner); | ||
return selector(r1); | ||
}); | ||
} | ||
|
||
public static IEffect<TResult> SelectMany<TSource1, TSource2, TResult>(this IEffect<TSource1> sourceEffect, | ||
Func<TSource1, IEffect<TSource2>> monadicFn, | ||
Func<TSource1, TSource2, TResult> resultSelector) | ||
{ | ||
return sourceEffect.ContinueWith(source => monadicFn(source).Select(x => resultSelector(source, x))); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Orchestration/NBB.ProcessManager.Definition/Effects/EffectFuncs.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,28 @@ | ||
using MediatR; | ||
using System; | ||
|
||
namespace NBB.ProcessManager.Definition.Effects | ||
{ | ||
|
||
public static class EffectFuncs | ||
{ | ||
public static EffectFunc<TEvent, TData> Aggregate<TEvent, TData>(EffectFunc<TEvent, TData> func1, EffectFunc<TEvent, TData> func2, | ||
Func<IEffect<Unit>, IEffect<Unit>, IEffect<Unit>> accumulator) | ||
where TData : struct | ||
{ | ||
return (@event, data) => | ||
{ | ||
var ef1 = func1(@event, data); | ||
var ef2 = func2(@event, data); | ||
return accumulator(ef1, ef2); | ||
}; | ||
} | ||
|
||
public static EffectFunc<TEvent, TData> Sequential<TEvent, TData>(EffectFunc<TEvent, TData> func1, EffectFunc<TEvent, TData> func2) | ||
where TData : struct | ||
{ | ||
return Aggregate(func1, func2, (effect1, effect2) => Effect.Sequential(effect1, effect2)); | ||
} | ||
} | ||
} |
Oops, something went wrong.