-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set nodes stateless, future version exist both versions stateless & stateful * Add some classes helper, tostring, equals... * Add Saga Pattern example
- Loading branch information
Showing
40 changed files
with
856 additions
and
64 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
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
namespace Magnett.Automation.Core.WorkFlows | ||
using Magnett.Automation.Core.Contexts; | ||
|
||
namespace Magnett.Automation.Core.WorkFlows | ||
{ | ||
public interface INode : INodeBase | ||
{ | ||
public NodeExit Execute(); | ||
public NodeExit Execute(Context context); | ||
} | ||
} |
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,9 +1,10 @@ | ||
using System.Threading.Tasks; | ||
using Magnett.Automation.Core.Contexts; | ||
|
||
namespace Magnett.Automation.Core.WorkFlows | ||
{ | ||
public interface INodeAsync : INodeBase | ||
{ | ||
Task<NodeExit> Execute(); | ||
Task<NodeExit> Execute(Context context); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...gnett.Automation.Core.IntegrationTest/WorkFlows/SagaPattern/Definitions/Entities/Order.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,26 @@ | ||
using System; | ||
using Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.States; | ||
|
||
namespace Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.Entities; | ||
|
||
public class Order | ||
{ | ||
public OrderState State { get; } | ||
public Guid Id { get; } | ||
public double Amount { get; } | ||
public string Description { get; } | ||
|
||
private Order(double amount, string description) | ||
{ | ||
Id = Guid.NewGuid(); | ||
Amount = amount; | ||
Description = description; | ||
|
||
State = OrderState.Create(); | ||
} | ||
|
||
public static Order Create(double amount, string description) | ||
{ | ||
return new Order(amount, description); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ett.Automation.Core.IntegrationTest/WorkFlows/SagaPattern/Definitions/Entities/Payment.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,25 @@ | ||
using System; | ||
using Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.States; | ||
using Magnett.Automation.Core.StateMachines; | ||
|
||
namespace Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.Entities; | ||
|
||
public class Payment | ||
{ | ||
public Guid Id { get; } | ||
public double Amount { get; } | ||
public PaymentState State { get; } | ||
|
||
private Payment(double amount) | ||
{ | ||
Id = Guid.NewGuid(); | ||
Amount = amount; | ||
|
||
State = PaymentState.Create(); | ||
} | ||
|
||
public static Payment Create(double amount) | ||
{ | ||
return new Payment(amount); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/Magnett.Automation.Core.IntegrationTest/WorkFlows/SagaPattern/Definitions/NodeName.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,20 @@ | ||
using Magnett.Automation.Core.Commons; | ||
|
||
namespace Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions | ||
{ | ||
internal class NodeName : CommonNamedKey | ||
{ | ||
public static readonly NodeName CreateOrder = new NodeName(nameof(CreateOrder)); | ||
public static readonly NodeName ConfirmOrder = new NodeName(nameof(ConfirmOrder)); | ||
public static readonly NodeName CancelOrder = new NodeName(nameof(CancelOrder)); | ||
|
||
public static readonly NodeName PreAuthorizePayment = new NodeName(nameof(PreAuthorizePayment)); | ||
public static readonly NodeName ConfirmPayment = new NodeName(nameof(ConfirmPayment)); | ||
public static readonly NodeName CancelPayment = new NodeName(nameof(CancelPayment)); | ||
|
||
private NodeName(string name) : base(name) | ||
{ | ||
|
||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...tt.Automation.Core.IntegrationTest/WorkFlows/SagaPattern/Definitions/Nodes/CancelOrder.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,53 @@ | ||
using System.Threading.Tasks; | ||
using Magnett.Automation.Core.Commons; | ||
using Magnett.Automation.Core.Contexts; | ||
using Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.Entities; | ||
using Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.States; | ||
using Magnett.Automation.Core.WorkFlows; | ||
using Magnett.Automation.Core.WorkFlows.Implementations; | ||
|
||
namespace Magnett.Automation.Core.IntegrationTest.WorkFlows.SagaPattern.Definitions.Nodes; | ||
|
||
/// <summary> | ||
/// Rollback Order operation and cancel process | ||
/// </summary> | ||
public class CancelOrder : NodeAsync | ||
{ | ||
private CancelOrder(string name) : base(name) | ||
{ | ||
} | ||
|
||
private readonly ContextField<Order> _orderField = ContextField<Order>.Create("Order"); | ||
|
||
#region ExitCodes | ||
|
||
public class ExitCode : Enumeration | ||
{ | ||
public static readonly ExitCode Done = new ExitCode(1, nameof(Done)); | ||
|
||
private ExitCode(int id, string name) : base(id, name) | ||
{ | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
public override async Task<NodeExit> Execute(Context context) | ||
{ | ||
var order = context.Value(_orderField); | ||
|
||
order.State.Dispatch(OrderStateDefinition.Action.Cancel); | ||
|
||
await Task.Delay(1000); | ||
|
||
return NodeExit.Create( | ||
ExitCode.Done, | ||
true, | ||
$"Order cancelled id [{order.Id}] [{order.State}]"); | ||
} | ||
|
||
public static CancelOrder Create(CommonNamedKey nodeName) | ||
{ | ||
return new CancelOrder(nodeName?.Name); | ||
} | ||
} |
Oops, something went wrong.