示例#1
0
        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;
                }
            }
        }
示例#2
0
        public bool HasStagedProjectChanges(string filePath)
        {
            if (!HasStagedProject)
            {
                throw new InvalidOperationException("Call 'StageProject(IProject)' first before calling this method.");
            }
            if (string.IsNullOrWhiteSpace(filePath))
            {
                return(true);
            }

            string connectionString = GetConnectionToExistingFile(filePath);

            try
            {
                byte[] originalHash;
                using (var dbContext = new Entities(connectionString))
                    originalHash = dbContext.VersionEntities.Select(v => v.FingerPrint).First();

                byte[] hash = FingerprintHelper.Get(stagedProject.Entity);
                return(!FingerprintHelper.AreEqual(originalHash, hash));
            }
            catch (Exception e)
            {
                if (e.InnerException is QuotaExceededException)
                {
                    throw new StorageException("Opgeslagen project bevat teveel objecten om een vingerafdruk van te maken", e);
                }
                throw new StorageException(e.Message, e);
            }
        }