@@ -89,9 +89,8 @@ namespace CalculatorApp
89
89
}
90
90
}
91
91
92
- CurrencyDataLoader::CurrencyDataLoader (_In_ unique_ptr<ICurrencyHttpClient> client, const wchar_t * forcedResponseLanguage)
93
- : m_client(move(client))
94
- , m_loadStatus(CurrencyLoadStatus::NotLoaded)
92
+ CurrencyDataLoader::CurrencyDataLoader (const wchar_t * forcedResponseLanguage)
93
+ : m_loadStatus(CurrencyLoadStatus::NotLoaded)
95
94
, m_responseLanguage(L" en-US" )
96
95
, m_ratioFormat(L" " )
97
96
, m_timestampFormat(L" " )
@@ -122,12 +121,7 @@ CurrencyDataLoader::CurrencyDataLoader(_In_ unique_ptr<ICurrencyHttpClient> clie
122
121
}
123
122
}
124
123
125
- if (m_client != nullptr )
126
- {
127
- m_client->SetSourceCurrencyCode (StringReference (DefaultCurrencyCode.data ()));
128
- m_client->SetResponseLanguage (m_responseLanguage);
129
- }
130
-
124
+ m_client.Initialize (StringReference{ DefaultCurrencyCode.data () }, m_responseLanguage);
131
125
auto localizationService = LocalizationService::GetInstance ();
132
126
if (CoreWindow::GetForCurrentThread () != nullptr )
133
127
{
@@ -199,26 +193,29 @@ void CurrencyDataLoader::LoadData()
199
193
if (!LoadFinished ())
200
194
{
201
195
RegisterForNetworkBehaviorChanges ();
202
- create_task ([this ]() -> task<bool > {
203
- vector<function<future<bool >()>> loadFunctions = {
204
- [this ]() { return TryLoadDataFromCacheAsync (); },
205
- [this ]() { return TryLoadDataFromWebAsync (); },
206
- };
207
-
208
- bool didLoad = false ;
209
- for (auto & f : loadFunctions)
196
+ create_task (
197
+ [this ]() -> task<bool >
210
198
{
211
- didLoad = co_await f ();
212
- if (didLoad)
199
+ vector<function<future<bool >()>> loadFunctions = {
200
+ [this ]() { return TryLoadDataFromCacheAsync (); },
201
+ [this ]() { return TryLoadDataFromWebAsync (); },
202
+ };
203
+
204
+ bool didLoad = false ;
205
+ for (auto & f : loadFunctions)
213
206
{
214
- break ;
207
+ didLoad = co_await f ();
208
+ if (didLoad)
209
+ {
210
+ break ;
211
+ }
215
212
}
216
- }
217
213
218
- co_return didLoad;
219
- })
214
+ co_return didLoad;
215
+ })
220
216
.then (
221
- [this ](bool didLoad) {
217
+ [this ](bool didLoad)
218
+ {
222
219
UpdateDisplayedTimestamp ();
223
220
NotifyDataLoadFinished (didLoad);
224
221
},
@@ -283,9 +280,7 @@ double CurrencyDataLoader::RoundCurrencyRatio(double ratio)
283
280
int numberDecimals = FORMATTER_RATE_MIN_DECIMALS;
284
281
if (ratio < 1 )
285
282
{
286
- numberDecimals = max (
287
- FORMATTER_RATE_MIN_DECIMALS,
288
- (int )(-log10 (ratio)) + FORMATTER_RATE_MIN_SIGNIFICANT_DECIMALS);
283
+ numberDecimals = max (FORMATTER_RATE_MIN_DECIMALS, (int )(-log10 (ratio)) + FORMATTER_RATE_MIN_SIGNIFICANT_DECIMALS);
289
284
}
290
285
291
286
unsigned long long scale = (unsigned long long )powl (10l , numberDecimals);
@@ -314,8 +309,7 @@ pair<wstring, wstring> CurrencyDataLoader::GetCurrencyRatioEquality(_In_ const U
314
309
auto ratioString = LocalizationStringUtil::GetLocalizedString (
315
310
m_ratioFormat, digitSymbol, StringReference (unit1.abbreviation .c_str ()), roundedFormat, StringReference (unit2.abbreviation .c_str ()));
316
311
317
- auto accessibleRatioString =
318
- LocalizationStringUtil::GetLocalizedString (
312
+ auto accessibleRatioString = LocalizationStringUtil::GetLocalizedString (
319
313
m_ratioFormat, digitSymbol, StringReference (unit1.accessibleName .c_str ()), roundedFormat, StringReference (unit2.accessibleName .c_str ()));
320
314
321
315
return make_pair (ratioString->Data (), accessibleRatioString->Data ());
@@ -415,18 +409,13 @@ future<bool> CurrencyDataLoader::TryLoadDataFromWebAsync()
415
409
{
416
410
ResetLoadStatus ();
417
411
418
- if (m_client == nullptr )
419
- {
420
- co_return false ;
421
- }
422
-
423
412
if (m_networkAccessBehavior == NetworkAccessBehavior::Offline || (m_networkAccessBehavior == NetworkAccessBehavior::OptIn && !m_meteredOverrideSet))
424
413
{
425
414
co_return false ;
426
415
}
427
416
428
- String ^ staticDataResponse = co_await m_client-> GetCurrencyMetadata ();
429
- String ^ allRatiosResponse = co_await m_client-> GetCurrencyRatios ();
417
+ String ^ staticDataResponse = co_await m_client. GetCurrencyMetadataAsync ();
418
+ String ^ allRatiosResponse = co_await m_client. GetCurrencyRatiosAsync ();
430
419
if (staticDataResponse == nullptr || allRatiosResponse == nullptr )
431
420
{
432
421
co_return false ;
@@ -550,9 +539,7 @@ bool CurrencyDataLoader::TryParseStaticData(_In_ String ^ rawJson, _Inout_ vecto
550
539
staticData[i] = CurrencyStaticData{ countryCode, countryName, currencyCode, currencyName, currencySymbol };
551
540
}
552
541
553
- auto sortCountryNames = [](const UCM::CurrencyStaticData & s) {
554
- return ref new String (s.countryName .c_str ());
555
- };
542
+ auto sortCountryNames = [](const UCM::CurrencyStaticData& s) { return ref new String (s.countryName .c_str ()); };
556
543
557
544
LocalizationService::GetInstance ()->Sort <UCM::CurrencyStaticData>(staticData, sortCountryNames);
558
545
@@ -577,7 +564,7 @@ bool CurrencyDataLoader::TryParseAllRatiosData(_In_ String ^ rawJson, _Inout_ Cu
577
564
{
578
565
obj = data->GetAt (i)->GetObject ();
579
566
}
580
- catch (COMException^ e)
567
+ catch (COMException ^ e)
581
568
{
582
569
if (e->HResult == E_ILLEGAL_METHOD_CALL)
583
570
{
0 commit comments