public async Task <ActionResult <List <Batteries> > > GetBatteriesProduct(long cid) { var build = await _context.Buildings.FindAsync(cid); Console.WriteLine("3333333333333333333333333333333333333333333333333333333333333"); var batt = await _context.Batteries.Where(bat => bat.BuildingId == build.Id).ToListAsync(); List <Batteries> liste = new List <Batteries>(); foreach (Batteries i in batt) { var list = new Batteries { Id = i.Id }; liste.Add(list); } // List<Batteries> liste = new List<Batteries>{new Batteries{Id = batt.FirstOrDefault().Id,}}; if (batt == null) { return(NotFound()); } // var listBulding = (from i in batt select i.Building).ToList(); // var listBatt= from i in listBulding select i.Batteries; return(liste); }
public async Task <IActionResult> PutmodifyBatterisStatus(long id, [FromBody] Batteries body) { if (body.Status == null) { return(BadRequest()); } var battery = await _context.Batteries.FindAsync(id); battery.Status = body.Status; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BatteriesExists(id)) { return(NotFound()); } else { throw; } } return(new OkObjectResult("success")); }
public async Task <IActionResult> PutOne(int id, [FromBody] Batteries body) { await Db.Connection.OpenAsync(); var query = new BatteriesQuery(Db); var result = await query.FindOneAsync(id); //check the request sent if it valid if (body is null) { return(new NotFoundObjectResult("Please enter something in the status")); } if (body.Status.ToLower() != "intervention" && body.Status.ToLower() != "active" && body.Status.ToLower() != "inactive") { return(new NotFoundObjectResult("The status you entered is invalide!")); } if (result is null) { return(new NotFoundResult()); } result.Status = body.Status; await result.UpdateAsync(); return(new OkObjectResult(result)); }
public async Task <IActionResult> PutBatteries(long id, Batteries batteries) { if (id != batteries.Id) { return(BadRequest()); } _context.Entry(batteries).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BatteriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Batteries> > PostBatteries(Batteries batteries) { _context.Batteries.Add(batteries); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBatteries", new { id = batteries.Id }, batteries)); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); string databasePath; switch (Device.RuntimePlatform) { case Device.Android: databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DatabaseName); break; case Device.iOS: Batteries.Init(); databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", DatabaseName); break; case Device.UWP: databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DatabaseName); break; default: throw new NotImplementedException("Platform not supported"); } optionsBuilder.UseSqlite($"Filename={databasePath}"); }
public static string FormattedString(this Batteries battery) { string returnString = ""; switch (battery) { case Batteries.FORWARD: returnString = "Forward"; break; case Batteries.STERN: returnString = "Stern"; break; case Batteries.STARBOARD: returnString = "Starboard"; break; case Batteries.PORT: returnString = "Port"; break; default: returnString = "Battery"; break; } return(returnString); }
public static void Load() { var assembly = Assembly.GetExecutingAssembly(); new Harmony($"DaWrecka_{assembly.GetName().Name}").PatchAll(assembly); Batteries.PostPatch(); }
public async Task <IActionResult> PutBatteries(long id, Batteries batteries) { if (id != batteries.id) { return(BadRequest()); } _context.Entry(batteries).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BatteriesExists(id)) { return(NotFound()); } else { throw; } } var jsonPut = new JObject(); jsonPut["Update"] = "Update done to batteries id : " + id; return(Content(jsonPut.ToString(), "application/json")); }
public void UnRegisterSubGrid(MyCubeGrid grid, bool clean = false) { if (!SubGridsRegistered.Contains(grid)) { Log.Line($"sub Grid Already UnRegistered: [Main]:{grid == MyGrid}"); } if (!clean) { SubGrids.Remove(grid); } SubGridsRegistered.Remove(grid); grid.OnFatBlockAdded -= FatBlockAdded; grid.OnFatBlockRemoved -= FatBlockRemoved; foreach (var cube in grid.GetFatBlocks()) { var battery = cube as MyBatteryBlock; if (InventoryMonitor.ContainsKey(cube) || battery != null && Batteries.Contains(battery)) { FatBlockRemoved(cube); } } GridAi removeAi; if (!Session.GridTargetingAIs.ContainsKey(grid)) { Session.GridToMasterAi.TryRemove(grid, out removeAi); } }
private static List <string> GetAllTableNames(string dbName) { List <string> tableNames = new List <string>(); Batteries.Init(); sqlite3 connection; int rc = raw.sqlite3_open(dbName, out connection); VerifySQLiteResponse(rc, raw.SQLITE_OK, connection); using (connection) { sqlite3_stmt statement; rc = raw.sqlite3_prepare_v2(connection, "SELECT name FROM sqlite_master WHERE type = 'table'", out statement); VerifySQLiteResponse(rc, raw.SQLITE_OK, connection); using (statement) { int index = 0; while ((rc = raw.sqlite3_step(statement)) == raw.SQLITE_ROW) { string tableName = raw.sqlite3_column_text(statement, index); index++; if (tableName != null) { tableNames.Add(tableName); } } } } return(tableNames); }
private void FatBlockRemoved(MyCubeBlock cube) { try { var sessionNull = Session == null; var weaponType = (cube is MyConveyorSorter || cube is IMyUserControllableGun); var cubeDef = cube.BlockDefinition; var isWeaponBase = weaponType && cubeDef != null && !sessionNull && (Session.ReplaceVanilla && Session.VanillaIds.ContainsKey(cubeDef.Id) || Session.WeaponPlatforms.ContainsKey(cubeDef.Id)); var battery = cube as MyBatteryBlock; if (sessionNull) { Log.Line($"FatBlockRemoved Session was null: AiMarked:{MarkedForClose} - AiClosed:{Closed} - cubeMarked:{cube.MarkedForClose} - CubeGridMarked:{cube.CubeGrid.MarkedForClose} - isRegistered:{SubGridsRegistered.Contains(cube.CubeGrid)} - regCnt:{SubGridsRegistered.Count}"); } MyInventory inventory; if (!isWeaponBase && cube.HasInventory && cube.TryGetInventory(out inventory)) { if (!InventoryRemove(cube, inventory)) { Log.Line($"FatBlock inventory remove failed: {cube.BlockDefinition?.Id.SubtypeName} - gridMatch:{cube.CubeGrid == MyGrid} - aiMarked:{MarkedForClose} - {cube.CubeGrid.DebugName} - {MyGrid?.DebugName}"); } } else if (battery != null) { if (Batteries.Remove(battery)) { SourceCount--; } UpdatePowerSources = true; } } catch (Exception ex) { Log.Line($"Exception in FatBlockRemoved last: {ex} - Marked: {MarkedForClose} - Closed:{Closed}"); } }
public void CreateDatabase(int version) { using (var scope = Scope()) { Batteries.Init(); scope.Db.Database.EnsureCreated(); } }
async static Task <Stream> ReturnText(string hash) { Batteries.Init(); var ipfs = new IpfsEngine("".ToCharArray()); var data = await ipfs.FileSystem.ReadFileAsync(hash); return(data); }
public SqliteIntegrationTest(ITestOutputHelper output) { if (File.Exists("./mydb.db")) { File.Delete("./mydb.db"); } Batteries.Init(); _output = output; }
internal static sqlite3 GetSqliteConnection(string filename) { Batteries.Init(); sqlite3 connection; int rc = raw.sqlite3_open(filename, out connection); VerifySQLiteResponse(rc, raw.SQLITE_OK, connection); return(connection); }
public void SaveBatteries(IEnumerable <Battery> list, int time) { IBatteries batteries = new Batteries(); List <BatteryDTO> list2 = new List <BatteryDTO>(); foreach (var b in list) { list2.Add(new BatteryDTO(b.Capacity, b.Id, b.MaxPower, b.State, time)); } batteries.SaveAll(list2); }
internal void FatBlockAdded(MyCubeBlock cube) { try { var battery = cube as MyBatteryBlock; var weaponType = (cube is MyConveyorSorter || cube is IMyUserControllableGun); var isWeaponBase = weaponType && cube.BlockDefinition != null && (Session.ReplaceVanilla && Session.VanillaIds.ContainsKey(cube.BlockDefinition.Id) || Session.WeaponPlatforms.ContainsKey(cube.BlockDefinition.Id)); if (!isWeaponBase && (cube is MyConveyor || cube is IMyConveyorTube || cube is MyConveyorSorter || cube is MyCargoContainer || cube is MyCockpit || cube is IMyAssembler || cube is IMyShipConnector) && cube.CubeGrid.IsSameConstructAs(MyGrid)) { MyInventory inventory; if (cube.HasInventory && cube.TryGetInventory(out inventory) && InventoryMonitor.TryAdd(cube, inventory)) { inventory.InventoryContentChanged += CheckAmmoInventory; Construct.RootAi.Construct.NewInventoryDetected = true; int monitors; if (!Session.InventoryMonitors.TryGetValue(inventory, out monitors)) { Session.InventoryMonitors[inventory] = 0; Session.InventoryItems[inventory] = Session.PhysicalItemListPool.Get(); Session.AmmoThreadItemList[inventory] = Session.BetterItemsListPool.Get(); } else { Session.InventoryMonitors[inventory] = monitors + 1; } } } else if (battery != null) { if (Batteries.Add(battery)) { SourceCount++; } UpdatePowerSources = true; } else if (isWeaponBase) { MyOrientedBoundingBoxD b; BoundingSphereD s; MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(cube, out blockBox); if (Session.IsWeaponAreaRestricted(cube.BlockDefinition.Id.SubtypeId, blockBox, cube.CubeGrid, cube.EntityId, null, out b, out s)) { if (Session.IsServer) { cube.CubeGrid.RemoveBlock(cube.SlimBlock); } } } } catch (Exception ex) { Log.Line($"Exception in Controller FatBlockAdded: {ex} - {cube?.BlockDefinition == null} - RootAiNull: {Construct.RootAi == null}"); } }
public List <BatteryDTO> GetBatteryProduction(string id, DateTime date) { IBatteries batteries = new Batteries(); DateTime centuryBegin = new DateTime(2020, 1, 1); long ticks = date.Ticks - centuryBegin.Ticks; long secondsStart = ticks / 10000000; long secondsEnd = secondsStart + 86400; List <BatteryDTO> list = (List <BatteryDTO>)batteries.FindAllById(id, (int)secondsStart, (int)secondsEnd);; return(list); }
async static Task <Ipfs.Cid> AddObjectSaveHash(string hash) { Batteries.Init(); using (var ie = new IpfsEngine("".ToCharArray())) { var newdata = await ie.FileSystem.AddFileAsync(hash) .ConfigureAwait(false); return(newdata.Id); } }
internal void CleanUp() { RegisterMyGridEvents(false); foreach (var grid in SubGrids) { if (grid == MyGrid) { continue; } RemSubGrids.Add(grid); } AddSubGrids.Clear(); SubGridChanges(); SubGrids.Clear(); Obstructions.Clear(); TargetAis.Clear(); EntitiesInRange.Clear(); Batteries.Clear(); Targets.Clear(); SortedTargets.Clear(); BlockGroups.Clear(); Weapons.Clear(); WeaponsIdx.Clear(); WeaponBase.Clear(); AmmoInventories.Clear(); Inventories.Clear(); LiveProjectile.Clear(); DeadProjectiles.Clear(); ControllingPlayers.Clear(); SourceCount = 0; BlockCount = 0; MyOwner = 0; PointDefense = false; FadeOut = false; SupressMouseShoot = false; OverPowered = false; UpdatePowerSources = false; AvailablePowerChanged = false; PowerIncrease = false; RequestedPowerChanged = false; RequestIncrease = false; DbReady = false; Focus.Clean(); MyShieldTmp = null; MyShield = null; MyPlanetTmp = null; MyPlanet = null; TerminalSystem = null; LastWeaponTerminal = null; LastTerminal = null; PowerDistributor = null; }
public List <Battery> GetBatteries() { IBatteries batteries = new Batteries(); List <Tuple <string, int> > ids = batteries.GetIdsForInit(); List <Battery> list = new List <Battery>(); foreach (var s in ids) { Battery b = batteries.FindById(s.Item1, s.Item2); list.Add(b); } return(list); }
public void InitializeOnce() { if (_IsInitialized) { return; } lock (_Lock) { Batteries.Init(); _IsInitialized = true; } }
private void FatBlockRemoved(MyCubeBlock cube) { try { var sessionNull = Session == null; var weaponType = (cube is MyConveyorSorter || cube is IMyUserControllableGun); var cubeDef = cube.BlockDefinition; var isWeaponBase = weaponType && cubeDef != null && !sessionNull && (Session.ReplaceVanilla && Session.VanillaIds.ContainsKey(cubeDef.Id) || Session.WeaponPlatforms.ContainsKey(cubeDef.Id)); if (sessionNull) { Log.Line($"FatBlockRemoved Session was null: AiMarked:{MarkedForClose} - AiClosed:{Closed} - cubeMarked:{cube.MarkedForClose} - CubeGridMarked:{cube.CubeGrid.MarkedForClose} - isRegistered:{SubGridsRegistered.Contains(cube.CubeGrid)} - regCnt:{SubGridsRegistered.Count}"); } try { var battery = cube as MyBatteryBlock; MyInventory inventory; if (!isWeaponBase && cube.HasInventory && cube.TryGetInventory(out inventory)) { try { if (inventory != null && !sessionNull && Session.UniqueListRemove(inventory, InventoryIndexer, Inventories)) { inventory.InventoryContentChanged -= CheckAmmoInventory; List <MyPhysicalInventoryItem> removedPhysical; List <BetterInventoryItem> removedBetter; if (Session.InventoryItems.TryRemove(inventory, out removedPhysical)) { removedPhysical.Clear(); } if (Session.AmmoThreadItemList.TryRemove(inventory, out removedBetter)) { removedBetter.Clear(); } } } catch (Exception ex) { Log.Line($"Exception in FatBlockRemoved inventory: {ex}"); } } else if (battery != null) { if (Batteries.Remove(battery)) { SourceCount--; } UpdatePowerSources = true; } } catch (Exception ex) { Log.Line($"Exception in FatBlockRemoved main: {ex}"); } } catch (Exception ex) { Log.Line($"Exception in FatBlockRemoved last: {ex} - Marked: {MarkedForClose} - Closed:{Closed}"); } }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { // ReSharper disable once RedundantAssignment - Used if not debugging var dbLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Artemis\\Storage.db"); #if DEBUG dbLocation = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\Artemis.Storage\Storage.db")); #endif optionsBuilder.UseSqlite("Data Source=" + dbLocation); // Requires Microsoft.Data.Sqlite in the startup project Batteries.Init(); }
//public void Put(int id, [FromBody] string value) public IActionResult Update(long id, Batteries item) { var change = _context.Batteries.Find(id); if (change == null) { return(NotFound()); } //change.IsComplete = item.IsComplete; change.Status = item.Status; _context.Batteries.Update(change); _context.SaveChanges(); return(NoContent()); }
public ActionResult Update(long id, Batteries battery) { var bat = _context.Batteries.Find(id); if (bat == null) { return(NotFound()); } bat.Status = battery.Status; _context.Batteries.Update(bat); _context.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> UpdateStatus([FromRoute] long id, Batteries current) { if (id != current.Id) { return(BadRequest()); } if (current.BatteryStatus == "Active" || current.BatteryStatus == "Inactive" || current.BatteryStatus == "Intervention") { _context.Entry(current).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Content("Battery: " + current.Id + ", status as been change to: " + current.BatteryStatus)); } return(Content("Please insert a valid status : Intervention, Inactive, Active, Tray again ! ")); }
public IActionResult PutBatteryStatus(long id, Batteries item) { var bat = _context.Batteries.Find(id); if (bat == null) { return(NotFound()); } bat.status = item.status; _context.Batteries.Update(bat); _context.SaveChanges(); var jsonPut = new JObject(); jsonPut["Update"] = "Update done to battery id : " + id + " to the status : " + bat.status; return(Content(jsonPut.ToString(), "application/json")); }
//public async Task DeleteAllAsync() //{ // using var txn = await Db.Connection.BeginTransactionAsync(); // using var cmd = Db.Connection.CreateCommand(); // cmd.CommandText = @"DELETE FROM `rocketApp_development`"; // await cmd.ExecuteNonQueryAsync(); // await txn.CommitAsync(); //} private async Task <List <Batteries> > ReadAllAsync(DbDataReader reader) { var posts = new List <Batteries>(); using (reader) { while (await reader.ReadAsync()) { var post = new Batteries(Db) { BatteryId = reader.GetInt32(0), Status = reader.GetString(1), }; posts.Add(post); } } return(posts); }