예제 #1
0
        public IProject LoadProject(string databaseFilePath)
        {
            string connectionString = GetConnectionToExistingFile(databaseFilePath);

            try
            {
                RiskeerProject project;
                using (var dbContext = new RiskeerEntities(connectionString))
                {
                    ValidateDatabaseVersion(dbContext, databaseFilePath);

                    dbContext.LoadTablesIntoContext();

                    ProjectEntity projectEntity;
                    try
                    {
                        projectEntity = dbContext.ProjectEntities.Local.Single();
                    }
                    catch (InvalidOperationException exception)
                    {
                        throw CreateStorageReaderException(databaseFilePath, Resources.StorageSqLite_LoadProject_Invalid_Riskeer_database_file, exception);
                    }

                    project = projectEntity.Read(new ReadConversionCollector());
                }

                project.Name = Path.GetFileNameWithoutExtension(databaseFilePath);
                return(project);
            }
            catch (DataException exception)
            {
                throw CreateStorageReaderException(databaseFilePath, Resources.StorageSqLite_LoadProject_Invalid_Riskeer_database_file, exception);
            }
            catch (EntityReadException exception)
            {
                throw CreateStorageReaderException(databaseFilePath, exception.Message, exception);
            }
            catch (SystemException exception)
            {
                throw CreateStorageReaderException(databaseFilePath, Resources.StorageSqLite_LoadProject_Invalid_Riskeer_database_file, exception);
            }
        }