// TODO: It is temporary solution in CC phase. In near future, I will make a general approach // to address localization of enum members. private string GetOperatorDisplayName(MatchOperator operator_) { string result = null; switch (operator_) { case MatchOperator.Equals: result = Properties.Resources.Equal; break; case MatchOperator.GreaterThan: result = Properties.Resources.GreaterThan; break; case MatchOperator.GreaterThanOrEqual: result = Properties.Resources.GreaterThanOrEqual; break; case MatchOperator.LessThan: result = Properties.Resources.LessThan; break; case MatchOperator.LessThanOrEqual: result = Properties.Resources.LessThanOrEqual; break; case MatchOperator.NotEqual: result = Properties.Resources.NotEqual; break; } return(result); }
private ErrorQueueConsumerSetting(MatchOperator mo, int rc, int delayInSeconds, IErrorQueueProcessingStrategy eqps) { MatchOperator = mo; RetryCount = rc; ErrorQueueProcessingStrategy = eqps; DelayInSeconds = delayInSeconds; }
IEnumerable <int> FindStaticsOld(HashSet <int> objects, MatchOperator oper) { for (var cellindex = 0; cellindex < _level.Length; ++cellindex) { if (objects.Count == 0) { yield return(cellindex); } else if (oper == MatchOperator.All) { if (objects.All(o => _level[cellindex, _gamedef.GetLayer(o)] == o)) { yield return(cellindex); } } else { var found = objects.Any(o => _level[cellindex, _gamedef.GetLayer(o)] == o); if (found == (oper != MatchOperator.No)) { yield return(cellindex); } } } }
// find object in level using object map IEnumerable <int> FindStatics(HashSet <int> objects, MatchOperator oper) { for (var cellindex = 0; cellindex < _level.Length; ++cellindex) { if (objects.Count == 0) { yield return(cellindex); } else if (oper == MatchOperator.All) { if (_objectmap[cellindex].IsSupersetOf(objects)) { yield return(cellindex); } } else // Any or No { var found = _objectmap[cellindex].Overlaps(objects); if (found == (oper != MatchOperator.No)) { yield return(cellindex); } } } }
internal void AddWinCondition(MatchOperator action, IList <int> objects, IList <int> others, ScriptFunctionCall call) { WinConditions.Add(new WinCondition { testKind = action, objectIds = objects, otherObjectIds = others, functionCall = call, }); }
public override AlgebraOperatorResult Run(IModelMap inMap, IEnumerable <ProjectArgument> inAttributesToProject = null) { RuleMap = inMap; MatchOperator MatchOp = new MatchOperator(LogicalExpression.ToExpr()); return(new AlgebraOperatorResult(new List <MongoDBOperator>() { MatchOp })); }
// Find object in level, moving or not bool IsInLevel(int cellindex, HashSet <int> objects, MatchOperator oper) { if (oper == MatchOperator.All) { return(_objectmap[cellindex].IsSupersetOf(objects)); } var found = _objectmap[cellindex].Overlaps(objects); return(found == (oper != MatchOperator.No)); }
public void RegisterStrategy(MatchOperator mo, int rc, int delayInSeconds, string errorQueueProcessingStrategyType, Dictionary <string, string> plugin_settings) { var newItem = new ErrorQueueConsumerSetting(mo, rc, delayInSeconds, errorQueueProcessingStrategyType); newItem.ErrorQueueProcessingStrategy.Init(plugin_settings); settings.Add(newItem); }
// Test locations for moving objects internal bool OpTestOMN(HashSet <int> objectids, Direction direction, MatchOperator oper) { foreach (var trail in _vm_trail.GetLeaves()) { if (!_levelstate.IsMatch(trail.Location, objectids, direction, oper)) { _vm_trail.RemoveLeaf(trail); } } return(_vm_trail.IsEmpty); }
// Test locations for moving objects using offset into path internal bool OpTestXMN(int trailvar, Direction direction, MatchOperator oper) { foreach (var trail in _vm_trail.GetLeaves()) { var objids = trail.GetRef(~trailvar); if (!_levelstate.IsMatch(trail.Location, new HashSet <int>(objids), direction, oper)) { _vm_trail.RemoveLeaf(trail); } } return(_vm_trail.IsEmpty); }
// return cellindex list with objects that are moving this way internal IList <int> FindMatches(HashSet <int> objects, Direction direction, MatchOperator oper) { if (direction == Direction.None) { return(FindStatics(objects, oper).ToList()); } if (direction == Direction.Stationary) { return(FindStatics(objects, oper) .Where(x => !_movers.Any(m => m.CellIndex == x && objects.Contains(m.ObjectId))) .ToList()); } return(FindMovers(objects, direction, oper).ToList()); }
public void Test_MatchQuery_MatchOperator(MatchOperator matchOperator) { var request = new SearchRequest { Index = "idx_travel", Query = new MatchQuery("inn").MatchOperator(matchOperator) }; var result = request.ToJson(); var json = new JObject(new JProperty("ctl", new JObject()), new JProperty("query", new JObject(new JProperty("match", "inn"), new JProperty("prefix_length", 0), new JProperty("fuzziness", 0), new JProperty("operator", matchOperator.GetDescription())))); var expected = JsonConvert.SerializeObject(json, Formatting.None); Assert.Equal(expected, result); }
/// <summary> /// Generate stage code /// </summary> /// <returns></returns> public override AlgebraOperatorResult Run(IModelMap inMap, IEnumerable <ProjectArgument> inAttributesToProject = null) { RuleMap = inMap; MatchOperator MatchOp; if (UseSimplerMatch) { MatchOp = new MatchOperator(KeyPairs); } else { MatchOp = new MatchOperator(new Expr(Argument.Expression)); } return(new AlgebraOperatorResult(new List <MongoDBOperator>() { MatchOp })); }
IEnumerable <int> FindMovers(HashSet <int> objects, Direction direction, MatchOperator oper) { if (!(oper == MatchOperator.Any || oper == MatchOperator.All)) { throw Error.Assert("oper {0}", oper); } if (!(direction == Direction.Moving || GameDef.MoveDirections.Contains(direction))) { throw Error.Assert("dir {0}", direction); } var moves = _movers .Where(m => direction == Direction.Moving || direction == m.Direction) .OrderBy(m => m.CellIndex); if (oper == MatchOperator.Any) { foreach (var move in moves) { if (objects.Contains(move.ObjectId)) { yield return(move.CellIndex); } } } else { foreach (var move in moves) { if (objects.Contains(move.ObjectId)) { if (objects .All(o => moves .Any(m => m.ObjectId == move.ObjectId && m.CellIndex == move.CellIndex))) { yield return(move.CellIndex); } } } } }
// Return true if any locations contain objects moving any of these ways // if found add this location to every trail (usually just the root) internal bool OpFindOM(HashSet <int> objectids, Direction direction, MatchOperator oper) { var matches = _levelstate.FindMatches(objectids, direction, oper).ToList(); if (matches.Count == 0) { _vm_trail = new Trail(); // Hmmm. Maybe clear all is better? } //_trail.Clear(); else { // combinatorially add match to all trails foreach (var trail in _vm_trail.GetLeaves()) { foreach (var match in matches) { _vm_trail.Add(trail, match); } } } return(_vm_trail.IsEmpty); }
private static string MatchOperatorTranslateItem(ActivityTranslator translator, ModelItem item) { object obj = item.GetCurrentValue(); Debug.Assert(obj is MatchOperator); MatchOperator operator_ = (MatchOperator)obj; string result = null; switch (operator_) { case MatchOperator.Equals: result = Autodesk.IM.UI.Rule.Properties.Resources.Equal; break; case MatchOperator.GreaterThan: result = Autodesk.IM.UI.Rule.Properties.Resources.GreaterThan; break; case MatchOperator.GreaterThanOrEqual: result = Autodesk.IM.UI.Rule.Properties.Resources.GreaterThanOrEqual; break; case MatchOperator.LessThan: result = Autodesk.IM.UI.Rule.Properties.Resources.LessThan; break; case MatchOperator.LessThanOrEqual: result = Autodesk.IM.UI.Rule.Properties.Resources.LessThanOrEqual; break; case MatchOperator.NotEqual: result = Autodesk.IM.UI.Rule.Properties.Resources.NotEqual; break; } return(result); }
private static ExpTreeNode GetAsExpressionTree(this ParseTreeNode parsedNode, ExpTreeNode parentExpNode) { //The current node is a variable / value token. Create a value node and return it back if (!parsedNode.ChildNodes.Any()) { switch (parsedNode.Term.Name) { case "variable": { var varName = parsedNode.FindTokenAndGetValue <string>(); return(new VariableValue(varName, parentExpNode)); } case "boolean": return(new LiteralValue(parsedNode.FindTokenAndGetValue <bool>(), parentExpNode)); case "integer": case "decimal": return(new LiteralValue(parsedNode.FindTokenAndGetValue <double>(), parentExpNode)); case "SingleQuoteString": case "DoubleQuoteString": return(new LiteralValue(parsedNode.FindTokenAndGetValue <string>(), parentExpNode)); default: throw parsedNode.GetException($"Invalid token type '{parsedNode.Term.Name}' in expression"); } } // Look on the next node down else if (parsedNode.ChildNodes.Count == 1) { return(GetAsExpressionTree(parsedNode.ChildNodes[0], parentExpNode)); } //Ignore parenthesis, the middle non-terminal is what we want // Look on the next node down else if (parsedNode.ChildNodes.Count == 3 && parsedNode.ChildNodes[0]?.Token?.Text == "(") { return(GetAsExpressionTree(parsedNode.ChildNodes[1], parentExpNode)); } //Binary operator else if (parsedNode.ChildNodes.Count == 3) { BinaryOperatorBase binaryOp; var opStr = parsedNode.ChildNodes[1].FindToken().ValueString; switch (opStr) { // Math case "+": binaryOp = new AdditionOperator(parentExpNode); break; case "-": binaryOp = new SubtractionOperator(parentExpNode); break; case "*": binaryOp = new MultiplacationOperator(parentExpNode); break; case "/": binaryOp = new DivisionOperator(parentExpNode); break; case "%": binaryOp = new ModulusOperator(parentExpNode); break; case "^": binaryOp = new PowerOperator(parentExpNode); break; // Bool case "~==": binaryOp = new LooseEqualsOperator(parentExpNode); break; case "~!=": binaryOp = new LooseNotEqualsOperator(parentExpNode); break; case "==": binaryOp = new EqualsOperator(parentExpNode); break; case "!=": binaryOp = new NotEqualsOperator(parentExpNode); break; case "like": binaryOp = new LikeOperator(parentExpNode); break; case "match": binaryOp = new MatchOperator(parentExpNode); break; case ">": binaryOp = new GreaterThanOperator(parentExpNode); break; case ">=": binaryOp = new GreaterThanOrEqualOperator(parentExpNode); break; case "<": binaryOp = new LessThanOperator(parentExpNode); break; case "<=": binaryOp = new LessThanOrEqualOperator(parentExpNode); break; case "&&": binaryOp = new AndOperator(parentExpNode); break; case "||": binaryOp = new OrOperator(parentExpNode); break; default: throw parsedNode.ChildNodes[1].GetException($"Unrecognized operator '{opStr}'"); } binaryOp.LeftOperand = GetAsExpressionTree(parsedNode.ChildNodes[0], binaryOp); binaryOp.RightOperand = GetAsExpressionTree(parsedNode.ChildNodes[2], binaryOp); //Optimize if (binaryOp.LeftOperand is LiteralValue && binaryOp.RightOperand is LiteralValue) { return(new LiteralValue(binaryOp.Eval(), parentExpNode)); } return(binaryOp); } // Unary operator else if (parsedNode.ChildNodes.Count == 2) { var opVal = parsedNode.ChildNodes[0].FindToken().Value; UnaryOperatorBase unaryOp; if (parsedNode.ChildNodes[0].FindToken().Value is TypeCode convertType) { unaryOp = new TypeConversionOperator(convertType, parentExpNode); } else { var opStr = opVal.ToString(); switch (opStr) { case "!": unaryOp = new NotOperator(parentExpNode); break; //Property Checking case "lengthof": unaryOp = new LengthOperator(parentExpNode); break; case "typeof": unaryOp = new TypeOperator(parentExpNode); break; default: unaryOp = new GenericUnaryMathFunctionOperator(opStr, parentExpNode); break; } } unaryOp.Operand = GetAsExpressionTree(parsedNode.ChildNodes[1], unaryOp); //Optimize if (unaryOp.Operand is LiteralValue) { return(new LiteralValue(unaryOp.Eval(), parentExpNode)); } return(unaryOp); } else { throw parsedNode.GetException($"Invalid number of tokens ({parsedNode.ChildNodes.Count})"); } }
internal void Emit(MatchOperator oper) { _gcode.Add((int)oper); }
// Test for moving objects, stepping in given direction internal bool OpScanOMDN(HashSet <int> objectids, Direction step, Direction direction, MatchOperator oper) { foreach (var trail in _vm_trail.GetLeaves()) { var mark = _vm_trail.NodeCount; for (var newindex = trail.Location; newindex != -1; newindex = _levelstate.Step(newindex, step) ?? -1) { if (_levelstate.IsMatch(newindex, objectids, direction, oper)) { _vm_trail.Add(trail, newindex); } } if (mark == _vm_trail.NodeCount) // nothing added, give up on this trail { _vm_trail.RemoveLeaf(trail); } } return(_vm_trail.IsEmpty); }
// Test for matching objects, stepping in given direction internal bool OpScanODN(HashSet <int> objectids, Direction step, MatchOperator oper) { return(OpScanOMDN(objectids, step, Direction.None, oper)); }
// check for matching object, return true on failure to abort internal bool OpCheckOMN(HashSet <int> objectids, Direction direction, MatchOperator oper) { var cellindex = _vm_matchpath[_vm_pathindex]; return(!_levelstate.IsMatch(cellindex, objectids, direction, oper)); }
public MatchQuery MatchOperator(MatchOperator matchOperator) { _matchOperator = matchOperator; return(this); }
public ErrorQueueConsumerSetting(MatchOperator mo, int rc, int delayInSeconds, string errorQueueProcessingStrategyType) : this(mo, rc, delayInSeconds, findStrategyByName(errorQueueProcessingStrategyType)) { StrategyClassName = errorQueueProcessingStrategyType; }
// test whether there is a matching object at this location // direction can be specified, None for ignore or Stationary for not moving // oper is No, All or Any internal bool IsMatch(int cellindex, HashSet <int> objects, Direction direction, MatchOperator oper) { // no objects matches no objects (ignore direction and operator) if (objects.Count == 0) { return(true); // don't care } var found = IsInLevel(cellindex, objects, oper); if (found && direction != Direction.None) { found = IsMover(cellindex, objects, direction); } return(found); }