public async Task <IDataItem> ReadNextAsync(ReadOutputByRef readOutput, CancellationToken cancellation)
        {
            if (file == null)
            {
                file = new StreamReader(await sourceStreamProvider.CreateStream(cancellation));
            }

            readOutput.DataItemId = String.Format(CultureInfo.InvariantCulture,
                                                  Resources.DataItemIdFormat, sourceStreamProvider.Id, ++lineNumber);

            string jsonData = null;

            while (!file.EndOfStream &&
                   String.IsNullOrEmpty(jsonData = await file.ReadLineAsync()))
            {
                ;
            }

            if (file.EndOfStream && String.IsNullOrEmpty(jsonData))
            {
                return(null);
            }

            try
            {
                return(new BsonDocumentDataItem(BsonDocument.Parse(jsonData)));
            }
            catch (Exception parseError)
            {
                throw new NonFatalReadException(parseError.Message, parseError.InnerException);
            }
        }
示例#2
0
        public async Task <IDataItem> ReadNextAsync(ReadOutputByRef readOutput, CancellationToken cancellation)
        {
            try
            {
                if (reader == null)
                {
                    reader = new CsvReader(
                        new StreamReader(await sourceStreamProvider.CreateStream(cancellation)),
                        new CsvReaderConfiguration
                    {
                        TrimQuoted          = configuration.TrimQuoted,
                        IgnoreUnquotedNulls = configuration.NoUnquotedNulls,
                        ParserCulture       = configuration.UseRegionalSettings ? CultureInfo.CurrentCulture : CultureInfo.InvariantCulture
                    });
                    header = ReadHeaderRow();
                }

                if (header == null)
                {
                    return(null);
                }

                return(await Task.Factory.StartNew <IDataItem>(ReadNext));
            }
            finally
            {
                readOutput.DataItemId = String.Format(CultureInfo.InvariantCulture,
                                                      Resources.DataItemIdFormat, sourceStreamProvider.Id, reader == null ? 0 : reader.Row);
            }
        }
示例#3
0
        public async Task <IDataItem> ReadNextAsync(ReadOutputByRef readOutput, CancellationToken cancellation)
        {
            try
            {
                if (file == null)
                {
                    file       = new StreamReader(await sourceStreamProvider.CreateStream(cancellation));
                    jsonReader = new JsonTextReader(file)
                    {
                        SupportMultipleContent = true
                    };
                    jsonReader.DateParseHandling = DateParseHandling.None;
                }

                return(await Task.Factory.StartNew(() =>
                {
                    while (jsonReader.Read() && jsonReader.TokenType != JsonToken.StartObject)
                    {
                        ;
                    }

                    if (jsonReader.TokenType != JsonToken.StartObject)
                    {
                        return null;
                    }

                    return serializer.Deserialize <IDataItem>(jsonReader);
                }));
            }
            finally
            {
                int lineNumber = 0, linePosition = 0;
                if (jsonReader != null)
                {
                    lineNumber   = jsonReader.LineNumber;
                    linePosition = jsonReader.LinePosition;
                }

                readOutput.DataItemId = String.Format(CultureInfo.InvariantCulture,
                                                      Resources.DataItemIdFormat, sourceStreamProvider.Id, lineNumber, linePosition);
            }
        }
 public async Task <Stream> CreateStream(CancellationToken cancellation)
 {
     return(new GZipStream(
                await innerStreamProvider.CreateStream(cancellation),
                CompressionMode.Decompress));
 }