diff --git a/src/Taiizor.Essentials.Maui.AppCenter/Services/AppCenterService.cs b/src/Taiizor.Essentials.Maui.AppCenter/Services/AppCenterService.cs index b05ede2..90b3db9 100644 --- a/src/Taiizor.Essentials.Maui.AppCenter/Services/AppCenterService.cs +++ b/src/Taiizor.Essentials.Maui.AppCenter/Services/AppCenterService.cs @@ -1,6 +1,7 @@ using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; +using Newtonsoft.Json; using System.Globalization; using System.Runtime.ExceptionServices; using System.Text; @@ -45,6 +46,8 @@ public static void TestCrash() if (Internal.AppCenterState) { Crashes.GenerateTestCrash(); + + WatchError("TestCrash"); } } @@ -97,6 +100,8 @@ public static void TrackEvent(string Name) if (Internal.AppCenterState) { Analytics.TrackEvent(Name); + + WatchEvent(Name); } } @@ -105,6 +110,8 @@ public static void TrackEvent(string Name, string Key, string Value) if (Internal.AppCenterState) { Analytics.TrackEvent(Name, new Dictionary() { { Key, Value } }); + + WatchEvent(Name, Key, Value); } } @@ -113,6 +120,8 @@ public static void TrackEvent(string Name, IDictionary Propertie if (Internal.AppCenterState) { Analytics.TrackEvent(Name, Properties); + + WatchEvent(Name, Properties); } } @@ -121,6 +130,8 @@ public static void TrackError(Exception Exception) if (Internal.AppCenterState) { Crashes.TrackError(Exception); + + WatchError(Exception); } } @@ -129,6 +140,8 @@ public static void TrackError(Exception Exception, string Key, string Value) if (Internal.AppCenterState) { Crashes.TrackError(Exception, new Dictionary() { { Key, Value } }); + + WatchError(Exception, Key, Value); } } @@ -137,6 +150,8 @@ public static void TrackError(Exception Exception, IDictionary P if (Internal.AppCenterState) { Crashes.TrackError(Exception, Properties); + + WatchError(Exception, Properties); } } @@ -161,6 +176,12 @@ public static void TrackError(Exception Exception, IDictionary P ErrorAttachmentLog.AttachmentWithText(Text, TextFile), ErrorAttachmentLog.AttachmentWithBinary(Image, ImageFile, Extension) }); + + WatchError(Exception, Properties, new ErrorAttachmentLog[] + { + ErrorAttachmentLog.AttachmentWithText(Text, TextFile), + ErrorAttachmentLog.AttachmentWithBinary(Image, ImageFile, Extension) + }); } } @@ -169,22 +190,72 @@ public static void TrackError(Exception Exception, IDictionary P if (Internal.AppCenterState) { Crashes.TrackError(Exception, Properties, Attachments); + + WatchError(Exception, Properties, Attachments); } } - private static void WatchEvent() + private static void WatchEvent(string Name) + { + if (Internal.AppCenterWatch.Event == WatchEnum.Open) + { + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.EventName), new Dictionary() { { "Name", Name } }); + } + } + + private static void WatchEvent(string Name, string Key, string Value) + { + if (Internal.AppCenterWatch.Event == WatchEnum.Open) + { + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.EventName), new Dictionary() { { Name, $"{Key}: {Value}" } }); + } + } + + private static void WatchEvent(string Name, IDictionary Properties) { if (Internal.AppCenterWatch.Event == WatchEnum.Open) { - TrackEvent(Watch.GetText("Event")); + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.EventName), new Dictionary() { { Name, JsonConvert.SerializeObject(Properties, Formatting.None) } }); //Formatting.Indented + } + } + + private static void WatchError(string Name) + { + if (Internal.AppCenterWatch.Error == WatchEnum.Open) + { + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary() { { "Error", Name } }); + } + } + + private static void WatchError(Exception Exception) + { + if (Internal.AppCenterWatch.Error == WatchEnum.Open) + { + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary() { { "Error", JsonConvert.SerializeObject(Exception, Formatting.None) } }); //Formatting.Indented + } + } + + private static void WatchError(Exception Exception, string Key, string Value) + { + if (Internal.AppCenterWatch.Error == WatchEnum.Open) + { + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary() { { Key, Value }, { "Error", JsonConvert.SerializeObject(Exception, Formatting.None) } }); //Formatting.Indented + } + } + + private static void WatchError(Exception Exception, IDictionary Properties) + { + if (Internal.AppCenterWatch.Error == WatchEnum.Open) + { + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary() { { "Properties", JsonConvert.SerializeObject(Properties, Formatting.None) }, { "Error", JsonConvert.SerializeObject(Exception, Formatting.None) } }); //Formatting.Indented } } - private static void WatchError() + private static void WatchError(Exception Exception, IDictionary Properties, ErrorAttachmentLog[] Attachments) { if (Internal.AppCenterWatch.Error == WatchEnum.Open) { - TrackEvent(Watch.GetText("Error")); + Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary() { { "Properties", JsonConvert.SerializeObject(Properties, Formatting.None) }, { "Attachments", JsonConvert.SerializeObject(Attachments, Formatting.None) }, { "Error", JsonConvert.SerializeObject(Exception, Formatting.None) } }); //Formatting.Indented } } diff --git a/src/Taiizor.Essentials.Maui.AppCenter/Struct/WatchStruct.cs b/src/Taiizor.Essentials.Maui.AppCenter/Struct/WatchStruct.cs index b6caef1..fa5cde8 100644 --- a/src/Taiizor.Essentials.Maui.AppCenter/Struct/WatchStruct.cs +++ b/src/Taiizor.Essentials.Maui.AppCenter/Struct/WatchStruct.cs @@ -6,11 +6,13 @@ namespace Taiizor.Essentials.Maui.AppCenter.Struct [StructLayout(LayoutKind.Sequential)] public struct WatchStruct { + public string Name; public string Format; public string Prefix; public string Suffix; - public string Name; public WatchEnum Event; public WatchEnum Error; + public string EventName; + public string ErrorName; } } \ No newline at end of file diff --git a/src/Taiizor.Essentials.Maui.AppCenter/Taiizor.Essentials.Maui.AppCenter.csproj b/src/Taiizor.Essentials.Maui.AppCenter/Taiizor.Essentials.Maui.AppCenter.csproj index 4504e3a..66a2ebd 100644 --- a/src/Taiizor.Essentials.Maui.AppCenter/Taiizor.Essentials.Maui.AppCenter.csproj +++ b/src/Taiizor.Essentials.Maui.AppCenter/Taiizor.Essentials.Maui.AppCenter.csproj @@ -53,7 +53,7 @@ Changes are detailed at https://github.com/Taiizor/Taiizor.Essentials.Maui/relea $(Version) $(Version) $(Version) - 1.0.2.1 + 1.0.2.2 $(VersionPrefix)$(Version)$(VersionSuffix) @@ -94,6 +94,7 @@ Changes are detailed at https://github.com/Taiizor/Taiizor.Essentials.Maui/relea + \ No newline at end of file diff --git a/src/Taiizor.Essentials.Maui.AppCenter/Value/Internal.cs b/src/Taiizor.Essentials.Maui.AppCenter/Value/Internal.cs index 59fa090..ec4bb63 100644 --- a/src/Taiizor.Essentials.Maui.AppCenter/Value/Internal.cs +++ b/src/Taiizor.Essentials.Maui.AppCenter/Value/Internal.cs @@ -12,6 +12,8 @@ internal class Internal Format = "{0}-{1}{2}-{3}-{4}", Event = WatchEnum.Close, Error = WatchEnum.Close, + EventName = "Event", + ErrorName = "Error", Prefix = "Prefix", Suffix = "Suffix", Name = "Watch"