public Index <ApiCatalogEntry> LoadCatalog() { var dir = Db.CaptureContextRoot(); var files = dir.Files(FS.Csv).Where(f => f.FileName.StartsWith(ApiCatalogEntry.TableId)).OrderBy(f => f.Name); var rows = root.list <ApiCatalogEntry>(); if (files.Length != 0) { var src = files[files.Length - 1]; var flow = Wf.Running(Msg.LoadingApiCatalog.Format(src)); using var reader = src.Reader(); reader.ReadLine(); var line = reader.ReadLine(); while (line != null) { var outcome = parse(line, out var row); if (outcome) { rows.Add(row); } else { Wf.Error(outcome.Message); return(sys.empty <ApiCatalogEntry>()); } line = reader.ReadLine(); } Wf.Ran(flow, Msg.LoadedApiCatalog.Format(rows.Count, src)); } return(rows.ToArray()); }
public void Dispatch(CmdLine cmd) { var args = cmd.Parts; if (args.IsEmpty) { return; } var name = first(args).Content; var a0 = args.Length >= 2 ? args[1].Content : EmptyString; var a1 = args.Length >= 3 ? args[2].Content : EmptyString; var a2 = args.Length >= 4 ? args[3].Content : EmptyString; var a3 = args.Length >= 5 ? args[4].Content : EmptyString; switch (name) { case RunScriptCmd.CmdName: Builder.RunScript(FS.path(a0)).RunDirect(Wf); break; default: Wf.Error(string.Format("Processor for {0} not found", name)); break; } }
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(); } }