예제 #1
0
 private void InquireConfirmation(ReadHydraulicBoundaryDatabase readHydraulicBoundaryDatabase)
 {
     if (updateHandler.IsConfirmationRequired(ImportTarget, readHydraulicBoundaryDatabase) &&
         !updateHandler.InquireConfirmation())
     {
         Cancel();
     }
 }
예제 #2
0
 private void AddHydraulicBoundaryDatabaseToDataModel(ReadHydraulicBoundaryDatabase readHydraulicBoundaryDatabase,
                                                      ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase,
                                                      IEnumerable <long> excludedLocationIds)
 {
     NotifyProgress(RiskeerCommonIOResources.Importer_ProgressText_Adding_imported_data_to_AssessmentSection, 4, numberOfSteps);
     changedObservables.AddRange(updateHandler.Update(ImportTarget, readHydraulicBoundaryDatabase, readHydraulicLocationConfigurationDatabase,
                                                      excludedLocationIds, FilePath, GetHlcdFilePath()));
 }
예제 #3
0
        protected override bool OnImport()
        {
            ReadResult <ReadHydraulicBoundaryDatabase> readHydraulicBoundaryDatabaseResult = ReadHydraulicBoundaryDatabase();

            if (readHydraulicBoundaryDatabaseResult.CriticalErrorOccurred || Canceled)
            {
                return(false);
            }

            ReadHydraulicBoundaryDatabase readHydraulicBoundaryDatabase = readHydraulicBoundaryDatabaseResult.Items.Single();

            InquireConfirmation(readHydraulicBoundaryDatabase);

            if (Canceled)
            {
                return(false);
            }

            string hlcdFilePath = GetHlcdFilePath();

            ReadResult <ReadHydraulicLocationConfigurationDatabase> readHydraulicLocationConfigurationDatabaseResult = ReadHydraulicLocationConfigurationDatabase(
                hlcdFilePath, readHydraulicBoundaryDatabase.TrackId);

            if (readHydraulicLocationConfigurationDatabaseResult.CriticalErrorOccurred || Canceled)
            {
                return(false);
            }

            ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = readHydraulicLocationConfigurationDatabaseResult.Items.Single();
            IEnumerable <ReadHydraulicLocationConfigurationDatabaseSettings> hydraulicLocationConfigurationDatabaseSettings =
                readHydraulicLocationConfigurationDatabase.ReadHydraulicLocationConfigurationDatabaseSettings;

            if (hydraulicLocationConfigurationDatabaseSettings != null && hydraulicLocationConfigurationDatabaseSettings.Count() != 1)
            {
                Log.Error(BuildErrorMessage(hlcdFilePath, Resources.HydraulicBoundaryDatabaseImporter_HLCD_Invalid_number_of_ScenarioInformation_entries));
                return(false);
            }

            if (readHydraulicLocationConfigurationDatabase.UsePreprocessorClosure &&
                !File.Exists(HydraulicBoundaryDatabaseHelper.GetPreprocessorClosureFilePath(hlcdFilePath)))
            {
                Log.Error(BuildErrorMessage(hlcdFilePath, Resources.HydraulicBoundaryDatabaseImporter_PreprocessorClosure_sqlite_Not_Found));
                return(false);
            }

            ReadResult <IEnumerable <long> > readExcludedLocationsResult = ReadExcludedLocations();

            if (readExcludedLocationsResult.CriticalErrorOccurred || Canceled)
            {
                return(false);
            }

            AddHydraulicBoundaryDatabaseToDataModel(readHydraulicBoundaryDatabase, readHydraulicLocationConfigurationDatabase,
                                                    readExcludedLocationsResult.Items.Single());

            return(true);
        }
예제 #4
0
        private static void AssertReadHydraulicBoundaryDatabase(ReadHydraulicBoundaryDatabase readHydraulicBoundaryDatabase)
        {
            Assert.AreEqual("Dutch coast South19-11-2015 12:0013", readHydraulicBoundaryDatabase.Version);
            Assert.AreEqual((long)13, readHydraulicBoundaryDatabase.TrackId);
            Assert.AreEqual(18, readHydraulicBoundaryDatabase.Locations.Count());

            ReadHydraulicBoundaryLocation location = readHydraulicBoundaryDatabase.Locations.First();

            Assert.AreEqual(1, location.Id);
            Assert.AreEqual("punt_flw_ 1", location.Name);
            Assert.AreEqual(52697.5, location.CoordinateX);
            Assert.AreEqual(427567.0, location.CoordinateY);
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            const long   trackId = 1;
            const string version = "version";
            IEnumerable <ReadHydraulicBoundaryLocation> locations = Enumerable.Empty <ReadHydraulicBoundaryLocation>();

            // Call
            var database = new ReadHydraulicBoundaryDatabase(trackId, version, locations);

            // Assert
            Assert.AreEqual(trackId, database.TrackId);
            Assert.AreEqual(version, database.Version);
            Assert.AreSame(locations, database.Locations);
        }
        public void Read_ValidFile_ReturnsReadHydraulicBoundaryDatabase()
        {
            // Setup
            string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "complete.sqlite");

            using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile))
            {
                // Call
                ReadHydraulicBoundaryDatabase readDatabase = reader.Read();

                // Assert
                Assert.AreEqual("Dutch coast South19-11-2015 12:0013", readDatabase.Version);
                Assert.AreEqual(13, readDatabase.TrackId);
                Assert.AreEqual(18, readDatabase.Locations.Count());
                ReadHydraulicBoundaryLocation location = readDatabase.Locations.First();
                Assert.AreEqual(1, location.Id);
                Assert.AreEqual("punt_flw_ 1", location.Name);
                Assert.AreEqual(52697.5, location.CoordinateX);
                Assert.AreEqual(427567.0, location.CoordinateY);
            }
        }
예제 #7
0
        public IEnumerable <IObservable> Update(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, ReadHydraulicBoundaryDatabase readHydraulicBoundaryDatabase,
                                                ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase,
                                                IEnumerable <long> excludedLocationIds, string hydraulicBoundaryDatabaseFilePath, string hlcdFilePath)
        {
            if (hydraulicBoundaryDatabase == null)
            {
                throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase));
            }

            if (readHydraulicBoundaryDatabase == null)
            {
                throw new ArgumentNullException(nameof(readHydraulicBoundaryDatabase));
            }

            if (readHydraulicLocationConfigurationDatabase == null)
            {
                throw new ArgumentNullException(nameof(readHydraulicLocationConfigurationDatabase));
            }

            if (excludedLocationIds == null)
            {
                throw new ArgumentNullException(nameof(excludedLocationIds));
            }

            if (hydraulicBoundaryDatabaseFilePath == null)
            {
                throw new ArgumentNullException(nameof(hydraulicBoundaryDatabaseFilePath));
            }

            if (hlcdFilePath == null)
            {
                throw new ArgumentNullException(nameof(hlcdFilePath));
            }

            if (!IsValidReadHydraulicLocationConfigurationDatabase(readHydraulicLocationConfigurationDatabase))
            {
                string errorMessage = $"{nameof(readHydraulicLocationConfigurationDatabase)} must be null or contain exactly one item for " +
                                      "the collection of hydraulic location configuration database settings.";
                throw new ArgumentException(errorMessage);
            }

            var changedObjects = new List <IObservable>();

            updateLocations = !hydraulicBoundaryDatabase.IsLinked() || hydraulicBoundaryDatabase.Version != readHydraulicBoundaryDatabase.Version;

            if (updateLocations)
            {
                hydraulicBoundaryDatabase.FilePath = hydraulicBoundaryDatabaseFilePath;
                hydraulicBoundaryDatabase.Version  = readHydraulicBoundaryDatabase.Version;

                SetLocations(hydraulicBoundaryDatabase, readHydraulicBoundaryDatabase.Locations,
                             readHydraulicLocationConfigurationDatabase.LocationIdMappings,
                             excludedLocationIds.ToArray());

                assessmentSection.SetHydraulicBoundaryLocationCalculations(hydraulicBoundaryDatabase.Locations);

                duneLocationsReplacementHandler.Replace(hydraulicBoundaryDatabase.Locations);

                changedObjects.AddRange(GetLocationsAndCalculationsObservables(hydraulicBoundaryDatabase));
                changedObjects.AddRange(RiskeerDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection));
            }
            else
            {
                if (hydraulicBoundaryDatabase.FilePath != hydraulicBoundaryDatabaseFilePath)
                {
                    hydraulicBoundaryDatabase.FilePath = hydraulicBoundaryDatabaseFilePath;
                }
            }

            HydraulicLocationConfigurationSettingsUpdateHelper.SetHydraulicLocationConfigurationSettings(
                hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings,
                readHydraulicLocationConfigurationDatabase.ReadHydraulicLocationConfigurationDatabaseSettings?.Single(),
                readHydraulicLocationConfigurationDatabase.UsePreprocessorClosure,
                hlcdFilePath);

            return(changedObjects);
        }
예제 #8
0
        public bool IsConfirmationRequired(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, ReadHydraulicBoundaryDatabase readHydraulicBoundaryDatabase)
        {
            if (hydraulicBoundaryDatabase == null)
            {
                throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase));
            }

            if (readHydraulicBoundaryDatabase == null)
            {
                throw new ArgumentNullException(nameof(readHydraulicBoundaryDatabase));
            }

            return(hydraulicBoundaryDatabase.IsLinked() && hydraulicBoundaryDatabase.Version != readHydraulicBoundaryDatabase.Version);
        }