public void ProcessDirectory(DirectoryInfo directory, Dictionary <ImportFileType, string> fileTypes = null) { try { if (directory == null || !directory.Exists) { throw new Exception( "The specified directory does not exist! Unable to process a directory from nothing or a non-existent path."); } LH.WriteLine($"\r{DateTime.Now} | Processing files in {directory.Name}\t\t\t\t\t"); fileTypes = fileTypes ?? FileTypes; IReadOnlyCollection <FileInfo> files; // Kept separate from first definition so we can comment out certain sections to work on only what we want //files = directory.GetFiles($"*{fileTypes[ImportFileType.CodePage]}"); //if (!files.Any()) // LH.WriteLine($"\rNo Code Page Files were found. Defaulting to {DefaultCodePage.Encoding.EncodingName}\t\t\t\t\t"); //else // foreach (FileInfo file in files) // CodePageFiles.Add(new CodePageFile(file)); //files = directory.GetFiles($"*{fileTypes[ImportFileType.Projection]}"); //if (!files.Any()) // LH.WriteLine($"\rNo Projection Files were found. Defaulting to SRID {DefaultSRID}\t\t\t\t\t"); //else // foreach (FileInfo file in files) // ProjectionFiles.Add(new ProjectionFile(file)); files = directory.GetFiles($"*{fileTypes[ImportFileType.XmlFile]}").OrderBy(o => o.Name).ToArray(); if (!files.Any()) { throw new Exception($"\rNo Metadata Files were found! Unable to generate appropriate schemas!"); } foreach (FileInfo file in files) { MetadataFiles.Add(new MetadataFile(file)); } //Parallel.ForEach(files, f => MetadataFiles.Add(new MetadataFile(f))); } catch (Exception e) { LH.Error($"\r\n{e.Message}\r\n{e}"); throw; } }
public void ProcessFile(FileInfo file) { try { if (file == null || !file.Exists) { throw new FileNotFoundException("Please specify a valid file and try the ProcessFile method again."); } LH.Write($"\rProcessing {file.Name}\t\t\t\t\t"); ImportFileType importFileType = GetImportFileType(file); string fileExtension = GetImportFileExtension(importFileType); //LH.Write($"\r{file.Name} is a(n) {importFileType} file with an extension of {fileExtension}\t\t\t\t\t"); switch (importFileType) { case ImportFileType.CodePage: //CodePageFile codePageFile = new CodePageFile(file); break; case ImportFileType.XmlFile: MetadataFile metadataFile = new MetadataFile(file); break; case ImportFileType.Projection: ProjectionFile projectionFile = new ProjectionFile(file); break; case ImportFileType.Attribute: //AttributeFile attributeFile = new AttributeFile(file); break; case ImportFileType.Index: //IndexFile indexFile = new IndexFile(file); break; case ImportFileType.Shape: //ShapeFile shapeFile = new ShapeFile(file); //LH.Write($"\rShapeFile Inserted: {shapeFile.Name}\t\t\t\t\t"); break; case ImportFileType.GeocodingIndex: case ImportFileType.ODBGeocodingIndex: throw new NotImplementedException( "We currently do not handle the processing of Geocoding Indexes or ODB Geocoding indexes. (We make our own in SQL Server)"); case ImportFileType.XmlSchema: LH.WriteLine( $"\rNo data is contained within {file.Name}. This application generates and utilizes it's own schema XML schema documentation. No actions performed with this file."); break; default: throw new NotImplementedException( $"{file.Extension} is not a supported file type. Extensions must match the ESRI Shapefile specifications."); } } catch (Exception e) { LH.Error($"\r\n{e.Message}\r\n{e}"); throw; } }