using System; namespace Deltares.Maps { public class FeatureImporter : IFeatureImporter { private readonly IFeatureRepository repository; private IReader reader; public FeatureImporter(IFeatureRepository repository, IReader reader) { if (repository == null) { throw new ArgumentNullException("repository"); } if (reader == null) { throw new ArgumentNullException("reader"); } this.repository = repository; this.reader = reader; } #region Implementation of IGeometryRepositoryImporter public IFeatureRepository Repository { get { return repository; } } public IReader Reader { set { reader = value; } } public void Import() { repository.Add(reader.Read()); } #endregion public static void ImportFromShapeFile(ShapeFileLocation shapeFileLocation, IFeatureRepository featureRepository, bool ignoreAttributeData = false) { if (shapeFileLocation == null) { throw new ArgumentNullException("shapeFileLocation"); } if (featureRepository == null) { throw new ArgumentNullException("featureRepository"); } try { IReader reader = new ShapeFileReader(shapeFileLocation) { IgnoreAttributeData = ignoreAttributeData }; IFeatureImporter importer = new FeatureImporter(featureRepository, reader); importer.Import(); } catch (Exception e) { throw new FeatureImportException(shapeFileLocation.FullPath, e); } } } }