Exemple #1
0
        /// <summary>
        /// Converts the string representation of LinearDimension value to <see cref="LinearDimension"/> object
        /// </summary>
        /// <param name="stringvalue">String representation of <see cref="LinearDimension"/> value</param>
        /// <param name="depthUnit"><see cref="LinearDimension"/> unit</param>
        /// <param name="depth">Conversion succeeded or failed</param>
        /// <returns></returns>
        public static bool TryParse(string stringvalue, LinearDimensionUnit depthUnit, out LinearDimension depth)
        {
            var isSuccessParse = double.TryParse(stringvalue, NumberStyles.Any, CultureInfo.InvariantCulture, out var result);

            depth = null;
            if (isSuccessParse)
            {
                depth = new LinearDimension(result, depthUnit);
            }

            return(isSuccessParse);
        }
Exemple #2
0
        /// <summary>
        /// Create instance of <see cref="LinearDimension"/>.
        /// </summary>
        /// <param name="value"><see cref="LinearDimension"/> value.</param>
        /// <param name="unit"><see cref="LinearDimension"/> unit.</param>
        public LinearDimension(double value, LinearDimensionUnit unit)
        {
            switch (unit)
            {
            case LinearDimensionUnit.Meter:
                _valueInMeters = value;
                _valueInFoots  = value / _metersInOneFoot;
                break;

            case LinearDimensionUnit.Foot:
                _valueInFoots  = value;
                _valueInMeters = value * _metersInOneFoot;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(unit), unit, null);
            }
        }
Exemple #3
0
        /// <summary>
        /// TryParse CSV log string, consists of Latitude, Longitude, Depth(and may be other values), separated by comma
        /// </summary>
        /// <param name="cvsLogEntryString">String to parse</param>
        /// <param name="charForSplit">Char for sting split</param>
        /// <param name="depthUnit">Depth unit</param>
        /// <param name="valuesOrder">Represent order of CvsLogEntry properties in string</param>
        /// <param name="result">CvsLogEntry</param>
        /// <returns>Conversion succeeded or failed</returns>
        public static bool TryParse(string cvsLogEntryString, char charForSplit, LinearDimensionUnit depthUnit, IDictionary <int, string> valuesOrder, out CsvLogEntry result)
        {
            result = new CsvLogEntry {
                UnexpectedValues = new List <string>()
            };

            Latitude        lat    = null;
            Longitude       lon    = null;
            LinearDimension dpt    = null;
            var             values = cvsLogEntryString.Split(charForSplit);

            // if string doesn't contains values or values count less then expect return false
            if (values.Length == 0 || values.Length < valuesOrder.Count)
            {
                return(false);
            }

            for (var i = 0; i < values.Length; i++)
            {
                if (valuesOrder.ContainsKey(i))
                {
                    if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(valuesOrder[i],
                                                                         "Latitude", CompareOptions.IgnoreCase) >= 0)
                    {
                        var parceresult = Latitude.TryParse(values[i], out lat);

                        if (parceresult)
                        {
                            continue;
                        }
                        return(false);
                    }

                    if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(valuesOrder[i],
                                                                         "Longitude", CompareOptions.IgnoreCase) >= 0)
                    {
                        var parceresult = Longitude.TryParse(values[i], out lon);

                        if (parceresult)
                        {
                            continue;
                        }
                        return(false);
                    }

                    if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(valuesOrder[i],
                                                                         "Depth", CompareOptions.IgnoreCase) >= 0)
                    {
                        var parceresult = LinearDimension.TryParse(values[i], depthUnit, out dpt);

                        if (parceresult)
                        {
                            continue;
                        }
                        return(false);
                    }
                }
                else
                {
                    result.UnexpectedValues.Add(values[i]);
                }
            }

            if (lat != null && lon != null && dpt != null)
            {
                result.Point = new CoordinatePoint(lat, lon);
                result.Depth = dpt;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
 /// <summary>
 /// Create instance of CvsLogEntry object from double values of Latitude, Longitude add Depth
 /// </summary>
 /// <param name="latitude">Latitude degrees double value</param>
 /// <param name="longitude">Longitude degrees double value</param>
 /// <param name="depth">Depth double value</param>
 /// <param name="depthUnit">Depth value unit</param>
 public CsvLogEntry(double latitude, double longitude, double depth, LinearDimensionUnit depthUnit)
     : this(new Latitude(latitude), new Longitude(longitude), new LinearDimension(depth, depthUnit))
 {
 }