public void PushValues(TIn input, Action <TOut> push) { using (var sr = new StreamReader(_args.DataStreamSelector(input))) { if (_args.Mapping.HasColumnHeader) { int index = 0; LineSerializer <TParsed> lineSerializer = null; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (index == _args.Mapping.FirstLinesToIgnore) { lineSerializer = _args.Mapping.GetSerializer(line); } else if (index > _args.Mapping.FirstLinesToIgnore && !string.IsNullOrWhiteSpace(line)) { TParsed parsed; try { parsed = lineSerializer.Deserialize(line); } catch (Exception ex) { throw new FlatFileLineDeserializeException(index, ex); } push(_args.ResultSelector(input, parsed)); } index++; } } else { int index = 0; LineSerializer <TParsed> lineSerializer = _args.Mapping.GetSerializer(); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (index >= _args.Mapping.FirstLinesToIgnore && !string.IsNullOrWhiteSpace(line)) { TParsed parsed; try { parsed = lineSerializer.Deserialize(line); } catch (Exception ex) { throw new FlatFileLineDeserializeException(index, ex); } push(_args.ResultSelector(input, parsed)); } index++; } } } }
public override IDeferedPushObservable <TOut> PushValues(TIn input) { var src = new DeferedPushObservable <string>(pushValue => { using (base.OpenProcess()) using (var sr = new StreamReader(_args.DataStreamSelector(input))) while (!sr.EndOfStream) { pushValue(sr.ReadLine()); } }); if (_args.Mapping.HasColumnHeader) { var lineParserS = src .Skip(_args.Mapping.FirstLinesToIgnore) .Take(1) .Map(_args.Mapping.GetSerializer); var ret = src .Skip(1 + _args.Mapping.FirstLinesToIgnore) .Filter(i => !string.IsNullOrWhiteSpace(i)) .CombineWithLatest(lineParserS, (txt, parser) => parser.Deserialize(txt)) .Map(i => _args.ResultSelector(input, i)); return(new DeferedWrapperPushObservable <TOut>(ret, src.Start)); } else { var serializer = _args.Mapping.GetSerializer(); var ret = src .Skip(_args.Mapping.FirstLinesToIgnore) .Filter(i => !string.IsNullOrWhiteSpace(i)) .Map(serializer.Deserialize) .Map(i => _args.ResultSelector(input, i)); return(new DeferedWrapperPushObservable <TOut>(ret, src.Start)); } }
public void PushValues(TIn input, Action <TOut> push) { var src = new PushSubject <string>(); Exception exception = null; if (_args.Mapping.HasColumnHeader) { var numberedSrc = src .Map((txt, idx) => new { txt, idx }); var lineParserS = numberedSrc .Skip(_args.Mapping.FirstLinesToIgnore) .Take(1) .Map(i => _args.Mapping.GetSerializer(i.txt)) .CompletesOnException(i => exception = i); numberedSrc .Skip(1 + _args.Mapping.FirstLinesToIgnore) .Filter(i => !string.IsNullOrWhiteSpace(i.txt)) .CombineWithLatest(lineParserS, (line, parser) => { try { return(parser.Deserialize(line.txt)); } catch (Exception ex) { throw new FlatFileLineDeserializeException(line.idx, ex); } }) .CompletesOnException(i => exception = i) .Map(i => _args.ResultSelector(input, i)) .Do(push); } else { var serializer = _args.Mapping.GetSerializer(); var numberedSrc = src .Map((txt, idx) => new { txt, idx }); numberedSrc .Skip(_args.Mapping.FirstLinesToIgnore) .Filter(i => !string.IsNullOrWhiteSpace(i.txt)) .Map(i => { try { return(serializer.Deserialize(i.txt)); } catch (Exception ex) { throw new FlatFileLineDeserializeException(i.idx, ex); } }) .Map(i => _args.ResultSelector(input, i)) .Do(push) .CompletesOnException(i => exception = i); } using (var sr = new StreamReader(_args.DataStreamSelector(input))) while (!sr.EndOfStream) { src.PushValue(sr.ReadLine()); } if (exception != null) { throw exception; } //src.PushException(exception); src.Complete(); }