From 2b17f8265229c6e270aa27f384e7dd2495388b20 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Fri, 31 May 2019 12:55:06 -0700 Subject: [PATCH] Migrate currency converter endpoints (#524) We are migrating the REST endpoint that Currency Converter uses. The REST endpoint is not licensed for your use. To continue to enable community participation in the development of the feature, developer builds will use an alternate REST endpoint that serves mock data (clearly identifiable as it references planets instead of countries). --- .gitignore | 1 + README.md | 6 ++++++ src/CalcViewModel/CalcViewModel.vcxproj | 17 +++++++++++++++++ src/CalcViewModel/CalcViewModel.vcxproj.filters | 6 ++++++ .../DataLoaders/CurrencyDataLoader.cpp | 17 +++++++++++++++++ .../DataLoaders/CurrencyHttpClient.cpp | 11 +++++++---- .../DataLoaders/DataLoaderMockConstants.h | 13 +++++++++++++ 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/CalcViewModel/DataLoaders/DataLoaderMockConstants.h diff --git a/.gitignore b/.gitignore index 1088272..415b87d 100644 --- a/.gitignore +++ b/.gitignore @@ -290,6 +290,7 @@ __pycache__/ # Calculator specific Generated Files/ src/GraphControl/GraphingImplOverrides.props +src/CalcViewModel/DataLoaders/DataLoaderConstants.h !/build/config/TRexDefs/** !src/Calculator/TemporaryKey.pfx !src/CalculatorUnitTests/CalculatorUnitTests_TemporaryKey.pfx \ No newline at end of file diff --git a/README.md b/README.md index 0024314..fd39861 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ Read our [privacy statement](https://go.microsoft.com/fwlink/?LinkId=521839) to Telemetry is disabled in development builds by default, and can be enabled with the `SEND_TELEMETRY` build flag. +## Currency Converter +Windows Calculator includes a currency converter feature that uses mock data in developer builds. The data that +Microsoft uses for the currency converter feature (e.g., in the retail version of the application) is not licensed +for your use. The mock data will be clearly identifiable as it references planets instead of countries, +and remains static regardless of selected inputs. + ## Reporting Security Issues Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at <[secure@microsoft.com](mailto:secure@microsoft.com)>. diff --git a/src/CalcViewModel/CalcViewModel.vcxproj b/src/CalcViewModel/CalcViewModel.vcxproj index 4eaed17..c5ed5af 100644 --- a/src/CalcViewModel/CalcViewModel.vcxproj +++ b/src/CalcViewModel/CalcViewModel.vcxproj @@ -408,6 +408,23 @@ {311e866d-8b93-4609-a691-265941fee101} + + + /DUSE_MOCK_DATA %(AdditionalOptions) + + + + + + + + + + + + + + diff --git a/src/CalcViewModel/CalcViewModel.vcxproj.filters b/src/CalcViewModel/CalcViewModel.vcxproj.filters index d05aca0..bd0d75f 100644 --- a/src/CalcViewModel/CalcViewModel.vcxproj.filters +++ b/src/CalcViewModel/CalcViewModel.vcxproj.filters @@ -213,6 +213,12 @@ Common + + DataLoaders + + + DataLoaders + diff --git a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp index 2fb8f0a..286422c 100644 --- a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp @@ -644,6 +644,23 @@ void CurrencyDataLoader::GuaranteeSelectedUnits() isConversionTargetSet = true; } } + + // If still not set for either source or target, just select the first currency in the list + + if (!m_currencyUnits.empty()) + { + if (!isConversionSourceSet) + { + m_currencyUnits[0].isConversionSource = true; + isConversionSourceSet = true; + } + + if (!isConversionTargetSet) + { + m_currencyUnits[0].isConversionTarget = true; + isConversionTargetSet = true; + } + } } void CurrencyDataLoader::NotifyDataLoadFinished(bool didLoad) diff --git a/src/CalcViewModel/DataLoaders/CurrencyHttpClient.cpp b/src/CalcViewModel/DataLoaders/CurrencyHttpClient.cpp index 04167da..e9d42c6 100644 --- a/src/CalcViewModel/DataLoaders/CurrencyHttpClient.cpp +++ b/src/CalcViewModel/DataLoaders/CurrencyHttpClient.cpp @@ -1,18 +1,21 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" #include "CurrencyHttpClient.h" +#ifdef USE_MOCK_DATA +#include "DataLoaderMockConstants.h" +#else +#include "DataLoaderConstants.h" +#endif + using namespace CalculatorApp::DataLoaders; using namespace Platform; using namespace std; using namespace Windows::Foundation; using namespace Windows::Web::Http; -static constexpr auto sc_MetadataUriLocalizeFor = L"https://go.microsoft.com/fwlink/?linkid=2041093&localizeFor="; -static constexpr auto sc_RatiosUriRelativeTo = L"https://go.microsoft.com/fwlink/?linkid=2041339&localCurrency="; - CurrencyHttpClient::CurrencyHttpClient() : m_client(ref new HttpClient()) , m_responseLanguage(L"en-US") diff --git a/src/CalcViewModel/DataLoaders/DataLoaderMockConstants.h b/src/CalcViewModel/DataLoaders/DataLoaderMockConstants.h new file mode 100644 index 0000000..02e7e34 --- /dev/null +++ b/src/CalcViewModel/DataLoaders/DataLoaderMockConstants.h @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +namespace CalculatorApp +{ + namespace DataLoaders + { + static constexpr auto sc_MetadataUriLocalizeFor = L"https://go.microsoft.com/fwlink/?linkid=2091028&localizeFor="; + static constexpr auto sc_RatiosUriRelativeTo = L"https://go.microsoft.com/fwlink/?linkid=2091307&localCurrency="; + } +}