public List <DirFile> GetFilesFromDB(string condition) { List <DirFile> files = new List <DirFile>(); SQLiteCommand dbQuery = conn.CreateCommand(); dbQuery.CommandText = "SELECT * from files WHERE " + condition; SQLiteDataReader reader = dbQuery.ExecuteReader(); DirFile file; try { while (reader.Read()) { file = new DirFile(reader["name"].ToString(), reader["addr"].ToString()); file.Owner = reader["owner"].ToString(); file.Size = reader["size"].ToString(); file.ReserveAddress = reader["reserv_addr"].ToString(); files.Add(file); } reader.Close(); } catch (SQLiteException err) { Console.WriteLine("GetFilesFromDB: " + err.Message); } return(files); }
public void RegFile(string name, string size, string storageId, string owner) { string mainAddress = FileSystem.db.GetStorageAddressById(storageId); string filePath; if (CurrentPath == "/") { filePath = CurrentPath + name; } else { filePath = CurrentPath + "/" + name; } List <string> excludedId = new List <string>(); excludedId.Add(storageId); int response = 0; bool foundReserve = false; string reserveId = ""; string reserveAddress = ""; do { reserveId = FileSystem.db.ChooseReplicateStorage(size, excludedId); if (reserveId != "") { reserveAddress = FileSystem.db.GetStorageAddressById(reserveId); response = StorageAPI.GetRequest(reserveAddress, "api/name/replicate?path=" + FileSystem.GetUserPathFromFull(owner, CurrentPath) + "&name=" + name + "&target=" + mainAddress + "&user="******""); DirFile file = new DirFile(name, mainAddress); file.Size = size; file.Owner = owner; Files.Add(name, file); if (foundReserve) { FileSystem.db.ExecuteNonQuery("INSERT INTO files(full_path, dir_path, name, addr, size, reserv_addr, owner) VALUES ('" + filePath + "', '" + CurrentPath + "', '" + name + "', '" + mainAddress + "', '" + size + "', '" + reserveAddress + "', '" + owner + "')"); Files[name].ReserveAddress = reserveAddress; FileSystem.db.UpdateStorageFreeSpace(reserveId, size); } else { FileSystem.db.ExecuteNonQuery("INSERT INTO files(full_path, dir_path, name, addr, size, owner) VALUES ('" + filePath + "', '" + CurrentPath + "', '" + name + "', '" + mainAddress + "', '" + size + "', '" + owner + "')"); } FileSystem.db.ExecuteNonQuery("INSERT INTO file_to_dir(dir_path, file_path) VALUES ('" + CurrentPath + "', '" + filePath + "')"); }