private bool IsAuthorized(ref ScriptNode Node, object State) { if (State is IUser User) { return(User.HasPrivilege(Node.GetType().FullName)); } else { return(false); } }
protected override void DefaultVisit(ScriptNode node) { bool isTerminal = (node is IScriptTerminal); string padding = new string(' ', deepCounter * 2); string value = node.ToString(); string type = node.GetType().Name; string offset = $" ({node.Span.Start.Offset} - {node.Span.End.Offset}) "; output.Append(padding + type + offset + (isTerminal ? $" [{value}]\n" : "\n")); deepCounter++; base.DefaultVisit(node); deepCounter--; }
private Filter Convert(ScriptNode Node, Variables Variables) { string FieldName; object Value; if (Node is And And) { return(new FilterAnd(this.Convert(And.LeftOperand, Variables), this.Convert(And.RightOperand, Variables))); } else if (Node is Or Or) { return(new FilterOr(this.Convert(Or.LeftOperand, Variables), this.Convert(Or.RightOperand, Variables))); } else if (Node is Operators.Dual.And And2) { return(new FilterAnd(this.Convert(And2.LeftOperand, Variables), this.Convert(And2.RightOperand, Variables))); } else if (Node is Operators.Dual.Or Or2) { return(new FilterOr(this.Convert(Or2.LeftOperand, Variables), this.Convert(Or2.RightOperand, Variables))); } else if (Node is Not Not) { return(new FilterNot(this.Convert(Not.Operand, Variables))); } else if (Node is EqualTo) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldEqualTo(FieldName, Value)); } else if (Node is NotEqualTo) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldNotEqualTo(FieldName, Value)); } else if (Node is LesserThan) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldLesserThan(FieldName, Value)); } else if (Node is GreaterThan) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldGreaterThan(FieldName, Value)); } else if (Node is LesserThanOrEqualTo) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldLesserOrEqualTo(FieldName, Value)); } else if (Node is GreaterThanOrEqualTo) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldGreaterOrEqualTo(FieldName, Value)); } else if (Node is Like) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterFieldLikeRegEx(FieldName, Value.ToString())); } else if (Node is NotLike) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); return(new FilterNot(new FilterFieldLikeRegEx(FieldName, Value.ToString()))); } else { throw new ScriptRuntimeException("Invalid operation for filters: " + Node.GetType().FullName, this); } }
private Filter Convert(ScriptNode Node, Variables Variables) { string FieldName; object Value; if (Node is null) { return(null); } else if (Node is And And) { return(new FilterAnd(this.Convert(And.LeftOperand, Variables), this.Convert(And.RightOperand, Variables))); } else if (Node is Or Or) { return(new FilterOr(this.Convert(Or.LeftOperand, Variables), this.Convert(Or.RightOperand, Variables))); } else if (Node is Operators.Dual.And And2) { return(new FilterAnd(this.Convert(And2.LeftOperand, Variables), this.Convert(And2.RightOperand, Variables))); } else if (Node is Operators.Dual.Or Or2) { return(new FilterOr(this.Convert(Or2.LeftOperand, Variables), this.Convert(Or2.RightOperand, Variables))); } else if (Node is Not Not) { return(new FilterNot(this.Convert(Not.Operand, Variables))); } else if (Node is EqualTo EQ) { this.CheckBinaryOperator(EQ, Variables, out FieldName, out Value); return(new FilterFieldEqualTo(FieldName, Value)); } else if (Node is NotEqualTo NEQ) { this.CheckBinaryOperator(NEQ, Variables, out FieldName, out Value); return(new FilterFieldNotEqualTo(FieldName, Value)); } else if (Node is LesserThan LT) { this.CheckBinaryOperator(LT, Variables, out FieldName, out Value); return(new FilterFieldLesserThan(FieldName, Value)); } else if (Node is GreaterThan GT) { this.CheckBinaryOperator(GT, Variables, out FieldName, out Value); return(new FilterFieldGreaterThan(FieldName, Value)); } else if (Node is LesserThanOrEqualTo LTE) { this.CheckBinaryOperator(LTE, Variables, out FieldName, out Value); return(new FilterFieldLesserOrEqualTo(FieldName, Value)); } else if (Node is GreaterThanOrEqualTo GTE) { this.CheckBinaryOperator(GTE, Variables, out FieldName, out Value); return(new FilterFieldGreaterOrEqualTo(FieldName, Value)); } else if (Node is Range Range) { this.CheckTernaryOperator(Range, Variables, out FieldName, out object Min, out object Max); Filter[] Filters = new Filter[2]; if (Range.LeftInclusive) { Filters[0] = new FilterFieldGreaterOrEqualTo(FieldName, Min); } else { Filters[0] = new FilterFieldGreaterThan(FieldName, Min); } if (Range.RightInclusive) { Filters[1] = new FilterFieldLesserOrEqualTo(FieldName, Max); } else { Filters[1] = new FilterFieldLesserThan(FieldName, Max); } return(new FilterAnd(Filters)); } else if (Node is Like) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); string RegEx = Database.WildcardToRegex(Value is string s ? s : Expression.ToString(Value), "*"); return(new FilterFieldLikeRegEx(FieldName, RegEx)); } else if (Node is NotLike) { this.CheckBinaryOperator((BinaryOperator)Node, Variables, out FieldName, out Value); string RegEx = Database.WildcardToRegex(Value is string s ? s : Expression.ToString(Value), "*"); return(new FilterNot(new FilterFieldLikeRegEx(FieldName, RegEx))); } else { throw new ScriptRuntimeException("Invalid operation for filters: " + Node.GetType().FullName, this); } }