Example #1
0
        private static void ValidateDatabaseVersion(Entities storyTreeEntities, string databaseFilePath)
        {
            try
            {
                string databaseVersion = storyTreeEntities.VersionEntities.Select(v => v.Version).Single();
                if (!StoryTreeVersionHelper.IsValidVersion(databaseVersion))
                {
                    string m = string.Format("Database versie ('{0}') is ongeldig",
                                             databaseVersion);
                    string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(m);
                    throw new FormatException(message);
                }

                if (StoryTreeVersionHelper.IsNewerThanCurrent(databaseVersion))
                {
                    string m = string.Format("Database versie ('{0}') is nieuwer dan de huidige versie ('{1}')",
                                             databaseVersion, StoryTreeVersionHelper.GetCurrentDatabaseVersion());
                    string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(m);
                    throw new FormatException(message);
                }
            }
            catch (InvalidOperationException e)
            {
                string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build("Er mag maximaal 1 rij aanwezig zijn in de VersionEntity tabel van het opslagformaat.");
                throw new FormatException(message);
            }
        }
Example #2
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("Bestandslocatie moet zijn gespecificeerd");
                throw new ArgumentException(message);
            }

            string name;

            try
            {
                name = Path.GetFileName(path);
            }
            catch (ArgumentException exception)
            {
                string message = new FileReaderErrorMessageBuilder(path)
                                 .Build("Bestandslocatie bevat invalide karakters");
                throw new ArgumentException(message, exception);
            }
            if (string.IsNullOrEmpty(name))
            {
                string message = new FileReaderErrorMessageBuilder(path).Build("Bestandslocatie mag niet leeg zijn");
                throw new ArgumentException(message);
            }
        }
Example #3
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("Bestand bestaat niet");
                throw new Exception(message);
            }

            return(GetConnectionToStorage(databaseFilePath));
        }
Example #4
0
        /// <summary>
        /// Sets the connection to the Ringtoets database.
        /// </summary>
        /// <param name="databaseFilePath">The path of the file, which is used for creating exceptions.</param>
        /// <exception cref="StorageValidationException">Thrown when the database does not contain the table <c>version</c>.</exception>
        private static string GetConnectionToStorage(string databaseFilePath)
        {
            string connectionString = SqLiteEntityConnectionStringBuilder.BuildSqLiteEntityConnectionString(databaseFilePath);

            using (var dbContext = new Entities(connectionString))
            {
                try
                {
                    dbContext.Database.Initialize(true);
                    dbContext.LoadVersionTableIntoContext();
                }
                catch (Exception exception)
                {
                    string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build("Geen geldig opslagbestand");
                    throw new Exception(message, exception);
                }
            }
            return(connectionString);
        }
Example #5
0
        /// <summary>
        /// Creates a configured instance of <see cref="StorageException"/> when reading the storage file failed.
        /// </summary>
        /// <param name="databaseFilePath">The path of the file that was attempted to connect with.</param>
        /// <param name="errorMessage">The critical error message.</param>
        /// <param name="innerException">Exception that caused this exception to be thrown.</param>
        /// <returns>Returns a new <see cref="StorageException"/>.</returns>
        private static StorageException CreateStorageReaderException(string databaseFilePath, string errorMessage, Exception innerException = null)
        {
            string message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(errorMessage);

            return(new StorageException(message, innerException));
        }