public override Expression GetDeleteExpression(MappingEntity entity, Expression instance, LambdaExpression deleteCheck) { var tables = this.mapping.GetTables(entity); if (tables.Count < 2) { return(base.GetDeleteExpression(entity, instance, deleteCheck)); } var commands = new List <Expression>(); foreach (var table in this.GetDependencyOrderedTables(entity).Reverse()) { TableExpression tex = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table)); var where = this.GetIdentityCheck(tex, entity, instance); commands.Add(new DeleteCommand(tex, where)); } Expression block = new BlockCommand(commands); if (deleteCheck != null) { var test = this.GetEntityStateTest(entity, instance, deleteCheck); return(new IFCommand(test, block, null)); } return(block); }
public void ImplicitSelectorUsedInAggregateCondition() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("if any battery ratio < 0.75 turn on the generators"); Assert.IsTrue(command is ConditionalCommand); ConditionalCommand conditionalCommand = (ConditionalCommand)command; Assert.IsTrue(conditionalCommand.Condition is AggregateConditionVariable); AggregateConditionVariable condition = (AggregateConditionVariable)conditionalCommand.Condition; Assert.IsTrue(condition.entityProvider is AllEntityProvider); Assert.AreEqual(Block.BATTERY, condition.entityProvider.GetBlockType()); Assert.AreEqual(AggregationMode.ANY, condition.aggregationMode); Assert.IsTrue(condition.blockCondition is BlockPropertyCondition); BlockPropertyCondition propertyCondition = (BlockPropertyCondition)condition.blockCondition; Assert.AreEqual(Property.RATIO + "", propertyCondition.property.propertyType()); Assert.IsTrue(conditionalCommand.conditionMetCommand is BlockCommand); BlockCommand metCommand = (BlockCommand)conditionalCommand.conditionMetCommand; Assert.IsTrue(metCommand.entityProvider is AllEntityProvider); Assert.AreEqual(Block.GENERATOR, metCommand.entityProvider.GetBlockType()); }
public override Expression GetDeleteExpression(MappingEntity entity, Expression instance, LambdaExpression deleteCheck) { var tables = this.mapping.GetTables(entity); if (tables.Count < 2) { return base.GetDeleteExpression(entity, instance, deleteCheck); } var commands = new List<Expression>(); foreach (var table in this.GetDependencyOrderedTables(entity).Reverse()) { TableExpression tex = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table)); var where = this.GetIdentityCheck(tex, entity, instance); commands.Add(new DeleteCommand(tex, where)); } Expression block = new BlockCommand(commands); if (deleteCheck != null) { var test = this.GetEntityStateTest(entity, instance, deleteCheck); return new IFCommand(test, block, null); } return block; }
private void Start() { this.player = GetComponent <Player>(); attack = new AttackCommand(this.player); block = new BlockCommand(this.player); dodge = new DodgeCommand(this.player); }
protected BlockCommand UpdateBlock(BlockCommand block, IList<Expression> commands) { if (block.Commands != commands) { return new BlockCommand(commands); } return block; }
public void WhenIBlockThePositionAnd(int blocked_x, int blocked_y) { var robot = scenarioContext.Get <Robot>("robot"); var table = scenarioContext.Get <Table>("table"); var status = new BlockCommand(new Position(blocked_x, blocked_y)).Execute(table); this.scenarioContext.Set(status, "status"); this.scenarioContext.Set(status.Data, "table"); }
public void ConditionalSelector() { var command = ParseCommand("recharge \"batteries\" whose ratio < 0.5"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is ConditionalEntityProvider); }
public void InLineIndexSelector() { var command = ParseCommand("turn on \"batteries\" @0"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); }
public void ConditionalIndexSelectorWithValueProperty() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("drain the \"cargo containers\" whose \"gold ingot\" amount < 0.5"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is ConditionalEntityProvider); }
public bool ControlCommand(BlockCommand _instructionType) //Add type as arg { bool temp = grid.CodingAreaInstruction(_instructionType); if (!temp) { Restart(); } return(temp); }
public void ConditionalSelector() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("recharge \"batteries\" whose ratio < 0.5"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is ConditionalEntityProvider); }
public void InLineIndexSelector() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("turn on \"batteries\" @0"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); }
private void Start() { this.player = GetComponent <Player>(); detector = player.GetComponentInChildren <LockOnDetector>(); attack = new AttackCommand(this.player); block = new BlockCommand(this.player); dodge = new DodgeCommand(this.player); lockOn = new LockOnCommand(this.player); lockOnChange = new LockOnChangeCommand(this.player); }
public void LastBlockTypeImpliedIsUsed() { var command = ParseCommand("turn on the \"Boom Door Program\""); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is SelectorEntityProvider); SelectorEntityProvider sep = (SelectorEntityProvider)bc.entityProvider; Assert.AreEqual(BlockType.PROGRAM, sep.GetBlockType()); }
public void ConditionalIndexSelector() { var command = ParseCommand("set the \"batteries\" whose ratio < 0.5 @0 to recharge"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); IndexEntityProvider iep = (IndexEntityProvider)bc.entityProvider; Assert.IsTrue(iep.provider is ConditionalEntityProvider); }
public void ImplicitAllGroupSelector() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("turn on the lights"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is AllEntityProvider); AllEntityProvider aep = (AllEntityProvider)bc.entityProvider; Assert.AreEqual(Block.LIGHT, aep.GetBlockType()); }
public void AllSelectorGroup() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("set the height of all pistons to 0"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is AllEntityProvider); AllEntityProvider aep = (AllEntityProvider)bc.entityProvider; Assert.AreEqual(Block.PISTON, aep.GetBlockType()); }
public void MySelectorWithBlockType() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("set my display @0 text to \"hello world\""); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); IndexEntityProvider iep = (IndexEntityProvider)bc.entityProvider; Assert.IsTrue(iep.provider is SelfEntityProvider); Assert.AreEqual(Block.DISPLAY, iep.provider.GetBlockType()); }
protected override Expression VisitBlock(BlockCommand block) { for (int i = 0, n = block.Commands.Count; i < n; i++) { if (i > 0) { this.AppendLine(Indentation.Same); this.AppendLine(Indentation.Same); } this.VisitStatement(block.Commands[i]); } return(block); //throw new NotSupportedException(); }
public void BasicSelector() { var command = ParseCommand("recharge the \"batteries\""); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is SelectorEntityProvider); SelectorEntityProvider sep = (SelectorEntityProvider)bc.entityProvider; Assert.AreEqual(BlockType.BATTERY, sep.GetBlockType()); Assert.IsTrue(sep.isGroup); Assert.IsTrue(sep.selector is StaticVariable); Assert.AreEqual("batteries", CastString(sep.selector.GetValue()).GetStringValue()); }
public void AssignListIndexSelectorValuePlusList() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("set my display[0] to \"Offset: \" + [offset]"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); IndexEntityProvider iep = (IndexEntityProvider)bc.entityProvider; List <Variable> listIndexes = CastList(iep.index.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(1, listIndexes.Count); Assert.AreEqual(0f, listIndexes[0].GetValue().GetValue()); }
public void ListIndexSelector() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("turn on \"batteries\"[0]"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); IndexEntityProvider iep = (IndexEntityProvider)bc.entityProvider; List <Variable> listIndexes = CastList(iep.index.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(1, listIndexes.Count); Assert.AreEqual(0f, listIndexes[0].GetValue().GetValue()); }
public async Task <ActionResult> Block(Domain.Models.DomainType blockType, string name) { //Used by voat.js var cmd = new BlockCommand(blockType, name, true); var result = await cmd.Execute(); if (Request.IsAjaxRequest()) { return(Json(result)); } else { return(await Blocked(blockType, null)); } }
public async Task <JsonResult> BlockSubverse(string subverseName) { var loggedInUser = User.Identity.Name; var cmd = new BlockCommand(Domain.Models.DomainType.Subverse, subverseName).SetUserContext(User); var response = await cmd.Execute(); if (response.Success) { return(Json("Subverse block request was successful." /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */)); } else { Response.StatusCode = 400; return(Json(response.Message /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */)); } }
public void AllSelectorGroupWithCondition() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("recharge all batteries whose ratio < 0.25"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is ConditionalEntityProvider); ConditionalEntityProvider cep = (ConditionalEntityProvider)bc.entityProvider; Assert.IsTrue(cep.provider is AllEntityProvider); AllEntityProvider aep = (AllEntityProvider)cep.provider; Assert.AreEqual(Block.BATTERY, aep.GetBlockType()); }
public void VariableSelector() { var command = ParseCommand("turn on the [a] sirens"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is SelectorEntityProvider); SelectorEntityProvider sep = (SelectorEntityProvider)bc.entityProvider; Assert.IsTrue(sep.selector is InMemoryVariable); InMemoryVariable variable = (InMemoryVariable)sep.selector; Assert.AreEqual("a", variable.variableName); Assert.AreEqual(BlockType.SOUND, sep.blockType); }
public void ImplicitVariableSelector() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("turn on the $a"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is SelectorEntityProvider); SelectorEntityProvider sep = (SelectorEntityProvider)bc.entityProvider; Assert.IsTrue(sep.selector is InMemoryVariable); InMemoryVariable variable = (InMemoryVariable)sep.selector; Assert.AreEqual("a", variable.variableName); }
public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression @else) { var tables = this.mapping.GetTables(entity); if (tables.Count < 2) { return(base.GetUpdateExpression(entity, instance, updateCheck, selector, @else)); } var commands = new List <Expression>(); foreach (var table in this.GetDependencyOrderedTables(entity)) { TableExpression tex = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table)); var assignments = this.GetColumnAssignments(tex, instance, entity, (e, m) => this.mapping.GetAlias(e, m) == this.mapping.GetAlias(table) && this.mapping.IsUpdatable(e, m), null); var where = this.GetIdentityCheck(tex, entity, instance); commands.Add(new UpdateCommand(tex, where, assignments)); } if (selector != null) { commands.Add( new IFCommand( this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count - 1]).GreaterThan(Expression.Constant(0)), this.GetUpdateResult(entity, instance, selector), @else)); } else if (@else != null) { commands.Add( new IFCommand( this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count - 1]).LessThanOrEqual(Expression.Constant(0)), @else, null)); } Expression block = new BlockCommand(commands); if (updateCheck != null) { var test = this.GetEntityStateTest(entity, instance, updateCheck); return(new IFCommand(test, block, null)); } return(block); }
protected override Expression VisitBlock(BlockCommand block) { if (!this.Language.AllowsMultipleCommands) { return(base.VisitBlock(block)); } for (int i = 0, n = block.Commands.Count; i < n; i++) { if (i > 0) { this.WriteLine(Indentation.Same); this.WriteLine(Indentation.Same); } this.VisitStatement(block.Commands[i]); } return(block); }
protected override Expression VisitBlock(BlockCommand block) { if (!this.Dialect.SupportMultipleCommands) { return(base.VisitBlock(block)); } for (int i = 0, n = block.Commands.Count; i < n; i++) { if (i > 0) { this.AppendLine(Indentation.Same); this.AppendLine(Indentation.Same); } this.VisitStatement(block.Commands[i]); } return(block); }
protected override Expression VisitBlock(BlockCommand block) { if (!this.Dialect.SupportMultipleCommands) { return base.VisitBlock(block); } for (int i = 0, n = block.Commands.Count; i < n; i++) { if (i > 0) { this.AppendLine(Indentation.Same); this.AppendLine(Indentation.Same); } this.VisitStatement(block.Commands[i]); } return block; }
public void VariableSelectorWithIndex() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("turn on the $mySirens[0]"); Assert.IsTrue(command is BlockCommand); BlockCommand bc = (BlockCommand)command; Assert.IsTrue(bc.entityProvider is IndexEntityProvider); IndexEntityProvider iep = (IndexEntityProvider)bc.entityProvider; List <Variable> listIndexes = CastList(iep.index.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(1, listIndexes.Count); Assert.AreEqual(0f, listIndexes[0].GetValue().GetValue()); Assert.IsTrue(iep.provider is SelectorEntityProvider); SelectorEntityProvider variableSelector = (SelectorEntityProvider)iep.provider; Assert.IsTrue(variableSelector.selector is InMemoryVariable); InMemoryVariable variable = (InMemoryVariable)variableSelector.selector; }
public async Task QuerySubmissions_Verify_BlockedSubverses() { //Ensure v/unit does not show up in v/all for user BlocksUnit TestHelper.SetPrincipal("BlocksUnit"); var cmd = new BlockCommand(Domain.Models.DomainType.Subverse, "unit"); var r = await cmd.Execute(); var q = new QuerySubmissions("_all", SearchOptions.Default); //q.CachePolicy.Duration = cacheTime; //Cache this request var result = q.ExecuteAsync().Result; Assert.IsNotNull(result); Assert.IsTrue(result.Any(), "Found no results"); foreach (var s in result) { Assert.AreNotEqual("unit", s.Subverse.ToLower(), "Found blocked sub in BlocksUnit's v/all query"); } }
public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression @else) { var tables = this.mapping.GetTables(entity); if (tables.Count < 2) { return base.GetUpdateExpression(entity, instance, updateCheck, selector, @else); } var commands = new List<Expression>(); foreach (var table in this.GetDependencyOrderedTables(entity)) { TableExpression tex = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table)); var assignments = this.GetColumnAssignments(tex, instance, entity, (e, m) => this.mapping.GetAlias(e, m) == this.mapping.GetAlias(table) && this.mapping.IsUpdatable(e, m), null); var where = this.GetIdentityCheck(tex, entity, instance); commands.Add(new UpdateCommand(tex, where, assignments)); } if (selector != null) { commands.Add( new IFCommand( this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count-1]).GreaterThan(Expression.Constant(0)), this.GetUpdateResult(entity, instance, selector), @else ) ); } else if (@else != null) { commands.Add( new IFCommand( this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count-1]).LessThanOrEqual(Expression.Constant(0)), @else, null ) ); } Expression block = new BlockCommand(commands); if (updateCheck != null) { var test = this.GetEntityStateTest(entity, instance, updateCheck); return new IFCommand(test, block, null); } return block; }
protected override Expression VisitBlock(BlockCommand block) { if (!this.Language.AllowsMultipleCommands) { return base.VisitBlock(block); } for (int i = 0, n = block.Commands.Count; i < n; i++) { if (i > 0) { this.WriteLine(Indentation.Same); this.WriteLine(Indentation.Same); } this.VisitStatement(block.Commands[i]); } return block; }
protected virtual bool CompareBlock(BlockCommand x, BlockCommand y) { if (x.Commands.Count != y.Commands.Count) return false; for (int i = 0, n = x.Commands.Count; i < n; i++) { if (!this.Compare(x.Commands[i], y.Commands[i])) return false; } return true; }
protected override Expression VisitBlock(BlockCommand block) { for (int i = 0, n = block.Commands.Count; i < n; i++) { if (i > 0) { this.AppendLine(Indentation.Same); this.AppendLine(Indentation.Same); } this.VisitStatement(block.Commands[i]); } return block; //throw new NotSupportedException(); }
protected virtual Expression VisitBlock(BlockCommand block) { var commands = this.VisitExpressionList(block.Commands); return this.UpdateBlock(block, commands); }
protected override Expression VisitBlock(BlockCommand block) { throw new NotSupportedException(); }
private bool CompareBlock(BlockCommand x, BlockCommand y) { if (x.Commands.Count != y.Commands.Count) { return false; } for (int i = 0, n = x.Commands.Count; i < n; i++) { if (!this.Compare(x.Commands[i], y.Commands[i])) { return false; } } return true; }