Esempio n. 1
0
        /// <summary>
        /// Transforms the surface lines into mechanism specific surface lines with characteristic
        /// points set.
        /// </summary>
        /// <param name="surfaceLines">The surface lines to transform.</param>
        /// <param name="characteristicPointsCollection">The characteristic points to use in the
        /// transformation.</param>
        /// <returns>Returns a collection of mechanism specific surface lines.</returns>
        /// <exception cref="ImportedDataTransformException">Thrown when transforming a surface
        /// line with characteristic points failed.</exception>
        private IEnumerable <T> GetTransformedSurfaceLines(IEnumerable <SurfaceLine> surfaceLines, IEnumerable <CharacteristicPoints> characteristicPointsCollection)
        {
            LogMissingSurfaceLinesOrCharacteristicPoints(surfaceLines, characteristicPointsCollection);
            IEnumerable <Tuple <SurfaceLine, CharacteristicPoints> > surfaceLinesWithCharacteristicPoints = surfaceLines.Select(
                sl => Tuple.Create(sl, characteristicPointsCollection.FirstOrDefault(cp => cp.Name == sl.Name))).ToArray();

            string progressText         = RiskeerCommonIOResources.Importer_ProgressText_Validating_imported_data;
            int    numberOfSurfaceLines = surfaceLinesWithCharacteristicPoints.Count();

            NotifyProgress(progressText, 0, numberOfSurfaceLines);

            var surfaceLineNumber = 1;

            foreach (Tuple <SurfaceLine, CharacteristicPoints> surfaceLineWithCharacteristicPoints in surfaceLinesWithCharacteristicPoints)
            {
                if (Canceled)
                {
                    yield break;
                }

                NotifyProgress(progressText, surfaceLineNumber++, numberOfSurfaceLines);
                SurfaceLine          surfaceLine          = surfaceLineWithCharacteristicPoints.Item1;
                CharacteristicPoints characteristicPoints = surfaceLineWithCharacteristicPoints.Item2;

                yield return(surfaceLineTransformer.Transform(surfaceLine, characteristicPoints));
            }
        }
        /// <summary>
        /// Creates a new <see cref="CharacteristicPoints"/> from the <paramref name="readText"/>.
        /// </summary>
        /// <param name="readText">A single line read from file.</param>
        /// <returns>A new <see cref="CharacteristicPoints"/> with name and characteristic points set.</returns>
        /// <exception cref="LineParseException">Thrown when:
        /// <list type="bullet">
        /// <item><paramref name="readText"/> has too many or few columns.</item>
        /// <item><paramref name="readText"/> contains a coordinate value which could not be parsed to <see cref="double"/>.</item>
        /// </list></exception>
        private CharacteristicPoints CreateCharacteristicPointsLocation(string readText)
        {
            string[] tokenizedString = TokenizeString(readText);
            string   locationName    = GetLocationName(tokenizedString);

            if (tokenizedString.Length != columnsInFile.Count)
            {
                throw CreateLineParseException(lineNumber, locationName, Resources.CharacteristicPointsCsvReader_ReadCharacteristicPointsLocation_Location_lacks_values_for_characteristic_points);
            }

            var location = new CharacteristicPoints(locationName);

            SetCharacteristicPoints(tokenizedString, location);

            return(location);
        }
Esempio n. 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);
            }
        }
 /// <summary>
 /// Sets the characteristic points from the given <paramref name="tokenizedString"/> to the given <paramref name="location"/>.
 /// </summary>
 /// <param name="tokenizedString">The string read from file.</param>
 /// <param name="location">The <see cref="CharacteristicPoints"/> to set the characteristic points for.</param>
 /// <exception cref="LineParseException">Thrown when <paramref name="tokenizedString"/>
 /// contains a coordinate value which could not be parsed to <see cref="double"/>.</exception>
 private void SetCharacteristicPoints(string[] tokenizedString, CharacteristicPoints location)
 {
     location.SurfaceLevelInside    = GetPoint3D(tokenizedString, surfaceLevelInsideKey, location.Name);
     location.DitchPolderSide       = GetPoint3D(tokenizedString, ditchPolderSideKey, location.Name);
     location.BottomDitchPolderSide = GetPoint3D(tokenizedString, bottomDitchPolderSideKey, location.Name);
     location.BottomDitchDikeSide   = GetPoint3D(tokenizedString, bottomDitchDikeSideKey, location.Name);
     location.DitchDikeSide         = GetPoint3D(tokenizedString, ditchDikeSideKey, location.Name);
     location.DikeToeAtPolder       = GetPoint3D(tokenizedString, dikeToeAtPolderKey, location.Name);
     location.ShoulderTopInside     = GetPoint3D(tokenizedString, shoulderTopInsideKey, location.Name);
     location.ShoulderBaseInside    = GetPoint3D(tokenizedString, shoulderBaseInsideKey, location.Name);
     location.DikeTopAtPolder       = GetPoint3D(tokenizedString, dikeTopAtPolderKey, location.Name);
     location.TrafficLoadInside     = GetPoint3D(tokenizedString, trafficLoadInsideKey, location.Name);
     location.TrafficLoadOutside    = GetPoint3D(tokenizedString, trafficLoadOutsideKey, location.Name);
     location.DikeTopAtRiver        = GetPoint3D(tokenizedString, dikeTopAtRiverKey, location.Name);
     location.ShoulderBaseOutside   = GetPoint3D(tokenizedString, shoulderBaseOutsideKey, location.Name);
     location.ShoulderTopOutside    = GetPoint3D(tokenizedString, shoulderTopOutsideKey, location.Name);
     location.DikeToeAtRiver        = GetPoint3D(tokenizedString, dikeToeAtRiverKey, location.Name);
     location.SurfaceLevelOutside   = GetPoint3D(tokenizedString, surfaceLevelOutsideKey, location.Name);
     location.DikeTableHeight       = GetPoint3D(tokenizedString, dikeTableHeightKey, location.Name);
     location.InsertRiverChannel    = GetPoint3D(tokenizedString, insertRiverChannelKey, location.Name);
     location.BottomRiverChannel    = GetPoint3D(tokenizedString, bottomRiverChannelKey, location.Name);
 }
Esempio n. 5
0
        private bool IsCharacteristicPointsLocationsAlreadyDefined(IEnumerable <CharacteristicPoints> list, CharacteristicPoints location)
        {
            if (list.Any(i => i.Name == location.Name))
            {
                Log.WarnFormat(RiskeerCommonIOResources.SurfaceLinesCsvImporter_AddImportedDataToModel_Duplicate_definitions_for_same_characteristic_point_location_0_,
                               location.Name);
                return(false);
            }

            return(true);
        }