示例#1
0
        /// <summary>
        /// Waits until a saga exists with the specified correlationId
        /// </summary>
        /// <param name="sagaId"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public async Task <Guid?> Exists(Guid sagaId, TimeSpan?timeout = default(TimeSpan?))
        {
            if (_querySagaRepository == null)
            {
                throw new InvalidOperationException("The repository does not support Query operations");
            }

            var giveUpAt = DateTime.Now + (timeout ?? _testTimeout);

            while (DateTime.Now < giveUpAt)
            {
                var saga = (await _querySagaRepository.Where(x => x.CorrelationId == sagaId).ConfigureAwait(false)).FirstOrDefault();
                if (saga != Guid.Empty)
                {
                    return(saga);
                }

                await Task.Delay(10).ConfigureAwait(false);
            }

            return(default(Guid?));
        }
示例#2
0
        public static async Task <Guid?> ShouldContainSaga <TSaga>(this IQuerySagaRepository <TSaga> repository, Guid sagaId, TimeSpan timeout)
            where TSaga : class, ISaga
        {
            DateTime giveUpAt = DateTime.Now + timeout;

            while (DateTime.Now < giveUpAt)
            {
                Guid saga = (await repository.Where(x => x.CorrelationId == sagaId).ConfigureAwait(false)).FirstOrDefault();
                if (saga != Guid.Empty)
                {
                    return(saga);
                }

                await Task.Delay(10).ConfigureAwait(false);
            }

            return(default);
        public static async Task <Guid?> ShouldContainSaga <TSaga>(this IQuerySagaRepository <TSaga> repository,
                                                                   Expression <Func <TSaga, bool> > filter,
                                                                   TimeSpan timeout)
            where TSaga : class, ISaga
        {
            DateTime giveUpAt = DateTime.Now + timeout;

            var query = new SagaQuery <TSaga>(filter);

            while (DateTime.Now < giveUpAt)
            {
                var sagas = (await repository.Where(query.FilterExpression).ConfigureAwait(false)).ToList();
                if (sagas.Count > 0)
                {
                    return(sagas.Single());
                }

                await Task.Delay(10).ConfigureAwait(false);
            }

            return(default(Guid?));
        }