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); } }
private void SaveProjectInDatabase(string databaseFilePath) { string connectionString = GetConnectionToNewFile(databaseFilePath); using (var dbContext = new Entities(connectionString)) { try { dbContext.VersionEntities.Add(new VersionEntity { Version = StoryTreeVersionHelper.GetCurrentDatabaseVersion(), TimeStamp = DateTime.Now.ToString(CultureInfo.InvariantCulture.DateTimeFormat), FingerPrint = FingerprintHelper.Get(stagedProject.Entity) }); dbContext.ProjectEntities.Add(stagedProject.Entity); dbContext.SaveChanges(); } catch (DataException exception) { throw CreateStorageWriterException(databaseFilePath, "Er is een fout opgetreden bij het opslaan", exception); } catch (SystemException exception) { if (exception is InvalidOperationException || exception is NotSupportedException) { throw CreateStorageWriterException(databaseFilePath, "Het was niet mogelijk een connectie te maken", exception); } throw; } } }