public void Emit(Type src, FS.FilePath dst) { var flow = Wf.EmittingFile(dst); using var writer = dst.Writer(); var patterns = Sources(src); var view = patterns.View; var count = view.Length; for (var i = 0; i < count; i++) { writer.WriteLine(skip(view, i).Format()); } Wf.EmittedFile(flow, count); }
public Outcome <FileSplitInfo> Run(FileSplitSpec spec) { var writer = default(StreamWriter); try { var flow = Wf.Running(Msg.SplittingFile.Format(spec.SourceFile.ToUri(), spec.MaxLineCount)); using var reader = spec.SourceFile.Reader(); var paths = root.list <FS.FilePath>(); var subcount = 0u; var linecount = 0u; var splitcount = 0u; var emptycount = 0; var emptylimit = 5; var path = NextPath(spec, ref splitcount); paths.Add(path); writer = path.Writer(); var emitting = Wf.EmittingFile(path); while (!reader.EndOfStream) { var line = reader.ReadLine(); if (text.empty(line)) { emptycount++; } else { emptycount = 0; } if (emptycount > emptylimit) { continue; } writer.WriteLine(line); subcount++; if (subcount >= spec.MaxLineCount) { writer.Flush(); writer.Dispose(); Wf.EmittedFile(emitting, subcount); path = NextPath(spec, ref splitcount); paths.Add(path); writer = path.Writer(); linecount += subcount; subcount = 0; } } Wf.Ran(flow, Msg.FinishedFileSplit.Format(linecount, spec.SourceFile.ToUri(), splitcount)); return(new FileSplitInfo(spec, paths.ToArray(), linecount)); } catch (Exception e) { Wf.Error(e); return(e); } finally { writer.Flush(); writer.Dispose(); } }