public string Convert(int number)
        {
            string word = "";

            if (number <= 10)
            {
                word += _unitConverter.Convert(number);
            }
            else if (number > 10 && number < 20)
            {
                word += _teensConverter.Convert(number);
            }
            else if (number >= 20 && number < 100)
            {
                word += _tensConverter.Convert(number);
                if ((number % 10) > 0)
                {
                    word += " " + _unitConverter.Convert(number % 10);
                }
            }
            else
            {
                word += _oneHundredConverter.Convert(number);
            }
            return(word);
        }
Beispiel #2
0
        public IActionResult Get(string fromUnit, string toUnit, float temperatureValue)
        {
            // check fromUnit/toUnits are valid
            if (!Enum.TryParse(fromUnit, out Temperature fromUnitVal))
            {
                return(BadRequest());
            }

            if (!Enum.TryParse(toUnit, out Temperature toUnitVal))
            {
                return(BadRequest());
            }

            // check if both from and to unit are same , if yes just send back the value to convert.
            // ideally should be handled at client side
            if (fromUnitVal == toUnitVal)
            {
                return(Ok(temperatureValue));
            }

            //check which value to convert and call converter
            var convertedValue = _converter.Convert(temperatureValue, fromUnitVal, toUnitVal);

            return(Ok(convertedValue));
        }
        public void Convert_FromCelsius_ToFarenheit_ExpectCorrectValue()
        {
            // arrange
            // act
            var convertedVal = _tempConverter.Convert(1, Temperature.Celsius, Temperature.Farenheit);

            Assert.Equal(33.8F, convertedVal);
        }
Beispiel #4
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (double.TryParse(values[0].ToString(), out var val) && Enum.TryParse <VolumeUnits>(values[1].ToString(), out var unit))
            {
                return(Math.Round(_converter.Convert(val, VolumeUnits.CubicMeter, unit), 0));
            }

            return("NaN");
        }
 IConversionExpressionWithValue UseUnitConverter(IConversionExpression expression, bool toMetric) => mUnitConverter.Convert(expression, toMetric);
Beispiel #6
0
        private void RunDemo()
        {
            // Add Top Horizon
            var topHorizonX = new IntervalReaderSettings
            {
                Interval    = _converterService.Convert(200, LengthUnits.Foot, LengthUnits.Meter),
                PointsCount = 16,
                StartPoint  = 0
            };
            var topHorizonY = new IntervalReaderSettings
            {
                Interval    = _converterService.Convert(200, LengthUnits.Foot, LengthUnits.Meter),
                PointsCount = 26,
                StartPoint  = 0
            };
            var topHorizonZ = new FileReaderSettings
            {
                FilePath = AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings.Get("demoDepthsFile")
            };

            var topHorizon = new LayerModel
            {
                Name  = "Top Horizon",
                Color = new SolidColorBrush(Color.FromArgb(180, 33, 175, 17)),
                X     = _intervalReaderService.ReadPoints(topHorizonX),
                Y     = _intervalReaderService.ReadPoints(topHorizonY),
                Z     = _fileReaderService.ReadPoints(topHorizonZ).Select(p =>
                {
                    return(_converterService.Convert(p * -1, LengthUnits.Foot, LengthUnits.Meter));
                }).ToArray()
            };

            AddLayer(topHorizon, UpperLayers, nameof(UpperLayers));

            // Add Base Horizon
            var baseHorizon = new LayerModel
            {
                Name  = "Base Horizon",
                Color = new SolidColorBrush(Color.FromRgb(235, 179, 25)),
                X     = topHorizon.X,
                Y     = topHorizon.Y,
                Z     = topHorizon.Z.Select(p => p - 100).ToArray()
            };

            AddLayer(baseHorizon, LowerLayers, nameof(LowerLayers));

            // Add Fluid Body
            var fluidBody = new LayerModel
            {
                Name  = "Fluid Body",
                Color = new SolidColorBrush(Color.FromRgb(148, 192, 230)),
                X     = topHorizon.X,
                Y     = topHorizon.Y,
                Z     = _intervalReaderService.ReadPoints(new IntervalReaderSettings
                {
                    Interval    = 0,
                    PointsCount = topHorizon.Z.Length,
                    StartPoint  = -3000
                })
            };

            AddLayer(fluidBody, LowerLayers, nameof(LowerLayers));
        }