/// <summary> /// Notifies the observer of a new value in the sequence. It's best to override Dispatch or TreatRow than this method because this method contains pipelining logic. /// </summary> public override void Trigger() { CountTreated++; try { IEnumerator fList = null; if (_strm != null) { using (StreamReader reader = new StreamReader(_strm)) { fList = FluentFile.For(_type).From(reader).GetEnumerator(); } } else if (_strmReader != null) { fList = FluentFile.For(_type).From(_strmReader).GetEnumerator(); } else if (_filename != null) { fList = FluentFile.For(_type).From(_filename).GetEnumerator(); } IterateElements(fList); } catch (Exception ex) { log4net.LogManager.GetLogger(this.GetType()).Error("Operation error", ex); Observers.PropagateOnError(ex); } Completed = true; Observers.PropagateOnCompleted(); }
public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { using (FileEngine file = FluentFile.For <UserAddressRecord>().From(filePath)) { foreach (object obj in file) { yield return(Row.FromObject(obj)); } } }
public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { using (var file = FluentFile.For <DataRecord>().From(FilePath)) { foreach (var obj in file) { yield return(Row.FromObject(obj)); } } }
protected override async Task ExecuteYield(IAsyncEnumerable <Row> rows, AsyncEnumerator <Row> .Yield yield, CancellationToken cancellationToken = default) { using (FileEngine file = FluentFile.For <UserRecord>().From("users.txt")) { foreach (object obj in file) { await @yield.ReturnAsync(Row.FromObject(obj)); } } }
public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { using (FileEngine file = FluentFile.For <FlatFile>().From(FilePath)) { int i = 0; foreach (FlatFile fileRow in file) { yield return(Row.FromObject(fileRow)); i++; } } }
public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { FluentFile engine = FluentFile.For <UserFullRecord>(); engine.HeaderText = "Id\tName\tAddress"; using (FileEngine file = engine.To(filePath)) { foreach (Row row in rows) { file.Write(row.ToObject <UserFullRecord>()); //pass through rows if needed for another later operation yield return(row); } } }
/// <summary> /// Executes this operation /// </summary> /// <param name="rows">The rows.</param> /// <returns></returns> public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { FluentFile engine = FluentFile.For <UserRecord>(); engine.HeaderText = "Id\tName\tEmail"; using (FileEngine file = engine.To("users.txt")) { foreach (Row row in rows) { UserRecord record = new UserRecord(); record.Id = (int)row["id"]; record.Name = (string)row["name"]; record.Email = (string)row["email"]; file.Write(record); } } yield break; }
protected override async Task ExecuteYield(IAsyncEnumerable <Row> rows, AsyncEnumerator <Row> .Yield yield, CancellationToken cancellationToken = default) { FluentFile engine = FluentFile.For <UserRecord>(); engine.HeaderText = "Id\tName\tEmail"; using (FileEngine file = engine.To("users.txt")) { await rows.ForEachAsync(row => { UserRecord record = new UserRecord(); record.Id = (int)row["id"]; record.Name = (string)row["name"]; record.Email = (string)row["email"]; file.Write(record); }, cancellationToken); } @yield.Break(); }
/// <summary> /// Initialize the file engine /// </summary> /// <returns>initialized engine</returns> public FileEngine InitializeEngine() { if (Engine != null) { return(Engine); } if (this.Stream != null && _innerstrmwriter == null) { _innerstrmwriter = new StreamWriter(this.Stream); } var ff = FluentFile.For <T>(); if (PrepareFluentFile != null) { PrepareFluentFile(ff); } if (_innerstrmwriter != null) { Engine = ff.To(_innerstrmwriter); } else if (Writer != null) { Engine = ff.To(Writer); } else if (FileName != null) { Engine = ff.To(FileName); } if (Engine == null) { throw new InvalidOperationException("File write is not initialized appropriately"); } return(Engine); }