public IndexAccessUnit( IValueGetter arg, Token firstToken) { this.arg = arg; FirstToken = firstToken; }
public INumberMatch Initialize( IValueGetter valueGetter, CompareOperation compareOperation, int match, bool inverted = false, int defaultValue = 0) { _match = match; _valueGetter = valueGetter; _compareOperation = compareOperation; _inverted = inverted; _defaultValue = defaultValue; switch (compareOperation) { case CompareOperation.Equals: _testFunc = (ruleResult, number) => number == _match; break; case CompareOperation.Less: _testFunc = (ruleResult, number) => number < _match; break; case CompareOperation.Greater: _testFunc = (ruleResult, number) => number > _match; break; default: throw new Exception("Number match does not know how to compare numbers using " + compareOperation); } return(this); }
public void Initialize() { _request1 = new MockRequestInfo("/path1/path2?param=value", "http", "test.com", 80); _request2 = new MockRequestInfo("/path1/path2", "https", "secure.test.com", 443); _request3 = new MockRequestInfo("/path1/path2/", "http", "test.com", 80); _request1.NewPath[1] = "changed1"; _request1.NewParameters["param"] = new List <string> { "changed" }; _request1.PathChanged(); _request1.SetServerVariable("PATH_INFO", "/company/news/"); _request1.SetHeader("HOST", "www.mysite.com"); _request2.NewPath[2] = "changed2"; _request2.PathChanged(); _request2.SetServerVariable("SERVER_PORT", "443"); _request2.SetHeader("USER_AGENT", "blah blah blah"); _request3.NewUrlString = "/changed1/changed2/"; _request3.NewParameters["param"] = new List <string> { "added" }; _request3.ParametersChanged(); IFactory factory = new NinjectFactory(); _valueGetter = factory.Create <IValueGetter>(); _ruleResult = factory.Create <IRuleResult>(); }
public static IExpression CreateNegationOperation( IValueGetter arg, Token source) { Type argType = arg.GetValueType(); if (!(argType == typeof(double) || argType == typeof(int))) { throw new ScriptParsingException( source: source, message: $"Cannot negate a non-numerical value {arg} of type {argType.Name}"); } if (arg is LiteralToken litArg) { if (argType == typeof(int)) { return(new LiteralToken <int>(source, -litArg.GetAs <int>())); } else { return(new LiteralToken <double>(source, -litArg.GetAs <double>())); } } return(new NegationOperation(arg, argType)); }
public static IValueGetter[] ParseItems( IEnumerator <Token> tokens, Type itemType, CompilationContext context) { List <IValueGetter> items = new List <IValueGetter>(); tokens.AssertAndSkip(Separator.OpenCurlyBoi); if (!tokens.TestWithoutSkipping(Separator.CloseCurlyBoi)) { do { Token temp = tokens.Current; IValueGetter nextValue = ParseNextGetterExpression(tokens, context); if (!itemType.AssignableFromType(nextValue.GetValueType())) { throw new ScriptParsingException( source: temp, message: $"Initializer List Argument must be of appropriate value type: Expected: {itemType.Name}, Found: {nextValue.GetValueType().Name}"); } items.Add(nextValue); }while (tokens.TestAndConditionallySkip(Separator.Comma)); } tokens.AssertAndSkip(Separator.CloseCurlyBoi); return(items.ToArray()); }
public static IExpression CreateCastOperation( IValueGetter arg, OperatorToken operatorToken) { Type argType = arg.GetValueType(); if (!(argType == typeof(double) || argType == typeof(int))) { throw new ScriptParsingException( source: operatorToken, message: $"Argument of operator {operatorToken.operatorType} is not numerical: type {argType.Name}."); } if (arg is LiteralToken litArg) { switch (operatorToken.operatorType) { case Operator.CastDouble: return(new LiteralToken <double>(operatorToken, litArg.GetAs <double>())); case Operator.CastInteger: return(new LiteralToken <int>(operatorToken, (int)litArg.GetAs <double>())); default: throw new ArgumentException($"Unexpected Operator: {operatorToken.operatorType}"); } } return(new CastOperation(arg, operatorToken.operatorType)); }
private ConcatenateOperator( IValueGetter arg1, IValueGetter arg2) { this.arg1 = arg1; this.arg2 = arg2; }
private static void ReducePreOperator(Operator op, List <ParsingUnit> units) { for (int i = 0; i < units.Count; i++) { if (units[i].OperatorType == op) { if (i == units.Count - 1) { throw new ScriptParsingException( source: units[i].FirstToken, message: $"Unable to parse PreOperator {op}: No following value"); } if (units[i + 1].AsValueGetter == null) { throw new ScriptParsingException( source: units[i + 1].FirstToken, message: $"Unable to parse PreOperator {op}: Following value is not value not retrievable: {units[i + 1].FirstToken}"); } //Cache Value and remove IValueGetter value = units[i + 1].AsValueGetter; units.RemoveAt(i + 1); OperatorToken operatorToken = units[i].FirstToken as OperatorToken; //Swap the ParsingUnit for the calculated value switch (op) { case Operator.CastInteger: case Operator.CastDouble: units[i] = new ParsedValuedUnit( value: CastOperation.CreateCastOperation( arg: value, operatorToken: operatorToken), firstToken: units[i].FirstToken); break; case Operator.Negate: units[i] = new ParsedValuedUnit( value: NegationOperation.CreateNegationOperation( arg: value, source: operatorToken), firstToken: units[i].FirstToken); break; case Operator.Not: units[i] = new ParsedValuedUnit( value: NotOperation.CreateNotOperation( arg: value, operatorToken: operatorToken), firstToken: units[i].FirstToken); break; default: throw new ArgumentException($"Unexpected Operator: {op}"); } } } }
private BinaryNumericalOperation( IValueGetter arg1, IValueGetter arg2, Type valueType, Operator operatorType) { this.arg1 = arg1; this.arg2 = arg2; this.valueType = valueType; this.operatorType = operatorType; switch (this.operatorType) { case Operator.Plus: case Operator.Minus: case Operator.Times: case Operator.Divide: case Operator.Power: case Operator.Modulo: //Acceptable break; default: throw new ArgumentException($"Unexpected Operator {this.operatorType}"); } }
public bool Equals(PropertyChain other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (_chain.Length != other._chain.Length) { return(false); } for (int i = 0; i < _chain.Length; i++) { IValueGetter info = _chain[i]; IValueGetter otherInfo = other._chain[i]; if (!info.Equals(otherInfo)) { return(false); } } return(_innerProperty.Equals(other._innerProperty)); }
public BooleanInPlaceOperation( IValue assignee, IValueGetter value, Operator operatorType, Token source) { if (assignee.GetValueType() != typeof(bool)) { throw new ScriptParsingException( source: source, message: $"Left Argument {assignee} of Operator {source} is not a bool: type {assignee.GetValueType().Name}"); } if (value.GetValueType() != typeof(bool)) { throw new ScriptParsingException( source: source, message: $"Right Argument {value} of Operator {source} is not a bool."); } this.assignee = assignee; this.value = value; this.operatorType = operatorType; switch (operatorType) { case Operator.AndEquals: case Operator.OrEquals: //Acceptable break; default: throw new ArgumentException($"Unexpected Operator: {operatorType}"); } }
public static IExpression CreateBinaryBoolOperator( IValueGetter arg1, IValueGetter arg2, OperatorToken operatorToken) { if (arg1.GetValueType() != typeof(bool)) { throw new ScriptParsingException( source: operatorToken, message: $"Left side of operator {operatorToken.operatorType} not of expected type bool: {arg1.GetValueType().Name}"); } if (arg2.GetValueType() != typeof(bool)) { throw new ScriptParsingException( source: operatorToken, message: $"Right side of operator {operatorToken.operatorType} not of expected type bool: {arg2.GetValueType().Name}"); } //Constant case if (arg1 is LiteralToken litArg1 && arg2 is LiteralToken litArg2) { switch (operatorToken.operatorType) { case Operator.And: return(new LiteralToken <bool>(operatorToken, litArg1.GetAs <bool>() && litArg2.GetAs <bool>())); case Operator.Or: return(new LiteralToken <bool>(operatorToken, litArg1.GetAs <bool>() || litArg2.GetAs <bool>())); default: throw new ArgumentException($"Unexpected Operator {operatorToken.operatorType}"); } } return(new BinaryBoolOperation(arg1, arg2, operatorToken.operatorType)); }
public ForEachStatement( IExecutable declarationStatement, IValue loopVariable, IValueGetter containerExpression, IExecutable loopBody, KeywordToken keywordToken) { if (!typeof(IEnumerable).IsAssignableFrom(containerExpression.GetValueType())) { throw new ScriptParsingException( source: keywordToken, message: $"Collection of ForEach statement is not an Enumerable collection: {containerExpression.GetValueType().Name}"); } if (!loopVariable.GetValueType().AssignableFromType(containerExpression.GetValueType().GetGenericArguments()[0])) { throw new ScriptParsingException( source: keywordToken, message: $"Collection items of type " + $"({containerExpression.GetValueType().GetGenericArguments()[0].Name}) " + $"not assignable to declared item type: {loopVariable.GetValueType().Name}"); } this.loopVariable = loopVariable; this.declarationStatement = declarationStatement; this.containerExpression = containerExpression; this.loopBody = loopBody; }
private NegationOperation( IValueGetter arg, Type valueType) { this.arg = arg; this.valueType = valueType; }
private ICondition ParseConditionsAddElement(XElement element, ParserContext context) { IValueGetter valueGetter = null; var defaultScope = Scope.Url; // only applies when there is no "input" attribute var compareOperation = CompareOperation.MatchRegex; var inverted = false; var ignoreCase = true; var text = ".*"; var isFileMatch = false; var isDirectoryMatch = false; if (element.HasAttributes) { foreach (var attribute in element.Attributes()) { switch (attribute.Name.LocalName.ToLower()) { case "input": valueGetter = ParseTextWithMacros(attribute.Value, context); break; case "matchtype": defaultScope = Scope.Path; if (attribute.Value.ToLower() == "isfile") { isFileMatch = true; } else if (attribute.Value.ToLower() == "isdirectory") { isDirectoryMatch = true; } break; case "pattern": text = attribute.Value; break; case "negate": inverted = attribute.Value.ToLower() == "true"; break; case "ignorecase": ignoreCase = attribute.Value.ToLower() == "true"; break; } } } if (valueGetter == null) { valueGetter = ConstructValueGetter(defaultScope); } if (isFileMatch || isDirectoryMatch) { return(_factory.Create <IStaticFileMatch>().Initialize(valueGetter, isDirectoryMatch, inverted)); } return(_factory.Create <IStringMatch>().Initialize(valueGetter, compareOperation, text, inverted, ignoreCase)); }
public MemberDeclaration( IdentifierToken identifierToken, Type valueType, IValueGetter initializer, CompilationContext context) : base(identifierToken, valueType, initializer, context) { }
/// <inheritdoc/> public IPropertyItem AddEntry(string virtualPropertyName, IValueGetter getter, IValueSetter setter, IEqualityComparer comparer) { DefaultPropertyItem item = new DefaultPropertyItem(getter, setter, comparer); internalMap[virtualPropertyName] = item; return(item); }
private DeclarationAssignmentOperation( string identifier, Type valueType, IValueGetter initializer) { this.identifier = identifier; this.valueType = valueType; this.initializer = initializer; }
public IValueGetter Initialize(IValueGetter value, IOperation operation) { _values = new List <IValueGetter> { value }; _separator = null; _operation = operation; return(this); }
public CastingPropertyValueOperation( IValueGetter value, Type outputType, Func <object, object> operation) { this.value = value; this.outputType = outputType; this.operation = operation; }
public CastingMemberValueExecutableOperation( IValueGetter value, Type outputType, Func <object, object> operation) { this.value = value; this.outputType = outputType; this.operation = operation; }
public static IExpression CreateEqualityComparisonOperator( IValueGetter arg1, IValueGetter arg2, OperatorToken operatorToken) { Type argType; Type arg1Type = arg1.GetValueType(); Type arg2Type = arg2.GetValueType(); if (arg1Type == arg2Type) { argType = arg1Type; } else if (arg1Type.AssignableFromType(arg2Type)) { argType = arg1Type; } else if (arg2Type.AssignableFromType(arg1Type)) { argType = arg2Type; } else { throw new ScriptParsingException( source: operatorToken, message: $"Incompatible Types for {operatorToken.operatorType} operator: {arg1Type.Name} and {arg2Type.Name}"); } //Constant case if (arg1 is LiteralToken litArg1 && arg2 is LiteralToken litArg2) { object value1 = litArg1.GetAs <object>(); object value2 = litArg2.GetAs <object>(); if (argType != arg1Type) { value1 = Convert.ChangeType(value1, argType); } if (argType != arg2Type) { value2 = Convert.ChangeType(value2, argType); } switch (operatorToken.operatorType) { case Operator.IsEqualTo: return(new LiteralToken <bool>(operatorToken, value1.Equals(value2))); case Operator.IsNotEqualTo: return(new LiteralToken <bool>(operatorToken, !value1.Equals(value2))); default: throw new ArgumentException($"Unexpected Operator: {operatorToken.operatorType}"); } } return(new EqualityCompairsonOperation(arg1, arg2, argType, operatorToken.operatorType)); }
public IReplaceAction Initialize(Scope scope, string scopeIndex, IValueGetter valueGetter) { _scope = scope; _scopeIndex = scopeIndex; _valueGetter = valueGetter; if (string.IsNullOrEmpty(scopeIndex)) { switch (scope) { case Scope.Header: throw new Exception("When replacing the request headers you must specify the name of the header to replace"); case Scope.ServerVariable: throw new Exception("When replacing server variables you must specify the name of the server variable to replace"); case Scope.Parameter: _scope = Scope.QueryString; break; case Scope.PathElement: _scope = Scope.Path; break; } } else { if (int.TryParse(scopeIndex, out _scopeIndexValue)) { if (_scopeIndexValue == 0) { if (scope == Scope.PathElement) { _scope = Scope.Path; } else if (scope == Scope.HostElement) { _scope = Scope.Host; } } } else { if (scope == Scope.PathElement) { _scope = Scope.Path; } else if (scope == Scope.HostElement) { _scope = Scope.Host; } } } return(this); }
public MonitorBounds(string path, Func <object> getInstance, IValueGetter valueGetter) : base(path, getInstance) { Func <object> subGetInstance = () => valueGetter.GetValue <Bounds>(getInstance()); this.children = new List <MonitorData>(2) { new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + "extents", subGetInstance, valueGetter.Type.GetProperty("extents")), new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + "center", subGetInstance, valueGetter.Type.GetProperty("center")) }; }
public static IValueGetter GetPropertyGetter(PropertyInfo propertyInfo) { if (!m_GetterDict.ContainsKey(propertyInfo)){ IValueGetter getter = CreatePropertyGetter(propertyInfo); m_GetterDict.Add(propertyInfo, getter); return getter; } return m_GetterDict[propertyInfo]; }
public IStaticFileMatch Initialize( IValueGetter valueGetter, bool isDirectory, bool inverted = false) { _valueGetter = valueGetter; _inverted = inverted; _isDirectory = isDirectory; _testFunc = isDirectory ? (Func <string, bool>)IsDirectory : IsStaticFile; return(this); }
public ICondition ConstructCondition(string name, XElement configuration, IValueGetter valueGetter) { Type type; if (_conditions.TryGetValue(name, out type)) { var condition = _factory.Create(type) as ICondition; condition?.Initialize(configuration, valueGetter); return(condition); } return(null); }
public MonitorRect(string path, Func <object> getInstance, IValueGetter valueGetter) : base(path, getInstance) { Func <object> subGetInstance = () => valueGetter.GetValue <Rect>(getInstance()); this.children = new List <MonitorData>(4) { new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + 'x', subGetInstance, valueGetter.Type.GetProperty("x")), new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + 'y', subGetInstance, valueGetter.Type.GetProperty("y")), new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + "width", subGetInstance, valueGetter.Type.GetProperty("width")), new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + "height", subGetInstance, valueGetter.Type.GetProperty("height")) }; }
public MonitorQuaternion(string path, Func <object> getInstance, IValueGetter valueGetter) : base(path, getInstance) { Func <object> subGetInstance = () => valueGetter.GetValue <Quaternion>(getInstance()); this.children = new List <MonitorData>(4) { new MonitorField(this.path + NGServerScene.ValuePathSeparator + 'x', subGetInstance, valueGetter.Type.GetField("x")), new MonitorField(this.path + NGServerScene.ValuePathSeparator + 'y', subGetInstance, valueGetter.Type.GetField("y")), new MonitorField(this.path + NGServerScene.ValuePathSeparator + 'z', subGetInstance, valueGetter.Type.GetField("z")), new MonitorField(this.path + NGServerScene.ValuePathSeparator + 'w', subGetInstance, valueGetter.Type.GetField("w")) }; }
public IsNaNMathFunction( IValueGetter arg, Token source) { if (!(arg.GetValueType() == typeof(double) || arg.GetValueType() == typeof(int))) { throw new ScriptParsingException( source: source, message: $"Argument of IsNaN is not numerical: type {arg.GetValueType().Name}"); } this.arg = arg; }