public async Task <SubMachine> Update(SubMachine data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } await using var transaction = await _context.Database .BeginTransactionAsync() .ConfigureAwait(false); try { _context.SubMachines.Update(data); await _context.SaveChangesAsync().ConfigureAwait(false); await transaction.CommitAsync().ConfigureAwait(false); return(data); } catch (Exception e) { await transaction.RollbackAsync().ConfigureAwait(false); throw new Exception(e.Message); } }
public override SimulationState MoveToNextStepState() { if (CurrentMachine == null) { CurrentMachine = Machine[0]; } StepState = CurrentMachine.MoveToNextStepState(); if (StepState == SimulationState.StateChanged) { Data.Store[Util.CounterName(SubMachine.Name)] = 0; SubMachine.AckStateChanged(); StepState = SimulationState.EndOfCycle; Data.LogStateChange(SubMachine.PreviousState.Alias, SubMachine.CurrentState.Alias); } else if (StepState == SimulationState.ChangedToSubMachine) { Data.Store[Util.CounterName(SubMachine.Name)] = 0; Data.LogStateChange(SubMachine.PreviousState.Alias, SubMachine.CurrentState.Alias); } if (StepState == SimulationState.EndOfCycle) { //Change to next machine if (CurrentMachine != Machine.Last()) { while (CurrentMachine != Machine.Last()) { //Move to the next machine CurrentMachine = Machine.ElementAt(Machine.IndexOf(CurrentMachine) + 1); if (CurrentMachine.MoveToNextStepState() != SimulationState.EndOfCycle) { break; } } } else { //Erase events foreach (EventInput var in Data.Variables.EventInputs) { Data.Store[var.Name] = false; } //End condition step CurrentMachine = null; Data.IncrementMasterCounter(); variablesStatus.MaxTimeDraw = Data.MasterCounter; return(SimulationState.EndOfCycle); } } return(CurrentMachine.StepState == SimulationState.EndOfCycle ? SimulationState.EndOfSubMachine : CurrentMachine.StepState); }
public async Task <IActionResult> PutMachine(SubMachine data) { if (data == null) { return(BadRequest()); } try { var result = await _service.Update(data).ConfigureAwait(false); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public override void Create() { Main.Instance.IsMouseVisible = false; _areneBounds = new Rectangle(92, 92, Assets.Arene.Width - 92 * 2, Assets.Arene.Height - 92 * 2); _gameOver = false; _camera = new Camera(); _weapons = new List <Weapon>(); _enemies = new List <Enemy>(); _uiManager = new UiManager(); ReplayDelegate replay = Replay; QuitDelegate quit = Quit; _uiManager.AddParticle(new UiButton(_camera.ScreenToWorld(new Vector2(Utils.WIDTH / 2 - 250, .7f * Utils.HEIGHT)), Replay, Assets.ReplayButton)); _uiManager.AddParticle(new UiButton(_camera.ScreenToWorld(new Vector2(Utils.WIDTH / 2 + 50, .7f * Utils.HEIGHT)), Quit, Assets.QuitButton)); _loots = new List <Loot>(); _player = new Player(Assets.Player, new Vector2(Utils.WIDTH / 2 - 25, Utils.HEIGHT / 2 - 25), _camera); var nbLoot = Utils.RANDOM.Next(5, 16); for (var i = 0; i < nbLoot; i++) { Loot potentialLoot; bool intersectWithEntity; do { intersectWithEntity = false; var lootX = Utils.RANDOM.Next(_areneBounds.Left, _areneBounds.Right - 150); var lootY = Utils.RANDOM.Next(_areneBounds.Top, _areneBounds.Bottom - 150); potentialLoot = new Loot(new Vector2(lootX, lootY)); foreach (var enemy in _enemies) { if (potentialLoot.Hitbox.Intersects(enemy.Hitbox)) { intersectWithEntity = true; break; } } if (potentialLoot.Hitbox.Intersects(Player.Hitbox)) { intersectWithEntity = true; } } while (intersectWithEntity); _loots.Add(potentialLoot); } var nbWeapon = Utils.RANDOM.Next(10, 31); for (var i = 0; i < nbWeapon; i++) { Weapon potentialWeapon; bool intersectWithEntity; do { intersectWithEntity = false; var weaponX = Utils.RANDOM.Next(_areneBounds.Left, _areneBounds.Right - 150); var weaponY = Utils.RANDOM.Next(_areneBounds.Top, _areneBounds.Bottom - 150); var rnd = Utils.RANDOM.Next(3); switch (rnd) { case 0: potentialWeapon = new Gun(new Vector2(weaponX, weaponY), WeaponState.OnFloor, _camera); break; case 1: potentialWeapon = new SubMachine(new Vector2(weaponX, weaponY), WeaponState.OnFloor, _camera); break; case 2: potentialWeapon = new Sniper(new Vector2(weaponX, weaponY), WeaponState.OnFloor, _camera); break; default: potentialWeapon = new Gun(new Vector2(weaponX, weaponY), WeaponState.OnFloor, _camera); break; } foreach (var enemy in _enemies) { if (potentialWeapon.Hitbox.Intersects(enemy.Hitbox)) { intersectWithEntity = true; break; } } if (potentialWeapon.Hitbox.Intersects(Player.Hitbox)) { intersectWithEntity = true; } } while (intersectWithEntity); _weapons.Add(potentialWeapon); } for (var i = 0; i < 15; i++) { Enemy potentialEnemy; bool intersectWithEntity; do { intersectWithEntity = false; var enemyX = Utils.RANDOM.Next(_areneBounds.Left, _areneBounds.Right - 50); var enemyY = Utils.RANDOM.Next(_areneBounds.Top, _areneBounds.Bottom - 50); potentialEnemy = new Enemy(Assets.Enemy, new Vector2(enemyX, enemyY), _player, _camera); foreach (var enemy in _enemies) { if (potentialEnemy.Hitbox.Intersects(enemy.Hitbox)) { intersectWithEntity = true; break; } } if (potentialEnemy.Hitbox.Intersects(Player.Hitbox)) { intersectWithEntity = true; } } while (intersectWithEntity); _enemies.Add(potentialEnemy); } Assets.MusicShooter.Volume = 0.5f; Assets.MusicShooter.IsLooped = true; Assets.MusicShooter.Play(); }