/* * From the downloaded folder, check if all the required files, mentioned in * the gtfs_file_structure are present. */ private bool CheckIfAllRequiredFilesExists(GTFSTableCollection tableCollection) { var GTFSPath = ConfigurationManager.AppSettings["GTFSPath"]; var fileNames = GetFileNames(GTFSPath, "*.txt"); var requiredFileExists = false; foreach (var gtfsTable in tableCollection) { if (!gtfsTable.required) { continue; } if (fileNames.Contains(gtfsTable.name)) { requiredFileExists = true; } else { Log.Info("Required file " + gtfsTable.name + " does not exist."); return(false); } } return(requiredFileExists); }
/* * Create schema if it does not exists. * For each table, drop the table from the database. * Create a new table in the database * Create indices on the column of tables as required. */ private void CreateTablesFromCollection(GTFSTableCollection tableCollection) { CreateScehma(); foreach (var gtfsTable in tableCollection) { ExecuteDropTableQuery(gtfsTable); ExecuteCreateTableQuery(gtfsTable); } }
private bool PopulateGTFSTable(GTFSTableCollection tableCollection) { Log.Info("Start populating gtfs_next schema tables."); var requiredFileExists = CheckIfAllRequiredFilesExists(tableCollection); if (requiredFileExists) { var requiredFileList = GetRequiredFileList(tableCollection); UpdateAnyNewColumn(requiredFileList); foreach (var requiredFile in requiredFileList) { UploadData(requiredFile); } //Parallel.ForEach(requiredFileList, requiredFile => UploadData(requiredFile)); return(true); } return(false); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var tableCollection = new GTFSTableCollection(); while (reader.Read()) { switch (reader.TokenType) { case JsonToken.EndObject: return(tableCollection); case JsonToken.PropertyName: var tableName = (string)reader.Value; reader.Read(); var table = serializer.Deserialize <GTFSTable>(reader); table.name = tableName; tableCollection.Add(table); break; } } return(tableCollection); }
private void CreateGTFSTables(GTFSTableCollection tableCollection) { CreateTablesFromCollection(tableCollection); Log.Info("Table creation successful in database."); }
/* * From the GTFS table collection return the list of the * rewquired tables ie files. */ private static List <string> GetRequiredFileList(GTFSTableCollection tableCollection) { return((from gtfsTable in tableCollection where gtfsTable.required select gtfsTable.name).ToList()); }