public LoadedSagaRepositoryQueryContext(SagaRepositoryContext <TSaga, TMessage> repositoryContext, IEnumerable <TSaga> instances)
            : base(repositoryContext)
        {
            _repositoryContext = repositoryContext;

            _index = instances.ToDictionary(x => x.CorrelationId);
        }
Example #2
0
        public async Task Send(SagaRepositoryContext <TSaga, T> context)
        {
            SagaConsumeContext <TSaga, T> sagaConsumeContext = null;

            if (_policy.PreInsertInstance(context, out var instance))
            {
                sagaConsumeContext = await context.Insert(instance).ConfigureAwait(false);
            }

            sagaConsumeContext ??= await context.Load(_correlationId).ConfigureAwait(false);

            if (sagaConsumeContext != null)
            {
                try
                {
                    sagaConsumeContext.LogUsed();

                    await _policy.Existing(sagaConsumeContext, _next).ConfigureAwait(false);

                    if (_policy.IsReadOnly)
                    {
                        await context.Undo(sagaConsumeContext).ConfigureAwait(false);
                    }
                    else
                    {
                        if (sagaConsumeContext.IsCompleted)
                        {
                            await context.Delete(sagaConsumeContext).ConfigureAwait(false);

                            sagaConsumeContext.LogRemoved();
                        }
                        else
                        {
                            await context.Update(sagaConsumeContext).ConfigureAwait(false);
                        }
                    }
                }
                finally
                {
                    switch (sagaConsumeContext)
                    {
                    case IAsyncDisposable asyncDisposable:
                        await asyncDisposable.DisposeAsync().ConfigureAwait(false);

                        break;

                    case IDisposable disposable:
                        disposable.Dispose();
                        break;
                    }
                }
            }
            else
            {
                await _policy.Missing(context, new MissingSagaPipe <TSaga, T>(context, _next)).ConfigureAwait(false);
            }
        }
Example #3
0
        public async Task Send(SagaRepositoryContext <TSaga, T> context)
        {
            SagaConsumeContext <TSaga, T> sagaConsumeContext = null;

            if (_policy.PreInsertInstance(context, out var instance))
            {
                sagaConsumeContext = await context.Insert(instance).ConfigureAwait(false);
            }

            if (sagaConsumeContext == null)
            {
                sagaConsumeContext = await context.Load(_correlationId).ConfigureAwait(false);
            }

            if (sagaConsumeContext != null)
            {
                try
                {
                    sagaConsumeContext.LogUsed();

                    await _policy.Existing(sagaConsumeContext, _next).ConfigureAwait(false);
                }
                finally
                {
                    switch (sagaConsumeContext)
                    {
                    case IAsyncDisposable asyncDisposable:
                        await asyncDisposable.DisposeAsync().ConfigureAwait(false);

                        break;

                    case IDisposable disposable:
                        disposable.Dispose();
                        break;
                    }
                }
            }
            else
            {
                var missingPipe = new MissingSagaPipe <TSaga, T>(context, _next);

                await _policy.Missing(context, missingPipe).ConfigureAwait(false);
            }
        }
 public DefaultSagaRepositoryQueryContext(SagaRepositoryContext <TSaga, TMessage> context, IList <Guid> results)
     : base(context)
 {
     _context = context;
     _results = results;
 }
Example #5
0
 public MissingSagaPipe(SagaRepositoryContext <TSaga, TMessage> repositoryContext, IPipe <SagaConsumeContext <TSaga, TMessage> > next)
 {
     _repositoryContext = repositoryContext;
     _next = next;
 }