/// <summary>
        /// Reads and parses the next data row to create a new instance of <see cref="CharacteristicPoints"/>,
        /// which will contain all the declared characteristic points for some surface line.
        /// </summary>
        /// <returns>Returns the parsed characteristic points location, or <c>null</c> when at the end of the file.</returns>
        /// <exception cref="CriticalFileReadException">Thrown when a critical error has occurred, which may be caused by:
        /// <list type="bullet">
        /// <item>The file cannot be found at specified path.</item>
        /// <item>The specified path is invalid, such as being on an unmapped drive.</item>
        /// <item>Some other I/O related issue occurred, such as: path includes an incorrect
        /// or invalid syntax for file name, directory name, or volume label.</item>
        /// <item>There is insufficient memory to allocate a buffer for the returned string.</item>
        /// <item>The file is incompatible for importing characteristic points.</item>
        /// </list>
        /// </exception>
        /// <exception cref="LineParseException">Thrown when a parse error has occurred for the current row, which may be caused by:
        /// <list type="bullet">
        /// <item>The row doesn't use ';' as separator character.</item>
        /// <item>The row contains a coordinate value that cannot be parsed as a double.</item>
        /// <item>The row contains a number that is too big or too small to be represented with a double.</item>
        /// <item>The row is missing an identifier value.</item>
        /// <item>The row is missing values to form a characteristic point.</item>
        /// </list>
        /// </exception>
        public CharacteristicPoints ReadCharacteristicPointsLocation()
        {
            if (fileReader == null)
            {
                fileReader = StreamReaderHelper.InitializeStreamReader(filePath);

                ValidateHeader(fileReader);
                lineNumber = 2;
            }

            string readText = ReadNextNonEmptyLine();

            if (readText != null)
            {
                try
                {
                    return(CreateCharacteristicPointsLocation(readText));
                }
                finally
                {
                    lineNumber++;
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Reads and consumes the next data row which contains a surface line, parsing the data to create an instance
        /// of <see cref="SurfaceLine"/>.
        /// </summary>
        /// <returns>Returns the parsed surface line, or null when at the end of the file.</returns>
        /// <exception cref="CriticalFileReadException">Thrown when a critical error has occurred, which may be caused by:
        /// <list type="bullet">
        /// <item>The file cannot be found at specified path.</item>
        /// <item>The specified path is invalid, such as being on an unmapped drive.</item>
        /// <item>Some other I/O related issue occurred, such as: path includes an incorrect
        /// or invalid syntax for file name, directory name, or volume label.</item>
        /// <item>There is insufficient memory to allocate a buffer for the returned string.</item>
        /// <item>The file is incompatible for importing surface lines.</item>
        /// </list>
        /// </exception>
        /// <exception cref="LineParseException">Thrown when a parse error has occurred for the current row, which may be caused by:
        /// <list type="bullet">
        /// <item>The row doesn't use ';' as separator character.</item>
        /// <item>The row contains a coordinate value that cannot be parsed as a double.</item>
        /// <item>The row contains a number that is too big or too small to be represented with a double.</item>
        /// <item>The row is missing an identifier value.</item>
        /// <item>The row is missing values to form a surface line point.</item>
        /// </list>
        /// </exception>
        public SurfaceLine ReadSurfaceLine()
        {
            if (fileReader == null)
            {
                fileReader = StreamReaderHelper.InitializeStreamReader(filePath);

                ValidateHeader(fileReader, 1);
                lineNumber = 2;
            }

            string readText = ReadNextNonEmptyLine();

            if (readText != null)
            {
                try
                {
                    return(CreateSurfaceLine(readText));
                }
                finally
                {
                    lineNumber++;
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Reads the next structure parameter from file.
        /// </summary>
        /// <returns>The next <see cref="StructuresParameterRow"/> based on the read file,
        /// or <c>null</c> when at the end of the file.</returns>
        /// <exception cref="CriticalFileReadException">
        /// Thrown when either:
        /// <list type="bullet">
        /// <item>The file or directory cannot be found.</item>
        /// <item>The file is empty.</item>
        /// <item>Some I/O related problem occurred.</item>
        /// <item>The header is not in the required format.</item>
        /// </list></exception>
        /// <exception cref="LineParseException">Thrown when either:
        /// <list type="bullet">
        /// <item>The line does not contain the separator character.</item>
        /// <item>Location id field is empty or consists only of white-space characters.</item>
        /// <item>Parameter id field is empty or consists only of white-space characters.</item>
        /// <item>Numeric value field is not a number or too large/small to be represented as <see cref="double"/>.</item>
        /// <item>Variance value field is not a number or too large/small to be represented as <see cref="double"/>.</item>
        /// <item>Boolean field is not a valid value.</item>
        /// </list></exception>
        public StructuresParameterRow ReadLine()
        {
            if (fileReader == null)
            {
                fileReader = StreamReaderHelper.InitializeStreamReader(filePath);

                lineNumber = 1;
                IndexFile(fileReader);
                lineNumber++;
            }

            string readText = ReadNextNonEmptyLine(fileReader);

            if (readText != null)
            {
                try
                {
                    return(CreateStructuresParameterRow(readText));
                }
                finally
                {
                    lineNumber++;
                }
            }

            return(null);
        }
        /// <summary>
        /// Reads the file to determine the number of available <see cref="CharacteristicPoints"/>
        /// data rows.
        /// </summary>
        /// <returns>A value greater than or equal to 0.</returns>
        /// <exception cref="CriticalFileReadException">Thrown when a critical error has occurred, which may be caused by:
        /// <list type="bullet">
        /// <item>The file cannot be found at specified path.</item>
        /// <item>The specified path is invalid, such as being on an unmapped drive.</item>
        /// <item>Some other I/O related issue occurred, such as: path includes an incorrect
        /// or invalid syntax for file name, directory name, or volume label.</item>
        /// <item>There is insufficient memory to allocate a buffer for the returned string.</item>
        /// <item>The file is incompatible for importing characteristic points locations.</item>
        /// </list>
        /// </exception>
        public int GetLocationsCount()
        {
            using (StreamReader reader = StreamReaderHelper.InitializeStreamReader(filePath))
            {
                ValidateHeader(reader);

                return(CountNonEmptyLines(reader, 2));
            }
        }
예제 #5
0
        public void InitializeStreamReader_ValidFile_ReturnsStreamReader()
        {
            // Setup
            string filePath = Path.Combine(testDataPath, "empty.csv");

            // Call
            using (StreamReader streamReader = StreamReaderHelper.InitializeStreamReader(filePath))
            {
                // Assert
                Assert.IsInstanceOf <StreamReader>(streamReader);
            }
        }
예제 #6
0
        public void InitializeStreamReader_NotExistingFolder_ThrowsCriticalFileReadExceptionWithInnerDirectoryNotFoundException()
        {
            // Setup
            string filePath        = Path.Combine(notExistingTestDataPath, "empty.csv");
            string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bestandspad verwijst naar een map die niet bestaat.";

            // Call
            TestDelegate call = () => StreamReaderHelper.InitializeStreamReader(filePath);

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

            Assert.AreEqual(expectedMessage, exception.Message);
            Assert.IsInstanceOf <DirectoryNotFoundException>(exception.InnerException);
        }
예제 #7
0
        public void InitializeStreamReader_NotExistingFile_ThrowsCriticalFileReadExceptionWithInnerFileNotFoundException()
        {
            // Setup
            const string filePath        = "nothing";
            string       expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bestand bestaat niet.";

            // Call
            TestDelegate call = () => StreamReaderHelper.InitializeStreamReader(filePath);

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

            Assert.AreEqual(expectedMessage, exception.Message);
            Assert.IsInstanceOf <FileNotFoundException>(exception.InnerException);
        }