public DataFile Export(string database) { if (!context.DatabaseExists(database)) { throw new InvalidOperationException("database does not exist"); } string folderName = Guid.NewGuid().ToString(); string zipName = folderName + DataConfig.zipExt; string absoluteFolderPath = Path.Combine(DataConfig.baseDir, DataConfig.exportDir, folderName); string absoluteZipPath = Path.Combine(DataConfig.baseDir, DataConfig.exportDir, zipName); Directory.CreateDirectory(absoluteFolderPath); TableCollection tables = context.Tables; for (int i = 0; i < tables.Count; i++) { string tableName = tables[i].Name; StreamWriter writer = new StreamWriter(Path.Combine(absoluteFolderPath, tableName + DataConfig.csvExt)); string selectQuery = SQLQueryGenerator.GetSelectQuery(tableName); context.ExecuteReader(selectQuery, (reader) => CSVReadWrite.CreateCsvFile(reader, writer)); } ZipFile.CreateFromDirectory(absoluteFolderPath, absoluteZipPath); Directory.Delete(absoluteFolderPath, true); DataFile file = new DataFile(Path.Combine(DataConfig.baseDir, DataConfig.exportDir, zipName), zipName, database); return(file); }
public List <ColumnModel> GetColumns(string table) { List <ColumnModel> columns = new List <ColumnModel>(); ColumnCollection collection = context.Tables[table].Columns; string query = SQLQueryGenerator.GetSelectQuery(table); context.ExecuteReader(query, (reader) => DataModelFactory.FillColumns(reader, collection, columns)); return(columns); }