resolve TODO items

This commit is contained in:
tian-lt 2021-06-23 22:28:47 +08:00
commit 00e4dc908c
7 changed files with 19 additions and 36 deletions

View file

@ -15,29 +15,17 @@ namespace CalculatorApp::ViewModel
private: private:
LocalizationSettings() LocalizationSettings()
// Use DecimalFormatter as it respects the locale and the user setting // Use DecimalFormatter as it respects the locale and the user setting
// CSHARP_MIGRATION: TODO:
//: LocalizationSettings(LocalizationService::GetInstance()->GetRegionalSettingsAwareDecimalFormatter())
{ {
InitializeLocalizationSettings(LocalizationService::GetInstance()->GetRegionalSettingsAwareDecimalFormatter()); Initialize(LocalizationService::GetInstance()->GetRegionalSettingsAwareDecimalFormatter());
} }
public: public:
// This is only public for unit testing purposes. // This is only public for unit testing purposes.
LocalizationSettings(Windows::Globalization::NumberFormatting::DecimalFormatter ^ formatter) LocalizationSettings(Windows::Globalization::NumberFormatting::DecimalFormatter ^ formatter)
{ {
InitializeLocalizationSettings(formatter); Initialize(formatter);
} }
// A LocalizationSettings object is not copyable.
// CSHARP_MIGRATION: TODO: deleted and defaulted functions are not supported in managed/WinRT classes
//LocalizationSettings(const LocalizationSettings^) = delete;
//LocalizationSettings^ operator=(const LocalizationSettings^) = delete;
// A LocalizationSettings object is not moveable.
// CSHARP_MIGRATION: TODO: Double check how should we hanlde move constrcutor and move assignment
//LocalizationSettings(LocalizationSettings&&) = delete;
//LocalizationSettings& operator=(LocalizationSettings&&) = delete;
// Provider of the singleton LocalizationSettings instance. // Provider of the singleton LocalizationSettings instance.
static LocalizationSettings^ GetInstance() static LocalizationSettings^ GetInstance()
{ {
@ -202,7 +190,7 @@ namespace CalculatorApp::ViewModel
private: private:
void InitializeLocalizationSettings(Windows::Globalization::NumberFormatting::DecimalFormatter ^ formatter) void Initialize(Windows::Globalization::NumberFormatting::DecimalFormatter ^ formatter)
{ {
formatter->FractionDigits = 0; formatter->FractionDigits = 0;
formatter->IsDecimalPointAlwaysDisplayed = false; formatter->IsDecimalPointAlwaysDisplayed = false;

View file

@ -148,16 +148,21 @@ namespace CalculatorApp
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields); TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields);
} }
void TraceLogger::LogPlatformException(ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e) void TraceLogger::LogPlatformExceptionInfo(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::String^ message, int hresult)
{ {
auto fields = ref new LoggingFields(); auto fields = ref new LoggingFields();
fields->AddString(StringReference(CALC_MODE), NavCategory::GetFriendlyName(mode)); fields->AddString(StringReference(CALC_MODE), NavCategory::GetFriendlyName(mode));
fields->AddString(StringReference(L"FunctionName"), functionName); fields->AddString(StringReference(L"FunctionName"), functionName);
fields->AddString(StringReference(L"Message"), e->Message); fields->AddString(StringReference(L"Message"), message);
fields->AddInt32(StringReference(L"HRESULT"), e->HResult); fields->AddInt32(StringReference(L"HRESULT"), hresult);
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields); TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields);
} }
void TraceLogger::LogPlatformException(ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e)
{
LogPlatformExceptionInfo(mode, functionName, e->Message, e->HResult);
}
void TraceLogger::UpdateButtonUsage(NumbersAndOperatorsEnum button, ViewMode mode) void TraceLogger::UpdateButtonUsage(NumbersAndOperatorsEnum button, ViewMode mode)
{ {
// IsProgrammerMode, IsScientificMode, IsStandardMode and None are not actual buttons, so ignore them // IsProgrammerMode, IsScientificMode, IsStandardMode and None are not actual buttons, so ignore them

View file

@ -83,12 +83,12 @@ namespace CalculatorApp::ViewModel::Common
void LogVariableSettingsChanged(Platform::String ^ setting); void LogVariableSettingsChanged(Platform::String ^ setting);
void LogGraphSettingsChanged(GraphSettingsType settingsType, Platform::String ^ settingValue); void LogGraphSettingsChanged(GraphSettingsType settingsType, Platform::String ^ settingValue);
void LogGraphTheme(Platform::String ^ graphTheme); void LogGraphTheme(Platform::String ^ graphTheme);
void LogInputPasted(CalculatorApp::ViewModel::Common::ViewMode mode);
void LogPlatformExceptionInfo(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::String ^ message, int hresult);
internal: internal:
// CSHARP_MIGRATION: TODO:
void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e); void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e);
void LogStandardException(CalculatorApp::ViewModel::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e); void LogStandardException(CalculatorApp::ViewModel::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e);
void LogInputPasted(CalculatorApp::ViewModel::Common::ViewMode mode);
private: private:
// Create an instance of TraceLogger // Create an instance of TraceLogger

View file

@ -708,7 +708,8 @@ namespace CalculatorApp
namespace ViewModel::Common namespace ViewModel::Common
{ {
// CSHARP_MIGRATION: TODO: Review below utils // below utilities are intended to support interops between C# and C++/CX
// they can be removed if the entire codebase has been migrated to C#
public ref class Utilities sealed public ref class Utilities sealed
{ {
public: public:

View file

@ -734,8 +734,6 @@ namespace CalculatorApp
} }
} }
// CSHARP_MIGRATION: TODO: reinterpreted SortedDictionary<MyVirtualKey, List<WeakReference>> to SortedDictionary<char, List<WeakReference>>
// double check this is equivalent before and after migration
private static SortedDictionary<MyVirtualKey, List<WeakReference>> GetCurrentKeyDictionary(bool controlKeyPressed, bool shiftKeyPressed, bool altPressed) private static SortedDictionary<MyVirtualKey, List<WeakReference>> GetCurrentKeyDictionary(bool controlKeyPressed, bool shiftKeyPressed, bool altPressed)
{ {
int viewId = Utilities.GetWindowId(); int viewId = Utilities.GetWindowId();
@ -785,7 +783,6 @@ namespace CalculatorApp
} }
} }
// CSHARP_MIGRATION: TODO: double check below design
// EqualRange is a helper function to pick a range from std::multimap. // EqualRange is a helper function to pick a range from std::multimap.
private static IEnumerable<TValue> EqualRange<TKey, TValue>(SortedDictionary<TKey, List<TValue>> source, TKey key) private static IEnumerable<TValue> EqualRange<TKey, TValue>(SortedDictionary<TKey, List<TValue>> source, TKey key)
{ {
@ -800,7 +797,6 @@ namespace CalculatorApp
} }
} }
// CSHARP_MIGRATION: TODO: double check below design
// Insert is a helper function to insert a pair into std::multimap. // Insert is a helper function to insert a pair into std::multimap.
private static void Insert<Tkey, TValue>(SortedDictionary<Tkey, List<TValue>> dest, Tkey key, TValue value) private static void Insert<Tkey, TValue>(SortedDictionary<Tkey, List<TValue>> dest, Tkey key, TValue value)
{ {

View file

@ -353,13 +353,11 @@ namespace CalculatorApp
catch (System.Runtime.InteropServices.COMException ex) catch (System.Runtime.InteropServices.COMException ex)
{ {
// COMException and HResult, long RPC_E_SERVERCALL_RETRYLATER is out of range of int // COMException and HResult, long RPC_E_SERVERCALL_RETRYLATER is out of range of int
// LogPlatformException is internal
long rpc_e_servercall_retrylater = 0x8001010A; long rpc_e_servercall_retrylater = 0x8001010A;
if (ex.HResult == unchecked(rpc_e_servercall_retrylater)) if (ex.HResult == unchecked(rpc_e_servercall_retrylater))
{ {
ShowShareError(); ShowShareError();
// CSHARP_MIGRATION: TODO: CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogPlatformExceptionInfo(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.HResult);
//TraceLogger.GetInstance().LogPlatformException(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
} }
else else
{ {
@ -505,10 +503,7 @@ namespace CalculatorApp
catch (Exception ex) catch (Exception ex)
{ {
ShowShareError(); ShowShareError();
CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogPlatformExceptionInfo(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.HResult);
// CSHARP_MIGRATION: TODO:
//TraceLogger.GetInstance().LogPlatformException(ViewMode.Graphing,
// System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
} }
} }

View file

@ -110,11 +110,9 @@ namespace CalculatorApp
{ {
if (e.Key == VirtualKey.Enter) if (e.Key == VirtualKey.Enter)
{ {
// CSHARP_MIGRATION: TODO: if (FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Next) == null)
// check if condition
if (FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Next).Status != AsyncStatus.Completed)
{ {
IAsyncOperation<FocusMovementResult> result = FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Previous); _ = FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Previous);
} }
e.Handled = true; e.Handled = true;
} }