/// <summary> /// Build data to allow creation on MapTube. /// Output is a set of directories in the outputDirectory, with one for each file source. /// Also included is a SQL insert file which can be used to add the maps to the database. /// </summary> /// <param name="outputDirectory"></param> public void Build(string outputDirectory) { this.outputDirectory = outputDirectory; Directory.CreateDirectory(outputDirectory); DataTable cat = datastore.DatastoreCatalogue; DatastoreSchema schema = datastore.DSSchema; int TitleColIdx = cat.Columns.IndexOf(schema.TitleField); int LinkColIdx = cat.Columns.IndexOf(schema.LinkField); int UniqueKeyColIdx = cat.Columns.IndexOf(schema.UniqueKeyField); //delete any existing sql file File.Delete(Path.Combine(outputDirectory, MapTubeSQLFilename)); //todo: check whether you need to create the data staging directory here for (int i = 0; i < cat.Rows.Count; i++) { DataRow Row = cat.Rows[i]; string Title = Row[TitleColIdx] as string; string DataLink = Row[LinkColIdx] as string; string UniqueKey = Row[UniqueKeyColIdx] as string; //this is only unique for the table's name and file, so we're going to need to add a column number to this if (string.IsNullOrEmpty(DataLink)) { continue; //no data so skip } //Data staging - download to the local file system and unzip if necessary Uri StagedDataUri = datastore.StageData(new Uri(DataLink)); //this is either the root of the extracted zip hierarchy, or an actual file Uri[] StagedDataFiles = datastore.FilterDataFiles(StagedDataUri); //get a list of files under the staging area that might contain data //now get the files and analyse it foreach (Uri FileUri in StagedDataFiles) { //we should have a true file (not dir) at this point and it should be a valid type as it's been filtered (*.csv) if (FileUri.LocalPath.ToLower().EndsWith(".csv")) { Console.WriteLine("Staged File: " + FileUri.LocalPath); ProcessFile(FileUri, UniqueKey, Title); } } } }