private async Task LoadListAsync() { await Task.Run(async() => { XmlSerializer formatter = new XmlSerializer(typeof(ConvertedValueViewModel[])); var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "listtoconvert.xml"); using (var fs = new StreamReader(path)) { string baseCurrencyCode = ""; ConvertedValueViewModel[] loadedList = (ConvertedValueViewModel[])formatter.Deserialize(fs); foreach (ConvertedValueViewModel newCurVM in loadedList) { ConvertedValuesList.Add(newCurVM); if (ConvertedValuesList.Count == 1) { baseCurrencyCode = newCurVM.Code; newCurVM.Rate = 1; } else { newCurVM.Rate = await RateService.GetRateAsync(baseCurrencyCode, newCurVM.Code); } } } }); OnPropertyChanged(nameof(ConvertedValuesList)); }
public async void AddCurrency(CurrencyViewModel currencyViewModel) { var baseCurrencyCode = ConvertedValuesList.Count > 0 ? ConvertedValuesList[0].Code : currencyViewModel.Code; var newCurVM = new ConvertedValueViewModel() { Rate = await RateService.GetRateAsync(baseCurrencyCode, currencyViewModel.Code), Code = currencyViewModel.Code, FlagUri = currencyViewModel.FlagUri, Value = 0 }; ConvertedValuesList.Add(newCurVM); OnPropertyChanged(nameof(ConvertedValuesList)); SaveListAsync(); }