Skip to content

Commit

Permalink
Adding Diagnostic Info (#195)
Browse files Browse the repository at this point in the history
Adding Diagnostic Info to help me understand unhandled exceptions better
  • Loading branch information
0x7c13 committed Sep 18, 2019
1 parent 34cc755 commit 708f2b9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 34 deletions.
47 changes: 45 additions & 2 deletions src/Notepads/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Microsoft.Toolkit.Uwp.Helpers;
using Notepads.Services;
using Notepads.Settings;
using Notepads.Utilities;
Expand Down Expand Up @@ -56,14 +57,56 @@ private static void OnUnhandledException(object sender, Windows.UI.Xaml.Unhandle

LoggingService.LogError($"OnUnhandledException: {e.Exception}");

Analytics.TrackEvent("OnUnhandledException", new Dictionary<string, string>() {
var diagnosticInfo = new Dictionary<string, string>()
{
{
"Message", e.Message
},
{
"Exception", e.Exception.ToString()
},
{
"OSArchitecture", SystemInformation.OperatingSystemArchitecture.ToString()
},
{
"OSVersion", SystemInformation.OperatingSystemVersion.ToString()
},
{
"Culture", SystemInformation.Culture.EnglishName
},
{
"AvailableMemory", SystemInformation.AvailableMemory.ToString("F0")
},
{
"IsFirstRun", SystemInformation.IsFirstRun.ToString()
},
{
"IsFirstRunAfterUpdate", SystemInformation.IsAppUpdated.ToString()
},
{
"FirstVersionInstalled", $"{SystemInformation.ApplicationVersion.Major}.{SystemInformation.ApplicationVersion.Minor}.{SystemInformation.ApplicationVersion.Build}.{SystemInformation.ApplicationVersion.Revision}"
},
{
"FirstUseTimeUTC", SystemInformation.FirstUseTime.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss")
},
{
"LastLaunchTimeUTC", SystemInformation.LastLaunchTime.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss")
},
{
"LaunchTimeUTC", SystemInformation.LaunchTime.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss")
},
{
"CurrentLaunchCount", SystemInformation.LaunchCount.ToString()
},
{
"TotalLaunchCount", SystemInformation.TotalLaunchCount.ToString()
},
{
"AppUptime", SystemInformation.AppUptime.ToString()
}
});
};

Analytics.TrackEvent("OnUnhandledException", diagnosticInfo);

// if you want to suppress and handle it manually,
// otherwise app shuts down.
Expand Down
73 changes: 41 additions & 32 deletions src/Notepads/Controls/TextEditor/TextEditorCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AppCenter.Analytics;
using Notepads.Commands;
using Notepads.Services;
using Notepads.Utilities;
Expand Down Expand Up @@ -559,46 +560,54 @@ private void InsertDataTimeString()

private void DuplicateText()
{
GetCurrentLineColumn(out int lineIndex, out int columnIndex, out int selectedCount);
GetTextSelectionPosition(out var start, out var end);

if (end == start)
{
// Duplicate Line
var line = _contentLinesCache[lineIndex - 1];
var column = Document.Selection.EndPosition + line.Length + 1;

if (columnIndex == 1)
Document.Selection.EndPosition += 1;

Document.Selection.EndOf(TextRangeUnit.Paragraph, false);

if (lineIndex < (_contentLinesCache.Length - 1))
Document.Selection.EndPosition -= 1;

Document.Selection.SetText(TextSetOptions.None, RichEditBoxDefaultLineEnding + line);
Document.Selection.StartPosition = Document.Selection.EndPosition = column;
}
else
try
{
// Duplicate selection
var textRange = Document.GetRange(start, end);
textRange.GetText(TextGetOptions.None, out string text);
GetCurrentLineColumn(out int lineIndex, out int columnIndex, out int selectedCount);
GetTextSelectionPosition(out var start, out var end);

if (text.EndsWith(RichEditBoxDefaultLineEnding))
if (end == start)
{
Document.Selection.EndOf(TextRangeUnit.Line, false);
// Duplicate Line
var line = _contentLinesCache[lineIndex - 1];
var column = Document.Selection.EndPosition + line.Length + 1;

if (columnIndex == 1)
Document.Selection.EndPosition += 1;

Document.Selection.EndOf(TextRangeUnit.Paragraph, false);

if (lineIndex < (_contentLinesCache.Length - 1))
Document.Selection.StartPosition = Document.Selection.EndPosition - 1;
Document.Selection.EndPosition -= 1;

Document.Selection.SetText(TextSetOptions.None, RichEditBoxDefaultLineEnding + line);
Document.Selection.StartPosition = Document.Selection.EndPosition = column;
}
else
{
Document.Selection.StartPosition = Document.Selection.EndPosition;
}
{
// Duplicate selection
var textRange = Document.GetRange(start, end);
textRange.GetText(TextGetOptions.None, out string text);

Document.Selection.SetText(TextSetOptions.None, text);
}
if (text.EndsWith(RichEditBoxDefaultLineEnding))
{
Document.Selection.EndOf(TextRangeUnit.Line, false);

if (lineIndex < (_contentLinesCache.Length - 1))
Document.Selection.StartPosition = Document.Selection.EndPosition - 1;
}
else
{
Document.Selection.StartPosition = Document.Selection.EndPosition;
}

Document.Selection.SetText(TextSetOptions.None, text);
}
}
catch (Exception ex)
{
LoggingService.LogError($"[TextEditorCore] Failed to duplicate text: {ex}");
Analytics.TrackEvent("TextEditorCore_FailedToDuplicateText", new Dictionary<string, string> {{ "Exception", ex.ToString() }});
}
}

private void ShowEasterEgg()
Expand Down

0 comments on commit 708f2b9

Please sign in to comment.