Skip to content

Commit

Permalink
Infrastructure Preparation 29
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 26, 2022
1 parent b6887b5 commit 964dea2
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/Taiizor.Essentials.Maui.AppCenter/Enum/WatchEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Taiizor.Essentials.Maui.AppCenter.Enum
{
public enum WatchEnum
{
Open,
Close
}
}
13 changes: 13 additions & 0 deletions src/Taiizor.Essentials.Maui.AppCenter/Helper/Watch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Taiizor.Essentials.Maui.AppCenter.Services;
using Taiizor.Essentials.Maui.AppCenter.Value;

namespace Taiizor.Essentials.Maui.AppCenter.Helper
{
internal class Watch
{
public static string GetText(string Title)
{
return string.Format($"{Internal.AppCenterWatch.Format}", Internal.AppCenterWatch.Prefix, Internal.AppCenterWatch.Name, Title, AppCenterService.UserId, Internal.AppCenterWatch.Suffix);
}
}
}
64 changes: 49 additions & 15 deletions src/Taiizor.Essentials.Maui.AppCenter/Services/AppCenterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
using System.Runtime.ExceptionServices;
using System.Text;
using Taiizor.Essentials.Maui.AppCenter.Enum;
using Taiizor.Essentials.Maui.AppCenter.Helper;
using Taiizor.Essentials.Maui.AppCenter.Struct;
using Taiizor.Essentials.Maui.AppCenter.Value;
using AC = Microsoft.AppCenter.AppCenter;

#if WINDOWS || ANDROID || MACCATALYST || IOS

using Service = Taiizor.Essentials.Maui.AppCenter.Platforms.Services.AppCenterService;

#endif

#if WINDOWS

using Unhandled = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;
Expand All @@ -26,17 +23,21 @@ public class AppCenterService
{
public static void Engine(Dictionary<AppEnum, string> Keys)
{
Engine(Keys, Internal.AppCenterWatch);
}

public static void Engine(Dictionary<AppEnum, string> Keys, WatchStruct Watch)
{
Internal.AppCenterWatch = Watch;

Key(Keys);

Enabled(); //
Level(); //
User();
Country();

#if WINDOWS || ANDROID || MACCATALYST || IOS

Service.Start();

#endif
}

public static void TestCrash()
Expand Down Expand Up @@ -170,6 +171,22 @@ public static void TrackError(Exception Exception, IDictionary<string, string> P
Crashes.TrackError(Exception, Properties, Attachments);
}
}

private static void WatchEvent()
{
if (Internal.AppCenterWatch.Event == WatchEnum.Open)
{
TrackEvent(Watch.GetText("Event"));
}
}

private static void WatchError()
{
if (Internal.AppCenterWatch.Error == WatchEnum.Open)
{
TrackEvent(Watch.GetText("Error"));
}
}

private static void Key(Dictionary<AppEnum, string> Keys)
{
Expand All @@ -187,16 +204,12 @@ private static void Key(Dictionary<AppEnum, string> Keys)

private static void Country()
{
AC.SetCountryCode(RegionInfo.CurrentRegion.TwoLetterISORegionName);
//AC.SetCountryCode(RegionInfo.CurrentRegion.Name);

//AC.SetCountryCode(CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
//AC.SetCountryCode(CultureInfo.InstalledUICulture.TwoLetterISOLanguageName);
AC.SetCountryCode(CountryCode);
}

private static void User()
{
AC.SetUserId($"{DeviceInfo.Current.Name}-{DeviceInfo.Current.Model}");
AC.SetUserId(UserId);
}

private static void Level()
Expand All @@ -208,5 +221,26 @@ private static void Enabled()
{
Crashes.SetEnabledAsync(true);
}

internal static string CountryCode
{
get
{
return RegionInfo.CurrentRegion.TwoLetterISORegionName;

//return RegionInfo.CurrentRegion.Name;

//return CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
//return CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
}
}

internal static string UserId
{
get
{
return $"{DeviceInfo.Current.Name}-{DeviceInfo.Current.Model}";
}
}
}
}
16 changes: 16 additions & 0 deletions src/Taiizor.Essentials.Maui.AppCenter/Struct/WatchStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.InteropServices;
using Taiizor.Essentials.Maui.AppCenter.Enum;

namespace Taiizor.Essentials.Maui.AppCenter.Struct
{
[StructLayout(LayoutKind.Sequential)]
public struct WatchStruct
{
public string Format;
public string Prefix;
public string Suffix;
public string Name;
public WatchEnum Event;
public WatchEnum Error;
}
}
11 changes: 11 additions & 0 deletions src/Taiizor.Essentials.Maui.AppCenter/Value/Internal.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using Taiizor.Essentials.Maui.AppCenter.Enum;
using Taiizor.Essentials.Maui.AppCenter.Struct;

namespace Taiizor.Essentials.Maui.AppCenter.Value
{
internal class Internal
{
public static bool AppCenterState = false;

public static WatchStruct AppCenterWatch = new()
{
Format = "{0}-{1}{2}-{3}-{4}",
Event = WatchEnum.Close,
Error = WatchEnum.Close,
Prefix = "Prefix",
Suffix = "Suffix",
Name = "Watch"
};

public static Dictionary<AppEnum, string> AppCenterKey = new()
{
{ AppEnum.iOS, "{Your iOS App secret here}" },
Expand Down
1 change: 1 addition & 0 deletions src/Taiizor.Essentials.Maui/Cross/CrossException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class CrossException
{

#if WINDOWS
private static Exception _lastFirstChanceException;
#endif
Expand Down

0 comments on commit 964dea2

Please sign in to comment.