Exemplo n.º 1
0
        public async Task <FetchEventsResult> FetchStreamEvents(string stream, EventStreamHeader header, StreamVersion fromVersion, int sliceSize)
        {
            // fromVersion already in slice
            var isFetchingCompleted = false;
            var nextSliceVersion    = fromVersion.Increment(sliceSize - 1);

            if (nextSliceVersion >= header.Version)
            {
                nextSliceVersion    = header.Version;
                isFetchingCompleted = true;
            }

            const string queryTemplate =
                "((PartitionKey eq '{0}') and (RowKey eq 'HEAD')) or " +
                "((PartitionKey eq '{0}') and (RowKey ge '{1}' and RowKey le '{2}'))";

            var query = m_table.PrepareEntityFilterRangeQuery(
                queryTemplate.FormatString(
                    stream,
                    fromVersion.ToString(),
                    nextSliceVersion.ToString()));

            var queryResult = await query.ExecuteAsync();

            var events = new SortedList <StreamVersion, JournaledEvent>(sliceSize);

            foreach (var properties in queryResult)
            {
                var rowKey = (string)properties[KnownProperties.RowKey];
                if (!rowKey.EqualsCi("HEAD"))
                {
                    events.Add(StreamVersion.Parse((string)properties[KnownProperties.RowKey]), JournaledEvent.Create(properties));
                }
            }

            return(new FetchEventsResult(isFetchingCompleted, events));
        }
Exemplo n.º 2
0
 private static string GetRowKey(string streamName, StreamVersion streamVersion)
 {
     return("{0}|{1}".FormatString(streamName, streamVersion.ToString()));
 }
Exemplo n.º 3
0
        private async Task<SortedList<StreamVersion, JournaledEvent>> FetchEvents(
            string stream,
            StreamVersion fromVersion,
            StreamVersion toVersion,
            int sliceSize)
        {
            var nextSliceVersion = fromVersion.Increment(sliceSize);
            if (nextSliceVersion >= toVersion)
            {
                nextSliceVersion = toVersion;
            }

            var query = m_table.PrepareEntityFilterRangeQuery(
                "(PartitionKey eq '{0}') and (RowKey ge '{1}' and RowKey le '{2}')".FormatString(
                    stream,
                    fromVersion.ToString(),
                    nextSliceVersion.ToString()), JournaledEventPropertyNames.All);

            var queryResult = await query.ExecuteAsync();

            var result = new SortedList<StreamVersion, JournaledEvent>(sliceSize);
            foreach (var properties in queryResult)
            {
                result.Add(StreamVersion.Parse((string)properties[KnownProperties.RowKey]), JournaledEvent.Create(properties));
            }

            return result;
        }