public SagaMessageExecutionResult Run(object message, ISagaState state)
 {
     return (SagaMessageExecutionResult) realHandler.GetType().GetMethod("Run", new[]
         {
             message.GetType(),
             state.GetType()
         }).Invoke(realHandler, new[]
             {
                 message,
                 state
             });
 }
 public ISagaState Apply(object message, ISagaState state)
 {
     return (ISagaState) realHandler.GetType().GetMethod("Apply", new[]
         {
             message.GetType(),
             state.GetType()
         }).Invoke(realHandler, new[]
             {
                 message,
                 state
             });
 }
Ejemplo n.º 3
0
        private static void Update(DbConnection db, ISagaState data, string correlationId)
        {
            var old = data.AutoTimestamp;
            var result=db.Update<SagaRow>()
                .Set(d => d.Data, data.Serialize().ToByteArray())
                .Set(d => d.Version,data.AutoTimestamp)
                .Set(d => d.LastChangedOn, DateTime.UtcNow)
                .Set(d => d.IsCompleted, data.IsCompleted)
                .Where(d => d.SagaId == SagaRow.GetId(correlationId, data.GetType()) && d.Version == old)
                .Execute();
            if (result!=1) throw new SagaConcurrencyException();

        }
Ejemplo n.º 4
0
        private static void Update(DbConnection db, ISagaState data, string correlationId)
        {
            var old    = data.AutoTimestamp;
            var result = db.Update <SagaRow>()
                         .Set(d => d.Data, data.Serialize().ToByteArray())
                         .Set(d => d.Version, data.AutoTimestamp)
                         .Set(d => d.LastChangedOn, DateTime.UtcNow)
                         .Set(d => d.IsCompleted, data.IsCompleted)
                         .Where(d => d.SagaId == SagaRow.GetId(correlationId, data.GetType()) && d.Version == old)
                         .Execute();

            if (result != 1)
            {
                throw new SagaConcurrencyException();
            }
        }
Ejemplo n.º 5
0
 private static void Insert(DbConnection db, ISagaState data, string correlationId)
 {
     try
     {
         db.Insert(new SagaRow()
         {
             SagaId = SagaRow.GetId(correlationId, data.GetType()),
             Data = data.Serialize().ToByteArray(),
             IsCompleted = false,
             LastChangedOn = DateTime.UtcNow,
             Version = data.AutoTimestamp
         });
     }
     catch (DbException ex)
     {
         if (db.IsUniqueViolation(ex)) throw new SagaExistsException();
      
     }
 }
Ejemplo n.º 6
0
 private static void Insert(DbConnection db, ISagaState data, string correlationId)
 {
     try
     {
         db.Insert(new SagaRow()
         {
             SagaId        = SagaRow.GetId(correlationId, data.GetType()),
             Data          = data.Serialize().ToByteArray(),
             IsCompleted   = false,
             LastChangedOn = DateTime.UtcNow,
             Version       = data.AutoTimestamp
         });
     }
     catch (DbException ex)
     {
         if (db.IsUniqueViolation(ex))
         {
             throw new SagaExistsException();
         }
     }
 }