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 ApiHostCatalog HostCatalog(IApiHost src) { var flow = Wf.Running(Msg.CreatingHostCatalog.Format(src.HostUri)); var members = ApiJit.JitHost(src); var result = members.Length == 0 ? ApiHostCatalog.Empty : new ApiHostCatalog(src, members); Wf.Ran(flow, Msg.CreatedHostCatalog.Format(src.HostUri, members.Count)); return(result); }
public Index <ApiResAccessor> ResPackAccessors() { var path = ResPackPath(); var flow = Wf.Running(Msg.LoadingRespackAccessors.Format(path)); if (!path.Exists) { Throw.sourced(FS.Msg.DoesNotExist.Format(path)); } var assembly = Assembly.LoadFrom(path.Name); var loaded = Resources.accessors(assembly); Wf.Ran(flow, Msg.LoadedRespackAccessors.Format(loaded.Count, path)); return(loaded); }
public Index <ApiCodeBlock> Read(ApiHostUri host) { var file = FS.file(host.Part, host.HostName, Ext); var path = Paths().Where(f => f.FileName.Name == file.Name).FirstOrDefault(FS.FilePath.Empty); if (path.IsEmpty) { Wf.Warn(Msg.HostFileMissing.Format(host, path)); return(sys.empty <ApiCodeBlock>()); } var flow = Wf.Running(path); var data = Read(path); Wf.Ran(flow, data.Length); return(data); }
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(); } }