public void ReadCharacteristicPointsLocation_FileLacksIdsWithWhiteLine_ThrowsLineParseExceptionOnCorrectLine()
        {
            // Setup
            string path = Path.Combine(testDataPath, "2locations_each_missing_id_with_white_line.krp.csv");

            // Precondition
            Assert.IsTrue(File.Exists(path));

            using (var reader = new CharacteristicPointsCsvReader(path))
            {
                // Call
                TestDelegate call = () => reader.ReadCharacteristicPointsLocation();

                // Assert
                // 1st line has no text at all:
                var    exception       = Assert.Throws <LineParseException>(call);
                string expectedMessage = new FileReaderErrorMessageBuilder(path)
                                         .WithLocation("op regel 2")
                                         .Build("Regel heeft geen ID.");
                Assert.AreEqual(expectedMessage, exception.Message);

                // 2nd line has only whitespace text:
                expectedMessage = new FileReaderErrorMessageBuilder(path)
                                  .WithLocation("op regel 4")
                                  .Build("Regel heeft geen ID.");
                exception = Assert.Throws <LineParseException>(call);
                Assert.AreEqual(expectedMessage, exception.Message);
            }
        }
        public void ReadCharacteristicPointsLocation_FileHasTooManyValues_ThrowsLineParseException()
        {
            // Setup
            string path = Path.Combine(testDataPath, "2locations_each_too_many_values.krp.csv");

            // Precondition
            Assert.IsTrue(File.Exists(path));

            using (var reader = new CharacteristicPointsCsvReader(path))
            {
                // Call
                TestDelegate call = () => reader.ReadCharacteristicPointsLocation();

                // Assert
                // 1st row lacks 1 coordinate value:
                var    exception       = Assert.Throws <LineParseException>(call);
                string expectedMessage = new FileReaderErrorMessageBuilder(path)
                                         .WithLocation("op regel 2")
                                         .WithSubject("locatie 'OneValueTooMuch'")
                                         .Build("Het aantal kolommen voor deze locatie komt niet overeen met het aantal kolommen in de koptekst.");
                Assert.AreEqual(expectedMessage, exception.Message);

                // 2nd row lacks 2 coordinate values:
                exception       = Assert.Throws <LineParseException>(call);
                expectedMessage = new FileReaderErrorMessageBuilder(path)
                                  .WithLocation("op regel 3")
                                  .WithSubject("locatie 'ThreeValuesTooMuch'")
                                  .Build("Het aantal kolommen voor deze locatie komt niet overeen met het aantal kolommen in de koptekst.");
                Assert.AreEqual(expectedMessage, exception.Message);
            }
        }
        public void Constructor_WithReaderInvalidProfileId_ThrowsCriticalFileReadException()
        {
            // Setup
            var          reader               = mocks.StrictMock <IRowBasedDatabaseReader>();
            const string profileName          = "profile";
            const int    layerCount           = 1;
            const string path                 = "A";
            var          invalidCastException = new InvalidCastException();

            reader.Expect(r => r.Read <string>(SoilProfileTableDefinitions.ProfileName)).IgnoreArguments().Return(profileName);
            reader.Expect(r => r.Read <long>(SoilProfileTableDefinitions.LayerCount)).IgnoreArguments().Return(layerCount);
            reader.Expect(r => r.Read <long>(SoilProfileTableDefinitions.SoilProfileId)).IgnoreArguments().Throw(invalidCastException);
            reader.Expect(r => r.Path).Return(path);

            mocks.ReplayAll();

            // Call
            TestDelegate test = () => new CriticalProfileProperties(reader);

            // Assert
            var exception = Assert.Throws <CriticalFileReadException>(test);

            Assert.AreSame(invalidCastException, exception.InnerException);
            string expectedMessage = new FileReaderErrorMessageBuilder(path)
                                     .WithSubject($"ondergrondschematisatie '{profileName}'")
                                     .Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.");

            Assert.AreEqual(expectedMessage, exception.Message);
        }
        private static string[] GetShapeFilesInFolder(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                string message = new FileReaderErrorMessageBuilder(path).Build(Resources.Error_Path_must_be_specified);
                throw new ArgumentException(message);
            }

            try
            {
                return(Directory.GetFiles(path, "*.shp"));
            }
            catch (ArgumentException e)
            {
                string message = new FileReaderErrorMessageBuilder(path)
                                 .Build(Resources.Error_Path_cannot_contain_invalid_characters);
                throw new ArgumentException(message, e);
            }
            catch (Exception e)
            {
                if (e is IOException || e is SecurityException)
                {
                    string message = string.Format(RiskeerCommonIOResources.ReferenceLineMetaImporter_ValidateDirectory_Directory_Invalid,
                                                   path);
                    throw new CriticalFileReadException(message, e);
                }

                throw;
            }
        }
        /// <summary>
        /// Reads the track Id from the hydraulic boundary database.
        /// </summary>
        /// <returns>The track Id found in the database.</returns>
        /// <exception cref="LineParseException">Thrown when the database contains incorrect values for required properties.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when the track Id cannot be read.</exception>
        public long ReadTrackId()
        {
            try
            {
                using (IDataReader reader = CreateDataReader(HydraulicBoundaryDatabaseQueryBuilder.GetTrackIdQuery(),
                                                             new SQLiteParameter
                {
                    DbType = DbType.String
                }))
                {
                    if (reader.Read())
                    {
                        return(Convert.ToInt64(reader[GeneralTableDefinitions.TrackId]));
                    }

                    throw new CriticalFileReadException(new FileReaderErrorMessageBuilder(Path)
                                                        .Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column));
                }
            }
            catch (InvalidCastException exception)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
                throw new LineParseException(message, exception);
            }
            catch (SQLiteException exception)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_HydraulicBoundaryLocation_read_from_database);
                throw new CriticalFileReadException(message, exception);
            }
        }
        private static WmtsConnectionInfo TryCreateWmtsConnectionInfo(string path, XContainer element)
        {
            XElement nameElement = element.Element(WmtsConnectionInfoXmlDefinitions.WmtsConnectionNameElement);
            XElement urlElement  = element.Element(WmtsConnectionInfoXmlDefinitions.WmtsConnectionUrlElement);

            if (nameElement == null || urlElement == null)
            {
                return(null);
            }

            try
            {
                return(new WmtsConnectionInfo(nameElement.Value, urlElement.Value));
            }
            catch (ArgumentException exception)
            {
                string errorMessage = string.Format(Resources.WmtsConnectionInfoReader_Unable_To_Create_WmtsConnectionInfo,
                                                    nameElement.Value,
                                                    urlElement.Value);
                string message = new FileReaderErrorMessageBuilder(path).Build(errorMessage);

                log.Warn(message, exception);
            }

            return(null);
        }
Esempio n. 7
0
        private static ReferenceLine CreateReferenceLine(MapLineData lineMapData, string shapeFilePath)
        {
            MapFeature[] lineFeatures = lineMapData.Features.ToArray();

            if (lineFeatures.Length > 1)
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(RiskeerCommonIOResources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
                throw new CriticalFileReadException(message);
            }

            var        referenceLine        = new ReferenceLine();
            MapFeature referenceLineFeature = lineMapData.Features.First();

            MapGeometry[] referenceGeometries = referenceLineFeature.MapGeometries.ToArray();

            if (referenceGeometries.Length > 1)
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(RiskeerCommonIOResources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
                throw new CriticalFileReadException(message);
            }

            MapGeometry referenceGeometry = referenceGeometries[0];

            referenceLine.SetGeometry(referenceGeometry.PointCollections.First().Select(t => new Point2D(t)).ToArray());
            return(referenceLine);
        }
Esempio n. 8
0
        public void ReadLine_FileLacksIdsWithWhiteLine_ThrowLineParseExceptionOnCorrectLine()
        {
            // Setup
            string path = Path.Combine(testDataPath, "TwoInvalidRows_LacksIdWithWhiteLine.csv");

            // Precondition
            Assert.IsTrue(File.Exists(path));

            using (var reader = new SurfaceLinesCsvReader(path))
            {
                // Call
                TestDelegate call = () => reader.ReadSurfaceLine();

                // Assert
                // 1st line has no text at all:
                var    exception       = Assert.Throws <LineParseException>(call);
                string expectedMessage = new FileReaderErrorMessageBuilder(path)
                                         .WithLocation("op regel 2")
                                         .Build("Regel heeft geen ID.");
                Assert.AreEqual(expectedMessage, exception.Message);

                // 2nd line has only whitespace text:
                expectedMessage = new FileReaderErrorMessageBuilder(path)
                                  .WithLocation("op regel 4")
                                  .Build("Regel heeft geen ID.");
                exception = Assert.Throws <LineParseException>(call);
                Assert.AreEqual(expectedMessage, exception.Message);
            }
        }
Esempio n. 9
0
        public void Import_FromPathContainingInvalidPathCharacters_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            const string filePath = "c:\\Invalid_Characters.shp";

            char[] invalidPathChars = Path.GetInvalidPathChars();
            string invalidPath      = filePath.Replace('_', invalidPathChars[0]);

            var testStructuresImporter = new TestStructuresImporter(testImportTarget,
                                                                    testReferenceLine,
                                                                    invalidPath,
                                                                    updateStrategy,
                                                                    messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testStructuresImporter.Import();

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string expectedMessage = new FileReaderErrorMessageBuilder(invalidPath)
                                         .Build("Er zitten ongeldige tekens in het bestandspad. Alle tekens in het bestandspad moeten geldig zijn.");
                StringAssert.StartsWith(expectedMessage, messages.First());
            });
            Assert.IsFalse(importResult);
        }
        /// <summary>
        /// Gets the version of the hydraulic boundary database.
        /// </summary>
        /// <returns>The version found in the database, or <see cref="string.Empty"/> if the version cannot be found.</returns>
        /// <exception cref="CriticalFileReadException">Thrown when the version cannot be read..</exception>
        public string ReadVersion()
        {
            try
            {
                using (IDataReader reader = CreateDataReader(HydraulicBoundaryDatabaseQueryBuilder.GetVersionQuery(), null))
                {
                    if (reader.Read())
                    {
                        string version = Convert.ToString(reader[GeneralTableDefinitions.GeneratedVersion]);

                        if (!string.IsNullOrEmpty(version))
                        {
                            return(version);
                        }
                    }

                    string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
                    throw new CriticalFileReadException(message);
                }
            }
            catch (SQLiteException e)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_HydraulicBoundaryLocation_read_from_database);
                throw new CriticalFileReadException(message, e);
            }
        }
Esempio n. 11
0
        public void Import_FromDirectoryPath_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            string folderPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO) + Path.DirectorySeparatorChar;

            var testStructuresImporter = new TestStructuresImporter(testImportTarget,
                                                                    testReferenceLine,
                                                                    folderPath,
                                                                    updateStrategy,
                                                                    messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testStructuresImporter.Import();

            // Assert
            string expectedMessage = new FileReaderErrorMessageBuilder(folderPath)
                                     .Build(CoreCommonUtilResources.Error_Path_must_not_point_to_empty_file_name);

            TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
            Assert.IsFalse(importResult);
        }
Esempio n. 12
0
        /// <summary>
        /// Validates the file path.
        /// </summary>
        /// <param name="path">The file path to be validated.</param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="path"/> is invalid.</exception>
        /// <remarks>A valid path:
        /// <list type="bullet">
        /// <item>is not empty or <c>null</c>,</item>
        /// <item>does not consist out of only whitespace characters,</item>
        /// <item>does not contain an invalid character,</item>
        /// <item>does not end with a directory or path separator (empty file name).</item>
        /// </list></remarks>
        /// <seealso cref="Path.GetInvalidPathChars()"/>
        public static void ValidateFilePath(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                string message = new FileReaderErrorMessageBuilder(path).Build(Resources.Error_Path_must_be_specified);
                throw new ArgumentException(message);
            }

            string name;

            try
            {
                name = Path.GetFileName(path);
            }
            catch (ArgumentException exception)
            {
                string message = new FileReaderErrorMessageBuilder(path)
                                 .Build(Resources.Error_Path_cannot_contain_invalid_characters);
                throw new ArgumentException(message, exception);
            }

            if (string.IsNullOrEmpty(name))
            {
                string message = new FileReaderErrorMessageBuilder(path).Build(Resources.Error_Path_must_not_point_to_empty_file_name);
                throw new ArgumentException(message);
            }
        }
Esempio n. 13
0
        public void Import_FromInvalidEmptyPath_FalseAndLogError(string filePath)
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            var testStructuresImporter = new TestStructuresImporter(testImportTarget,
                                                                    testReferenceLine,
                                                                    filePath,
                                                                    updateStrategy,
                                                                    messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testStructuresImporter.Import();

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string[] messageArray  = messages.ToArray();
                string expectedMessage = new FileReaderErrorMessageBuilder(filePath)
                                         .Build(CoreCommonUtilResources.Error_Path_must_be_specified);
                StringAssert.StartsWith(expectedMessage, messageArray[0]);
            });
            Assert.IsFalse(importResult);
        }
Esempio n. 14
0
        private static void ValidateDatabaseVersion(RiskeerEntities riskeerEntities, string databaseFilePath)
        {
            try
            {
                string databaseVersion = riskeerEntities.VersionEntities.Select(v => v.Version).Single();
                if (!ProjectVersionHelper.IsValidVersion(databaseVersion))
                {
                    string m = string.Format(Resources.StorageSqLite_ValidateDatabaseVersion_DatabaseVersion_0_is_invalid,
                                             databaseVersion);
                    string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(m);
                    throw new StorageValidationException(message);
                }

                if (ProjectVersionHelper.IsNewerThanCurrent(databaseVersion))
                {
                    string m = string.Format(Resources.StorageSqLite_ValidateDatabaseVersion_DatabaseVersion_0_higher_then_current_DatabaseVersion_1_,
                                             databaseVersion, ProjectVersionHelper.GetCurrentDatabaseVersion());
                    string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(m);
                    throw new StorageValidationException(message);
                }
            }
            catch (InvalidOperationException e)
            {
                string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(Resources.StorageSqLite_ValidateDatabaseVersion_Database_must_have_one_VersionEntity_row);
                throw new StorageValidationException(message, e);
            }
        }
Esempio n. 15
0
        public void ReadLine_FileHasIncompleteCoordinateTriplets_ThrowLineParseException()
        {
            // Setup
            string path = Path.Combine(testDataPath, "TwoInvalidRows_IncompleteCoordinateTriplets.csv");

            // Precondition
            Assert.IsTrue(File.Exists(path));

            using (var reader = new SurfaceLinesCsvReader(path))
            {
                // Call
                TestDelegate call = () => reader.ReadSurfaceLine();

                // Assert
                // 1st row lacks 1 coordinate value:
                var    exception       = Assert.Throws <LineParseException>(call);
                string expectedMessage = new FileReaderErrorMessageBuilder(path)
                                         .WithLocation("op regel 2")
                                         .WithSubject("profielschematisatie 'LacksOneCoordinate'")
                                         .Build("Voor de profielschematisatie ontbreken er waardes om een 3D (X,Y,Z) punt aan te maken.");
                Assert.AreEqual(expectedMessage, exception.Message);

                // 2nd row lacks 2 coordinate values:
                exception       = Assert.Throws <LineParseException>(call);
                expectedMessage = new FileReaderErrorMessageBuilder(path)
                                  .WithLocation("op regel 3")
                                  .WithSubject("profielschematisatie 'LacksTwoCoordinates'")
                                  .Build("Voor de profielschematisatie ontbreken er waardes om een 3D (X,Y,Z) punt aan te maken.");
                Assert.AreEqual(expectedMessage, exception.Message);
            }
        }
        /// <summary>
        /// Gets the correct schema definition depending on the version.
        /// </summary>
        /// <param name="schemaDefinitions">All the schema definitions.</param>
        /// <returns>The schema definition that corresponds to the XML file.</returns>
        /// <exception cref="CriticalFileReadException">Thrown when the version
        /// from the XML file is not supported.</exception>
        private CalculationConfigurationSchemaDefinition GetSchemaDefinition(IEnumerable <CalculationConfigurationSchemaDefinition> schemaDefinitions)
        {
            int versionNumber;

            try
            {
                var combinedXmlSchemaDefinition = new CombinedXmlSchemaDefinition(Resources.VersieSchema, new Dictionary <string, string>());
                combinedXmlSchemaDefinition.Validate(xmlDocument);

                versionNumber = GetVersionNumber();
            }
            catch (XmlSchemaValidationException)
            {
                versionNumber = 0;
            }

            CalculationConfigurationSchemaDefinition schemaDefinition = schemaDefinitions.SingleOrDefault(sd => sd.VersionNumber == versionNumber);

            if (schemaDefinition == null)
            {
                string message = new FileReaderErrorMessageBuilder(xmlFilePath)
                                 .Build(Resources.CalculationConfigurationReader_GetSchemaDefinition_Not_supported_version);

                throw new CriticalFileReadException(message);
            }

            return(schemaDefinition);
        }
        /// <summary>
        /// Creates a configured instance of <see cref="LineParseException"/>.
        /// </summary>
        /// <param name="currentLine">The line number being read.</param>
        /// <param name="lineParseErrorMessage">The critical error message.</param>
        /// <returns>New <see cref="LineParseException"/> with message set.</returns>
        private LineParseException CreateLineParseException(int currentLine, string lineParseErrorMessage)
        {
            string locationDescription = string.Format(UtilResources.TextFile_On_LineNumber_0_, currentLine);
            string message             = new FileReaderErrorMessageBuilder(filePath).WithLocation(locationDescription)
                                         .Build(lineParseErrorMessage);

            return(new LineParseException(message));
        }
        /// <summary>
        /// Creates a configured instance of <see cref="CriticalFileReadException"/>.
        /// </summary>
        /// <param name="currentLine">The line number being read.</param>
        /// <param name="criticalErrorMessage">The critical error message.</param>
        /// <param name="innerException">Optional: exception that caused this exception to be thrown.</param>
        /// <returns>New <see cref="CriticalFileReadException"/> with message and inner exception set.</returns>
        private CriticalFileReadException CreateCriticalFileReadException(int currentLine, string criticalErrorMessage, Exception innerException = null)
        {
            string locationDescription = string.Format(UtilResources.TextFile_On_LineNumber_0_, currentLine);
            string message             = new FileReaderErrorMessageBuilder(filePath).WithLocation(locationDescription)
                                         .Build(criticalErrorMessage);

            return(new CriticalFileReadException(message, innerException));
        }
Esempio n. 19
0
        private static SoilProfileReadException CreateSoilProfileReadException(string filePath, string profileName, Exception innerException)
        {
            string message = new FileReaderErrorMessageBuilder(filePath)
                             .WithSubject(string.Format(Resources.SoilProfileReader_SoilProfileName_0_, profileName))
                             .Build(innerException.Message);

            return(new SoilProfileReadException(message, profileName, innerException));
        }
Esempio n. 20
0
 private void CheckRequiredAttributePresence(string shapeFilePath)
 {
     if (!pointsShapeFileReader.HasAttribute(idAttributeName))
     {
         string fullMessage = new FileReaderErrorMessageBuilder(shapeFilePath).Build(string.Format(Resources.ProfileLocationReader_CheckRequiredAttributePresence_Missing_attribute_0_, idAttributeName));
         throw new CriticalFileReadException(fullMessage);
     }
 }
Esempio n. 21
0
        public void Constructor_InvalidStringArgument_ThrowsArgumentException(string path)
        {
            // Call
            TestDelegate call = () => new SurfaceLinesCsvReader(path);

            // Assert
            string expectedMessage = new FileReaderErrorMessageBuilder(path).Build("Bestandspad mag niet leeg of ongedefinieerd zijn.");

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
        /// <summary>
        /// Creates a configured instance of <see cref="LineParseException"/>.
        /// </summary>
        /// <param name="currentLine">The line number being read.</param>
        /// <param name="locationName">The name of the location being read.</param>
        /// <param name="lineParseErrorMessage">The critical error message.</param>
        /// <param name="innerException">Optional: exception that caused this exception to be thrown.</param>
        /// <returns>New <see cref="LineParseException"/> with message and inner exceptions set.</returns>
        private LineParseException CreateLineParseException(int currentLine, string locationName, string lineParseErrorMessage, Exception innerException = null)
        {
            string locationDescription = string.Format(UtilResources.TextFile_On_LineNumber_0_, currentLine);
            string subjectDescription  = string.Format(Resources.CharacteristicPointsCsvReader_LocationName_0_, locationName);
            string message             = new FileReaderErrorMessageBuilder(filePath).WithLocation(locationDescription)
                                         .WithSubject(subjectDescription)
                                         .Build(lineParseErrorMessage);

            return(new LineParseException(message, innerException));
        }
Esempio n. 23
0
 /// <summary>
 /// Validates the <paramref name="shapeFilePath"/>.
 /// </summary>
 /// <param name="shapeFilePath">The file path to the shape file.</param>
 /// <exception cref="ArgumentException">Thrown when <paramref name="shapeFilePath"/> is invalid.</exception>
 /// <exception cref="CriticalFileReadException">Thrown when <paramref name="shapeFilePath"/> does not exist.</exception>
 private static void ValidateFilePath(string shapeFilePath)
 {
     IOUtils.ValidateFilePath(shapeFilePath);
     if (!File.Exists(shapeFilePath))
     {
         string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                          .Build(Resources.Error_File_does_not_exist);
         throw new CriticalFileReadException(message);
     }
 }
        public void Constructor_InvalidStringArgument_ThrowsArgumentException(string path)
        {
            // Call
            TestDelegate call = () => new StructuresCharacteristicsCsvReader(path);

            // Assert
            string expectedMessage = new FileReaderErrorMessageBuilder(path).Build(UtilResources.Error_Path_must_be_specified);

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
        /// <summary>
        /// Validates whether a file exists at the <see cref="xmlFilePath"/>.
        /// </summary>
        /// <exception cref="CriticalFileReadException">Thrown when no existing file is found.</exception>
        private void ValidateFileExists()
        {
            if (!File.Exists(xmlFilePath))
            {
                string message = new FileReaderErrorMessageBuilder(xmlFilePath)
                                 .Build(CoreCommonUtilResources.Error_File_does_not_exist);

                throw new CriticalFileReadException(message);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Establishes a connection to an existing <paramref name="databaseFilePath"/>.
        /// </summary>
        /// <param name="databaseFilePath">The path of the database file to connect to.</param>
        /// <exception cref="CouldNotConnectException">No file exists at <paramref name="databaseFilePath"/>.</exception>
        private static string GetConnectionToFile(string databaseFilePath)
        {
            if (!File.Exists(databaseFilePath))
            {
                string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(UtilResources.Error_File_does_not_exist);
                throw new CouldNotConnectException(message);
            }

            return(GetConnectionToStorage(databaseFilePath));
        }
        public void Constructor_PathToFolder_ThrowsArgumentException()
        {
            // Call
            TestDelegate call = () => new StructuresCharacteristicsCsvReader(testDataPath);

            // Assert
            var    exception       = Assert.Throws <ArgumentException>(call);
            string expectedMessage = new FileReaderErrorMessageBuilder(testDataPath).Build(UtilResources.Error_Path_must_not_point_to_empty_file_name);

            Assert.AreEqual(expectedMessage, exception.Message);
        }
Esempio n. 28
0
        /// <summary>
        /// Builds the error message as a consequence of validation errors during
        /// the import.
        /// </summary>
        /// <param name="structureName">The name of the structure.</param>
        /// <param name="structureId">The id of the structure.</param>
        /// <param name="validationErrors">The errors that occurred during the validation.</param>
        /// <exception cref="CriticalFileValidationException">Thrown when function is called.</exception>
        protected void ThrowValidationErrorForStructure(string structureName, string structureId, IEnumerable <string> validationErrors)
        {
            string shortMessage = new FileReaderErrorMessageBuilder(GetStructureDataCsvFilePath())
                                  .WithSubject(string.Format(Resources.StructuresImporter_StructureName_0_StructureId_1_, structureName, structureId))
                                  .Build(Resources.StructuresImporter_LogValidationErrorForStructure_Click_details_for_full_message_0_);
            string messageRemainder = string.Format(Resources.StructuresImporter_LogValidationErrorForStructure_One_or_more_erors_skip_structure_ErrorMessageList_0_,
                                                    string.Join(Environment.NewLine, validationErrors.Select(msg => "* " + msg)));
            string message = string.Format(shortMessage, messageRemainder);

            throw new CriticalFileValidationException(message);
        }
Esempio n. 29
0
        /// <summary>
        /// Gets the reference line map data.
        /// </summary>
        /// <param name="lineShapeReader">The line shape reader.</param>
        /// <param name="shapeFilePath">The shapefile path.</param>
        /// <returns>The map data representing the reference line.</returns>
        /// <exception cref="CriticalFileReadException">
        /// When either:
        /// <list type="bullet">
        /// <item>There isn't exactly 1 polyline in the shapefile.</item>
        /// <item>The shapefile doesn't contains lines.</item>
        /// </list>
        /// </exception>
        private static MapLineData GetReferenceLineMapData(PolylineShapeFileReader lineShapeReader, string shapeFilePath)
        {
            if (lineShapeReader.GetNumberOfFeatures() != 1)
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(RiskeerCommonIOResources.ReferenceLineReader_File_must_contain_1_polyline);
                throw new CriticalFileReadException(message);
            }

            return((MapLineData)lineShapeReader.ReadFeature(RiskeerCommonDataResources.ReferenceLine_DisplayName));
        }
Esempio n. 30
0
        public void Constructor_PathToFolder_ThrowsArgumentException()
        {
            // Call
            TestDelegate call = () => new SurfaceLinesCsvReader(testDataPath);

            // Assert
            var    exception       = Assert.Throws <ArgumentException>(call);
            string expectedMessage = new FileReaderErrorMessageBuilder(testDataPath).Build("Bestandspad mag niet verwijzen naar een lege bestandsnaam.");

            Assert.AreEqual(expectedMessage, exception.Message);
        }