mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 05:43:10 -07:00
Merged PR 10794979: Add Recall Telemetry
**Snapshot** EventName: `RecallSnapshot` Payload example:` { "CalcMode": "Standard"}` **_Fires when a snapshot (UserActivityRequested) is triggered_** **Restore** EventName: `RecallRestore` Payload example:`{ "CalcMode": "Standard"}` **_Fires when launching by snapshot (recall restore)** **Error** EventName: `Exception` Payload example: `{ "CalcMode": "Standard", "FunctionName" : "MainPage::ShowSnapshotLaunchErrorAsync", "Message": "SnapshotRestoreError" }` **_Fires when launching by snapshot failed_** Related work items: #51114542
This commit is contained in:
parent
abec67b73d
commit
7ebd296d69
3 changed files with 64 additions and 6 deletions
|
@ -43,6 +43,8 @@ namespace CalculatorApp
|
|||
constexpr auto EVENT_NAME_VARIABLE_SETTING_CHANGED = L"VariableSettingChanged";
|
||||
constexpr auto EVENT_NAME_GRAPH_SETTINGS_CHANGED = L"GraphSettingsChanged";
|
||||
constexpr auto EVENT_NAME_GRAPH_THEME = L"GraphTheme";
|
||||
constexpr auto EVENT_NAME_RECALL_SNAPSHOT = L"RecallSnapshot";
|
||||
constexpr auto EVENT_NAME_RECALL_RESTORE = L"RecallRestore";
|
||||
|
||||
constexpr auto EVENT_NAME_EXCEPTION = L"Exception";
|
||||
|
||||
|
@ -328,4 +330,27 @@ namespace CalculatorApp
|
|||
|
||||
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_GRAPH_THEME), fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogRecallSnapshot(ViewMode mode)
|
||||
{
|
||||
auto fields = ref new LoggingFields();
|
||||
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
|
||||
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_RECALL_SNAPSHOT), fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogRecallRestore(ViewMode mode)
|
||||
{
|
||||
auto fields = ref new LoggingFields();
|
||||
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
|
||||
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_RECALL_RESTORE), fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogRecallError(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String^ message)
|
||||
{
|
||||
auto fields = ref new LoggingFields();
|
||||
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
|
||||
fields->AddString(StringReference(L"FunctionName"), L"Recall");
|
||||
fields->AddString(StringReference(L"Message"), message);
|
||||
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,9 @@ namespace CalculatorApp::ViewModel::Common
|
|||
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);
|
||||
void LogRecallSnapshot(CalculatorApp::ViewModel::Common::ViewMode mode);
|
||||
void LogRecallRestore(CalculatorApp::ViewModel::Common::ViewMode mode);
|
||||
void LogRecallError(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ message);
|
||||
|
||||
internal:
|
||||
void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e);
|
||||
|
|
|
@ -78,6 +78,7 @@ namespace CalculatorApp
|
|||
await activity.SaveAsync();
|
||||
args.Request.SetUserActivity(activity);
|
||||
deferral.Complete();
|
||||
TraceLogger.GetInstance().LogRecallSnapshot(Model.Mode);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -169,17 +170,14 @@ namespace CalculatorApp
|
|||
var channel = UserActivityChannel.GetDefault();
|
||||
var activity = await channel.GetOrCreateUserActivityAsync(snapshotArgs.ActivityId);
|
||||
|
||||
// Work around for bug https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/48931227
|
||||
// where ContentInfo can't be directly accessed.
|
||||
if (snapshotArgs.VerifyIncomingActivity(activity) &&
|
||||
JsonObject.TryParse(activity.ToJson(), out var activityJson) &&
|
||||
activityJson.ContainsKey("contentInfo") &&
|
||||
Model.TryRestoreFromSnapshot(activityJson.GetNamedObject("contentInfo")))
|
||||
if (TryRestoreFromActivity(snapshotArgs, activity, out var errorMessage))
|
||||
{
|
||||
TraceLogger.GetInstance().LogRecallRestore(Model.Mode);
|
||||
SelectNavigationItemByModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceLogger.GetInstance().LogRecallError(Model.Mode, errorMessage);
|
||||
await ShowSnapshotLaunchErrorAsync();
|
||||
}
|
||||
});
|
||||
|
@ -191,6 +189,38 @@ namespace CalculatorApp
|
|||
}
|
||||
}
|
||||
|
||||
private bool TryRestoreFromActivity(SnapshotLaunchArguments snapshotArgs, UserActivity activity, out string errorMessage)
|
||||
{
|
||||
if (!snapshotArgs.VerifyIncomingActivity(activity))
|
||||
{
|
||||
errorMessage = "IncomingActivityFailed";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Work around for bug https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/48931227
|
||||
// where ContentInfo can't be directly accessed.
|
||||
if (!JsonObject.TryParse(activity.ToJson(), out var activityJson))
|
||||
{
|
||||
errorMessage = "ParseJsonError";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!activityJson.ContainsKey("contentInfo"))
|
||||
{
|
||||
errorMessage = "ContentInfoNotExist";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Model.TryRestoreFromSnapshot(activityJson.GetNamedObject("contentInfo")))
|
||||
{
|
||||
errorMessage = "RestoreFromSnapshotFailed";
|
||||
return false;
|
||||
}
|
||||
|
||||
errorMessage = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void InitializeNavViewCategoriesSource()
|
||||
{
|
||||
NavViewCategoriesSource = ExpandNavViewCategoryGroups(Model.Categories);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue