Example #1
0
 public Task Handle(AddItem message, IMessageHandlerContext context)
 {
     return(sagaManager.Process <OrderSagaData>(message.CorrelationId, context, x =>
     {
         x.Items.Add(message.Item);
         return Task.FromResult(x);
     }));
 }
    async Task ProcessMessage(ISagaManager managerA, TestController testController)
    {
        var completed = false;

        while (!completed)
        {
            try
            {
                await managerA.Process <SagaData>(MessageId, SagaId, new ContextBag(), HandlerCallback);

                completed = true;
                testController.Complete();
            }
            catch (ScenarioIncompleteException e)
            {
                Console.WriteLine("Scenario incomplete");
                break;
            }
            catch (ConcurrencyException e)
            {
                //Swallow and retry
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
Example #3
0
        public Order CreateOrder(string name, Guid carId, Guid hotelId)
        {
            var order = new Order(name);

            order.Finalize(carId, hotelId);
            var orderProxy =
                _sagaManager.Process(new BookingTripState(order.CarId, order.HotelId), new EmptySagaState());

            order.AddState(orderProxy);
            _databaseAdapter.Save(order);
            return(order);
        }
Example #4
0
    public static Task Process <T>(this ISagaManager sagaManager, string correlationId,
                                   IMessageHandlerContext context, Func <T, Task <T> > handlerCallback)
        where T : class, new()
    {
        return(sagaManager.Process(context.MessageId, correlationId, context.Extensions, (Func <T, ContextBag, Task <(T, PendingTransportOperations)> >)(async(sagaData, bag) =>
        {
            var pendingTransportOperations = new PendingTransportOperations();
            bag.Set(pendingTransportOperations); //override the one set by the outbox

            var newSagaData = await handlerCallback(sagaData).ConfigureAwait(false);

            bag.Remove <PendingTransportOperations>(); //Restore old value
            return (newSagaData, pendingTransportOperations);
        })));
    }
 async Task ProcessingLoop()
 {
     while (true)
     {
         try
         {
             await manager.Process <SagaData>(messageId, sagaId, new ContextBag(), HandlerCallback);
         }
         catch (ScenarioIncompleteException e)
         {
             Console.WriteLine("Scenario incomplete");
             break;
         }
         catch (ConcurrencyException e)
         {
             //Swallow and retry
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
     }
 }