Ejemplo n.º 1
0
        public async Task Initialize(int minRevision, int maxRevision)
        {
            var commits = _persistence.GetFrom(BucketId, StreamId, minRevision, maxRevision);

            await PopulateStream(minRevision, maxRevision, commits);

            if (minRevision > 0 && _committed.Count == 0)
            {
                throw new StreamNotFoundException();
            }
        }
Ejemplo n.º 2
0
 public OptimisticEventStream(Snapshot snapshot, ICommitEvents persistence, int maxRevision)
     : this(snapshot.StreamId, persistence)
 {
     var commits = persistence.GetFrom(snapshot.StreamId, snapshot.StreamRevision, maxRevision);
     this.PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits);
     this.StreamRevision = snapshot.StreamRevision + this.committed.Count;
 }
Ejemplo n.º 3
0
        public void CommitChanges(Guid commitId)
        {
            Logger.Debug(Resources.AttemptingToCommitChanges, StreamId);

            if (_identifiers.Contains(commitId))
            {
                throw new DuplicateCommitException();
            }

            if (!HasChanges())
            {
                return;
            }

            try
            {
                PersistChanges(commitId);
            }
            catch (ConcurrencyException)
            {
                Logger.Info(Resources.UnderlyingStreamHasChanged, StreamId);
                IEnumerable <ICommit> commits = _persistence.GetFrom(BucketId, StreamId, StreamRevision + 1, int.MaxValue);
                PopulateStream(StreamRevision + 1, int.MaxValue, commits);

                throw;
            }
        }
 public OptimisticEventStream(Snapshot snapshot, ICommitEvents persistence, int maxRevision)
     : this(snapshot.StreamId, persistence)
 {
     IEnumerable<Commit> commits = persistence.GetFrom(snapshot.StreamId, snapshot.StreamRevision, maxRevision);
     PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits);
     StreamRevision = snapshot.StreamRevision + _committed.Count;
 }
Ejemplo n.º 5
0
        public void CommitChanges(Guid commitId)
        {
            Logger.Verbose(Resources.AttemptingToCommitChanges, StreamId);

            if (_identifiers.Contains(commitId))
            {
                throw new DuplicateCommitException(String.Format(Messages.DuplicateCommitIdException, commitId));
            }

            if (!HasChanges())
            {
                return;
            }

            try
            {
                PersistChanges(commitId);
            }
            catch (ConcurrencyException cex)
            {
                Logger.Debug(Resources.UnderlyingStreamHasChanged, StreamId, cex.Message); //not useful to log info because the exception will be thrown
                IEnumerable <ICommit> commits = _persistence.GetFrom(BucketId, StreamId, StreamRevision + 1, int.MaxValue);
                PopulateStream(StreamRevision + 1, int.MaxValue, commits);

                throw;
            }
        }
Ejemplo n.º 6
0
        public OptimisticEventStream(ISnapshot snapshot, ICommitEvents persistence, int maxRevision)
            : this(snapshot.BucketId, snapshot.StreamId, persistence)
        {
            IEnumerable <ICommit> commits = persistence.GetFrom(snapshot.BucketId, snapshot.StreamId, snapshot.StreamRevision, maxRevision);

            PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits);
            StreamRevision = snapshot.StreamRevision + _committed.Count;
        }
Ejemplo n.º 7
0
        public OptimisticEventStream(Snapshot snapshot, ICommitEvents persistence, int maxRevision)
            : this(snapshot.StreamId, persistence)
        {
            var commits = persistence.GetFrom(snapshot.StreamId, snapshot.StreamRevision, maxRevision);

            this.PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits);
            this.StreamRevision = snapshot.StreamRevision + this.committed.Count;
        }
Ejemplo n.º 8
0
 /// <summary>
 ///     Gets the corresponding commits from the stream indicated starting at the revision specified until the
 ///     end of the stream sorted in ascending order--from oldest to newest from the default bucket.
 /// </summary>
 /// <param name="commitEvents">The <see cref="ICommitEvents"/> instance.</param>
 /// <param name="streamId">The stream from which the events will be read.</param>
 /// <param name="minRevision">The minimum revision of the stream to be read.</param>
 /// <param name="maxRevision">The maximum revision of the stream to be read.</param>
 /// <returns>A series of committed events from the stream specified sorted in ascending order.</returns>
 /// <exception cref="StorageException" />
 /// <exception cref="StorageUnavailableException" />
 public static IEnumerable <Commit> GetFrom(this ICommitEvents commitEvents, string streamId, int minRevision, int maxRevision)
 {
     if (commitEvents == null)
     {
         throw new ArgumentException("commitEvents is null");
     }
     return(commitEvents.GetFrom(Bucket.Default, streamId, minRevision, maxRevision));
 }
Ejemplo n.º 9
0
        public OptimisticEventStream(Guid streamId, ICommitEvents persistence, int minRevision, int maxRevision)
            : this(streamId, persistence)
        {
            var commits = persistence.GetFrom(streamId, minRevision, maxRevision);
            this.PopulateStream(minRevision, maxRevision, commits);

            if (minRevision > 0 && this.committed.Count == 0)
                throw new StreamNotFoundException();
        }
Ejemplo n.º 10
0
        public HttpResponseMessage GetStream(TenantId tenantId, string aggregateId)
        {
            if (string.IsNullOrEmpty(aggregateId))
            {
                return(null);
            }

            String identity = aggregateId;

            try
            {
                _identityConverter.ToIdentity(aggregateId);
            }
            catch (Exception)
            {
                //it could be a handle
                var handle = _handleMapper.TryTranslate(aggregateId);
                if (handle == null)
                {
                    throw new ArgumentException("Invalid aggregateId", "aggregateId");
                }

                identity = handle.AsString();
            }


            var commits = _commits.GetFrom("Jarvis", identity, 0, int.MaxValue);

            var commitsList = new List <CommitModel>();

            foreach (var commit in commits)
            {
                _enhancer.Enhance(commit);
                commitsList.Add(new CommitModel(commit));
            }
            EventStreamResult result = new EventStreamResult();

            result.Commits     = commitsList;
            result.AggregateId = identity;

            var all = result.ToJson()
                      .Replace("\"_t\"", "\"Type\"")
                      .Replace("ISODate(", "")
                      .Replace("CSUUID(", "")
                      .Replace("\")", "\"");

            var sc = new StringContent(all);

            sc.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var resp = new HttpResponseMessage {
                Content = sc
            };

            return(resp);
        }
        public OptimisticEventStream(string bucketId, string streamId, ICommitEvents persistence, int minRevision, int maxRevision)
            : this(bucketId, streamId, persistence)
        {
            IEnumerable<ICommit> commits = persistence.GetFrom(bucketId, streamId, minRevision, maxRevision);
            PopulateStream(minRevision, maxRevision, commits);

            if (minRevision > 0 && _committed.Count == 0)
            {
                throw new StreamNotFoundException();
            }
        }
Ejemplo n.º 12
0
        public OptimisticEventStream(string bucketId, string streamId, ICommitEvents persistence, int minRevision, int maxRevision)
            : this(bucketId, streamId, persistence)
        {
            IEnumerable <ICommit> commits = persistence.GetFrom(bucketId, streamId, minRevision, maxRevision);

            PopulateStream(minRevision, maxRevision, commits);

            if (minRevision > 0 && _committed.Count == 0)
            {
                throw new StreamNotFoundException();
            }
        }
Ejemplo n.º 13
0
        public OptimisticEventStream(Guid streamId, ICommitEvents persistence, int minRevision, int maxRevision)
            : this(streamId, persistence)
        {
            var commits = persistence.GetFrom(streamId, minRevision, maxRevision);

            this.PopulateStream(minRevision, maxRevision, commits);

            if (minRevision > 0 && this.committed.Count == 0)
            {
                throw new StreamNotFoundException();
            }
        }