Example #1
0
		private static IEnumerable<IEnumerable<JsonDocument>> YieldBatches(IHttpContext context)
		{
			using (var inputStream = context.Request.GetBufferLessInputStream())
			{
				var binaryReader = new BinaryReader(inputStream);
				while (true)
				{
					int size;
					try
					{
						size = binaryReader.ReadInt32();
					}
					catch (EndOfStreamException)
					{
						break;
					}
					using (var stream = new PartialStream(inputStream, size))
					{
						yield return YieldDocumentsInBatch(stream);
					}
				}
			}
		}
Example #2
0
		private static IEnumerable<IEnumerable<JsonDocument>> YieldBatches(IHttpContext context, ManualResetEventSlim mre, Action<int> increaseDocumentsCount)
		{
			try
			{
				using (var inputStream = context.Request.GetBufferLessInputStream())
				{
					var binaryReader = new BinaryReader(inputStream);
					while (true)
					{
						int size;
						try
						{
							size = binaryReader.ReadInt32();
						}
						catch (EndOfStreamException)
						{
							break;
						}
						using (var stream = new PartialStream(inputStream, size))
						{
							yield return YieldDocumentsInBatch(stream, increaseDocumentsCount);
						}
					}
				}
			}
			finally
			{
				mre.Set();
			}
		}
        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();
            }
        }