Skip to content

Commit

Permalink
Infrastructure Preparation 30
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 26, 2022
1 parent 964dea2 commit 4fd760e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
79 changes: 75 additions & 4 deletions src/Taiizor.Essentials.Maui.AppCenter/Services/AppCenterService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,6 +46,8 @@ public static void TestCrash()
if (Internal.AppCenterState)
{
Crashes.GenerateTestCrash();

WatchError("TestCrash");
}
}

Expand Down Expand Up @@ -97,6 +100,8 @@ public static void TrackEvent(string Name)
if (Internal.AppCenterState)
{
Analytics.TrackEvent(Name);

WatchEvent(Name);
}
}

Expand All @@ -105,6 +110,8 @@ public static void TrackEvent(string Name, string Key, string Value)
if (Internal.AppCenterState)
{
Analytics.TrackEvent(Name, new Dictionary<string, string>() { { Key, Value } });

WatchEvent(Name, Key, Value);
}
}

Expand All @@ -113,6 +120,8 @@ public static void TrackEvent(string Name, IDictionary<string, string> Propertie
if (Internal.AppCenterState)
{
Analytics.TrackEvent(Name, Properties);

WatchEvent(Name, Properties);
}
}

Expand All @@ -121,6 +130,8 @@ public static void TrackError(Exception Exception)
if (Internal.AppCenterState)
{
Crashes.TrackError(Exception);

WatchError(Exception);
}
}

Expand All @@ -129,6 +140,8 @@ public static void TrackError(Exception Exception, string Key, string Value)
if (Internal.AppCenterState)
{
Crashes.TrackError(Exception, new Dictionary<string, string>() { { Key, Value } });

WatchError(Exception, Key, Value);
}
}

Expand All @@ -137,6 +150,8 @@ public static void TrackError(Exception Exception, IDictionary<string, string> P
if (Internal.AppCenterState)
{
Crashes.TrackError(Exception, Properties);

WatchError(Exception, Properties);
}
}

Expand All @@ -161,6 +176,12 @@ public static void TrackError(Exception Exception, IDictionary<string, string> P
ErrorAttachmentLog.AttachmentWithText(Text, TextFile),
ErrorAttachmentLog.AttachmentWithBinary(Image, ImageFile, Extension)
});

WatchError(Exception, Properties, new ErrorAttachmentLog[]
{
ErrorAttachmentLog.AttachmentWithText(Text, TextFile),
ErrorAttachmentLog.AttachmentWithBinary(Image, ImageFile, Extension)
});
}
}

Expand All @@ -169,22 +190,72 @@ public static void TrackError(Exception Exception, IDictionary<string, string> 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<string, string>() { { "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<string, string>() { { Name, $"{Key}: {Value}" } });
}
}

private static void WatchEvent(string Name, IDictionary<string, string> Properties)
{
if (Internal.AppCenterWatch.Event == WatchEnum.Open)
{
TrackEvent(Watch.GetText("Event"));
Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.EventName), new Dictionary<string, string>() { { 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<string, string>() { { "Error", Name } });
}
}

private static void WatchError(Exception Exception)
{
if (Internal.AppCenterWatch.Error == WatchEnum.Open)
{
Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary<string, string>() { { "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<string, string>() { { Key, Value }, { "Error", JsonConvert.SerializeObject(Exception, Formatting.None) } }); //Formatting.Indented
}
}

private static void WatchError(Exception Exception, IDictionary<string, string> Properties)
{
if (Internal.AppCenterWatch.Error == WatchEnum.Open)
{
Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary<string, string>() { { "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<string, string> Properties, ErrorAttachmentLog[] Attachments)
{
if (Internal.AppCenterWatch.Error == WatchEnum.Open)
{
TrackEvent(Watch.GetText("Error"));
Analytics.TrackEvent(Watch.GetText(Internal.AppCenterWatch.ErrorName), new Dictionary<string, string>() { { "Properties", JsonConvert.SerializeObject(Properties, Formatting.None) }, { "Attachments", JsonConvert.SerializeObject(Attachments, Formatting.None) }, { "Error", JsonConvert.SerializeObject(Exception, Formatting.None) } }); //Formatting.Indented
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Taiizor.Essentials.Maui.AppCenter/Struct/WatchStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Changes are detailed at https://github.com/Taiizor/Taiizor.Essentials.Maui/relea
<FileVersion>$(Version)</FileVersion>
<AssemblyVersion>$(Version)</AssemblyVersion>
<AssemblyFileVersion>$(Version)</AssemblyFileVersion>
<Version>1.0.2.1</Version>
<Version>1.0.2.2</Version>
<VersionPrefix></VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageVersion>$(VersionPrefix)$(Version)$(VersionSuffix)</PackageVersion>
Expand Down Expand Up @@ -94,6 +94,7 @@ Changes are detailed at https://github.com/Taiizor/Taiizor.Essentials.Maui/relea
<PackageReference Include="Microsoft.AppCenter" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/Taiizor.Essentials.Maui.AppCenter/Value/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4fd760e

Please sign in to comment.