Beispiel #1
0
        protected virtual async Task <IEventStream> GetStreamAsync(ICommitTrailStore commitLogs)
        {
            var stream = new EventStream(
                this._credentials, this._tenant,
                this._streamName, commitLogs, this._loggerFactory);

            await stream.Init(false);

            return(stream);
        }
Beispiel #2
0
        public EventStream(
            StorageCredentials credentials,
            Tenant tenant,
            string streamName,
            ICommitTrailStore commitLogs,
            ILoggerFactory loggerFactory)
        {
            Ensure.ArgumentNotNullOrWhiteSpace(streamName, nameof(streamName));
            Ensure.ArgumentNotNull(tenant, nameof(tenant));
            Ensure.ArgumentNotNull(credentials, nameof(credentials));
            Ensure.ArgumentNotNull(loggerFactory, nameof(loggerFactory));
            Ensure.ArgumentNotNull(commitLogs, nameof(commitLogs));

            this._streamName  = streamName;
            this._tenant      = tenant;
            this._credentials = credentials;
            this._commitLogs  = commitLogs;
            this._logger      = loggerFactory.CreateLogger <EventStream>();
        }
Beispiel #3
0
        private async Task <long> ConsumeEvents(
            Action <IEnumerable <EventBase> > onEventReceived,
            ICommitTrailStore commitLogs, ILeaseStore leaseStore, long recentCommitId, long offsetCommitId)
        {
            // we have commits to take care ...
            var logs = (await commitLogs
                        .GetCommitsAsync(offsetCommitId, recentCommitId)
                        .ConfigureAwait(false))
                       .Where(log =>
                              log.StreamName.Equals(this._streamName, StringComparison.OrdinalIgnoreCase));

            if (logs.Any())
            {
                var stream = await GetStreamAsync(commitLogs).ConfigureAwait(false);

                var events = await stream.ReadEventsAsync(logs).ConfigureAwait(false);

                onEventReceived(events);

                await leaseStore.SetOffsetCommitIdAsync((offsetCommitId = recentCommitId));
            }

            return(offsetCommitId);
        }