예제 #1
0
 private int GetNumberOfCharacteristicPointLocations(CharacteristicPointsCsvReader reader)
 {
     try
     {
         return(reader.GetLocationsCount());
     }
     catch (CriticalFileReadException e)
     {
         Log.Error(e.Message, e);
         return(-1);
     }
 }
예제 #2
0
        private ReadResult <CharacteristicPoints> ReadCharacteristicPoints()
        {
            NotifyProgress(RiskeerCommonIOResources.SurfaceLinesCsvImporter_Reading_characteristic_points_file, 1, 1);
            string characteristicPointsFilePath = GetCharacteristicPointsFilePath();

            if (characteristicPointsFilePath == null)
            {
                return(new ReadResult <CharacteristicPoints>(false));
            }

            using (CharacteristicPointsCsvReader reader = CreateCharacteristicPointsReader(characteristicPointsFilePath))
            {
                if (reader == null)
                {
                    return(new ReadResult <CharacteristicPoints>(true));
                }

                ReadResult <CharacteristicPoints> readCharacteristicPoints = ReadCharacteristicPoints(characteristicPointsFilePath, reader);
                return(readCharacteristicPoints);
            }
        }
예제 #3
0
        /// <summary>
        /// Adds a valid <see cref="CharacteristicPoints"/> read from <paramref name="reader"/> to the <paramref name="characteristicPointsList"/>.
        /// </summary>
        /// <param name="characteristicPointsList">The list to add the valid <see cref="CharacteristicPoints"/> to.</param>
        /// <param name="reader">The reader to read the <see cref="CharacteristicPoints"/> from.</param>
        /// <exception cref="CriticalFileReadException">Thrown when <paramref name="characteristicPointsList"/> already contains a <see cref="CharacteristicPoints"/>
        /// with the same name as the new <see cref="CharacteristicPoints"/>.</exception>
        private void AddValidCharacteristicPointsLocationToCollection(List <CharacteristicPoints> characteristicPointsList, CharacteristicPointsCsvReader reader)
        {
            try
            {
                CharacteristicPoints location = reader.ReadCharacteristicPointsLocation();

                if (IsCharacteristicPointsLocationsAlreadyDefined(characteristicPointsList, location))
                {
                    characteristicPointsList.Add(location);
                }
            }
            catch (LineParseException e)
            {
                Log.ErrorFormat(RiskeerCommonIOResources.SurfaceLinesCsvImporter_ReadCharacteristicPoints_ParseErrorMessage_0_CharacteristicPoints_skipped,
                                e.Message);
            }
        }
예제 #4
0
        private ReadResult <CharacteristicPoints> ReadCharacteristicPoints(string path, CharacteristicPointsCsvReader reader)
        {
            int itemCount = GetNumberOfCharacteristicPointLocations(reader);

            if (itemCount == -1)
            {
                return(new ReadResult <CharacteristicPoints>(true));
            }

            string stepName = string.Format(RiskeerCommonIOResources.SurfaceLinesCsvImporter_Read_CharacteristicPoints_0_,
                                            Path.GetFileName(path));

            NotifyProgress(stepName, 0, itemCount);

            var readCharacteristicPointsLocations = new List <CharacteristicPoints>(itemCount);

            for (var i = 0; i < itemCount && !Canceled; i++)
            {
                try
                {
                    AddValidCharacteristicPointsLocationToCollection(readCharacteristicPointsLocations, reader);
                }
                catch (CriticalFileReadException e)
                {
                    return(HandleCriticalReadError <CharacteristicPoints>(e));
                }

                NotifyProgress(stepName, i + 1, itemCount);
            }

            return(new ReadResult <CharacteristicPoints>(false)
            {
                Items = readCharacteristicPointsLocations
            });
        }