Ejemplo n.º 1
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var sagaWithCompenstate = new SagaBuilder <TestContext>()
                                      .With_Context_State(context)
                                      .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Add_Numbers(ctx);
                ctx.AddError("error adding two numbers");
            }))
                                      .With_Error_Behavior(Domain.Saga.ErrorBehavior.Terminate) // could be Terminate so saga halts at this step
                                      .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Add_Numbers(ctx);
            }))
                                      .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                           (err) =>
            {
                presenter.Respond(err);
            });

            sagaWithCompenstate.Run();
        }
Ejemplo n.º 2
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var sagaWithoutCompenstate = new SagaBuilder <TestContext>()
                                         .With_Context_State(context)
                                         .Using_Step(_addTask)
                                         .Using_Step(_errorTask)
                                         .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                              (err) =>
            {
                presenter.Respond(err);
            });

            var sagaWithCompenstate = new SagaBuilder <TestContext>()
                                      .With_Context_State(context)
                                      .Using_Step(_addTask)
                                      .With_Error_Behavior(Domain.Saga.ErrorBehavior.Continue) // could be Terminate so saga halts at this step
                                      .Using_Step(_errorTask)
                                      .With_Roll_Back_Action_On_Error((ctx) =>
            {
                ctx.Result -= 10;
            })
                                      .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                           (err) =>
            {
                presenter.Respond(err);
            });

            sagaWithCompenstate.Run();
            //sagaWithoutCompenstate.Run();
        }
Ejemplo n.º 3
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            // using inline actions
            var sagaWithActions = new SagaBuilder <TestContext>()
                                  .With_Context_State(context)
                                  .Using_Step((ctx) =>
            {
                ctx.Result = ctx.Value1 + ctx.Value2;
            })
                                  .Using_Step((ctx) =>
            {
                ctx.Result += 10;
            })
                                  .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            // using local methods to wrap actions
            var sagaWithActionWrappingMethods = new SagaBuilder <TestContext>()
                                                .With_Context_State(context)
                                                .Using_Step((ctx) =>
            {
                AddTwoNumbers(ctx);
            })
                                                .Using_Step((ctx) =>
            {
                AddTen(ctx);
            })
                                                .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            // using inline async actions
            var sagaWithAsyncActions = new SagaBuilder <TestContext>()
                                       .With_Context_State(context)
                                       .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Task.FromResult(ctx.Result = ctx.Value1 + ctx.Value2);
            }))
                                       .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Task.FromResult(ctx.Result += 10);
            }))
                                       .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            // using Steps
            var sagaWithSteps = new SagaBuilder <TestContext>()
                                .With_Context_State(context)
                                .Using_Step(_addTask)
                                .Using_Step(_plusTenTask)
                                .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            });

            sagaWithActions.Run();
            //sagaWithActionWrappingMethods.Run();
            //sagaWithAsyncActions.Run();
            //sagaWithSteps.Run();
        }