Пример #1
0
        public async Task <IDictionary <string, List <EventStreamUpdated> > > LoadAsync()
        {
            var result      = new Dictionary <string, List <EventStreamUpdated> >();
            var query       = m_table.PrepareEntityGetAllQuery();
            var queryResult = await query.ExecuteAsync();

            foreach (var row in queryResult)
            {
                var rowKey      = (string)row[KnownProperties.RowKey];
                var rowKeyParts = rowKey.Split('|');
                var streamName  = rowKeyParts[0];
                var fromVersion = StreamVersion.Parse(rowKeyParts[1]);
                var toVersion   = StreamVersion.Create((int)row["ToVersion"]);

                List <EventStreamUpdated> streamNotifications;
                if (result.ContainsKey(streamName))
                {
                    streamNotifications = result[streamName];
                }
                else
                {
                    streamNotifications = new List <EventStreamUpdated>();
                    result[streamName]  = streamNotifications;
                }

                streamNotifications.Add(new EventStreamUpdated(streamName, fromVersion, toVersion));
            }

            return(result);
        }
Пример #2
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));
        }
Пример #3
0
        public void Parse_ForZero_ReturnsUnknownVersion()
        {
            var version = StreamVersion.Parse("0");

            Assert.Equal(StreamVersion.Unknown, version);
        }
Пример #4
0
        public void IsUnknown_ForZeroVersion_ReturnsTrue()
        {
            var version = StreamVersion.Parse("0");

            Assert.True(StreamVersion.IsUnknown(version));
        }
Пример #5
0
 protected override void RestoreFromProperties(Dictionary <string, string> properties)
 {
     StreamName  = properties[NotificationPropertyKeys.Common.STREAM];
     FromVersion = StreamVersion.Parse(properties[NotificationPropertyKeys.EventStreamUpdated.FROM_VERSION]);
     ToVersion   = StreamVersion.Parse(properties[NotificationPropertyKeys.EventStreamUpdated.TO_VERSION]);
 }