private IEnumerable <IEnumerable <JsonDocument> > YieldBatches(CancellationTimeout timeout, Stream inputStream, ManualResetEventSlim mre, Action <int> increaseDocumentsCount)
        {
            try
            {
                using (inputStream)
                {
                    var binaryReader = new BinaryReader(inputStream);

                    while (true)
                    {
                        timeout.ThrowIfCancellationRequested();
                        int size;
                        try
                        {
                            size = binaryReader.ReadInt32();
                        }
                        catch (EndOfStreamException)
                        {
                            break;
                        }
                        using (var stream = new PartialStream(inputStream, size))
                        {
                            yield return(YieldDocumentsInBatch(timeout, stream, increaseDocumentsCount));
                        }
                    }
                }
            }
            finally
            {
                mre.Set();
                inputStream.Close();
            }
        }
Beispiel #2
0
        private IEnumerable <IEnumerable <TimeSeriesAppend> > YieldChangeBatches(Stream requestStream, CancellationTimeout timeout, Action <int> changeTimeSeriesFunc)
        {
            var serializer = JsonExtensions.CreateDefaultJsonSerializer();

            try
            {
                using (requestStream)
                {
                    var binaryReader = new BinaryReader(requestStream);
                    while (true)
                    {
                        timeout.ThrowIfCancellationRequested();
                        int batchSize;
                        try
                        {
                            batchSize = binaryReader.ReadInt32();
                        }
                        catch (EndOfStreamException)
                        {
                            break;
                        }
                        using (var stream = new PartialStream(requestStream, batchSize))
                        {
                            yield return(YieldBatchItems(stream, serializer, timeout, changeTimeSeriesFunc));
                        }
                    }
                }
            }
            finally
            {
                requestStream.Close();
            }
        }