/// <inheritdoc />
 public Commits Fetch(EventSourceKey eventSourceKey)
 {
     using (var es = _database.GetContext())
     {
         return(BuildCommits(es.Commits.Include(c => c.Events).Where(c => c.EventSourceId == eventSourceKey.Id.Value && c.EventSourceArtifact == eventSourceKey.Artifact.Value).OrderBy(c => c.Id)));
     }
 }
        /// <summary>
        /// Builds a <see cref="FilterDefinition{BsonDocument}" /> corresponding to the <see cref="EventSourceKey" /> supplied
        /// </summary>
        /// <param name="key">An <see cref="EventSourceKey" /></param>
        /// <returns>A <see cref="FilterDefinition{BsonDocument}" /> corresponding to the <see cref="EventSourceKey" /></returns>
        public static FilterDefinition <BsonDocument> ToFilter(this EventSourceKey key)
        {
            var builder = Builders <BsonDocument> .Filter;
            var filter  = builder.Eq(Constants.EVENTSOURCE_ID, key.Id.Value) & builder.Eq(Constants.EVENT_SOURCE_ARTIFACT, key.Artifact.Value);

            return(filter);
        }
        public static UncommittedEventStream BuildUncommitted(this EventSourceKey eventSource, DateTimeOffset?now = null, CorrelationId correlationId = null)
        {
            var committed = now ?? DateTimeOffset.Now;
            var events    = BuildEvents();
            VersionedEventSource versionedEventSource = eventSource.Id.InitialVersion(eventSource.Artifact);

            return(BuildFrom(versionedEventSource, committed, correlationId ?? Guid.NewGuid(), events));
        }
        VersionedEventSource ToVersionedEventSource(UncommittedEvents uncommittedEvents)
        {
            var commit   = Convert.ToUInt64(uncommittedEvents.EventSource.Version.Commit);
            var sequence = Convert.ToUInt32(uncommittedEvents.EventSource.Version.Sequence);
            var key      = new EventSourceKey(uncommittedEvents.EventSource.EventSourceId, _artifactMap.GetArtifactFor(uncommittedEvents.EventSource.GetType()).Id);

            return(new VersionedEventSource(new EventSourceVersion(commit, sequence), key));
        }
示例#5
0
        /// <inheritdoc />
        public EventSourceVersion GetCurrentVersionFor(EventSourceKey eventSource)
        {
            if (_versions.TryGetValue(eventSource, out VersionedEventSource v))
            {
                return(v.Version);
            }

            return(EventSourceVersion.NoVersion);
        }
        /// <inheritdoc />
        public Commits Fetch(EventSourceKey eventSource)
        {
            var commitsQuery = GetBasicCommitQuery()
                               .Where(_ => _.EventSourceId == eventSource.Id.Value && _.EventSourceArtifact == eventSource.Artifact.Value)
                               .OrderBy(_ => _.Id2)
                               .AsDocumentQuery();

            return(GetCommits(commitsQuery, $"Fetching {eventSource.Id.Value } of artitfact {eventSource.Artifact.Value}"));
        }
示例#7
0
        EventSourceVersion GetLastEventSourceVersion(EventSourceKey eventSourceKey)
        {
            var commits = Fetch(eventSourceKey);

            if (commits.IsEmpty)
            {
                return(EventSourceVersion.NoVersion);
            }
            return(commits.Last().LastEventVersion.ToEventSourceVersion());
        }
        VersionedEventSource GetVersionFromCommits(EventSourceKey eventSource)
        {
            var builder   = Builders <BsonDocument> .Sort;
            var sort      = builder.Ascending(Constants.VERSION);
            var commitDoc = _config.Commits.Find(eventSource.ToFilter()).Sort(sort).Limit(1).ToList().SingleOrDefault();

            if (commitDoc == null)
            {
                return(new VersionedEventSource(EventSourceVersion.NoVersion, eventSource));
            }

            return(commitDoc.ToCommittedEventStream().Source);
        }
        /// <inheritdoc />
        public EventSourceVersion GetCurrentVersionFor(EventSourceKey eventSource)
        {
            var queryString = $"SELECT TOP 1 c.commit, c.sequence FROM c where c.eventsource_id='{eventSource.Id.Value}' and c.event_source_artifact = '{eventSource.Artifact.Value}' order by c.commit desc";
            var result      = _config.Client.CreateDocumentQuery <dynamic>(_config.CommitsUri, queryString, GetCommitFeedOptions()).ToList().FirstOrDefault();

            if (result != null)
            {
                return(new EventSourceVersion((ulong)result.commit, (uint)result.sequence));
            }
            else
            {
                return(EventSourceVersion.NoVersion);
            }
        }
示例#10
0
        /// <inheritdoc />
        public EventSourceVersion GetCurrentVersionFor(EventSourceKey eventSource)
        {
            var builder = Builders <BsonDocument> .Sort;
            var filter  = eventSource.ToFilter();
            var sort    = builder.Descending(VersionConstants.COMMIT);
            var version = _config.Commits.Find <BsonDocument>(filter).Sort(sort).Limit(1).FirstOrDefault();

            if (version == null)
            {
                return(EventSourceVersion.NoVersion);
            }

            return(version.ToEventSourceVersion());
        }
 /// <inheritdoc />
 public EventSourceVersion GetCurrentVersionFor(EventSourceKey eventSource)
 {
     using (var es = _database.GetContext())
     {
         var result = es.FromSql(GET_CURRENT_VERSION, new Dictionary <string, object>()
         {
             { "@eventSource", eventSource.Id.Value },
             { "@artifact", eventSource.Artifact.Value }
         }).FirstOrDefault();
         if (result != null)
         {
             return(new EventSourceVersion((ulong)result.CommitNumber, (uint)result.Sequence));
         }
         else
         {
             return(EventSourceVersion.NoVersion);
         }
     }
 }
        /// <summary>
        /// Injects an event
        /// </summary>
        public void InjectEvent(TenantId tenant, EventSourceId eventSourceId, IEvent @event)
        {
            _logger.Information($"Injecting event!");

            _executionContextManager.CurrentFor(tenant);
            var executionContext = _executionContextManager.Current;

            using (var eventStore = _getEventStore())
            {
                var artifact       = _artifactTypeMap.GetArtifactFor(@event.GetType());
                var eventSourceKey = new EventSourceKey(eventSourceId, artifact.Id);
                var version        = eventStore.GetNextVersionFor(eventSourceKey);

                var uncommittedEventStream = new UncommittedEventStream(
                    CommitId.New(),
                    executionContext.CorrelationId,
                    new VersionedEventSource(version, eventSourceKey),
                    DateTimeOffset.Now,
                    EventStream.From(new [] {
                    new EventEnvelope(
                        new EventMetadata(
                            EventId.New(),
                            new VersionedEventSource(version, eventSourceKey),
                            executionContext.CorrelationId,
                            artifact,
                            DateTimeOffset.Now,
                            executionContext
                            ),
                        @event.ToPropertyBag()
                        )
                })
                    );

                _logger.Information("Commit events to store");
                var committedEventStream = eventStore.Commit(uncommittedEventStream);

                _logger.Information("Process committed events");
                _processingHub.Process(committedEventStream);
            }
        }
示例#13
0
 public EventSourceVersion GetNextVersionFor(EventSourceKey eventSourceKey)
 {
     return(new EventSourceVersion(0, 0));
 }
示例#14
0
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey key, CommitVersion commitVersion)
 {
     return(new Commits(_commits.Where(c => c.Source.Key == key && c.Source.Version.Commit >= commitVersion).ToList()));
 }
示例#15
0
 /// <inheritdoc />
 public Commits Fetch(EventSourceKey key)
 {
     return(new Commits(_commits.Where(c => c.Source.Key == key).ToList()));
 }
示例#16
0
 public Commits Fetch(EventSourceKey eventSourceKey)
 {
     return(new Commits(new CommittedEventStream[0]));
 }
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey eventSource, CommitVersion commitVersion)
 {
     ThrowIfDisposed();
     return(_event_committer_and_fetcher.FetchFrom(eventSource, commitVersion));
 }
示例#18
0
 /// <inheritdoc />
 public EventSourceVersion GetNextVersionFor(EventSourceKey eventSource)
 {
     return(_eventCommitterAndFetcher.GetNextVersionFor(eventSource));
 }
 /// <inheritdoc />
 public EventSourceVersion GetNextVersionFor(EventSourceKey eventSource)
 {
     ThrowIfDisposed();
     return(_event_committer_and_fetcher.GetNextVersionFor(eventSource));
 }
示例#20
0
 public Commits FetchFrom(EventSourceKey eventSourceKey, CommitVersion commitVersion)
 {
     return(new Commits(new CommittedEventStream[0]));
 }
示例#21
0
 /// <inheritdoc />
 public EventSourceVersion GetNextVersionFor(EventSourceKey eventSource)
 {
     return(GetCurrentVersionFor(eventSource).NextCommit());
 }
示例#22
0
 /// <inheritdoc />
 public Commits Fetch(EventSourceKey eventSource)
 {
     return(_eventCommitterAndFetcher.Fetch(eventSource));
 }
示例#23
0
 /// <inheritdoc />
 public Commits Fetch(EventSourceKey eventSourceKey)
 {
     return(new Commits(FetchAllCommits().Where(_ => _.Source.Artifact.Equals(eventSourceKey.Artifact) && _.Source.EventSource.Equals(eventSourceKey.Id))));
 }
示例#24
0
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey eventSourceKey, CommitVersion commitVersion)
 {
     return(new Commits(FetchAllCommits().Where(_ => _.Source.Version.Commit >= commitVersion && _.Source.Artifact.Equals(eventSourceKey.Artifact) && _.Source.EventSource.Equals(eventSourceKey.Id))));
 }
示例#25
0
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey eventSource, CommitVersion commitVersion)
 {
     return(GetCommits(QueryCommitsFor(_ => _.EventSourceId == eventSource.Id.Value && _.EventSourceArtifact == eventSource.Artifact.Value && _.CommitNumber >= commitVersion.Value),
                       $"Fetching commits on for event source { eventSource.Id.Value }  of artifact:{ eventSource.Artifact.Value} after {commitVersion.ToString()}"));
 }
 /// <inheritdoc />
 public Commits Fetch(EventSourceKey eventSource)
 {
     ThrowIfDisposed();
     return(_event_committer_and_fetcher.Fetch(eventSource));
 }
示例#27
0
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey eventSource, CommitVersion commitVersion)
 {
     return(_eventCommitterAndFetcher.FetchFrom(eventSource, commitVersion));
 }
示例#28
0
 /// <inheritdoc />
 public Commits Fetch(EventSourceKey eventSourceKey)
 {
     return(FindCommitsWithSorting(eventSourceKey.ToFilter()));
 }
示例#29
0
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey eventSourceKey, CommitVersion commitVersion)
 {
     return(FindCommitsWithSorting(eventSourceKey.ToFilter() & commitVersion.ToFilter()));
 }