public T GetOrThrow <T>(long id) where T : DomainObject { var item = Get <T>(id); if (item == null) { throw BMException.Unknown <T>(); } return(item); }
public void Import(PipelineContext ctx, IDatasourceSink sink) { _BeforeImport(ctx, sink); try { foreach (var elt in streamDirectory.GetProviders(ctx)) { try { ImportUrl(ctx, sink, elt); } catch (Exception e) { e = new BMException(e, WrapMessage(e, elt.ToString(), "{0}\r\nUrl={1}.")); ctx.HandleException(e); } } } finally { _AfterImport(ctx, sink); } }
protected override void ImportStream(PipelineContext ctx, IDatasourceSink sink, IStreamProvider elt, Stream strm) { int lineNo = -1; try { TextReader rdr = strm.CreateTextReader(encoding); int charsRead = 0; if ((mode & _Mode.lines) != 0) { while (charsRead < maxToRead) { lineNo++; String line = rdr.ReadLine(); if (line == null) { break; } if (line.Length == 0) { if ((mode & _Mode.stopAtEmpty) != 0) { break; } } sink.HandleValue(ctx, "record/line", line); charsRead += line.Length; } } else { lineNo++; String line = rdr.ReadLine(); if (line != null) { charsRead += line.Length; } String key, value; while (line != null) { lineNo++; String nextLine = rdr.ReadLine(); if (nextLine == null) { key = "record/" + splitKV(line, out value); sink.HandleValue(ctx, key, value); break; } charsRead += nextLine.Length; if (nextLine.Length == 0) { if ((mode & _Mode.stopAtEmpty) != 0) { break; } else { continue; } } int offs = 0; for (; offs < nextLine.Length; offs++) { switch (nextLine[offs]) { case ' ': case '\t': continue; } break; } if (offs > 0) { line = line + nextLine.Substring(offs); continue; } if (lenient && nextLine.IndexOf(':') < 0) { line = line + nextLine; continue; } key = "record/" + splitKV(line, out value); sink.HandleValue(ctx, key, value); line = nextLine; } } sink.HandleValue(ctx, "record", null); ctx.IncrementEmitted(); } catch (Exception e) { e = new BMException(e, "{0}\nLine={1}.", e.Message, lineNo); ctx.HandleException(e); } }