From 577aafb3f4b405c5cf64444a3f9e8e147259bf8f Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Tue, 5 Nov 2019 18:59:24 -0800 Subject: [PATCH] Migrate TraceLogger to runtime class (#772) --- src/CalcViewModel/ApplicationViewModel.cpp | 8 +-- src/CalcViewModel/Common/CopyPasteManager.cpp | 8 +-- src/CalcViewModel/Common/TraceLogger.cpp | 60 ++++++++++--------- src/CalcViewModel/Common/TraceLogger.h | 48 +++++++-------- .../DataLoaders/CurrencyDataLoader.cpp | 10 ++-- src/CalcViewModel/HistoryViewModel.cpp | 2 +- .../StandardCalculatorViewModel.cpp | 18 +++--- src/CalcViewModel/UnitConverterViewModel.cpp | 4 +- src/Calculator/App.xaml.cpp | 6 +- src/Calculator/Views/Calculator.xaml.cpp | 5 +- .../CalculatorProgrammerOperators.xaml.cpp | 8 +-- src/Calculator/Views/DateCalculator.xaml.cpp | 11 ++-- src/Calculator/Views/MainPage.xaml.cpp | 4 +- src/Calculator/Views/UnitConverter.xaml.cpp | 3 +- src/Calculator/WindowFrameService.cpp | 2 +- 15 files changed, 97 insertions(+), 100 deletions(-) diff --git a/src/CalcViewModel/ApplicationViewModel.cpp b/src/CalcViewModel/ApplicationViewModel.cpp index 027eed3..efe9bca 100644 --- a/src/CalcViewModel/ApplicationViewModel.cpp +++ b/src/CalcViewModel/ApplicationViewModel.cpp @@ -85,7 +85,7 @@ void ApplicationViewModel::Initialize(ViewMode mode) } catch (const std::exception& e) { - TraceLogger::GetInstance().LogStandardException(mode, __FUNCTIONW__, e); + TraceLogger::GetInstance()->LogStandardException(mode, __FUNCTIONW__, e); if (!TryRecoverFromNavigationModeFailure()) { // Could not navigate to standard mode either. @@ -95,7 +95,7 @@ void ApplicationViewModel::Initialize(ViewMode mode) } catch (Exception ^ e) { - TraceLogger::GetInstance().LogPlatformException(mode, __FUNCTIONW__, e); + TraceLogger::GetInstance()->LogPlatformException(mode, __FUNCTIONW__, e); if (!TryRecoverFromNavigationModeFailure()) { // Could not navigate to standard mode either. @@ -162,11 +162,11 @@ void ApplicationViewModel::OnModeChanged() // Log ModeChange event when not first launch, log WindowCreated on first launch if (NavCategory::IsValidViewMode(m_PreviousMode)) { - TraceLogger::GetInstance().LogModeChange(m_mode); + TraceLogger::GetInstance()->LogModeChange(m_mode); } else { - TraceLogger::GetInstance().LogWindowCreated(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread())); + TraceLogger::GetInstance()->LogWindowCreated(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread())); } RaisePropertyChanged(ClearMemoryVisibilityPropertyName); diff --git a/src/CalcViewModel/Common/CopyPasteManager.cpp b/src/CalcViewModel/Common/CopyPasteManager.cpp index f67d005..e4df0da 100644 --- a/src/CalcViewModel/Common/CopyPasteManager.cpp +++ b/src/CalcViewModel/Common/CopyPasteManager.cpp @@ -108,7 +108,7 @@ String if (pastedText->Length() > MaxPasteableLength) { // return NoOp to indicate don't paste anything. - TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed"); + TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed"); return PasteErrorString; } @@ -141,7 +141,7 @@ String // validate each operand with patterns for different modes if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType)) { - TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode"); + TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode"); return PasteErrorString; } @@ -187,7 +187,7 @@ vector CopyPasteManager::ExtractOperands(const wstring& pasteExpression if (operands.size() >= MaxOperandCount) { - TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"OperandCountGreaterThanMaxCount"); + TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ExtractOperands", L"OperandCountGreaterThanMaxCount"); operands.clear(); return operands; } @@ -201,7 +201,7 @@ vector CopyPasteManager::ExtractOperands(const wstring& pasteExpression // to disallow pasting of 1e+12345 as 1e+1234, max exponent that can be pasted is 9999. if (expLength > MaxExponentLength) { - TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"ExponentLengthGreaterThanMaxLength"); + TraceLogger::GetInstance()->LogError(mode, L"CopyPasteManager::ExtractOperands", L"ExponentLengthGreaterThanMaxLength"); operands.clear(); return operands; } diff --git a/src/CalcViewModel/Common/TraceLogger.cpp b/src/CalcViewModel/Common/TraceLogger.cpp index 6537554..845b010 100644 --- a/src/CalcViewModel/Common/TraceLogger.cpp +++ b/src/CalcViewModel/Common/TraceLogger.cpp @@ -10,6 +10,7 @@ using namespace CalculatorApp; using namespace CalculatorApp::Common; using namespace Concurrency; using namespace std; +using namespace Platform; using namespace winrt; using namespace winrt::Windows::Foundation; using namespace winrt::Windows::Foundation::Diagnostics; @@ -57,47 +58,43 @@ namespace CalculatorApp TraceLogger::TraceLogger() : g_calculatorProvider( - L"MicrosoftCalculator", - LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }), - GUID{ 0x905ca09, 0x610e, 0x401e, 0xb6, 0x50, 0x2f, 0x21, 0x29, 0x80, 0xb9, 0xe0 }) + L"MicrosoftCalculator", + LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }), + GUID{ 0x905ca09, 0x610e, 0x401e, 0xb6, 0x50, 0x2f, 0x21, 0x29, 0x80, 0xb9, 0xe0 }) , // Unique providerID {0905CA09-610E-401E-B650-2F212980B9E0} m_appLaunchActivity{ nullptr } { CoCreateGuid(&sessionGuid); } - TraceLogger::~TraceLogger() + TraceLogger ^ TraceLogger::GetInstance() { - } - - TraceLogger& TraceLogger::GetInstance() - { - static TraceLogger s_selfInstance; + static TraceLogger ^ s_selfInstance = ref new TraceLogger(); return s_selfInstance; } - bool TraceLogger::GetTraceLoggingProviderEnabled() const + bool TraceLogger::GetTraceLoggingProviderEnabled() { return g_calculatorProvider.Enabled(); } #pragma region Tracing methods - void TraceLogger::LogLevel1Event(wstring_view eventName, LoggingFields fields) const + void TraceLogger::LogLevel1Event(wstring_view eventName, LoggingFields fields) { g_calculatorProvider.LogEvent(eventName, fields, LoggingLevel::Verbose, LoggingOptions(MICROSOFT_KEYWORD_LEVEL_1)); } - void TraceLogger::LogLevel2Event(wstring_view eventName, LoggingFields fields) const + void TraceLogger::LogLevel2Event(wstring_view eventName, LoggingFields fields) { g_calculatorProvider.LogEvent(eventName, fields, LoggingLevel::Verbose, LoggingOptions(MICROSOFT_KEYWORD_LEVEL_2)); } - void TraceLogger::LogLevel3Event(wstring_view eventName, LoggingFields fields) const + void TraceLogger::LogLevel3Event(wstring_view eventName, LoggingFields fields) { g_calculatorProvider.LogEvent(eventName, fields, LoggingLevel::Verbose, LoggingOptions(MICROSOFT_KEYWORD_LEVEL_3)); } - unique_ptr TraceLogger::CreateTraceActivity(wstring_view eventName, LoggingFields fields) const + unique_ptr TraceLogger::CreateTraceActivity(wstring_view eventName, LoggingFields fields) { return make_unique(g_calculatorProvider, eventName, fields); } @@ -117,7 +114,7 @@ namespace CalculatorApp return true; } - void TraceLogger::LogVisualStateChanged(ViewMode mode, wstring_view state, bool isAlwaysOnTop) const + void TraceLogger::LogVisualStateChanged(ViewMode mode, String ^ state, bool isAlwaysOnTop) { if (!GetTraceLoggingProviderEnabled()) { @@ -127,7 +124,7 @@ namespace CalculatorApp LoggingFields fields{}; fields.AddGuid(L"SessionGuid", sessionGuid); fields.AddString(L"CalcMode", NavCategory::GetFriendlyName(mode)->Data()); - fields.AddString(L"VisualState", state); + fields.AddString(L"VisualState", state->Data()); fields.AddBoolean(L"IsAlwaysOnTop", isAlwaysOnTop); fields.AddUInt64(PDT_PRIVACY_DATA_TAG, PDT_PRODUCT_AND_SERVICE_USAGE); LogLevel2Event(EVENT_NAME_VISUAL_STATE_CHANGED, fields); @@ -152,7 +149,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_WINDOW_ON_CREATED, fields); } - void TraceLogger::LogModeChange(ViewMode mode) const + void TraceLogger::LogModeChange(ViewMode mode) { if (!GetTraceLoggingProviderEnabled()) return; @@ -167,7 +164,7 @@ namespace CalculatorApp } } - void TraceLogger::LogHistoryItemLoad(ViewMode mode, int historyListSize, int loadedIndex) const + void TraceLogger::LogHistoryItemLoad(ViewMode mode, int historyListSize, int loadedIndex) { if (!GetTraceLoggingProviderEnabled()) { @@ -183,7 +180,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_HISTORY_ITEM_LOAD, fields); } - void TraceLogger::LogMemoryItemLoad(ViewMode mode, int memoryListSize, int loadedIndex) const + void TraceLogger::LogMemoryItemLoad(ViewMode mode, int memoryListSize, int loadedIndex) { if (!GetTraceLoggingProviderEnabled()) { @@ -199,7 +196,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_MEMORY_ITEM_LOAD, fields); } - void TraceLogger::LogError(ViewMode mode, wstring_view functionName, wstring_view errorString) + void TraceLogger::LogError(ViewMode mode, Platform::String ^ functionName, Platform::String ^ errorString) { if (!GetTraceLoggingProviderEnabled()) return; @@ -207,13 +204,13 @@ namespace CalculatorApp LoggingFields fields{}; fields.AddGuid(L"SessionGuid", sessionGuid); fields.AddString(L"CalcMode", NavCategory::GetFriendlyName(mode)->Data()); - fields.AddString(L"FunctionName", functionName); - fields.AddString(L"Message", errorString); + fields.AddString(L"FunctionName", functionName->Data()); + fields.AddString(L"Message", errorString->Data()); fields.AddUInt64(PDT_PRIVACY_DATA_TAG, PDT_PRODUCT_AND_SERVICE_USAGE); LogLevel2Event(EVENT_NAME_EXCEPTION, fields); } - void TraceLogger::LogStandardException(ViewMode mode, wstring_view functionName, const exception& e) const + void TraceLogger::LogStandardException(ViewMode mode, wstring_view functionName, const exception& e) { if (!GetTraceLoggingProviderEnabled()) return; @@ -229,7 +226,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_EXCEPTION, fields); } - void TraceLogger::LogWinRTException(ViewMode mode, wstring_view functionName, hresult_error const& e) const + void TraceLogger::LogWinRTException(ViewMode mode, wstring_view functionName, hresult_error const& e) { if (!GetTraceLoggingProviderEnabled()) return; @@ -244,7 +241,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_EXCEPTION, fields); } - void TraceLogger::LogPlatformException(ViewMode mode, wstring_view functionName, Platform::Exception ^ e) const + void TraceLogger::LogPlatformException(ViewMode mode, wstring_view functionName, Platform::Exception ^ e) { if (!GetTraceLoggingProviderEnabled()) return; @@ -291,7 +288,7 @@ namespace CalculatorApp } } - void TraceLogger::UpdateWindowCount(size_t windowCount) + void TraceLogger::UpdateWindowCount(uint64 windowCount) { if (windowCount == 0) { @@ -301,6 +298,11 @@ namespace CalculatorApp currentWindowCount = windowCount; } + void TraceLogger::DecreaseWindowCount() + { + currentWindowCount = 0; + } + void TraceLogger::LogButtonUsage() { if (!GetTraceLoggingProviderEnabled()) @@ -348,7 +350,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_DATE_CALCULATION_MODE_USED, fields); } - void TraceLogger::LogConverterInputReceived(ViewMode mode) const + void TraceLogger::LogConverterInputReceived(ViewMode mode) { if (!GetTraceLoggingProviderEnabled()) return; @@ -360,7 +362,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_CONVERTER_INPUT_RECEIVED, fields); } - void TraceLogger::LogNavBarOpened() const + void TraceLogger::LogNavBarOpened() { if (!GetTraceLoggingProviderEnabled()) return; @@ -371,7 +373,7 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_NAV_BAR_OPENED, fields); } - void TraceLogger::LogInputPasted(ViewMode mode) const + void TraceLogger::LogInputPasted(ViewMode mode) { if (!GetTraceLoggingProviderEnabled()) return; diff --git a/src/CalcViewModel/Common/TraceLogger.h b/src/CalcViewModel/Common/TraceLogger.h index d8a4289..fa24f8e 100644 --- a/src/CalcViewModel/Common/TraceLogger.h +++ b/src/CalcViewModel/Common/TraceLogger.h @@ -28,33 +28,31 @@ namespace CalculatorApp } }; - class TraceLogger +public + ref class TraceLogger sealed { public: - TraceLogger(_In_ TraceLogger const&) = delete; - TraceLogger const& operator=(_In_ TraceLogger const&) = delete; - ~TraceLogger(); - static TraceLogger& GetInstance(); - bool GetTraceLoggingProviderEnabled() const; - - void LogModeChange(CalculatorApp::Common::ViewMode mode) const; - void LogHistoryItemLoad(CalculatorApp::Common::ViewMode mode, int historyListSize, int loadedIndex) const; - void LogMemoryItemLoad(CalculatorApp::Common::ViewMode mode, int memoryListSize, int loadedIndex) const; + static TraceLogger ^ GetInstance(); + bool GetTraceLoggingProviderEnabled(); + void LogModeChange(CalculatorApp::Common::ViewMode mode); + void LogHistoryItemLoad(CalculatorApp::Common::ViewMode mode, int historyListSize, int loadedIndex); + void LogMemoryItemLoad(CalculatorApp::Common::ViewMode mode, int memoryListSize, int loadedIndex); void UpdateButtonUsage(CalculatorApp::NumbersAndOperatorsEnum button, CalculatorApp::Common::ViewMode mode); void LogButtonUsage(); void LogDateCalculationModeUsed(bool AddSubtractMode); - void UpdateWindowCount(size_t windowCount = 0); + void UpdateWindowCount(uint64 windowCount); + void DecreaseWindowCount(); bool IsWindowIdInLog(int windowId); - void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, std::wstring_view state, bool isAlwaysOnTop = false) const; + void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, Platform::String ^ state, bool isAlwaysOnTop); void LogWindowCreated(CalculatorApp::Common::ViewMode mode, int windowId); - void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode) const; - void LogNavBarOpened() const; - - void LogError(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, std::wstring_view errorString); - void LogStandardException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e) const; - void LogWinRTException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ winrt::hresult_error const& e) const; - void LogPlatformException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ Platform::Exception ^ e) const; - void LogInputPasted(CalculatorApp::Common::ViewMode mode) const; + void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode); + void LogNavBarOpened(); + void LogError(CalculatorApp::Common::ViewMode mode, Platform::String ^ functionName, Platform::String ^ errorString); + internal : + void LogStandardException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ const std::exception& e); + void LogWinRTException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ winrt::hresult_error const& e); + void LogPlatformException(CalculatorApp::Common::ViewMode mode, std::wstring_view functionName, _In_ Platform::Exception ^ e); + void LogInputPasted(CalculatorApp::Common::ViewMode mode); private: // Create an instance of TraceLogger @@ -64,11 +62,11 @@ namespace CalculatorApp // sampling is involved in Microsoft's diagnostic data collection process. // These keywords provide additional input into how frequently an event might be sampled. // The lower the level of the keyword, the higher the possibility that the corresponding event may be sampled. - void LogLevel1Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const; - void LogLevel2Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const; - void LogLevel3Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const; + void LogLevel1Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields); + void LogLevel2Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields); + void LogLevel3Event(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields); - std::unique_ptr CreateTraceActivity(std::wstring_view activityName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const; + std::unique_ptr CreateTraceActivity(std::wstring_view activityName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields); winrt::Windows::Foundation::Diagnostics::LoggingChannel g_calculatorProvider; @@ -76,7 +74,7 @@ namespace CalculatorApp std::vector windowIdLog; GUID sessionGuid; - size_t currentWindowCount = 0; + uint64 currentWindowCount = 0; winrt::Windows::Foundation::Diagnostics::LoggingActivity m_appLaunchActivity; }; diff --git a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp index e976888..d098885 100644 --- a/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/CurrencyDataLoader.cpp @@ -351,12 +351,12 @@ future CurrencyDataLoader::TryLoadDataFromCacheAsync() } catch (Exception ^ ex) { - TraceLogger::GetInstance().LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex); + TraceLogger::GetInstance()->LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex); co_return false; } catch (const exception& e) { - TraceLogger::GetInstance().LogStandardException(ViewMode::Currency, __FUNCTIONW__, e); + TraceLogger::GetInstance()->LogStandardException(ViewMode::Currency, __FUNCTIONW__, e); co_return false; } catch (...) @@ -461,12 +461,12 @@ future CurrencyDataLoader::TryLoadDataFromWebAsync() } catch (Exception ^ ex) { - TraceLogger::GetInstance().LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex); + TraceLogger::GetInstance()->LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex); co_return false; } catch (const exception& e) { - TraceLogger::GetInstance().LogStandardException(ViewMode::Currency, __FUNCTIONW__, e); + TraceLogger::GetInstance()->LogStandardException(ViewMode::Currency, __FUNCTIONW__, e); co_return false; } catch (...) @@ -482,7 +482,7 @@ future CurrencyDataLoader::TryLoadDataFromWebOverrideAsync() if (!didLoad) { m_loadStatus = CurrencyLoadStatus::FailedToLoad; - TraceLogger::GetInstance().LogError(ViewMode::Currency, L"CurrencyDataLoader::TryLoadDataFromWebOverrideAsync", L"UserRequestedRefreshFailed"); + TraceLogger::GetInstance()->LogError(ViewMode::Currency, L"CurrencyDataLoader::TryLoadDataFromWebOverrideAsync", L"UserRequestedRefreshFailed"); } co_return didLoad; diff --git a/src/CalcViewModel/HistoryViewModel.cpp b/src/CalcViewModel/HistoryViewModel.cpp index 61abe4e..2075103 100644 --- a/src/CalcViewModel/HistoryViewModel.cpp +++ b/src/CalcViewModel/HistoryViewModel.cpp @@ -120,7 +120,7 @@ void HistoryViewModel::ShowItem(_In_ HistoryItemViewModel ^ e) { unsigned int index; Items->IndexOf(e, &index); - TraceLogger::GetInstance().LogHistoryItemLoad((ViewMode)m_currentMode, ItemSize, (int)(index)); + TraceLogger::GetInstance()->LogHistoryItemLoad((ViewMode)m_currentMode, ItemSize, (int)(index)); HistoryItemClicked(e); } diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index f5c0c25..ce4b54d 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -674,7 +674,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter) m_isLastOperationHistoryLoad = false; } - TraceLogger::GetInstance().UpdateButtonUsage(numOpEnum, GetCalculatorMode()); + TraceLogger::GetInstance()->UpdateButtonUsage(numOpEnum, GetCalculatorMode()); m_standardCalculatorManager.SendCommand(cmdenum); } } @@ -753,7 +753,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString) return; } - TraceLogger::GetInstance().LogInputPasted(GetCalculatorMode()); + TraceLogger::GetInstance()->LogInputPasted(GetCalculatorMode()); bool isFirstLegalChar = true; m_standardCalculatorManager.SendCommand(Command::CommandCENTR); bool sendNegate = false; @@ -899,7 +899,7 @@ void StandardCalculatorViewModel::OnClearMemoryCommand(Object ^ parameter) { m_standardCalculatorManager.MemorizedNumberClearAll(); - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode()); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode()); if (m_localizedMemoryCleared == nullptr) { @@ -1055,7 +1055,7 @@ void StandardCalculatorViewModel::OnMemoryButtonPressed() { m_standardCalculatorManager.MemorizeNumber(); - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode()); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode()); if (m_localizedMemorySavedAutomationFormat == nullptr) { @@ -1094,7 +1094,7 @@ void StandardCalculatorViewModel::OnMemoryItemPressed(Object ^ memoryItemPositio HideMemoryClicked(); auto mode = IsStandard ? ViewMode::Standard : IsScientific ? ViewMode::Scientific : ViewMode::Programmer; - TraceLogger::GetInstance().LogMemoryItemLoad(mode, MemorizedNumbers->Size, boxedPosition->Value); + TraceLogger::GetInstance()->LogMemoryItemLoad(mode, MemorizedNumbers->Size, boxedPosition->Value); } } @@ -1105,7 +1105,7 @@ void StandardCalculatorViewModel::OnMemoryAdd(Object ^ memoryItemPosition) if (MemorizedNumbers) { auto boxedPosition = safe_cast ^>(memoryItemPosition); - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryAdd, GetCalculatorMode()); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryAdd, GetCalculatorMode()); m_standardCalculatorManager.MemorizedNumberAdd(boxedPosition->Value); } } @@ -1116,7 +1116,7 @@ void StandardCalculatorViewModel::OnMemorySubtract(Object ^ memoryItemPosition) if (MemorizedNumbers) { auto boxedPosition = safe_cast ^>(memoryItemPosition); - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemorySubtract, GetCalculatorMode()); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::MemorySubtract, GetCalculatorMode()); m_standardCalculatorManager.MemorizedNumberSubtract(boxedPosition->Value); } } @@ -1142,7 +1142,7 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition { IsMemoryEmpty = true; } - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode()); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode()); wstring localizedIndex = to_wstring(boxedPosition->Value + 1); LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex); @@ -1189,7 +1189,7 @@ void StandardCalculatorViewModel::OnPropertyChanged(String ^ propertyname) } else if (propertyname == IsBitFlipCheckedPropertyName) { - TraceLogger::GetInstance().UpdateButtonUsage( + TraceLogger::GetInstance()->UpdateButtonUsage( IsBitFlipChecked ? NumbersAndOperatorsEnum::BitflipButton : NumbersAndOperatorsEnum::FullKeypadButton, ViewMode::Programmer); } } diff --git a/src/CalcViewModel/UnitConverterViewModel.cpp b/src/CalcViewModel/UnitConverterViewModel.cpp index 149f565..d4ab56a 100644 --- a/src/CalcViewModel/UnitConverterViewModel.cpp +++ b/src/CalcViewModel/UnitConverterViewModel.cpp @@ -494,7 +494,7 @@ void UnitConverterViewModel::OnButtonPressed(Platform::Object ^ parameter) m_model->SendCommand(command); - TraceLogger::GetInstance().LogConverterInputReceived(Mode); + TraceLogger::GetInstance()->LogConverterInputReceived(Mode); } void UnitConverterViewModel::OnCopyCommand(Platform::Object ^ parameter) @@ -887,7 +887,7 @@ void UnitConverterViewModel::OnPaste(String ^ stringToPaste) return; } - TraceLogger::GetInstance().LogInputPasted(Mode); + TraceLogger::GetInstance()->LogInputPasted(Mode); bool isFirstLegalChar = true; bool sendNegate = false; wstring accumulation = L""; diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp index ade73f0..0f6898c 100644 --- a/src/Calculator/App.xaml.cpp +++ b/src/Calculator/App.xaml.cpp @@ -97,7 +97,7 @@ void App::AddWindowToMap(_In_ WindowFrameService ^ frameService) { reader_writer_lock::scoped_lock lock(m_windowsMapLock); m_secondaryWindows[frameService->GetViewId()] = frameService; - TraceLogger::GetInstance().UpdateWindowCount(m_secondaryWindows.size()); + TraceLogger::GetInstance()->UpdateWindowCount(m_secondaryWindows.size()); } WindowFrameService ^ App::GetWindowFromMap(int viewId) @@ -363,7 +363,7 @@ void App::OnAppLaunch(IActivatedEventArgs ^ args, String ^ argument) } else { - TraceLogger::GetInstance().LogError(ViewMode::None, L"App::OnAppLaunch", L"Null_ActivationViewSwitcher"); + TraceLogger::GetInstance()->LogError(ViewMode::None, L"App::OnAppLaunch", L"Null_ActivationViewSwitcher"); } } // Set the preLaunched flag to false @@ -439,7 +439,7 @@ void App::OnActivated(IActivatedEventArgs ^ args) void CalculatorApp::App::OnSuspending(Object ^ sender, SuspendingEventArgs ^ args) { - TraceLogger::GetInstance().LogButtonUsage(); + TraceLogger::GetInstance()->LogButtonUsage(); } void App::DismissedEventHandler(SplashScreen ^ sender, Object ^ e) diff --git a/src/Calculator/Views/Calculator.xaml.cpp b/src/Calculator/Views/Calculator.xaml.cpp index 3e29ed0..2bf867f 100644 --- a/src/Calculator/Views/Calculator.xaml.cpp +++ b/src/Calculator/Views/Calculator.xaml.cpp @@ -137,7 +137,7 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^) WeakReference weakThis(this); this->Dispatcher->RunAsync( CoreDispatcherPriority::Normal, ref new DispatchedHandler([weakThis]() { - if (TraceLogger::GetInstance().IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) + if (TraceLogger::GetInstance()->IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) { auto refThis = weakThis.Resolve(); if (refThis != nullptr) @@ -707,8 +707,7 @@ void Calculator::OnMemoryAccessKeyInvoked(_In_ UIElement ^ sender, _In_ AccessKe void CalculatorApp::Calculator::OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e) { auto mode = IsStandard ? ViewMode::Standard : IsScientific ? ViewMode::Scientific : ViewMode::Programmer; - auto state = std::wstring(e->NewState->Name->Begin()); - TraceLogger::GetInstance().LogVisualStateChanged(mode, state, IsAlwaysOnTop); + TraceLogger::GetInstance()->LogVisualStateChanged(mode, e->NewState->Name, IsAlwaysOnTop); } void Calculator::Calculator_SizeChanged(Object ^ /*sender*/, SizeChangedEventArgs ^ /*e*/) diff --git a/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp index 3b2cb2e..a7259e9 100644 --- a/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp +++ b/src/Calculator/Views/CalculatorProgrammerOperators.xaml.cpp @@ -38,7 +38,7 @@ CalculatorProgrammerOperators::CalculatorProgrammerOperators() void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) { - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::HexButton, ViewMode::Programmer); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::HexButton, ViewMode::Programmer); if (Model) { Model->SwitchProgrammerModeBase(RADIX_TYPE::HEX_RADIX); @@ -47,7 +47,7 @@ void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ void CalculatorProgrammerOperators::DecButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) { - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::DecButton, ViewMode::Programmer); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::DecButton, ViewMode::Programmer); if (Model) { Model->SwitchProgrammerModeBase(RADIX_TYPE::DEC_RADIX); @@ -56,7 +56,7 @@ void CalculatorProgrammerOperators::DecButtonChecked(_In_ Object ^ sender, _In_ void CalculatorProgrammerOperators::OctButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) { - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::OctButton, ViewMode::Programmer); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::OctButton, ViewMode::Programmer); if (Model) { Model->SwitchProgrammerModeBase(RADIX_TYPE::OCT_RADIX); @@ -65,7 +65,7 @@ void CalculatorProgrammerOperators::OctButtonChecked(_In_ Object ^ sender, _In_ void CalculatorProgrammerOperators::BinButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e) { - TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::BinButton, ViewMode::Programmer); + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::BinButton, ViewMode::Programmer); if (Model) { Model->SwitchProgrammerModeBase(RADIX_TYPE::BIN_RADIX); diff --git a/src/Calculator/Views/DateCalculator.xaml.cpp b/src/Calculator/Views/DateCalculator.xaml.cpp index 5538f5b..9fc0084 100644 --- a/src/Calculator/Views/DateCalculator.xaml.cpp +++ b/src/Calculator/Views/DateCalculator.xaml.cpp @@ -103,7 +103,7 @@ void DateCalculator::FromDate_DateChanged(_In_ CalendarDatePicker ^ sender, _In_ { auto dateCalcViewModel = safe_cast(this->DataContext); dateCalcViewModel->FromDate = e->NewDate->Value; - TraceLogger::GetInstance().LogDateCalculationModeUsed(false /* AddSubtractMode */); + TraceLogger::GetInstance()->LogDateCalculationModeUsed(false /* AddSubtractMode */); } else { @@ -117,7 +117,7 @@ void DateCalculator::ToDate_DateChanged(_In_ CalendarDatePicker ^ sender, _In_ C { auto dateCalcViewModel = safe_cast(this->DataContext); dateCalcViewModel->ToDate = e->NewDate->Value; - TraceLogger::GetInstance().LogDateCalculationModeUsed(false /* AddSubtractMode */); + TraceLogger::GetInstance()->LogDateCalculationModeUsed(false /* AddSubtractMode */); } else { @@ -131,7 +131,7 @@ void DateCalculator::AddSubtract_DateChanged(_In_ CalendarDatePicker ^ sender, _ { auto dateCalcViewModel = safe_cast(this->DataContext); dateCalcViewModel->StartDate = e->NewDate->Value; - TraceLogger::GetInstance().LogDateCalculationModeUsed(true /* AddSubtractMode */); + TraceLogger::GetInstance()->LogDateCalculationModeUsed(true /* AddSubtractMode */); } else { @@ -145,7 +145,7 @@ void CalculatorApp::DateCalculator::OffsetValue_Changed(_In_ Platform::Object ^ // do not log diagnostics for no-ops and initialization of combo boxes if (dateCalcViewModel->DaysOffset != 0 || dateCalcViewModel->MonthsOffset != 0 || dateCalcViewModel->YearsOffset != 0) { - TraceLogger::GetInstance().LogDateCalculationModeUsed(true /* AddSubtractMode */); + TraceLogger::GetInstance()->LogDateCalculationModeUsed(true /* AddSubtractMode */); } } @@ -237,6 +237,5 @@ void DateCalculator::AddSubtractOption_Checked(_In_ Object ^ sender, _In_ Routed void CalculatorApp::DateCalculator::OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e) { - auto state = std::wstring(e->NewState->Name->Begin()); - TraceLogger::GetInstance().LogVisualStateChanged(ViewMode::Date, state); + TraceLogger::GetInstance()->LogVisualStateChanged(ViewMode::Date, e->NewState->Name, false); } diff --git a/src/Calculator/Views/MainPage.xaml.cpp b/src/Calculator/Views/MainPage.xaml.cpp index a573f6c..e9b29fe 100644 --- a/src/Calculator/Views/MainPage.xaml.cpp +++ b/src/Calculator/Views/MainPage.xaml.cpp @@ -256,7 +256,7 @@ void MainPage::OnPageLoaded(_In_ Object ^, _In_ RoutedEventArgs ^ args) // Delay load things later when we get a chance. this->Dispatcher->RunAsync( CoreDispatcherPriority::Normal, ref new DispatchedHandler([]() { - if (TraceLogger::GetInstance().IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) + if (TraceLogger::GetInstance()->IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) { AppLifecycleLogger::GetInstance().LaunchUIResponsive(); AppLifecycleLogger::GetInstance().LaunchVisibleComplete(); @@ -391,7 +391,7 @@ void MainPage::OnNavPaneOpening(_In_ MUXC::NavigationView ^ sender, _In_ Object void MainPage::OnNavPaneOpened(_In_ MUXC::NavigationView ^ sender, _In_ Object ^ args) { KeyboardShortcutManager::HonorShortcuts(false); - TraceLogger::GetInstance().LogNavBarOpened(); + TraceLogger::GetInstance()->LogNavBarOpened(); } void MainPage::OnNavPaneClosed(_In_ MUXC::NavigationView ^ sender, _In_ Object ^ args) diff --git a/src/Calculator/Views/UnitConverter.xaml.cpp b/src/Calculator/Views/UnitConverter.xaml.cpp index b94d838..dbfd1e6 100644 --- a/src/Calculator/Views/UnitConverter.xaml.cpp +++ b/src/Calculator/Views/UnitConverter.xaml.cpp @@ -377,6 +377,5 @@ void CalculatorApp::UnitConverter::SupplementaryResultsPanelInGrid_SizeChanged(P void CalculatorApp::UnitConverter::OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e) { auto mode = NavCategory::Deserialize(Model->CurrentCategory->GetModelCategory().id); - auto state = std::wstring(e->NewState->Name->Begin()); - TraceLogger::GetInstance().LogVisualStateChanged(mode, state); + TraceLogger::GetInstance()->LogVisualStateChanged(mode, e->NewState->Name, false); } diff --git a/src/Calculator/WindowFrameService.cpp b/src/Calculator/WindowFrameService.cpp index b710ed6..37ad911 100644 --- a/src/Calculator/WindowFrameService.cpp +++ b/src/Calculator/WindowFrameService.cpp @@ -118,7 +118,7 @@ namespace CalculatorApp void WindowFrameService::OnConsolidated(_In_ ApplicationView ^ sender, _In_ ApplicationViewConsolidatedEventArgs ^ e) { - TraceLogger::GetInstance().UpdateWindowCount(); + TraceLogger::GetInstance()->DecreaseWindowCount(); auto parent = m_parent.Resolve(); if (parent != nullptr) {