public static Task <ICommit> CommitNextAsync(
            this IPersistStreams persistence, CommitAttempt previous, CancellationToken cancellationToken)
        {
            var nextAttempt = previous.BuildNextAttempt();

            return(persistence.CommitAsync(nextAttempt, cancellationToken));
        }
        public static Task <ICommit> CommitSingleAsync(
            this IPersistStreams persistence, string streamId, CancellationToken cancellationToken)
        {
            var commitAttempt = (streamId ?? Guid.NewGuid().ToString()).BuildAttempt();

            return(persistence.CommitAsync(commitAttempt, cancellationToken));
        }
        public virtual async Task <ICommit> CommitAsync(CommitAttempt attempt, CancellationToken cancellationToken)
        {
            Guard.NotNull(() => attempt, attempt);

            foreach (var hook in _pipelineHooks)
            {
                cancellationToken.ThrowIfCancellationRequested();

                Logger.Debug(Resources.InvokingPreCommitHooks, attempt.CommitId, hook.GetType());
                if (await hook.PreCommitAsync(attempt, cancellationToken).ConfigureAwait(false))
                {
                    continue;
                }

                Logger.Info(Resources.CommitRejectedByPipelineHook, hook.GetType(), attempt.CommitId);
                return(null);
            }

            // Last chance before we attempt to commit
            cancellationToken.ThrowIfCancellationRequested();

            Logger.Info(Resources.CommittingAttempt, attempt.CommitId, attempt.Events.Count);
            var commit = await _persistence.CommitAsync(attempt, cancellationToken).ConfigureAwait(false);

            foreach (var hook in _pipelineHooks)
            {
                Logger.Debug(Resources.InvokingPostCommitPipelineHooks, attempt.CommitId, hook.GetType());
                await hook.PostCommitAsync(commit, cancellationToken).ConfigureAwait(false);
            }

            return(commit);
        }
        public async Task <ICommit> CommitAsync(CommitAttempt attempt, CancellationToken cancellationToken)
        {
            var clock = Stopwatch.StartNew();

            var commit = await _persistence
                         .CommitAsync(attempt, cancellationToken)
                         .ConfigureAwait(false);

            clock.Stop();
            _counters.CountCommit(attempt.Events.Count, clock.ElapsedMilliseconds);

            return(commit);
        }
        public static async Task <IEnumerable <CommitAttempt> > CommitManyAsync(
            this IPersistStreams persistence, int numberOfCommits, string streamId, string bucketId, CancellationToken cancellationToken)
        {
            var           commits = new List <CommitAttempt>();
            CommitAttempt attempt = null;

            for (var i = 0; i < numberOfCommits; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();

                attempt = attempt == null
                    ? (streamId ?? Guid.NewGuid().ToString()).BuildAttempt(null, bucketId)
                    : attempt.BuildNextAttempt();

                await persistence.CommitAsync(attempt, cancellationToken).ConfigureAwait(false);

                commits.Add(attempt);
            }

            return(commits);
        }
 public Task <ICommit> CommitAsync(CommitAttempt attempt, CancellationToken cancellationToken)
 {
     return(_original.CommitAsync(attempt, cancellationToken));
 }