Esempio n. 1
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 RiskeerEntities(connectionString))
                    originalHash = dbContext.VersionEntities.Select(v => v.FingerPrint).First();

                byte[] hash = FingerprintHelper.Get(stagedProject.Entity);
                return(!FingerprintHelper.AreEqual(originalHash, hash));
            }
            catch (CannotDetermineFingerprintException e)
            {
                if (e.InnerException is QuotaExceededException)
                {
                    throw new StorageException(Resources.StorageSqLite_HasStagedProjectChanges_Project_contains_too_many_objects_to_generate_fingerprint, e);
                }

                throw new StorageException(e.Message, e);
            }
        }
Esempio n. 2
0
        private void SaveProjectInDatabase(string databaseFilePath)
        {
            string connectionString = GetConnectionToNewFile(databaseFilePath);

            using (var dbContext = new RiskeerEntities(connectionString))
            {
                try
                {
                    dbContext.VersionEntities.Add(new VersionEntity
                    {
                        Version     = ProjectVersionHelper.GetCurrentDatabaseVersion(),
                        Timestamp   = DateTime.Now,
                        FingerPrint = FingerprintHelper.Get(stagedProject.Entity)
                    });
                    dbContext.ProjectEntities.Add(stagedProject.Entity);
                    dbContext.SaveChanges();
                }
                catch (DataException exception)
                {
                    throw CreateStorageWriterException(databaseFilePath, Resources.Error_saving_database, exception);
                }
                catch (CannotDetermineFingerprintException exception)
                {
                    throw CreateStorageWriterException(databaseFilePath, exception.Message, exception);
                }
                catch (SystemException exception)
                {
                    if (exception is InvalidOperationException || exception is NotSupportedException)
                    {
                        throw CreateStorageWriterException(databaseFilePath, Resources.Error_during_connection, exception);
                    }

                    throw;
                }

                stagedProject.Model.Name = Path.GetFileNameWithoutExtension(databaseFilePath);
            }
        }