/// <summary> /// Gets operation data from state providers. /// </summary> public async Task <OperationData> GetNextAsync(CancellationToken cancellationToken) { try { while (this.currentIndex < this.operationDataStreamCollection.Count) { StateProviderIdentifier stateProviderIdentifier = this.operationDataStreamCollection[this.currentIndex].Item1; IOperationDataStream operationDataStream = this.operationDataStreamCollection[this.currentIndex].Item2; OperationData operationData = await operationDataStream.GetNextAsync(cancellationToken).ConfigureAwait(false); if (operationData == null) { ++this.currentIndex; continue; } // Reserve the List space with expected size: Version, ID, OperationData List <ArraySegment <byte> > namedBytes = new List <ArraySegment <byte> >(2 + operationData.Count); byte[] versionAsBytes = BitConverter.GetBytes(this.version); namedBytes.Add(new ArraySegment <byte>(versionAsBytes)); long stateProviderId = stateProviderIdentifier.StateProviderId; byte[] idAsBytes = BitConverter.GetBytes(stateProviderId); namedBytes.Add(new ArraySegment <byte>(idAsBytes)); foreach (ArraySegment <byte> roll in operationData) { namedBytes.Add(roll); } return(new OperationData(namedBytes)); } FabricEvents.Events.NamedOperationDataCollectionGetNext(this.traceType); return(null); } catch (Exception e) { string msg = string.Format( CultureInfo.InvariantCulture, "OperationDataStreamCollection Count: {0}, CurrentIndex: {1}.", this.operationDataStreamCollection.Count, this.currentIndex); StateManagerStructuredEvents.TraceException( this.traceType, "NamedOperationDataCollection.GetNextAsync.", msg, e); throw; } }
/// <summary> /// Adds operation data stream to the collection. /// </summary> public void Add(StateProviderIdentifier stateProviderIdentifier, IOperationDataStream operationDataStream) { Utility.Assert( stateProviderIdentifier != null, "{0}: Named operation data cannot be empty in named operation data collection.", this.traceType); Utility.Assert( operationDataStream != null, "{0}: Operation data stream cannot be null.", this.traceType); this.operationDataStreamCollection.Add( new Tuple <StateProviderIdentifier, IOperationDataStream>(stateProviderIdentifier, operationDataStream)); }