Beispiel #1
0
        public async Task <List <Operation> > ProcessAsync(List <Operation> inputOps)
        {
            var           outputOps = new List <Operation>();
            var           opIndex   = 0;
            OperationCode?lastAttemptedOperation = null;  // used for error messages only

            using (var transaction = await _dbContext.Database.BeginTransactionAsync())
            {
                try
                {
                    foreach (var op in inputOps)
                    {
                        _jsonApiContext.BeginOperation();
                        lastAttemptedOperation = op.Op;
                        await ProcessOperation(op, outputOps);

                        opIndex++;
                    }

                    transaction.Commit();
                    return(outputOps);
                }
                catch (JsonApiException e)
                {
                    transaction.Rollback();
                    throw new JsonApiException(e.GetStatusCode(), $"Transaction failed on operation[{opIndex}] ({lastAttemptedOperation}).", e);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new JsonApiException(500, $"Transaction failed on operation[{opIndex}] ({lastAttemptedOperation}) for an unexpected reason.", e);
                }
            }
        }
Beispiel #2
0
 public async Task Invoke(HttpContext context, IJsonApiContext jsonApiContext)
 {
     if (IsValid(context))
     {
         // HACK: this currently results in allocation of
         // objects that may or may not be used and even double allocation
         // since the JsonApiContext is using field initializers
         // Need to work on finding a better solution.
         jsonApiContext.BeginOperation();
         await _next(context);
     }
 }
Beispiel #3
0
 public void ApplyFakeContext <T>(Controller controller) where T : class, IIdentifiable
 {
     _jsonApiContext.BeginOperation();
     _jsonApiContext.ApplyContext <T>(controller);
 }