Updated Calculator diagnostic data collection per the specification (#572)

- Removed unneeded diagnostic events and code
- Added and consolidated events into the events defined in the spec
This commit is contained in:
Stephanie Anderl
2019-07-17 18:09:39 -07:00
committed by Matt Cooley
parent 2ff7bb4089
commit a6384269bc
43 changed files with 449 additions and 1249 deletions

View File

@@ -82,7 +82,7 @@ void ApplicationViewModel::Initialize(ViewMode mode)
}
catch (const std::exception& e)
{
TraceLogger::GetInstance().LogStandardException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogStandardException(mode, __FUNCTIONW__, e);
if (!TryRecoverFromNavigationModeFailure())
{
// Could not navigate to standard mode either.
@@ -92,7 +92,7 @@ void ApplicationViewModel::Initialize(ViewMode mode)
}
catch (Exception ^ e)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogPlatformException(mode, __FUNCTIONW__, e);
if (!TryRecoverFromNavigationModeFailure())
{
// Could not navigate to standard mode either.
@@ -121,10 +121,8 @@ bool ApplicationViewModel::TryRecoverFromNavigationModeFailure()
void ApplicationViewModel::OnModeChanged()
{
assert(NavCategory::IsValidViewMode(m_mode));
TraceLogger::GetInstance().LogModeChangeBegin(m_PreviousMode, m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (NavCategory::IsCalculatorViewMode(m_mode))
{
TraceLogger::GetInstance().LogCalculatorModeViewed(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (!m_CalculatorViewModel)
{
m_CalculatorViewModel = ref new StandardCalculatorViewModel();
@@ -133,7 +131,6 @@ void ApplicationViewModel::OnModeChanged()
}
else if (NavCategory::IsDateCalculatorViewMode(m_mode))
{
TraceLogger::GetInstance().LogDateCalculatorModeViewed(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (!m_DateCalcViewModel)
{
m_DateCalcViewModel = ref new DateCalculatorViewModel();
@@ -141,7 +138,6 @@ void ApplicationViewModel::OnModeChanged()
}
else if (NavCategory::IsConverterViewMode(m_mode))
{
TraceLogger::GetInstance().LogConverterModeViewed(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
if (!m_ConverterViewModel)
{
auto dataLoader = make_shared<UnitConverterDataLoader>(ref new GeographicRegion());
@@ -155,13 +151,21 @@ void ApplicationViewModel::OnModeChanged()
auto resProvider = AppResourceProvider::GetInstance();
CategoryName = resProvider.GetResourceString(NavCategory::GetNameResourceKey(m_mode));
// This is the only place where a ViewMode enum should be cast to an int.
//
// Cast mode to an int in order to save it to app data.
// Save the changed mode, so that the new window launches in this mode.
// Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load.
ApplicationData::Current->LocalSettings->Values->Insert(ModePropertyName, NavCategory::Serialize(m_mode));
TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
// Log ModeChange event when not first launch, log WindowCreated on first launch
if (NavCategory::IsValidViewMode(m_PreviousMode))
{
TraceLogger::GetInstance().LogModeChange(m_mode);
}
else
{
TraceLogger::GetInstance().LogWindowCreated(m_mode);
}
RaisePropertyChanged(ClearMemoryVisibilityPropertyName);
}

View File

@@ -308,7 +308,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(IsStoreBuild)' == 'True'">
<ClCompile>
<AdditionalOptions>/DSEND_TELEMETRY %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>/DSEND_DIAGNOSTICS %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
@@ -439,4 +439,4 @@
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.UI.Xaml.2.0.181018003.1\build\native\Microsoft.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.UI.Xaml.2.0.181018003.1\build\native\Microsoft.UI.Xaml.targets'))" />
</Target>
</Project>
</Project>

View File

@@ -161,55 +161,14 @@ public
BINPOS62 = (int)CM::Command::CommandBINPOS62,
BINPOS63 = (int)CM::Command::CommandBINPOS63,
BINEND = (int)CM::Command::CommandBINEDITEND,
Hyp = (int)CM::Command::CommandHYP
};
Hyp = (int)CM::Command::CommandHYP,
// This contains list of functions whose usage we are tracelogging
public
enum class FunctionLogEnum
{
Invert = (int)CM::Command::CommandREC,
Sqrt = (int)CM::Command::CommandSQRT,
Percent = (int)CM::Command::CommandPERCENT,
Negate = (int)CM::Command::CommandSIGN,
Degrees = (int)CM::Command::CommandDegrees,
Pi = (int)CM::Command::CommandPI,
Sin = (int)CM::Command::CommandSIN,
Cos = (int)CM::Command::CommandCOS,
Tan = (int)CM::Command::CommandTAN,
Factorial = (int)CM::Command::CommandFAC,
XPower2 = (int)CM::Command::CommandSQR,
Mod = (int)CM::Command::CommandMOD,
FToE = (int)CM::Command::CommandFE,
LogBaseE = (int)CM::Command::CommandLN,
InvSin = (int)CM::Command::CommandASIN,
InvCos = (int)CM::Command::CommandACOS,
InvTan = (int)CM::Command::CommandATAN,
LogBase10 = (int)CM::Command::CommandLOG,
XPowerY = (int)CM::Command::CommandPWR,
YRootX = (int)CM::Command::CommandROOT,
TenPowerX = (int)CM::Command::CommandPOW10,
EPowerX = (int)CM::Command::CommandPOWE,
Exp = (int)CM::Command::CommandEXP,
DecButton = (int)CM::Command::CommandDec,
OctButton = (int)CM::Command::CommandOct,
HexButton = (int)CM::Command::CommandHex,
BinButton = (int)CM::Command::CommandBin,
And = (int)CM::Command::CommandAnd,
Ror = (int)CM::Command::CommandROR,
Rol = (int)CM::Command::CommandROL,
Or = (int)CM::Command::CommandOR,
Lsh = (int)CM::Command::CommandLSHF,
Rsh = (int)CM::Command::CommandRSHF,
Xor = (int)CM::Command::CommandXor,
Not = (int)CM::Command::CommandNot,
Sinh = (int)CM::Command::CommandSINH,
Cosh = (int)CM::Command::CommandCOSH,
Tanh = (int)CM::Command::CommandTANH,
InvSinh = (int)CM::Command::CommandASINH,
InvCosh = (int)CM::Command::CommandACOSH,
InvTanh = (int)CM::Command::CommandATANH,
Cube = (int)CM::Command::CommandCUB,
DMS = (int)CM::Command::CommandDMS,
// Enum values below are used for Tracelogging and do not map to the Calculator engine
MemoryAdd = (int)CM::Command::CommandMPLUS,
MemorySubtract = (int)CM::Command::CommandMMINUS,
MemoryRecall = (int)CM::Command::CommandRECALL,
MemoryClear = (int)CM::Command::CommandMCLEAR,
BitflipButton = 1000,
FullKeypadButton = 1001
};
}

View File

@@ -109,7 +109,7 @@ String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode
if (pastedText->Length() > MaxPasteableLength)
{
// return NoOp to indicate don't paste anything.
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"PastedExpressionSizeGreaterThanMaxAllowed", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"PastedExpressionSizeGreaterThanMaxAllowed");
return StringReference(PasteErrorString);
}
@@ -129,7 +129,7 @@ String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode
// Extract operands from the expression to make regex comparison easy and quick. For whole expression it was taking too much of time.
// Operands vector will have the list of operands in the pasteExpression
vector<wstring> operands = ExtractOperands(pasteExpression, mode, programmerNumberBase, bitLengthType);
vector<wstring> operands = ExtractOperands(pasteExpression, mode);
if (operands.empty())
{
// return NoOp to indicate don't paste anything.
@@ -144,14 +144,14 @@ String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode
// validate each operand with patterns for different modes
if (!ExpressionRegExMatch(operands, mode, modeType, programmerNumberBase, bitLengthType))
{
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"InvalidExpressionForPresentMode", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ValidatePasteExpression", L"InvalidExpressionForPresentMode");
return StringReference(PasteErrorString);
}
return ref new String(pastedText->Data());
}
vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode, int programmerNumberBase, int bitLengthType)
vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression, ViewMode mode)
{
vector<wstring> operands{};
size_t lastIndex = 0;
@@ -173,7 +173,7 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
if (operands.size() >= MaxOperandCount)
{
TraceLogger::GetInstance().LogInvalidPastedInputOccurred(L"OperandCountGreaterThanMaxCount", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"OperandCountGreaterThanMaxCount");
operands.clear();
return operands;
}
@@ -187,7 +187,7 @@ vector<wstring> 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().LogInvalidPastedInputOccurred(L"ExponentLengthGreaterThanMaxLength", mode, programmerNumberBase, bitLengthType);
TraceLogger::GetInstance().LogError(mode, L"CopyPasteManager::ExtractOperands", L"ExponentLengthGreaterThanMaxLength");
operands.clear();
return operands;
}

View File

@@ -51,7 +51,7 @@ namespace CalculatorApp
int bitLengthType);
static std::vector<std::wstring>
ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode, int programmerNumberBase = -1, int bitLengthType = -1);
ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode);
static bool ExpressionRegExMatch(
std::vector<std::wstring> operands,
CalculatorApp::Common::ViewMode mode,

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
#include "CalcManager/Command.h"
#include "TraceActivity.h"
#include "NavCategory.h"
#include "CalculatorButtonUser.h"
static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINEDITEND;
@@ -13,19 +14,17 @@ static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINE
// This class implements a singleton model ensure that only one instance is created.
namespace CalculatorApp
{
struct FuncLog
struct ButtonLog
{
public:
int count;
std::wstring funcName;
FuncLog()
CalculatorApp::NumbersAndOperatorsEnum button;
CalculatorApp::Common::ViewMode mode;
ButtonLog(CalculatorApp::NumbersAndOperatorsEnum btn, CalculatorApp::Common::ViewMode vMode)
{
count = 0;
}
FuncLog(std::wstring fName)
{
funcName = fName;
count = 0;
button = btn;
mode = vMode;
count = 1;
}
};
@@ -38,123 +37,45 @@ namespace CalculatorApp
static TraceLogger& GetInstance();
bool GetTraceLoggingProviderEnabled() const;
void LogAppLaunchStart();
void LogAppLaunchComplete();
void LogAppResumeComplete();
void LogOnAppLaunch(std::wstring_view previousExecutionState) const;
void LogMemoryClearAll(int);
void LogBitFlipPaneClicked() const;
void LogBitFlipUsed() const;
void LogHistoryBodyOpened() const;
void LogHistoryItemLoadBegin() const;
void LogHistoryItemLoadEnd(unsigned int) const;
void LogHistoryFlyoutOpenBegin(unsigned int) const;
void LogHistoryFlyoutOpenEnd(int) const;
void LogCalculatorModeViewed(CalculatorApp::Common::ViewMode, int);
void LogDateCalculatorModeViewed(CalculatorApp::Common::ViewMode, int);
void LogConverterModeViewed(CalculatorApp::Common::ViewMode, int);
void LogModeChangeBegin(CalculatorApp::Common::ViewMode, CalculatorApp::Common::ViewMode, int);
void LogModeChangeEnd(CalculatorApp::Common::ViewMode, int) const;
void LogClearHistory() const;
void InsertIntoMemoryMap(int, bool, bool, bool);
void UpdateMemoryMap(int, int, bool, bool, bool);
void DeleteFromMemoryMap(int, int);
void LogMemoryUsed(int, unsigned int, bool, bool, bool, unsigned int) const;
void LogMultipleMemoryUsed(unsigned int, unsigned int) const;
void LogSingleMemoryUsed(unsigned int) const;
void LogSharedMemoryUsed(std::wstring_view, std::wstring_view, unsigned int) const;
void LogMemoryBodyOpened() const;
void LogMemoryFlyoutOpenBegin(unsigned int) const;
void LogDebug(std::wstring_view debugData);
void LogMemoryFlyoutOpenEnd(unsigned int) const;
void LogInvalidPastedInputOccurred(std::wstring_view reason, CalculatorApp::Common::ViewMode mode, int ProgrammerNumberBase, int bitLengthType);
void LogValidInputPasted(CalculatorApp::Common::ViewMode mode) const;
void UpdateFunctionUsage(int func);
void LogFunctionUsage(int);
void InitFunctionLogArray();
void LogBitLengthButtonUsed(int windowId);
void LogRadixButtonUsed(int windowId);
void LogAngleButtonUsed(int windowId);
void LogHypButtonUsed(int windowId);
void LogNewWindowCreationBegin(int windowId);
void LogNewWindowCreationEnd(int windowId);
void LogError(std::wstring_view errorString);
void LogPrelaunchedAppActivatedByUser();
void LogAppPrelaunchedBySystem();
void UpdateWindowCount(size_t windowCount);
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;
void UpdateButtonUsage(CalculatorApp::NumbersAndOperatorsEnum button, CalculatorApp::Common::ViewMode mode);
void LogButtonUsage();
void LogDateCalculationModeUsed(bool AddSubtractMode);
void UpdateWindowCount(size_t windowCount = 0);
bool UpdateWindowIdLog(int windowId);
void LogMaxWindowCount();
void LogWindowActivated() const;
void LogWindowLaunched() const;
void LogUserRequestedRefreshFailed() const;
void LogConversionResult(std::wstring_view fromValue, std::wstring_view fromUnit, std::wstring_view toValue, std::wstring_view toUnit) const;
void LogAboutFlyoutOpened() const;
void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, std::wstring_view state) const;
void LogWindowCreated(CalculatorApp::Common::ViewMode mode) const;
void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode) const;
void LogNavBarOpened() const;
void LogViewClosingTelemetry(int);
void LogCoreWindowWasNull() const;
// Trace methods for Date Calculator usage
void LogDateDifferenceModeUsed(int windowId);
void LogDateAddSubtractModeUsed(int windowId, bool isAddMode);
void
LogDateClippedTimeDifferenceFound(winrt::Windows::Globalization::Calendar const& today, winrt::Windows::Foundation::DateTime const& clippedTime) const;
void LogStandardException(std::wstring_view functionName, _In_ const std::exception& e) const;
void LogWinRTException(std::wstring_view functionName, _In_ winrt::hresult_error const& e) const;
void LogPlatformException(std::wstring_view functionName, _In_ Platform::Exception ^ e) 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;
private:
// Create an instance of TraceLogger
TraceLogger();
// Any new Log method should
// a) decide the level of logging. This will help us in limiting recording of events only up to a certain level. See this link for guidance
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363742(v=vs.85).aspx We're using Verbose level for events that are called frequently and
// needed only for debugging or capturing perf for specific scenarios b) should decide whether or not to log to telemetry and pass
// TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) accordingly c) Should accept a variable number of additional data arguments if needed
void LogTelemetryEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogMeasureEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogCriticalDataEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogPerformanceEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
void LogInfoEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
// As mentioned in Microsoft's Privacy Statement(https://privacy.microsoft.com/en-US/privacystatement#maindiagnosticsmodule),
// 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;
std::unique_ptr<TraceActivity> CreateTraceActivity(std::wstring_view activityName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;
winrt::Windows::Foundation::Diagnostics::LoggingChannel g_calculatorProvider;
bool isSizeChangeLogged = false;
bool isHideIfShownLogged = false;
bool isSizeChangedFirstTime = true; // to track the first size changed event which is fired on the launch of app
bool isAutoConversionBeginLoggedInSession = false;
bool isAutoConversionEndLoggedInSession = false;
bool angleButtonLoggedInSession = false;
bool radixButtonLoggedInSession = false;
bool bitLengthButtonLoggedInSession = false;
GUID sessionGuid;
CalculatorApp::Common::ViewMode currentMode = CalculatorApp::Common::ViewMode::None;
std::vector<FuncLog> funcLog;
int functionCount = 0;
bool isHypButtonLogged = false;
bool isAngleButtonInitialized = false;
unsigned int findIndex[maxFunctionSize] = { 0 };
bool GetIndex(int& index);
std::wstring GetProgrammerType(int index);
size_t maxWindowCount = 0;
bool isAppLaunchBeginLogged = false;
bool isAppLaunchEndLogged = false;
std::map<int, int> bitLengthButtonUsage;
std::map<int, int> angleButtonUsage;
std::map<int, int> radixButtonUsage;
std::vector<ButtonLog> buttonLog;
std::map<int, bool> windowIdLog;
// Private variables for Date Calculator usage
bool m_dateDiffUsageLoggedInSession = false;
bool m_dateAddUsageLoggedInSession = false;
bool m_dateSubtractUsageLoggedInSession = false;
std::map<int, int> m_dateAddModeUsage;
std::map<int, int> m_dateSubtractModeUsage;
size_t windowLaunchCount = 0;
GUID sessionGuid;
size_t currentWindowCount = 0;
winrt::Windows::Foundation::Diagnostics::LoggingActivity m_appLaunchActivity;
};

View File

@@ -335,12 +335,12 @@ future<bool> CurrencyDataLoader::TryLoadDataFromCacheAsync()
}
catch (Exception ^ ex)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, ex);
TraceLogger::GetInstance().LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex);
co_return false;
}
catch (const exception& e)
{
TraceLogger::GetInstance().LogStandardException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogStandardException(ViewMode::Currency, __FUNCTIONW__, e);
co_return false;
}
catch (...)
@@ -445,12 +445,12 @@ future<bool> CurrencyDataLoader::TryLoadDataFromWebAsync()
}
catch (Exception ^ ex)
{
TraceLogger::GetInstance().LogPlatformException(__FUNCTIONW__, ex);
TraceLogger::GetInstance().LogPlatformException(ViewMode::Currency, __FUNCTIONW__, ex);
co_return false;
}
catch (const exception& e)
{
TraceLogger::GetInstance().LogStandardException(__FUNCTIONW__, e);
TraceLogger::GetInstance().LogStandardException(ViewMode::Currency, __FUNCTIONW__, e);
co_return false;
}
catch (...)
@@ -466,7 +466,7 @@ future<bool> CurrencyDataLoader::TryLoadDataFromWebOverrideAsync()
if (!didLoad)
{
m_loadStatus = CurrencyLoadStatus::FailedToLoad;
TraceLogger::GetInstance().LogUserRequestedRefreshFailed();
TraceLogger::GetInstance().LogError(ViewMode::Currency, L"CurrencyDataLoader::TryLoadDataFromWebOverrideAsync", L"UserRequestedRefreshFailed");
}
co_return didLoad;

View File

@@ -88,9 +88,6 @@ DateCalculatorViewModel::DateCalculatorViewModel()
if (calendar->DayOfWeek != trueDayOfWeek)
{
calendar->SetDateTime(today);
TraceLogger::GetInstance().LogDateClippedTimeDifferenceFound(
from_cx<winrt::Windows::Globalization::Calendar>(calendar),
winrt::Windows::Foundation::DateTime{ winrt::Windows::Foundation::TimeSpan{ clippedTime.UniversalTime } });
}
}

View File

@@ -118,6 +118,9 @@ void HistoryViewModel::SetCalculatorDisplay(CalculatorDisplay& calculatorDisplay
void HistoryViewModel::ShowItem(_In_ HistoryItemViewModel ^ e)
{
unsigned int index;
Items->IndexOf(e, &index);
TraceLogger::GetInstance().LogHistoryItemLoad((ViewMode)m_currentMode, ItemSize, (int)(index));
HistoryItemClicked(e);
}
@@ -149,7 +152,6 @@ void HistoryViewModel::OnHideCommand(_In_ Platform::Object ^ e)
void HistoryViewModel::OnClearCommand(_In_ Platform::Object ^ e)
{
TraceLogger::GetInstance().LogClearHistory();
if (AreHistoryShortcutsEnabled == true)
{
m_calculatorManager->ClearHistory();

View File

@@ -37,6 +37,7 @@ namespace
StringReference IsProgrammerPropertyName(L"IsProgrammer");
StringReference DisplayValuePropertyName(L"DisplayValue");
StringReference CalculationResultAutomationNamePropertyName(L"CalculationResultAutomationName");
StringReference IsBitFlipCheckedPropertyName(L"IsBitFlipChecked");
}
namespace CalculatorResourceKeys
@@ -599,8 +600,6 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
Command cmdenum = ConvertToOperatorsEnum(numOpEnum);
TraceLogger::GetInstance().UpdateFunctionUsage((int)numOpEnum);
if (IsInError)
{
m_standardCalculatorManager.SendCommand(Command::CommandCLEAR);
@@ -668,6 +667,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
m_isLastOperationHistoryLoad = false;
}
TraceLogger::GetInstance().UpdateButtonUsage(numOpEnum, GetCalculatorMode());
m_standardCalculatorManager.SendCommand(cmdenum);
}
}
@@ -748,7 +748,7 @@ void StandardCalculatorViewModel::OnPasteCommand(Object ^ parameter)
// Ensure that the paste happens on the UI thread
CopyPasteManager::GetStringToPaste(mode, NavCategory::GetGroupType(mode), NumberBase, bitLengthType)
.then([this, mode](String ^ pastedString) { OnPaste(pastedString, mode); }, concurrency::task_continuation_context::use_current());
.then([this, mode](String ^ pastedString) { OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
}
CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum(NumbersAndOperatorsEnum operation)
@@ -756,7 +756,7 @@ CalculationManager::Command StandardCalculatorViewModel::ConvertToOperatorsEnum(
return safe_cast<Command>(operation);
}
void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
void StandardCalculatorViewModel::OnPaste(String ^ pastedString)
{
// If pastedString is invalid("NoOp") then display pasteError else process the string
if (pastedString == StringReference(CopyPasteManager::PasteErrorString))
@@ -765,7 +765,6 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
return;
}
TraceLogger::GetInstance().LogValidInputPasted(mode);
bool isFirstLegalChar = true;
m_standardCalculatorManager.SendCommand(Command::CommandCENTR);
bool sendNegate = false;
@@ -884,7 +883,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
// Handle exponent and exponent sign (...e+... or ...e-... or ...e...)
if (mappedNumOp == NumbersAndOperatorsEnum::Exp)
{
//Check the following item
// Check the following item
switch (MapCharacterToButtonId(*(it + 1), canSendNegate))
{
case NumbersAndOperatorsEnum::Subtract:
@@ -896,7 +895,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
break;
case NumbersAndOperatorsEnum::Add:
{
//Nothing to do, skip to the next item
// Nothing to do, skip to the next item
++it;
}
break;
@@ -911,8 +910,7 @@ void StandardCalculatorViewModel::OnClearMemoryCommand(Object ^ parameter)
{
m_standardCalculatorManager.MemorizedNumberClearAll();
int windowId = Utils::GetWindowId();
TraceLogger::GetInstance().LogMemoryClearAll(windowId);
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(CalculatorResourceKeys::MemoryCleared, m_localizedMemoryCleared);
Announcement = CalculatorAnnouncement::GetMemoryClearedAnnouncement(announcement);
@@ -1046,8 +1044,7 @@ void StandardCalculatorViewModel::OnMemoryButtonPressed()
{
m_standardCalculatorManager.MemorizeNumber();
int windowId = Utils::GetWindowId();
TraceLogger::GetInstance().InsertIntoMemoryMap(windowId, IsStandard, IsScientific, IsProgrammer);
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::Memory, GetCalculatorMode());
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(
CalculatorResourceKeys::MemorySave, m_localizedMemorySavedAutomationFormat, m_DisplayValue->Data());
@@ -1079,49 +1076,31 @@ void StandardCalculatorViewModel::OnMemoryItemPressed(Object ^ memoryItemPositio
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
m_standardCalculatorManager.MemorizedNumberLoad(boxedPosition->Value);
HideMemoryClicked();
int windowId = Utils::GetWindowId();
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
auto mode = IsStandard ? ViewMode::Standard : IsScientific ? ViewMode::Scientific : ViewMode::Programmer;
TraceLogger::GetInstance().LogMemoryItemLoad(mode, MemorizedNumbers->Size, boxedPosition->Value);
}
}
void StandardCalculatorViewModel::OnMemoryAdd(Object ^ memoryItemPosition)
{
// M+ will add display to memorylist if memory list is empty.
int windowId = Utils::GetWindowId();
if (MemorizedNumbers)
{
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
if (MemorizedNumbers->Size > 0)
{
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
TraceLogger::GetInstance().UpdateMemoryMap(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer);
}
else
{
TraceLogger::GetInstance().InsertIntoMemoryMap(windowId, IsStandard, IsScientific, IsProgrammer);
}
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryAdd, GetCalculatorMode());
m_standardCalculatorManager.MemorizedNumberAdd(boxedPosition->Value);
}
}
void StandardCalculatorViewModel::OnMemorySubtract(Object ^ memoryItemPosition)
{
int windowId = Utils::GetWindowId();
// M- will add negative of displayed number to memorylist if memory list is empty.
if (MemorizedNumbers)
{
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
if (MemorizedNumbers->Size > 0)
{
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
TraceLogger::GetInstance().UpdateMemoryMap(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer);
}
else
{
TraceLogger::GetInstance().InsertIntoMemoryMap(windowId, IsStandard, IsScientific, IsProgrammer);
}
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemorySubtract, GetCalculatorMode());
m_standardCalculatorManager.MemorizedNumberSubtract(boxedPosition->Value);
}
}
@@ -1130,7 +1109,6 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
{
if (MemorizedNumbers && MemorizedNumbers->Size > 0)
{
int windowId = Utils::GetWindowId();
auto boxedPosition = safe_cast<Box<int> ^>(memoryItemPosition);
if (boxedPosition->Value >= 0)
@@ -1148,9 +1126,7 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
{
IsMemoryEmpty = true;
}
TraceLogger::GetInstance().LogMemoryUsed(windowId, boxedPosition->Value, IsStandard, IsScientific, IsProgrammer, MemorizedNumbers->Size);
TraceLogger::GetInstance().DeleteFromMemoryMap(windowId, boxedPosition->Value);
TraceLogger::GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum::MemoryClear, GetCalculatorMode());
wstring localizedIndex = to_wstring(boxedPosition->Value + 1);
LocalizationSettings::GetInstance().LocalizeDisplayValue(&localizedIndex);
@@ -1191,6 +1167,11 @@ void StandardCalculatorViewModel::OnPropertyChanged(String ^ propertyname)
RaisePropertyChanged(CalculationResultAutomationNamePropertyName);
Announcement = GetDisplayUpdatedNarratorAnnouncement();
}
else if (propertyname == IsBitFlipCheckedPropertyName)
{
TraceLogger::GetInstance().UpdateButtonUsage(
IsBitFlipChecked ? NumbersAndOperatorsEnum::BitflipButton : NumbersAndOperatorsEnum::FullKeypadButton, ViewMode::Programmer);
}
}
void StandardCalculatorViewModel::SetCalculatorType(ViewMode targetState)
@@ -1223,7 +1204,7 @@ void StandardCalculatorViewModel::SetCalculatorType(ViewMode targetState)
}
}
String^ StandardCalculatorViewModel::GetRawDisplayValue()
String ^ StandardCalculatorViewModel::GetRawDisplayValue()
{
if (IsInError)
{
@@ -1884,3 +1865,16 @@ NarratorAnnouncement ^ StandardCalculatorViewModel::GetDisplayUpdatedNarratorAnn
return CalculatorAnnouncement::GetDisplayUpdatedAnnouncement(announcement);
}
ViewMode StandardCalculatorViewModel::GetCalculatorMode()
{
if (IsStandard)
{
return ViewMode::Standard;
}
else if (IsScientific)
{
return ViewMode::Scientific;
}
return ViewMode::Programmer;
}

View File

@@ -317,7 +317,7 @@ namespace CalculatorApp
}
}
internal : void OnPaste(Platform::String ^ pastedString, CalculatorApp::Common::ViewMode mode);
internal : void OnPaste(Platform::String ^ pastedString);
void OnCopyCommand(Platform::Object ^ parameter);
void OnPasteCommand(Platform::Object ^ parameter);
@@ -348,7 +348,6 @@ namespace CalculatorApp
void OnBinaryOperatorReceived();
void OnMemoryItemChanged(unsigned int indexOfMemory);
Platform::String ^ GetLocalizedStringFormat(Platform::String ^ format, Platform::String ^ displayValue);
void OnPropertyChanged(Platform::String ^ propertyname);
void SetCalculatorType(CalculatorApp::Common::ViewMode targetState);
@@ -451,6 +450,8 @@ namespace CalculatorApp
bool IsViewPinned();
void SetViewPinnedState(bool pinned);
CalculatorApp::Common::ViewMode GetCalculatorMode();
friend class CalculatorDisplay;
friend class CalculatorFunctionalTests::HistoryTests;
friend class CalculatorUnitTests::MultiWindowUnitTests;

View File

@@ -502,6 +502,8 @@ void UnitConverterViewModel::OnButtonPressed(Platform::Object ^ parameter)
}
m_model->SendCommand(command);
TraceLogger::GetInstance().LogConverterInputReceived(Mode);
}
void UnitConverterViewModel::OnCopyCommand(Platform::Object ^ parameter)
@@ -523,7 +525,7 @@ void UnitConverterViewModel::OnPasteCommand(Platform::Object ^ parameter)
// EventWriteClipboardPaste_Start();
// Any converter ViewMode is fine here.
CopyPasteManager::GetStringToPaste(m_Mode, NavCategory::GetGroupType(m_Mode))
.then([this](String ^ pastedString) { OnPaste(pastedString, m_Mode); }, concurrency::task_continuation_context::use_current());
.then([this](String ^ pastedString) { OnPaste(pastedString); }, concurrency::task_continuation_context::use_current());
}
void UnitConverterViewModel::InitializeView()
@@ -882,7 +884,7 @@ NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wch
return mappedValue;
}
void UnitConverterViewModel::OnPaste(String ^ stringToPaste, ViewMode mode)
void UnitConverterViewModel::OnPaste(String ^ stringToPaste)
{
// If pastedString is invalid("NoOp") then display pasteError else process the string
if (stringToPaste == StringReference(CopyPasteManager::PasteErrorString))
@@ -891,7 +893,6 @@ void UnitConverterViewModel::OnPaste(String ^ stringToPaste, ViewMode mode)
return;
}
TraceLogger::GetInstance().LogValidInputPasted(mode);
bool isFirstLegalChar = true;
bool sendNegate = false;
wstring accumulation = L"";
@@ -1014,7 +1015,6 @@ void UnitConverterViewModel::StartConversionResultTimer()
{
String ^ valueFrom = m_Value1Active ? m_Value1 : m_Value2;
String ^ valueTo = m_Value1Active ? m_Value2 : m_Value1;
TraceLogger::GetInstance().LogConversionResult(valueFrom->Data(), UnitFrom->ToString()->Data(), valueTo->Data(), UnitTo->ToString()->Data());
}
});
}

View File

@@ -204,7 +204,7 @@ namespace CalculatorApp
NumbersAndOperatorsEnum MapCharacterToButtonId(const wchar_t ch, bool& canSendNegate);
void DisplayPasteError();
void OnValueActivated(IActivatable ^ control);
void OnPaste(Platform::String ^ stringToPaste, CalculatorApp::Common::ViewMode mode);
void OnPaste(Platform::String ^ stringToPaste);
void OnCopyCommand(Platform::Object ^ parameter);
void OnPasteCommand(Platform::Object ^ parameter);