/// <summary> /// 执行表达式 /// </summary> /// <param name="expr">表达式</param> /// <param name="spec">表示器代号</param> /// <returns>执行结果</returns> public IQueryResult Execute(string expr, string spec) { switch (expr) { case "T": return(ListTitles()); case "?": return(ListHelp()); case "reload": return(new NumberAffected(MetaConfigManager.ReloadAll())); case "die": Environment.Exit(0); break; } return(m_Composer.Execute(expr, GetSerializer(spec))); }
protected DistributedShell(Accountant helper) { Accountant = helper; var resetComopser = new ShellComposer { new ShellComponent( "soft", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); var rng = Parsing.Range(ref expr) ?? DateFilter.Unconstrained; Parsing.Eof(expr); return(ExecuteResetSoft(dist, rng)); }), new ShellComponent( "mixed", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); var rng = Parsing.Range(ref expr) ?? DateFilter.Unconstrained; Parsing.Eof(expr); return(ExcuteResetMixed(dist, rng)); }), new ShellComponent( "hard", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); var vouchers = Parsing.OptColVouchers(ref expr); Parsing.Eof(expr); return(ExecuteResetHard(dist, vouchers)); }) }; m_Composer = new ShellComposer { new ShellComponent( "all", (expr, serializer) => { var safe = Parsing.Token(ref expr, false, t => t == "unsafe") == null; var dist = Parsing.DistributedQuery(ref expr); Parsing.Eof(expr); if (dist.IsDangerous() && safe) { throw new SecurityException("检测到弱检索式"); } return(ExecuteList(dist, null, false, serializer)); }), new ShellComponent( "li", (expr, serializer) => { var safe = Parsing.Token(ref expr, false, t => t == "unsafe") == null; var dt = Parsing.UniqueTime(ref expr) ?? ClientDateTime.Today; var dist = Parsing.DistributedQuery(ref expr); Parsing.Eof(expr); if (dist.IsDangerous() && safe) { throw new SecurityException("检测到弱检索式"); } return(ExecuteList(dist, dt, true, serializer)); }), new ShellComponent( "q", (expr, serializer) => { var safe = Parsing.Token(ref expr, false, t => t == "unsafe") == null; var dist = Parsing.DistributedQuery(ref expr); Parsing.Eof(expr); if (dist.IsDangerous() && safe) { throw new SecurityException("检测到弱检索式"); } return(ExecuteQuery(dist, serializer)); }), new ShellComponent( "reg", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); var rng = Parsing.Range(ref expr) ?? DateFilter.Unconstrained; var vouchers = Parsing.OptColVouchers(ref expr); Parsing.Eof(expr); return(ExecuteRegister(dist, rng, vouchers, serializer)); }), new ShellComponent( "unreg", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); var rng = Parsing.Range(ref expr) ?? DateFilter.Unconstrained; var vouchers = Parsing.OptColVouchers(ref expr); Parsing.Eof(expr); return(ExecuteUnregister(dist, rng, vouchers, serializer)); }), new ShellComponent( "recal", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); Parsing.Eof(expr); return(ExecuteRecal(dist, serializer)); }), new ShellComponent("rst", (expr, serializer) => resetComopser.Execute(expr, serializer)), new ShellComponent( "ap", (expr, serializer) => { var collapse = Parsing.Optional(ref expr, "col"); var dist = Parsing.DistributedQuery(ref expr); var rng = Parsing.Range(ref expr) ?? DateFilter.Unconstrained; Parsing.Eof(expr); return(ExecuteApply(dist, rng, collapse)); }), new ShellComponent( "chk", (expr, serializer) => { var dist = Parsing.DistributedQuery(ref expr); Parsing.Eof(expr); return(ExecuteCheck(dist, new DateFilter(null, ClientDateTime.Today), serializer)); }), new ShellComponent( null, (expr, serializer) => { var dt = Parsing.UniqueTime(ref expr) ?? ClientDateTime.Today; var dist = Parsing.DistributedQuery(ref expr); Parsing.Eof(expr); return(ExecuteList(dist, dt, false, serializer)); }) }; }