public void DetailQueryTest(bool dangerous, string expr) { var query = ParsingF.DetailQuery(ref expr); ParsingF.Eof(expr); Assert.Equal(dangerous, query.IsDangerous()); }
public void RunTestQuery(int number, string query) { Assert.Equal(number, m_Adapter.SelectVoucherDetails(ParsingF.DetailQuery(query)).Count()); Assert.Equal( number, m_Adapter.SelectVoucherDetailsGrouped(ParsingF.GroupedQuery(query + "!v")).SingleOrDefault()?.Fund ?? 0); }
/// <inheritdoc /> public override IQueryResult Execute(string expr, IEntitiesSerializer serializer) { var csv = expr; expr = ParsingF.Line(ref csv); var parsed = new CsvParser(ParsingF.Optional(ref expr, "-")); var sb = new StringBuilder(); if (ParsingF.Optional(ref expr, "mark")) { var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); sb.AppendLine($"{parsed.Items.Count} parsed"); RunMark(filt, parsed, marker, sb); } else if (ParsingF.Optional(ref expr, "unmark")) { var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Eof(expr); RunUnmark(filt, sb); } else if (ParsingF.Optional(ref expr, "check")) { var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Eof(expr); parsed.Parse(csv); sb.AppendLine($"{parsed.Items.Count} parsed"); RunCheck(filt, parsed, sb); } else { ParsingF.Optional(ref expr, "auto"); var filt = Regularize(ParsingF.DetailQuery(ref expr)); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); sb.AppendLine($"{parsed.Items.Count} parsed"); var markerFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.DetailEmitFilter.DetailFilter, new StmtDetailQuery(marker))); var nullFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.DetailEmitFilter.DetailFilter, new StmtDetailQuery(""))); var nmFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.DetailEmitFilter.DetailFilter, new UnionQueries <IDetailQueryAtom>( new StmtDetailQuery(""), new StmtDetailQuery(marker)))); RunUnmark(markerFilt, sb); RunMark(nullFilt, parsed, marker, sb); RunCheck(nmFilt, parsed, sb); } return(new PlainText(sb.ToString())); }
/// <inheritdoc /> public override async IAsyncEnumerable <string> Execute(string expr, Session session) { var csv = expr; expr = ParsingF.Line(ref csv); var parsed = new CsvParser(ParsingF.Optional(ref expr, "-")); if (ParsingF.Optional(ref expr, "mark")) { var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); yield return($"{parsed.Items.Count} parsed\n"); await foreach (var s in RunMark(session, filt, parsed, marker)) { yield return(s); } } else if (ParsingF.Optional(ref expr, "unmark")) { var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Eof(expr); await foreach (var s in RunUnmark(session, filt)) { yield return(s); } } else if (ParsingF.Optional(ref expr, "check")) { var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Eof(expr); parsed.Parse(csv); yield return($"{parsed.Items.Count} parsed\n"); await foreach (var s in RunCheck(session, filt, parsed)) { yield return(s); } } else { ParsingF.Optional(ref expr, "auto"); var filt = ParsingF.DetailQuery(ref expr, session.Client); ParsingF.Optional(ref expr, "as"); var marker = ParsingF.Token(ref expr); ParsingF.Eof(expr); if (string.IsNullOrWhiteSpace(marker)) { throw new FormatException("格式错误"); } parsed.Parse(csv); yield return($"{parsed.Items.Count} parsed\n"); var markerFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.ActualDetailFilter(), new StmtDetailQuery(marker))); var nullFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.ActualDetailFilter(), new StmtDetailQuery(""))); var nmFilt = new StmtVoucherDetailQuery( filt.VoucherQuery, new IntersectQueries <IDetailQueryAtom>( filt.ActualDetailFilter(), new UnionQueries <IDetailQueryAtom>( new StmtDetailQuery(""), new StmtDetailQuery(marker)))); await foreach (var s in RunUnmark(session, markerFilt)) { yield return(s); } await foreach (var s in RunMark(session, nullFilt, parsed, marker)) { yield return(s); } await foreach (var s in RunCheck(session, nmFilt, parsed)) { yield return(s); } } }