/// <inheritdoc cref="IStreamDataGenerator{T}"/>
        public bool TryReadEvents(int maxCount, out IEnumerable <EventData> events)
        {
            if (!this.ShouldProduce)
            {
                events = null;
                return(false);
            }
            int count = maxCount;
            List <EventData> eventDataList = new List <EventData>();

            while (count-- > 0)
            {
                this.SequenceNumberCounter.Increment();
                var eventData = EventHubBatchContainer.ToEventData <int>(this.serializationManager, this.StreamId.Guid, this.StreamId.Namespace,
                                                                         this.GenerateEvent(this.SequenceNumberCounter.Value), RequestContext.Export(this.serializationManager));
#if !BUILD_FLAVOR_LEGACY
                //set partition key
                eventData.SetPartitionKey(this.StreamId.Guid.ToString());
#endif
                //set offset
                DateTime now    = DateTime.UtcNow;
                var      offSet = this.StreamId.Guid.ToString() + now.ToString();
                eventData.SetOffset(offSet);
                //set sequence number
                eventData.SetSequenceNumber(this.SequenceNumberCounter.Value);
                //set enqueue time
                eventData.SetEnqueuedTimeUtc(now);
                eventDataList.Add(eventData);
                this.logger.Info($"Generate data of SequemceNumber {SequenceNumberCounter.Value} for stream {this.StreamId.Namespace}-{this.StreamId.Guid}");
            }

            events = eventDataList;
            return(eventDataList.Count > 0);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public bool TryReadEvents(int maxCount, out IEnumerable <EventData> events)
        {
            if (!this.ShouldProduce)
            {
                events = null;
                return(false);
            }
            int count = maxCount;
            List <EventData> eventDataList = new List <EventData>();

            while (count-- > 0)
            {
                this.SequenceNumberCounter.Increment();

                var eventData = EventHubBatchContainer.ToEventData <int>(
                    this.serializationManager,
                    this.StreamId,
                    this.GenerateEvent(this.SequenceNumberCounter.Value),
                    RequestContextExtensions.Export(this.serializationManager));

                var wrapper = new WrappedEventData(
                    eventData.Body,
                    eventData.Properties,
                    eventData.SystemProperties,
                    partitionKey: StreamId.GetKeyAsString(),
                    offset: DateTime.UtcNow.Ticks,
                    sequenceNumber: this.SequenceNumberCounter.Value);

                eventDataList.Add(wrapper);

                this.logger.Info($"Generate data of SequemceNumber {SequenceNumberCounter.Value} for stream {this.StreamId}");
            }

            events = eventDataList;
            return(eventDataList.Count > 0);
        }