Пример #1
0
        private void ConvertMeasure(string stringValue)
        {
            double doubleValue;

            if (!double.TryParse(stringValue, out doubleValue))
            {
                return;
            }

            var convension = SelectedMeasuresGroup.Conversions.FirstOrDefault(c => c.SourceId == SelectedSourceMeasure.Id && c.TargerId == SelectedTargetMeasure.Id);

            if (convension != null)
            {
                var lc = new LinearConverter(convension.Factor, convension.Deltha);
                TargetMeasureValue = lc.Convert(doubleValue).ToString();
            }
            else
            {
                convension = SelectedMeasuresGroup.Conversions.FirstOrDefault(c => c.SourceId == SelectedTargetMeasure.Id && c.TargerId == SelectedSourceMeasure.Id);
                if (convension != null)
                {
                    var lc = new LinearConverter(convension.Factor, convension.Deltha).Inverse;
                    TargetMeasureValue = lc.Convert(doubleValue).ToString();
                }
                else if (SelectedTargetMeasure.Id == SelectedSourceMeasure.Id)
                {
                    TargetMeasureValue = SourceMeasureValue;
                }
            }
        }
Пример #2
0
 public static async Task <ConverterRepository> AddOrUpdateCurrencyConverters(this ConverterRepository converterRepository, ICurrencyDataLoader loader)
 {
     foreach (var item in await loader.LoadCurrencyConverterItem())
     {
         var unit = new Unit(DefaultCategories.Currency, item.CurrencyCode);
         converterRepository[unit] = new LinearConverter(ratio: 1.0 / item.Ratio);
     }
     return(converterRepository);
 }