Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C# Calc] Resolve some TODO items for C# conversion #1589

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions src/CalcViewModel/Common/LocalizationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,17 @@ namespace CalculatorApp::ViewModel
private:
LocalizationSettings()
// 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:
// This is only public for unit testing purposes.
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.
static LocalizationSettings^ GetInstance()
{
Expand Down Expand Up @@ -202,7 +190,7 @@ namespace CalculatorApp::ViewModel


private:
void InitializeLocalizationSettings(Windows::Globalization::NumberFormatting::DecimalFormatter ^ formatter)
void Initialize(Windows::Globalization::NumberFormatting::DecimalFormatter ^ formatter)
{
formatter->FractionDigits = 0;
formatter->IsDecimalPointAlwaysDisplayed = false;
Expand Down
11 changes: 8 additions & 3 deletions src/CalcViewModel/Common/TraceLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,21 @@ namespace CalculatorApp
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();
fields->AddString(StringReference(CALC_MODE), NavCategory::GetFriendlyName(mode));
fields->AddString(StringReference(L"FunctionName"), functionName);
fields->AddString(StringReference(L"Message"), e->Message);
fields->AddInt32(StringReference(L"HRESULT"), e->HResult);
fields->AddString(StringReference(L"Message"), message);
fields->AddInt32(StringReference(L"HRESULT"), hresult);
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)
{
// IsProgrammerMode, IsScientificMode, IsStandardMode and None are not actual buttons, so ignore them
Expand Down
4 changes: 2 additions & 2 deletions src/CalcViewModel/Common/TraceLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ namespace CalculatorApp::ViewModel::Common
void LogVariableSettingsChanged(Platform::String ^ setting);
void LogGraphSettingsChanged(GraphSettingsType settingsType, Platform::String ^ settingValue);
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:
// CSHARP_MIGRATION: TODO:
void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e);
tian-lt marked this conversation as resolved.
Show resolved Hide resolved
void LogStandardException(CalculatorApp::ViewModel::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e);
void LogInputPasted(CalculatorApp::ViewModel::Common::ViewMode mode);

private:
// Create an instance of TraceLogger
Expand Down
3 changes: 2 additions & 1 deletion src/CalcViewModel/Common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ namespace CalculatorApp

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:
Expand Down
4 changes: 0 additions & 4 deletions src/Calculator/Common/KeyboardShortcuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,6 @@ private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, Acceler
}
}

// 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)
{
int viewId = Utilities.GetWindowId();
Expand Down Expand Up @@ -785,7 +783,6 @@ private static SortedDictionary<MyVirtualKey, List<WeakReference>> GetCurrentKey
}
}

// CSHARP_MIGRATION: TODO: double check below design
// 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)
{
Expand All @@ -800,7 +797,6 @@ private static IEnumerable<TValue> EqualRange<TKey, TValue>(SortedDictionary<TKe
}
}

// CSHARP_MIGRATION: TODO: double check below design
// 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,11 @@ private void OnShareClick(object sender, RoutedEventArgs e)
catch (System.Runtime.InteropServices.COMException ex)
{
// COMException and HResult, long RPC_E_SERVERCALL_RETRYLATER is out of range of int
// LogPlatformException is internal
long rpc_e_servercall_retrylater = 0x8001010A;
if (ex.HResult == unchecked(rpc_e_servercall_retrylater))
{
ShowShareError();
// CSHARP_MIGRATION: TODO:
//TraceLogger.GetInstance().LogPlatformException(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogPlatformExceptionInfo(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.HResult);
}
else
{
Expand Down Expand Up @@ -505,10 +503,7 @@ private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs
catch (Exception ex)
{
ShowShareError();

// CSHARP_MIGRATION: TODO:
//TraceLogger.GetInstance().LogPlatformException(ViewMode.Graphing,
// System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogPlatformExceptionInfo(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.HResult);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ private void GridSettingsTextBox_PreviewKeyDown(object sender, KeyRoutedEventArg
{
if (e.Key == VirtualKey.Enter)
{
// CSHARP_MIGRATION: TODO:
// check if condition
if (FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Next).Status != AsyncStatus.Completed)
if (FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Next) == null)
tian-lt marked this conversation as resolved.
Show resolved Hide resolved
{
IAsyncOperation<FocusMovementResult> result = FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Previous);
_ = FocusManager.TryMoveFocusAsync(FocusNavigationDirection.Previous);
}
e.Handled = true;
}
Expand Down